Skip to content

Commit

Permalink
Update nasa-nex-gddp-cmip6-example.ipynb
Browse files Browse the repository at this point in the history
Fixes.
  • Loading branch information
dorbaker authored Nov 14, 2023
1 parent add826f commit bc592db
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 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,10 +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",
" )"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -3543,21 +3547,23 @@
"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",
"d = mzz.translate()\n",
"m = fsspec.get_mapper(\n",
" \"reference://\",\n",
" fo=d\n",
"mzz = MultiZarrToZarr(\n",
" single_ref_sets, concat_dims=[\"time\"], identical_dims=[\"lat\", \"lon\"]\n",
")\n",
"d = mzz.translate()\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(\n",
" 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 +3596,17 @@
"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.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(\n",
" \"Relative Humidity Vs Time @ ({},{}) for model {}\".format(\n",
" ds.lat.values[22], ds.lon.values[13], items[0].properties[\"cmip6:model\"]\n",
" )\n",
" )\n",
" plt.show()"
]
},
Expand Down

0 comments on commit bc592db

Please sign in to comment.