eoio package#
eoio - Data readers and preprocessing for satellite data
- eoio.product_options(path: str, read_params: Dict[str, Any] | None = None, *args, **kwargs) dict[source]#
Return dictionary of available
meas_varsoptions for the requested EO data product- Parameters:
path – satellite data product
:return : dictionary of available subsetting parameters
- eoio.read(path: str, vars_sel: Dict[str, List[str]] | None = None, subset: Dict[str, Any] | None = None, read_params: Dict[str, Any] | None = None, processors: Dict[str, Any] | List[Dict[str, Any]] | None = None, *args, **kwargs) Dataset[source]#
Reads an Earth Observation (EO) data product and returns the requested variables, optionally applying spatial subsetting and post-processing.
- Parameters:
path – Path to the EO data product (file or directory, depending on product type).
vars_sel –
Variable selection dictionary defining which variables to read from the product.
Supported keys are:
"meas"(list[str] | str | None, default:"all") – Measurement variables to read. Options are:"all"– read all available measurement variableslist[str]– explicit list of measurement variable namesNone– do not read any measurement variables
"mask"(list[str] | None, default:None) – Mask variable names to read. UseNoneto disable mask reading."aux"(list[str] | None, default:None) – Auxiliary data variable names to read. UseNoneto disable auxiliary data reading.
Available variable names and supported combinations for a given product can be inspected via
eoio.product_options.subset –
Optional definition of subsetting parameters. If omitted or
None, the full data product is read without subsetting.Supported keys (availability depends on the product type):
"roi"– Spatial region of interest for raster data. Supported forms are:None– no spatial subsettingshapelygeometry (interpreted inroi_crs_epsg)Bounding box tuple
(xmin, ymin, xmax, ymax)inroi_crs_epsgGeoJSON-like
dictwith a"type"keyList of
[x, y]coordinate pairs defining a polygon((x, y), half_width_m)defining a square region centred on a point
"roi_crs_epsg"(str) – EPSG code defining the coordinate reference system ofroi(e.g."EPSG:4326")."angle"– (Not implemented) Observation geometry range of interest"spectral"– (Not implemented) Spectral range of interest
read_params –
Optional parameters controlling how the data are read. If omitted, default behaviour is used.
Supported options include:
"save_extracted"(bool, default:False) – If the data product is extracted or uncompressed during reading, controls whether the extracted files are saved to disk."metadata_level"(None | bool, default:None) – Level of metadata to read:None– Standard/core metadata onlyFalse– Do not read metadataTrue– Read all available metadata
processors –
Optional definition of post-processing steps to apply after reading (e.g. interpolation, unit conversion, etc.).
Dictionary keys should be the names of the processors to run. The associated entry should be a subdictionary of parameters for that processor. Required parameters are defined at the processor level.
- Returns:
xarray.Datasetcontaining the requested variables and associated metadata from the EO data product.
Examples
Read all measurement variables from an EO product:
>>> ds = eoio.read("/path/to/product")
Read selected variables over a spatial region of interest:
>>> from shapely.geometry import box >>> ds = read_product( ... path="/path/to/product", ... vars_sel={ ... "meas": ["B02", "B03", "B04"], ... "mask": ["cloud_mask"], ... }, ... subset={ ... "roi": box(-2.0, 50.0, 0.0, 52.0), ... "roi_crs_epsg": "EPSG:4326", ... }, ... )
- eoio.read_multi(paths: str | List[str], vars_sel: Dict[str, List[str]] | None = None, subset: Dict[str, Any] | None = None, read_params: Dict[str, Any] | None = None, processors: Dict[str, Any] | List[Dict[str, Any]] | None = None, concat_dim: str = 'time', concat_coord: str | List[Any] | Callable[[str, Dataset], Any] | None = None, concat_processors: Dict[str, Any] | List[Dict[str, Any]] | None = None, on_mismatch: str = 'error', attrs: str = 'reconcile', coord_attrs: List[str] | None = None, *args, **kwargs) Dataset[source]#
Read several EO product files as one call and concatenate them along a new (or existing) dimension.
Each path is read independently via
read()(with identicalvars_sel/subset/read_params/processorsapplied to every file), then the resulting datasets are concatenated alongconcat_dim.Typical uses are an in-situ time series (e.g. one Hypernets file per measurement cycle, each already carrying its own
timedimension) or a multi-date raster stack (e.g. several Sentinel-2 scenes stacked along a newtimedimension).- Parameters:
paths – Explicit list of product paths, a directory (all files inside it recognised by a registered reader), or a glob pattern. All entries are expected to resolve to the same reader type.
vars_sel – See
read(). Applied identically to every file.subset – See
read(). Applied identically to every file.read_params – See
read(). Applied identically to every file.processors – Post-processing steps run per file, before concatenation. See
read().concat_dim –
Name of the dimension to concatenate along. Default
"time".If
concat_dimis already a dimension on every per-file dataset (e.g. in-situ readers that carry their owntimedimension), the datasets are concatenated directly. Otherwise a new dimension is created per file viaexpand_dims, using the coordinate value resolved fromconcat_coord(e.g. a multi-date raster stack).concat_coord –
How to compute the coordinate value for each file along
concat_dimwhen a new dimension needs to be created:str– dot-path intods.attrs, e.g."product_metadata.sensing_time".list– explicit values, one per path, same order as the resolvedpaths.callable(path, ds) -> value– escape hatch, e.g. to parse a timestamp out of the filename.None(default) – ifconcat_dimalready exists on every dataset, used as-is; otherwise falls back to file order as an integer index coordinate, with a warning.
concat_processors – Post-processing steps run once on the final concatenated dataset.
on_mismatch –
How to handle datasets whose variable set or per-file shape (other than
concat_dim) doesn’t match — this also covers raster grid mismatches (a mismatched x/y shape is just another schema mismatch):"error"(default) – raise, naming the offending files."skip"– drop mismatched files, with a warning."union"– outer-join concat; missing values become NaN.
attrs –
How to combine dataset-level and per-variable attrs across files:
"reconcile"(default) – attrs identical across every file are kept; attrs that differ are kept as a per-file list attr (or promoted to a coordinate, seecoord_attrs) rather than being silently dropped."first"– cheap legacy behaviour: just keep the first file’s attrs, discarding the rest (xarray’s ownxr.concatdefault).
coord_attrs – Dataset-level attribute names to promote to a coordinate on
concat_diminstead of being kept as a list attr — e.g.coord_attrs=["product_name"]gives you a per-fileproduct_namecoordinate alongsidetime. Only used whenattrs="reconcile".
- Returns:
The concatenated
xarray.Dataset.
- eoio.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"}, ... )
- eoio.writer_options(writer: str) dict[source]#
Return dictionary of available
write_paramsoptions for the requested writer.- Parameters:
writer – Name of the writer, e.g.
"netcdf".- Returns:
Dictionary of available writing parameters.
- Raises:
ValueError – If
writeris not a known writer name.
Subpackages#
- eoio.processors package
- Subpackages
- Submodules
- eoio.readers package
- Subpackages
- eoio.readers.ESAWorldCover package
- eoio.readers.airbus_pleiades package
- eoio.readers.constellr_skybee package
- eoio.readers.copernicus_dem package
- eoio.readers.ecmwf package
- eoio.readers.emit package
- eoio.readers.flex package
- eoio.readers.generic_netcdf package
- eoio.readers.gistda_theos package
- eoio.readers.hypernets package
- eoio.readers.landsat package
- eoio.readers.modis package
- eoio.readers.planetscope package
- eoio.readers.radcalnet package
- eoio.readers.sentinel2 package
- eoio.readers.sentinel3_olci package
- eoio.readers.sentinel3_slstr package
- eoio.readers.subset package
- Submodules
- Subpackages
- eoio.serialisation package
- eoio.utils package
- Submodules
- eoio.utils.aux_read module
- eoio.utils.crs_utils module
- eoio.utils.dict_tools module
change_type()clean_dict()create_parent_key()dict_merge()empty_dict()get_dict_path()get_nested_value()get_value()get_value_gen()key_exists()key_in_dict()key_present()list_keys()make_value_key()multiple_keys_present()pop_vals()remove_parent_tag()remove_tag()remove_tag_in_key()replace_key_names()rmv_empty_dict()
- eoio.utils.formatters module
- eoio.utils.instrument_rsr module
- eoio.utils.jp2_tools module
- eoio.utils.rasterio_utils module
- eoio.utils.read_utils module
- eoio.utils.tif_tools module
- Submodules
- eoio.writers package