pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.63k stars 1.09k forks source link

How to read zarr with different dims by xarray? #9685

Closed QLmount-snow closed 3 weeks ago

QLmount-snow commented 3 weeks ago

What is your issue?

Here is my test code:

import zarr
import xarray as xr
import os
d = 'gfs.2021032300.zarr'
store = zarr.DirectoryStore(d)
zarr_file = zarr.open(store)
print(zarr_file.tree())
ds = xr.open_zarr(store)
# ds = xr.open_zarr(d)

the zarr tree like this: / ├── APCP_surface (121, 257, 257) float32 ├── APTMP_2maboveground (122, 257, 257) float32 ├── DPT_2maboveground (122, 257, 257) float32 ├── DSWRF_surface (121, 257, 257) float32 ├── GUST_surface (122, 257, 257) float32 ├── HGT_1000mb (123, 257, 257) float32 ├── HGT_500mb (123, 257, 257) float32 ├── HGT_600mb (123, 257, 257) float32 ├── HGT_700mb (123, 257, 257) float32 ...... ├── latitude (257,) float64 ├── longitude (257,) float64 └── time (123,) float64 And I got an error from ds = xr.open_zarr(d): .... ValueError: conflicting sizes for dimension 'time': length 122 on 'APTMP_2maboveground' and length 121 on {'time': 'APCP_surface', 'latitude': 'APCP_surface', 'longitude': 'APCP_surface'} Then I don't kown how to read the zarr with such a structure (not the same dim length). Please tell me how to read the zarr into xarray.

welcome[bot] commented 3 weeks ago

Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!

TomNicholas commented 3 weeks ago

If your zarr store has two arrays in the same group that have the same dimension name but different lengths along that dimension, then you cannot read that group with Xarray unfortunately. This is because zarr 's data model is slightly more general than Xarray 's data model.

QLmount-snow commented 3 weeks ago

If your zarr store has two arrays in the same group that have the same dimension name but different lengths along that dimension, then you cannot read that group with Xarray unfortunately. This is because zarr 's data model is slightly more general than Xarray 's data model.

@TomNicholas Thank for your answer, I try it by dropping other variables. But I think if there is a select-variables parameter in the function to do this, it will be much useful.