Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataArrays to/from Zarr Arrays #2660

Open
rabernat opened this issue Jan 8, 2019 · 7 comments
Open

DataArrays to/from Zarr Arrays #2660

rabernat opened this issue Jan 8, 2019 · 7 comments
Labels
topic-zarr Related to zarr storage library

Comments

@rabernat
Copy link
Contributor

rabernat commented Jan 8, 2019

Right now, open_zarr and Dataset.to_zarr only work with Zarr groups. Zarr Groups can contain multiple Array objects.

It would be nice if we could open Zarr Arrays directly as xarray DataArrays and write xarray DataArrays directly to Zarr Arrays.

However, this might not make sense, because, unlike xarray DataArrays, zarr Arrays can't hold any coordinates.

Just raising this idea for discussion.

@rabernat rabernat added the topic-zarr Related to zarr storage library label Jan 8, 2019
@rabernat rabernat changed the title Open DataArrays to/from Zarr Arrays DataArrays to/from Zarr Arrays Jan 8, 2019
@shoyer
Copy link
Member

shoyer commented Jan 8, 2019

Take a look at DataArray.to_netcdf() for one approach. We save the DataArray into a netCDF group, saved into a variable with the special name __xarray_dataarray_variable__.

@maxrjones
Copy link
Contributor

We created https://github.com/carbonplan/xrefcoord to generate coordinates from GeoTiff metadata using kerchunk reference files and xarray without needing to store the coordinates. As discussed in fsspec/kerchunk#313, the ability to open Zarr arrays in xarray would allow using kerchunk on a broader set of GeoTIFFs but would require experience with the backend code and/or non-trivial amounts of time.

Do you think using xarray's flexible backends with zarrita could provide a way to both solve this problem and experiment with the most recent v3 spec in xarray without requiring as much experience with xarray's current backend code?

@krokosik
Copy link
Contributor

The functionality to call to_zarr has been added and they can be then opened using `open_dataset('...', engine='zarr'), so I think this issues could be closed?
#7692

@maxrjones
Copy link
Contributor

The functionality to call to_zarr has been added and they can be then opened using `open_dataset('...', engine='zarr'), so I think this issues could be closed? #7692

They primary functionality we found missing in fsspec/kerchunk#313 was the ability to open Zarr arrays as xarray DataArrays. afaik #7692 allows dataarrays to be written to Zarr groups, and Zarr groups can be read as datasets, but Zarr arrays still cannot be read by Xarray. The ability to directly read Zarr arrays would be extremely helpful for reading data objects created outside Xarray.

@LaurentBerder
Copy link

Hi, is there any update on this?
I also am saving a DataArray to zarr, which I would then need to read as a DataArray (right now it only reads as DataSet).

@rabernat
Copy link
Contributor Author

For everyone interested in this feature: we would welcome a PR! It should be a straightforward extension of open_dataaaray. The xarray core dev team would be happy to provide support and advice along the way. To get started, check out the contributing guide.

@dcherian dcherian reopened this Oct 26, 2023
@max-sixty max-sixty mentioned this issue Oct 27, 2023
4 tasks
@LaurentBerder
Copy link

For everyone interested in this feature: we would welcome a PR! It should be a straightforward extension of open_dataaaray. The xarray core dev team would be happy to provide support and advice along the way. To get started, check out the contributing guide.

Hi @rabernat,
Unhappily, I'm not (in any short-medium time) going to have bandwidth for a PR.
However, I managed to get this code running for myself:

import xarray as xr

ds = xr.open_zarr(path)
array = ds.to_array(dim='extra').squeeze('extra')

That seems to work easily enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-zarr Related to zarr storage library
Projects
None yet
Development

No branches or pull requests

7 participants