Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions intermediate/intro-to-zarr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@
"### Xarray and Zarr\n",
"\n",
"Xarray has built-in support for reading and writing Zarr data. You can use the `xarray.open_zarr()` function to open a Zarr store as an Xarray dataset.\n",
"\n"
"\n",
"We will create a small, synthetic precipitation dataset and write it to a local store. This example needs no cloud credentials or external dataset. The values are for demonstration only, not observations."
]
},
{
Expand All @@ -617,9 +618,19 @@
"source": [
"import xarray as xr\n",
"\n",
"store = \"https://ncsa.osn.xsede.org/Pangeo/pangeo-forge/gpcp-feedstock/gpcp.zarr\"\n",
"store = datadir / \"precipitation.zarr\"\n",
"sample = xr.Dataset(\n",
" {\"precip\": ((\"time\", \"lat\", \"lon\"), np.arange(124).reshape(31, 2, 2) / 10)},\n",
" coords={\n",
" \"time\": np.arange(\"2020-01-01\", \"2020-02-01\", dtype=\"datetime64[D]\"),\n",
" \"lat\": [10.0, 20.0],\n",
" \"lon\": [30.0, 40.0],\n",
" },\n",
")\n",
"sample.precip.attrs[\"units\"] = \"mm/day\"\n",
"sample.to_zarr(store, mode=\"w\", zarr_format=3, consolidated=False)\n",
"\n",
"ds = xr.open_dataset(store, engine=\"zarr\", chunks={}, consolidated=True)\n",
"ds = xr.open_zarr(store, chunks={}, consolidated=False)\n",
"ds"
]
},
Expand All @@ -641,7 +652,7 @@
"::::{admonition} Exercise\n",
":class: tip\n",
"\n",
"Can you calculate the mean precipitation for January 2020 in the GPCP dataset and plot it?\n",
"Can you calculate and plot the mean precipitation for January 2020 in this sample?\n",
"\n",
":::{admonition} Solution\n",
":class: dropdown\n",
Expand Down