Skip to content

Correct initialization of an "empty" Zarr dataset for region-based writing. #8878

Answered by mdespriee
mdespriee asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, I found out that dask.array.full can be used instead of np.full to initialize lazily.
And I forgot compute=False

In summary

empty = xr.Dataset(
   data_vars={'foo': (['x','y','t'], dask.array.full((20,20,20), np.nan)) },
   coords={'x':np.arange(20), 'y':np.arange(20), 't':np.arange(20)}
)
empty.to_zarr('my_dataset.zarr', compute=False)
part = xr.Dataset(
  {'foo': (['x','y','t'], np.full((5,5,5), 10)) },
   coords={'x':np.arange(5,10), 'y':np.arange(5,10), 't':np.arange(5,10)},
)
part.to_zarr('my_dataset.zarr', region={"x": "auto", "y": "auto", "t": "auto"})

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@mdespriee
Comment options

@dcherian
Comment options

@mdespriee
Comment options

Comment options

You must be logged in to vote
1 reply
@dcherian
Comment options

Answer selected by dcherian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants