Skip to content
Snippets Groups Projects

Migrate to Zarr 3

Merged Siddhant Tibrewal requested to merge 6-zarr3-migration into main
All threads resolved!
Files
6
@@ -15,7 +15,9 @@ def add_time(dataset, startdate, enddate, dt, name="time"):
time_data = (np.arange(startdate + dt, enddate + dt, dt) - startdate) // np.timedelta64(1, "s")
for g in _collect_groups(dataset):
time = dataset.create_array(name="time", fill_value=None, shape=time_data.shape, dtype=np.longlong)
time = g.create_array(
name="time", fill_value=None, shape=time_data.shape, dtype=np.longlong
)
time.append(data=time_data)
time.attrs["_ARRAY_DIMENSIONS"] = (name,)
time.attrs["axis"] = "T"
@@ -59,13 +61,13 @@ def add_variable(
for g in _collect_groups(dataset):
taxis_tuple = tuple() if taxis is None else (taxis,)
ntime = tuple() if taxis is None else (g[taxis].shape[0],)
grid_mapping_name = g['crs'].attrs["grid_mapping_name"]
grid_mapping_name = g["crs"].attrs["grid_mapping_name"]
spatial_attr = "point" if (grid_mapping_name == "point_cloud") else "cell"
crs_len = 0
if grid_mapping_name == "healpix":
crs_len = healpy.nside2npix(g['crs'].attrs["healpix_nside"])
crs_len = healpy.nside2npix(g["crs"].attrs["healpix_nside"])
elif grid_mapping_name == "point_cloud":
lon_coord, lat_coord = g['crs'].attrs["coordinates"].split(" ")
lon_coord, lat_coord = g["crs"].attrs["coordinates"].split(" ")
assert lon_coord in g and lat_coord in g
assert g[lon_coord].shape[0] == g[lat_coord].shape[0]
crs_len = g[lat_coord].shape[0]
@@ -76,18 +78,20 @@ def add_variable(
if zaxis is None:
shape = (*ntime, crs_len)
_chunk_shape = np.minimum(chunk_shape, shape) if chunk_shape is not None else None
_attributes["_ARRAY_DIMENSIONS"] = (*taxis_tuple, spatial_attr)
else:
nheight = g[zaxis].shape[0]
shape = (*ntime, nheight, crs_len)
_chunk_shape = np.minimum(chunk_shape, shape) if chunk_shape is not None else None
_attributes["_ARRAY_DIMENSIONS"] = (*taxis_tuple, zaxis, spatial_attr)
_attributes["grid_mapping"] = "crs"
_attributes["grid_mapping"] = "crs"
_chunk_shape = "auto"
_shard_shape = None
if chunks_per_shard is not None:
_shard_shape = tuple(i * chunks_per_shard for i in _chunk_shape)
if chunk_shape is not None:
_chunk_shape = tuple(min(chunk_shape, shape))
if chunks_per_shard is not None:
_shard_shape = tuple(i * chunks_per_shard for i in _chunk_shape)
v = g.create_array(
name,
Loading