diff --git a/notebooks/decadal_calendar_fix.ipynb b/notebooks/decadal_calendar_fix.ipynb index 6b8a1f9..f006323 100644 --- a/notebooks/decadal_calendar_fix.ipynb +++ b/notebooks/decadal_calendar_fix.ipynb @@ -10,13 +10,28 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "id": "06856aa1-30cb-4edd-a461-b1a08fde8ec5", "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", - "from rooki import rooki" + "from rook.utils.decadal_fixes import apply_decadal_fixes, decadal_fix_calendar\n", + "from roocs_utils.xarray_utils.xarray_utils import open_xr_dataset\n", + "from rooki import rooki\n", + "\n", + "import tempfile" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "b1ecf482-c9a6-46ab-9485-6a022756d16f", + "metadata": {}, + "outputs": [], + "source": [ + "tmp_dir = tempfile.TemporaryDirectory(dir=None)\n", + "tmp_dir.cleanup()" ] }, { @@ -40,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 3, "id": "5462716e-7b3c-4b0b-bfad-34eb3c134434", "metadata": {}, "outputs": [ @@ -50,7 +65,7 @@ "True" ] }, - "execution_count": 22, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -63,43 +78,94 @@ }, { "cell_type": "code", - "execution_count": 23, - "id": "2a5da580-0e23-4b34-a621-8e6e2020b7f6", + "execution_count": 4, + "id": "e172845a-ab17-4c16-8215-e67763d5b499", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['https://data.mips.climate.copernicus.eu/thredds/fileServer/esg_c3s-cmip6/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/s1976-r3i1p1f1/Amon/psl/gr/v20201215/psl_Amon_EC-Earth3_dcppA-hindcast_s1976-r3i1p1f1_gr_198411-198510.nc',\n", + " 'https://data.mips.climate.copernicus.eu/thredds/fileServer/esg_c3s-cmip6/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/s1976-r3i1p1f1/Amon/psl/gr/v20201215/psl_Amon_EC-Earth3_dcppA-hindcast_s1976-r3i1p1f1_gr_198511-198610.nc']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result.download_urls()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "d27ce3eb-9799-4b9e-ba7a-fe9899b3d68d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Downloading to /var/folders/qb/mg0csz190wd4rxybhhnwjln80000gn/T/metalink__vun7bgo/psl_Amon_EC-Earth3_dcppA-hindcast_s1976-r3i1p1f1_gr_198411-198510.nc.\n", - "Downloading to /var/folders/qb/mg0csz190wd4rxybhhnwjln80000gn/T/metalink__vun7bgo/psl_Amon_EC-Earth3_dcppA-hindcast_s1976-r3i1p1f1_gr_198511-198610.nc.\n", - "gregorian\n", - "proleptic_gregorian\n" + "Downloading to /var/folders/5f/t661zdnd181ck1dv429s4p8r0000gn/T/metalink_xp7si7xh/psl_Amon_EC-Earth3_dcppA-hindcast_s1976-r3i1p1f1_gr_198411-198510.nc.\n", + "Downloading to /var/folders/5f/t661zdnd181ck1dv429s4p8r0000gn/T/metalink_xp7si7xh/psl_Amon_EC-Earth3_dcppA-hindcast_s1976-r3i1p1f1_gr_198511-198610.nc.\n" ] } ], "source": [ - "for ds in result.datasets():\n", - " print(ds.time.encoding.get(\"calendar\"))" + "dsets = [\n", + " decadal_fix_calendar(ds_id, open_xr_dataset(file)) for file in result.download()\n", + " # open_xr_dataset(file) for file in result.download()\n", + "]" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "id": "6f89c9bc-1760-427a-91a8-eeef03944d42", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "gregorian\n", + "standard\n" + ] + } + ], "source": [ - "ds_path_g = \"/var/folders/qb/mg0csz190wd4rxybhhnwjln80000gn/T/metalink__vun7bgo/psl_Amon_EC-Earth3_dcppA-hindcast_s1976-r3i1p1f1_gr_198411-198510.nc\"\n", - "\n", - "ds_path_pg = \"/var/folders/qb/mg0csz190wd4rxybhhnwjln80000gn/T/metalink__vun7bgo/psl_Amon_EC-Earth3_dcppA-hindcast_s1976-r3i1p1f1_gr_198511-198610.nc\"\n", - "\n" + "for ds in dsets:\n", + " print(ds.time.encoding.get(\"calendar\"))\n" ] }, { "cell_type": "code", - "execution_count": 4, - "id": "07f7c176-a317-4a8e-add1-89f610614220", + "execution_count": 7, + "id": "6afe997f-91e1-4048-a2af-288818f36a07", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'gregorian'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ds = xr.concat(dsets, dim=\"time\")\n", + "ds.time.encoding.get(\"calendar\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "172318f6-f484-4854-a0dd-41e2f041b8bc", "metadata": {}, "outputs": [ { @@ -469,31 +535,34 @@ " fill: currentColor;\n", "}\n", "
<xarray.Dataset>\n", - "Dimensions: (time: 12, bnds: 2, lat: 256, lon: 512)\n", + "Dimensions: (time: 24, bnds: 2, lat: 256, lon: 512)\n", "Coordinates:\n", - " * time (time) object 1984-11-16 00:00:00 ... 1985-10-16 12:00:00\n", - " * lat (lat) float64 -89.46 -88.77 -88.07 -87.37 ... 88.07 88.77 89.46\n", - " * lon (lon) float64 0.0 0.7031 1.406 2.109 ... 357.2 357.9 358.6 359.3\n", + " * time (time) object 1984-11-16 00:00:00 ... 1986-10-16 12:00:00\n", + " * lat (lat) float64 -89.46 -88.77 -88.07 -87.37 ... 88.07 88.77 89.46\n", + " * lon (lon) float64 0.0 0.7031 1.406 2.109 ... 357.9 358.6 359.3\n", + " reftime datetime64[ns] 1976-11-01\n", + " leadtime (time) float64 2.937e+03 2.967e+03 ... 3.606e+03 3.636e+03\n", "Dimensions without coordinates: bnds\n", "Data variables:\n", - " time_bnds (time, bnds) object ...\n", - " lat_bnds (lat, bnds) float64 ...\n", - " lon_bnds (lon, bnds) float64 ...\n", - " psl (time, lat, lon) float32 ...\n", - "Attributes: (12/48)\n", - " Conventions: CF-1.7 CMIP-6.2\n", - " activity_id: DCPP\n", - " branch_method: no parent\n", - " branch_time: 0.0\n", - " branch_time_in_child: 0.0\n", - " branch_time_in_parent: 0.0\n", - " ... ...\n", - " cmor_version: 3.4.0\n", - " variant_info: Atmosphere initialization based on full-fields...\n", - " sub_experiment_id: s1976\n", - " history: Wed Sep 25 11:00:49 2019: ncatted -O -a sub_ex...\n", - " nominal_resolution: 100 km\n", - " sub_experiment: initialized near end of year 1976" ], "text/plain": [ "
<xarray.Dataset>\n", - "Dimensions: (time: 12, bnds: 2, lat: 256, lon: 512)\n", - "Coordinates:\n", - " * time (time) object 1985-11-16 00:00:00 ... 1986-10-16 12:00:00\n", - " * lat (lat) float64 -89.46 -88.77 -88.07 -87.37 ... 88.07 88.77 89.46\n", - " * lon (lon) float64 0.0 0.7031 1.406 2.109 ... 357.2 357.9 358.6 359.3\n", - "Dimensions without coordinates: bnds\n", - "Data variables:\n", - " time_bnds (time, bnds) object ...\n", - " lat_bnds (lat, bnds) float64 ...\n", - " lon_bnds (lon, bnds) float64 ...\n", - " psl (time, lat, lon) float32 ...\n", - "Attributes: (12/48)\n", - " Conventions: CF-1.7 CMIP-6.2\n", - " activity_id: DCPP\n", - " branch_method: no parent\n", - " branch_time: 0.0\n", - " branch_time_in_child: 0.0\n", - " branch_time_in_parent: 0.0\n", - " ... ...\n", - " license: CMIP6 model data produced by EC-Earth-Consorti...\n", - " cmor_version: 3.4.0\n", - " sub_experiment_id: s1976\n", - " history: Wed Sep 25 11:00:52 2019: ncatted -O -a sub_ex...\n", - " nominal_resolution: 100 km\n", - " sub_experiment: initialized near end of year 1976