Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active May 20, 2026 02:44
Show Gist options
  • Select an option

  • Save mdsumner/e6a37d3b539e55ac90b28e2a12d42b33 to your computer and use it in GitHub Desktop.

Select an option

Save mdsumner/e6a37d3b539e55ac90b28e2a12d42b33 to your computer and use it in GitHub Desktop.

This local example in the Usage for VirtualiZarr is (still) broken:

https://virtualizarr.readthedocs.io/en/latest/usage.html#__tabbed_1_7

I personally find it impossible to remember all this rigmarole (what's wrong with a file path?), so I need a reference example that actually works:

## local file 'data.nc' in your wd e.g. 
# wget -O data.nc https://www.ncei.noaa.gov/data/sea-surface-temperature-optimum-interpolation/v2.1/access/avhrr/198109/oisst-avhrr-v02r01.19810901.nc

import xarray as xr
from obstore.store import LocalStore
from obspec_utils.registry import ObjectStoreRegistry

from virtualizarr import open_virtual_dataset, open_virtual_mfdataset
from virtualizarr.parsers import HDFParser

from pathlib import Path

store_path = Path.cwd()
file_path = str(store_path / "data.nc")
file_url = f"file://{file_path}"

store = LocalStore(prefix=store_path)
registry = ObjectStoreRegistry({file_url: store})

parser = HDFParser()
vds = open_virtual_dataset(
  url=file_url,
  parser=parser,
  registry=registry,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment