Skip to content
Snippets Groups Projects
Commit 4160449a authored by Siddhant Tibrewal's avatar Siddhant Tibrewal
Browse files

fixed the right value to be passed for chunk-shape in zarr 3

parent 3403df03
No related branches found
No related tags found
1 merge request!43Draft: Resolve "Migrate to Zarr3 and add example for a dataset using sharding"
Pipeline #98438 waiting for manual action
......@@ -75,18 +75,20 @@ def add_variable(
if zaxis is None:
shape = (*ntime, crs_len)
_chunk_shape = (np.min(chunk_shape, shape),) if chunk_shape is not None else None
_attributes["_ARRAY_DIMENSIONS"] = (*taxis_tuple, spatial_attr)
else:
nheight = g.get(zaxis).shape[0]
shape = (*ntime, nheight, crs_len)
_chunk_shape = (np.min(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 = (np.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,
......
......@@ -5,7 +5,7 @@ import zarr
def add_coordinates(
dataset: zarr.Dataset,
dataset: zarr.Group,
coordinates: list[tuple[float, float]],
coord_names: tuple[str, str] = ("lon", "lat"),
) -> None:
......@@ -14,8 +14,8 @@ def add_coordinates(
Parameters
----------
dataset : zarr.Dataset
The Zarr dataset where the coordinates will be added.
dataset : zarr.Group
The Zarr group where the coordinates will be added.
coordinates : list[tuple[float, float]]
A list of tuples containing the (longitude, latitude) values for each point.
coord_names : tuple[str, str], optional
......@@ -35,33 +35,31 @@ def add_coordinates(
lat_list, lon_list = zip(*coordinates)
lon = dataset.create_array(
name=coord_names[0], fill_value=None, shape=lon_list.shape, dtype=np.float32
lon = dataset.create_dataset(
name=coord_names[0], data=np.array(lon_list), shape=(len(coordinates),)
)
lon[:] = np.array(lon_list)
lon.attrs["_ARRAY_DIMENSIONS"] = [coord_names[0]]
lon.attrs["long_name"] = "longitude"
lon.attrs["units"] = "degree"
lon.attrs["standard_name"] = "grid_longitude"
lat = dataset.create_array(
name=coord_names[1], fill_value=None, shape=lat_list.shape, dtype=np.float32
lat = dataset.create_dataset(
name=coord_names[1], data=np.array(lat_list), shape=(len(coordinates),)
)
lat[:] = np.array(lat_list)
lat.attrs["_ARRAY_DIMENSIONS"] = [coord_names[1]]
lat.attrs["long_name"] = "latitude"
lat.attrs["units"] = "degree"
lat.attrs["standard_name"] = "grid_latitude"
def add_healpix_grid(dataset: zarr.Dataset, order: int):
def add_healpix_grid(dataset: zarr.Group, order: int):
"""
Add a HealPix grid to the specified Zarr dataset.
Parameters
----------
dataset : zarr.Dataset
The Zarr dataset where the HealPix grid will be added to the crs.
dataset : zarr.Group
The Zarr group where the HealPix grid will be added to the crs.
order : int
The order of the HealPix grid. This corresponds to 2^order for the NSIDE.
......@@ -78,7 +76,7 @@ def add_healpix_grid(dataset: zarr.Dataset, order: int):
def add_healpix_hierarchy(
dataset: zarr.Dataset,
dataset: zarr.Group,
order: int,
nr_of_coarsenings: int = 4,
prefix: str = "healpix_",
......@@ -91,8 +89,8 @@ def add_healpix_hierarchy(
Parameters
----------
dataset : zarr.Dataset
The Zarr dataset where the hierarchy will be added.
dataset : zarr.Group
The Zarr group where the hierarchy will be added.
order : int
The maximum level in the hierarchy.
nr_of_coarsenings : int
......
......@@ -5,4 +5,4 @@ pre-commit
healpy
zarr>=3
aiohttp
rich
\ No newline at end of file
rich
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment