Store the dimension order when using Zarr
Open
Nobody has claimed this yet.
usage question
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Is your feature request related to a problem?
Currently, if a dataset is saved to Zarr and then reloaded, the dimensions are reloaded alphabetically.
Example:
import xarray as xr
import numpy as np
from pathlib import Path
original_dataset = xr.Dataset(
{
'temperature': (('time', 'lat', 'lon'), np.random.rand(5, 4, 3)),
'precipitation': (('time', 'lat', 'lon'), np.random.rand(5, 4, 3))
},
coords={
'time': np.arange(5),
'lat': np.linspace(-90, 90, 4),
'lon': np.linspace(0, 360, 3)
}
)
print('Original Dimensions:', list(original_dataset.dims))
zarr_path = Path('example_dataset.zarr')
original_dataset.to_zarr(zarr_path, mode='w')
reloaded_dataset = xr.open_zarr(zarr_path)
print('Reloaded Dimensions:', list(reloaded_dataset.dims))
outputs
Original Dimensions: ['time', 'lat', 'lon']
Reloaded Dimensions: ['lat', 'lon', 'time']
Describe the solution you'd like
Store the dimension order when using Zarr, such that when the dataset is reloaded from the Zarr file, the original dimension order is maintained.
Describe alternatives you've considered
N/A
Additional context
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided Python example, focusing on the Dataset.to_zarr and xr.open_zarr entry points. Trace how dimensions are written and reconstructed, then verify that reloading preserves the original ['time', 'lat', 'lon'] order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100