XarrayWriter#
- class XarrayWriter(params=None, **kwargs)#
Bases:
WriterAbstract[str,Dataset]Write Xarray dataset.
- Parameters:
params (Any | None)
kwargs (Any)
- add_metadata(ds, **metadata_kwargs)#
Set some dataset attributes with information on how it was created.
Wrapper around
get_metadata(). Attributes already present will not be overwritten.- Parameters:
ds (Dataset) – Dataset to add global attributes to. This is not done in-place.
metadata_kwargs (Any) – Passed to the
metadata_generator. SeeMetadataOptionsfor available options.
- Return type:
- send_calls_together(calls, client, chop=None, format=None, **kwargs)#
Send multiple calls together.
If Dask is correctly configured, the writing calls will be executed in parallel.
For all calls within a group, a list of delayed writing calls is constructed. It is then computed all at once using
client.compute(delayed), however to avoid lingering results (because we only care about the side-effect of writing to file, not the computed result), we get rid of ‘futures’ as soon as completed. This avoid a blow up in memory:for future in distributed.as_completed(client.compute(delayed)): log.debug("future completed: %s", future)
- Parameters:
client (Client) – Dask
Clientinstance.chop (int | None) – If None (default), all calls are sent together. If chop is an integer, groups of calls of size
chop(at most) will be sent one after the other, calls within each group being run in parallel.kwargs (Any) – Passed to writing function. Overwrites the defaults from
to_netcdf_kwargsorto_zarr_kwargs.calls (Sequence[CallXr])
format (Literal['nc', 'zarr', None])
- Return type:
None
- send_single_call(call: CallXr, format: Literal[None] = None, compute: Literal[True] = True, **kwargs: Any) None | ZarrStore#
- send_single_call(call: CallXr, format: Literal['nc'], compute: Literal[True], **kwargs: Any) None
- send_single_call(call: CallXr, format: Literal['zarr'], compute: Literal[True], **kwargs: Any) ZarrStore
- send_single_call(call: CallXr, *, compute: Literal[False], **kwargs: Any) Delayed
Execute a single call.
- Parameters:
kwargs – Passed to the writing function.
- write(data, target=None, metadata_kwargs=None, client=None, **kwargs)#
Write datasets to multiple targets.
Each dataset is written to its corresponding target (filename or store location). Directories will automatically be created if necessary. Metadata is added to the dataset.
- Parameters:
data (xr.Dataset | Sequence[xr.Dataset]) – Dataset or Sequence of datasets to write.
target (str | Sequence[str] | None) – If None (default), target location(s) are automatically obtained via
DataInterface.get_source().client (Client | None) – Dask
distributed.Clientinstance. If present multiple write calls will be send in parallel. Seesend_calls_together()for details. If left to None, the write calls will be sent serially.metadata_kwargs (Mapping[str, Any] | None) – Passed to the
metadata_generator. SeeMetadataOptionsfor available options.kwargs (Any) – Passed to the function that writes to disk (
xarray.Dataset.to_netcdf()orxarray.Dataset.to_zarr()).
- Return type:
Any