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:
Return type:

Dataset

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 Client instance.

  • 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_kwargs or to_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.

to_netcdf_kwargs: dict[str, Any] = {}#

Arguments passed to the function writing files.

to_zarr_kwargs: dict[str, Any] = {}#

Arguments passed to the writing function for zarr stores.

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:
Return type:

Any