write

Contents

write#

eoio.interface.write(obj: Dataset | DataTree, path: str | Path, writer: str, write_params: Dict[str, Any] | None = None, processors: Dict[str, Any] | List[Dict[str, Any]] | None = None) → str[source]#

Writes an xarray object to disk in the requested format.

Parameters:
  • obj – xarray.Dataset or xarray.DataTree to write.

  • path – Destination path. Missing parent directories are created unless the create_parents write parameter says otherwise.

  • writer –

    Name of the writer to use, e.g. "netcdf" or "zarr". Available names can be listed with eoio.writers.WriterFactory.list_writers().

    Unlike reading, where the format is a property of the file being opened and is detected automatically, the output format is a choice and so must be stated. It is deliberately not guessed from the file extension.

  • write_params –

    Optional parameters controlling how the data are written. Which parameters are accepted depends on the writer; inspect them with eoio.writer_options.

    Supported by every writer:

    • "encode_attrs" (bool, default: True) – Encode attributes that the format cannot store natively (nested dictionaries, datetimes, geometries) so that they survive the round trip.

    • "on_nonconformance" (str, default: "warn") – What to do when the dataset does not conform to CF-1.8 / ACDD / the controlled vocabulary: "warn", "error" or "ignore".

    • "update_history" (bool, default: True) – Record this write in the history and eoio:processing_steps attributes.

    • "create_parents" (bool, default: True) – Create missing parent directories of path.

  • processors –

    Optional definition of processing steps to apply before writing, in the same form as read(). Useful for expressing read-transform-write as two calls.

    Unlike in read(), the processing context’s path is the destination path given here, not a source product - write is not told where obj came from. A processor that needs the source product should be given it in its own parameters.

Returns:

The path written, as a string.

Raises:
  • ValueError – If writer is not a known writer name.

  • TypeError – If the chosen writer cannot express obj.

Examples

Write a dataset to netCDF:

>>> eoio.write(ds, "/path/to/output.nc", writer="netcdf")

Write to Zarr, appending along time as new observations arrive. The first call creates the store and later ones extend it:

>>> for scene in scenes:
...     eoio.write(
...         scene,
...         "/path/to/stack.zarr",
...         writer="zarr",
...         write_params={"append_dim": "time"},
...     )