Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dorbaker committed Nov 14, 2023
1 parent add826f commit 1dacf76
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions datasets/nasa-nex-gddp-cmip6/nasa-nex-gddp-cmip6-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"search = catalog.search(\n",
" collections=[\"nasa-nex-gddp-cmip6\"],\n",
" datetime=\"1950/1960\",\n",
" query={\"cmip6:model\": {\"eq\": 'ACCESS-CM2'}},\n",
" query={\"cmip6:model\": {\"eq\": \"ACCESS-CM2\"}},\n",
")\n",
"items = search.item_collection()\n",
"len(items)"
Expand Down Expand Up @@ -2033,9 +2033,14 @@
}
],
"source": [
"for i in range(len(items[0].properties['kerchunk:indices']['refs'])):\n",
"for i in range(len(items[0].properties[\"kerchunk:indices\"][\"refs\"])):\n",
" if i % 100 == 1:\n",
" print(list(items[0].properties['kerchunk:indices']['refs'].keys())[i], items[0].properties['kerchunk:indices']['refs'][list(items[0].properties['kerchunk:indices']['refs'].keys())[i]])"
" print(\n",
" list(items[0].properties[\"kerchunk:indices\"][\"refs\"].keys())[i], \n",
" items[0].properties[\"kerchunk:indices\"][\"refs\"][\n",
" list(items[0].properties[\"kerchunk:indices\"][\"refs\"].keys())[i]\n",
" ]\n",
" )"
]
},
{
Expand Down Expand Up @@ -3543,21 +3548,19 @@
"source": [
"%%time\n",
"from kerchunk.combine import MultiZarrToZarr\n",
"\n",
"single_ref_sets = []\n",
"sas_token = items[0].assets['pr'].href.split('?')[1]\n",
"for d in [item.properties['kerchunk:indices'] for item in items]:\n",
"sas_token = items[0].assets[\"pr\"].href.split(\"?\")[1]\n",
"for d in [item.properties[\"kerchunk:indices\"] for item in items]:\n",
" for key in d[\"templates\"]:\n",
" d[\"templates\"][key] = d[\"templates\"][key] + \"?\" + sas_token\n",
" single_ref_sets.append(d)\n",
"mzz = MultiZarrToZarr(single_ref_sets, concat_dims=['time'], identical_dims=['lat','lon'])\n",
"mzz = MultiZarrToZarr(single_ref_sets, concat_dims=[\"time\"], identical_dims=[\"lat\",\"lon\"])\n",
"d = mzz.translate()\n",
"m = fsspec.get_mapper(\n",
" \"reference://\",\n",
" fo=d\n",
")\n",
"m = fsspec.get_mapper(\"reference://\",fo=d)\n",
"m.fs.clear_instance_cache()\n",
"ds = xr.open_dataset(m, engine=\"zarr\", consolidated=False, decode_times=True, chunks='auto')#={'time':360,'lat':600,'lon':1440},cache=False)\n",
"ds = ds.convert_calendar(calendar = 'gregorian', align_on = 'date', missing = -99)\n",
"ds = xr.open_dataset(m, engine=\"zarr\", consolidated=False, decode_times=True, chunks=\"auto\")\n",
"ds = ds.convert_calendar(calendar = \"gregorian\", align_on = \"date\", missing = -99)\n",
"ds"
]
},
Expand Down Expand Up @@ -3590,12 +3593,15 @@
"source": [
"import matplotlib.pyplot as plt\n",
"from dask.diagnostics import ProgressBar\n",
"\n",
"with ProgressBar():\n",
" plt.figure(figsize=(30,5))\n",
" ds.isel(lat=22,lon=13).where(ds.isel(lat=22,lon=13).hurs>0).hurs.plot()\n",
" plt.ylabel(\"Relative Humidity\")\n",
" plt.xlabel(\"Date\")\n",
" plt.title(\"Relative Humidity Vs Time @ ({},{}) for model {}\".format(ds.lat.values[22], ds.lon.values[13], items[0].properties[\"cmip6:model\"] ))\n",
" plt.title(\"Relative Humidity Vs Time @ ({},{}) for model {}\".format(\n",
" ds.lat.values[22], ds.lon.values[13], items[0].properties[\"cmip6:model\"] \n",
" ))\n",
" plt.show()"
]
},
Expand Down

0 comments on commit 1dacf76

Please sign in to comment.