From e6898635c2868e9198bf592a52f25f5d6af4fb4d Mon Sep 17 00:00:00 2001 From: Himanshu Agrawal Date: Fri, 6 Nov 2026 00:54:05 +0530 Subject: [PATCH] Use a small local dataset for the Xarray Zarr example --- intermediate/intro-to-zarr.ipynb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/intermediate/intro-to-zarr.ipynb b/intermediate/intro-to-zarr.ipynb index 911ba391..3a5357f2 100644 --- a/intermediate/intro-to-zarr.ipynb +++ b/intermediate/intro-to-zarr.ipynb @@ -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." ] }, { @@ -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" ] }, @@ -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",