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
xarrayobject to disk in the requested format.- Parameters:
obj –
xarray.Datasetorxarray.DataTreeto write.path – Destination path. Missing parent directories are created unless the
create_parentswrite parameter says otherwise.writer –
Name of the writer to use, e.g.
"netcdf"or"zarr". Available names can be listed witheoio.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 thehistoryandeoio:processing_stepsattributes."create_parents"(bool, default:True) – Create missing parent directories ofpath.
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’spathis the destinationpathgiven here, not a source product -writeis not told whereobjcame 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
writeris 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
timeas 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"}, ... )