Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Overview

In this tutorial we’ll show how to append to a pre-existing Kerchunk reference. We’ll use the same datasets as in the NetCDF reference generation example.

Prerequisites

ConceptsImportanceNotes
Kerchunk BasicsRequiredCore
Multiple Files and KerchunkRequiredCore
Multi-File Datasets with KerchunkRequiredIO/Visualization
  • Time to learn: 45 minutes


Imports

Create Input File List

Here we are using fsspec's glob functionality along with the * wildcard operator and some string slicing to grab a list of NetCDF files from a s3 fsspec filesystem.

Start a Dask Client

To parallelize the creation of our reference files, we will use Dask. For a detailed guide on how to use Dask and Kerchunk, see the Foundations notebook: Kerchunk and Dask.

/home/runner/micromamba/envs/kerchunk-cookbook/lib/python3.14/site-packages/distributed/node.py:195: UserWarning: Port 8787 is already in use.
Perhaps you already have a cluster running?
Hosting the HTTP server on port 46279 instead
  warnings.warn(
Loading...

Create a Kerchunk reference file for the first 24 hours

(['/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_000.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_001.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_002.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_003.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_004.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_005.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_006.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_007.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_008.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_009.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_010.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_011.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_012.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_013.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_014.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_015.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_016.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_017.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_018.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_019.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_020.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_021.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_022.json', '/tmp/tmpevr0mess/WRFDETAR_01H_20221231_12_023.json'],)

Combine .json Kerchunk reference files and write a combined Kerchunk index

In the following cell, we are combining all the .json reference files that were generated above into a single reference file and writing that file to disk.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[8], line 16
     12     remote_options={"anon": True},
     13     coo_map={"time": "cf:time"},
     14 )
     15 # save translate reference in memory for later visualization
---> 16 multi_kerchunk = mzz.translate()
     17 
     18 # Write kerchunk .json record.
     19 output_fname = "ARG_combined.json"

File ~/micromamba/envs/kerchunk-cookbook/lib/python3.14/site-packages/kerchunk/combine.py:647, in MultiZarrToZarr.translate(self, filename, storage_options)
    645     self.first_pass()
    646 if 2 not in self.done:
--> 647     self.store_coords()
    648 if 3 not in self.done:
    649     self.second_pass()

File ~/micromamba/envs/kerchunk-cookbook/lib/python3.14/site-packages/kerchunk/combine.py:473, in MultiZarrToZarr.store_coords(self)
    470 self.out.update(kv)
    471 logger.debug("Written coordinates")
--> 473 metadata = asyncio.run(self._read_meta_files(m, [".zgroup", ".zattrs"]))
    474 self.out.update(metadata)
    475 logger.debug("Written global metadata")

File ~/micromamba/envs/kerchunk-cookbook/lib/python3.14/asyncio/runners.py:201, in run(main, debug, loop_factory)
    171 """Execute the coroutine and return the result.
    172 
    173 This function runs the passed coroutine, taking care of
   (...)    197     asyncio.run(main())
    198 """
    199 if events._get_running_loop() is not None:
    200     # fail fast with short traceback
--> 201     raise RuntimeError(
    202         "asyncio.run() cannot be called from a running event loop")
    204 with Runner(debug=debug, loop_factory=loop_factory) as runner:
    205     return runner.run(main)

RuntimeError: asyncio.run() cannot be called from a running event loop

Append references for the next 24 hours

We’ll now append the references for the next 24 hours. First, we create an individual temporary reference file for each input data file. Then, we load the original references and append the new references.

Opening Reference Dataset with Fsspec and Xarray