Replies: 1 comment 2 replies
-
The error says this object is not serializable. Delete the You may want to save this information somehow. I would ask over at rioxarray.
The defaults are sensible, though perhaps the error messages could be more useful (a PR to improve these is very welcome!). The software is forcing you to be explicit about what's written to disk, so you don't get surprised by missing variables or attributes when you read it back. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I can’t easily save an xarray DataArray to a Zarr. When I load a STAC catalog with stackstac
https://notebooksharing.space/view/d8e6268b7a122a4980322b8a69471056d0d90aa838475c986f12cd7c7f5135a3#displayOptions=
The above notebook gets a modest spatial subset for sentinel 1 rtc radar imagery and a pretty deep time series of 182 time points. It takes 1.5-2 minutes to load and materialize the DataArray on the Planetary Computer hub, so I’d like to save it to a Zarr for faster loading. The DataArray is called
s1rtc_2016_2019
But after a few rounds of debugging, I can’t save this xarray DataArray to a Zarr
s1rtc_2016_2019.to_zarr("../data/s1rtc_2016_2019.zarr")
doesn’t exist, which I wouldn’t expect. only Dataset’s can be saved as Zarr.
So next I thought I could do a quick conversion from DataArray to Dataset and then save to Zarr.
s1rtc_2016_2019.to_dataset(name='s1bands').to_zarr("../data/s1rtc_2016_2019.zarr")
This still doesn’t work because there are non essential coordinates interpreted by stackstac that the xarray Zarr driver doesn't handle.
The error
So I thought if I drop these coordinates, I'd be good. This still doesn't work because to_zarr doesn't like the empty attrs dictionary.
s1rtc_2016_2019.reset_coords(drop=True).to_dataset(name="s1bands").to_zarr("../data/s1rtc_2016_2019.zarr")
The error
I'd like to understand, how do folks get around these errors when saving DataArrays to zarr? Has anyone saved a DataArray produced by stackstac to Zarr? And are xarray maintainers open to providing a DataArray.to_zarr method that uses sensible defaults and support and empty attrs dict or ignores attrs entirely? This would remove the three debugging steps I went through above to 1) convert the DataArray to a Dataset, remove coords with "arbitrary Python Objects", and the empty
.attrs
error.Beta Was this translation helpful? Give feedback.
All reactions