/zarr-data-format:data-migrationfrom zarr-data-format
Migrates HDF5/NetCDF files to Zarr, upgrades Zarr v2 to v3, or builds virtual Zarr stores with VirtualiZarr/kerchunk. Handles encoding loss, chunk layout issues, and validation failures.
Ships in zarr-data-format. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Copies HDF5 and NetCDF data into Zarr, upgrades Zarr v2 stores to v3, or builds virtual Zarr references over files that stay where they are.
Core principle: a migration is done when the target's decoded values, attributes and time coordinate match the source, not when to_zarr returns. Most silent damage comes from encoding=, which replaces the source variable's dtype, packing and fill value instead of adding to them.
.h5 or .nc files into a Zarr store, or a Zarr v2 store into v3phony_dim_* names, lost packing or fill values, wrong dates, the source's tiny chunks, or failed comparisonsWhen NOT to use:
zarr-chunk-optimization:rechunking.zarr-xarray-integration.compression-codecs. Cloud stores and credentials: cloud-storage-backends.| Source | Route | Code |
|---|---|---|
| One file with named dimensions | xr.open_dataset(path, chunks=...), to_zarr | Below |
| Many NetCDF files | xr.open_mfdataset, .chunk(...) the result, to_zarr | patterns.md Pattern 2 |
| HDF5 groups xarray can't model | h5py walk, zarr.from_array per dataset | Pattern 4 |
| Zarr v2 store | Replace the v2 codec encoding, to_zarr(zarr_format=3) | Pattern 7 |
| Too large to copy | VirtualiZarr to kerchunk JSON or Icechunk | Pattern 3 |
| Thousands of files, restartable | Append per file with a checkpoint | Pattern 5 |
import numpy as np
import xarray as xr
KEEP = ("dtype", "scale_factor", "add_offset", "_FillValue", "missing_value")
def cf_encoding(var):
"""The source packing and fill keys, which encoding= would otherwise drop."""
enc = {k: v for k, v in var.encoding.items() if k in KEEP}
if var.encoding.get("_Unsigned") == "true": # zarr rejects _Unsigned: store the unsigned dtype
signed = np.dtype(enc["dtype"])
enc["dtype"] = np.dtype(f"u{signed.itemsize}")
for k in ("_FillValue", "missing_value"):
if k in enc:
enc[k] = np.asarray(enc[k], signed).astype(enc["dtype"])
return enc
target = {"time": 30, "lat": 90, "lon": 180}
ds = xr.open_dataset("climate_model_output.nc", chunks=target) # name every dimension
encoding = {
name: cf_encoding(var) | {"chunks": tuple(target[d] for d in var.dims)}
for name, var in ds.data_vars.items() if set(var.dims) <= set(target)
}
ds.to_zarr("climate_output.zarr", mode="w-", encoding=encoding)
A dimension left out of chunks= keeps the file's HDF5 chunks, and to_zarr can then raise would overlap multiple Dask chunks. encoding chunks are a tuple in dimension order. Coordinates stay out of encoding=, so time keeps its units and calendar. Without missing_value, masked values came back as 0; without the unsigned dtype, 200 came back as -56.
def lost_or_changed(a, b):
return {k for k in a if k not in b or not np.array_equal(a[k], b[k])}
src = xr.open_dataset("climate_model_output.nc", chunks=target)
dst = xr.open_zarr("climate_output.zarr")
xr.testing.assert_allclose(src, dst) # names, sizes, coords, values; NaN == NaN; chunk by chunk
assert not (bad := lost_or_changed(src.attrs, dst.attrs)), f"global attributes {bad}"
for name in src.variables: # assert_allclose ignores attributes
assert not (bad := lost_or_changed(src[name].attrs, dst[name].attrs)), f"{name} attributes {bad}"
Use xr.testing.assert_equal when no dtype was narrowed. Per-file checks: examples.md Example 4.
python assets/hdf5-to-zarr-migration.py builds a 47 MB HDF5 file with dimension scales in a temp directory, converts it, checks it, and exits 1 on any failed check.
| Mistake | Fix |
|---|---|
encoding chunks as a dict | TypeError: ... must be an int or a tuple of ints. Use a tuple. |
encoding={"v": {"chunks": ...}} alone | Replaces the source encoding: packed int16 became float64. Merge the KEEP keys. All of var.encoding raises unexpected encoding parameters. |
| HDF5 without dimension scales | Dimensions are phony_dim_N and chunks={"time": 30} is ignored. Rename them or attach scales. |
HDF5 fillvalue without _FillValue | Not masked, so sentinels stay numbers. Apply .where(...) first. |
open_mfdataset(..., chunks={"time": 30}) | Chunks are per file, so to_zarr raises would overlap multiple Dask chunks. .chunk(...) the combined dataset. |
.chunk(...) on data read from Zarr | The source encoding["chunks"] wins silently. Pop chunks, shards and preferred_chunks. |
rechunker | 0.5.4 pins zarr<3,>=2.11. See zarr-chunk-optimization:rechunking. |
zarr.from_array defaults | zarr 3.1.5 drops fill_value and attributes. Pass both. |
| Appending finer time steps than the store's units | Dates come out wrong with only a UserWarning. Set units for time and time_bnds on the first write. |
| Kerchunk or VirtualiZarr to change chunks | They reference the existing chunks, and files must share one chunk shape (contiguous monthly files fail). Copy instead. |
Kerchunk MultiZarrToZarr without coo_map={"time": "cf:time"} | Files with per-file time units merge silently: three 12-day files became 12 steps, the first file's dates over the last file's data. Pass coo_map. |
| VirtualiZarr 1.x code | 2.x needs registry= and parser=, and writes with .vz.to_kerchunk or .vz.to_icechunk. There is no to_zarr. |
.values plus np.allclose | Loads whole arrays (3.2 GB RSS for 400 MB) and fails on datetimes. Use xr.testing. |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (uw-ssec/savvy) — no native marketplace selected
npx claudepluginhub p/uw-ssec-zarr-data-format-plugins-zarr-data-format5 skills in this plugin
/cloud-storage-backendsUse when reading or writing Zarr data on Amazon S3, Google Cloud Storage, Azure Blob or an S3-compatible endpoint such as MinIO, when setting up FsspecStore, ObjectStore (obstore), s3fs, gcsfs, adlfs or Icechunk storage and credentials, or when remote Zarr access fails or is slow, with symptoms like 403 Forbidden, NoCredentialsError, requester-pays buckets, slow store opens, timeouts, high GET-request bills, CORS errors, or an fsspec simplecache or filecache that errors or never hits./compression-codecsUse when choosing or configuring Zarr compression in zarr-python 3 (Blosc, Zstd, Gzip, LZ4, LZMA, BZ2; numcodecs filters such as Delta, Quantize, BitRound, FixedScaleOffset, PackBits; compressors=, filters=, serializer=), when v2-style compressor= or numcodecs code fails on a v3 array, or when a store compresses poorly, decompresses slowly, raises codec errors, or may hold corrupted chunks after Blosc multiprocessing use./zarr-fundamentalsUse when creating, opening, indexing or organizing Zarr arrays and groups with zarr-python (.zarr stores, zarr.json or .zarray metadata), setting attributes, fill values, dimension names or shards, choosing between Zarr format v2 and v3, porting zarr 2 code that breaks on zarr 3 (FSStore, ProcessSynchronizer, len(), .compressor), or when parallel writes to one Zarr array lose data.Other plugins' skills for the same job