eoio.readers.sentinel2.layout module#

eoio.readers.sentinel2.layout - helper for Sentinel-2 SAFE layout parsing.

class eoio.readers.sentinel2.layout.S2Layout(safe_path: str)[source]#

Bases: object

SAFE layout helper for Sentinel-2 MSI products (L1C/L2A).

Solely responsible for filesystem/path logic. No heavy dependencies.

aux_data_dir(granule: Path | None = None) Path | None[source]#

Return AUX_DATA directory if present.

Parameters:

granule – Optional granule directory. If omitted, the primary granule is used.

Returns:

AUX_DATA directory path, or None if not found.

aux_path(name: str, granule: Path | None = None) Path[source]#

Return a path to an AUX product.

Parameters:
  • name – AUX product name.

  • granule – Optional granule directory. If omitted, the primary granule is used.

Returns:

Path to the AUX product.

Raises:

S2LayoutError – If AUX_DATA is missing or the requested product cannot be found.

available_band_tokens() List[str][source]#

Return unique band tokens inferred from IMG_DATA filenames.

Returns:

List of available band tokens.

available_img_tokens() List[str][source]#

Return unique IMG_DATA layer tokens inferred from filenames.

Includes band tokens and L2A layer tokens.

Returns:

Sorted list of available IMG_DATA tokens.

available_qi_tokens() List[str][source]#

Return unique QI_DATA token names.

Returns:

Sorted list of QI_DATA token names.

datastrip_dir(datastrip_id: str | None = None) Path[source]#

Return the Sentinel-2 datastrip directory.

Parameters:

datastrip_id – Optional datastrip identifier. If omitted, the SAFE must contain exactly one datastrip.

Returns:

Datastrip directory path.

Raises:

S2LayoutError – If the datastrip directory cannot be resolved.

default_meas_vars() List[str][source]#

Return default measurement variables to read.

Returns:

Default measurement variable list.

ds_metadata_xml(datastrip_id: str | None = None) Path[source]#

Return the Sentinel-2 datastrip metadata file.

Parameters:

datastrip_id – Optional datastrip identifier.

Returns:

Path to MTD_DS.xml.

Raises:

S2LayoutError – If the datastrip metadata file is missing.

granule_dir() Path[source]#

Return the primary granule directory.

Returns:

Primary granule directory.

granule_dirs() List[Path][source]#

Return GRANULE subdirectories.

Returns:

List of granule directories.

Raises:

S2LayoutError – If GRANULE directory or granule subdirectories are missing.

img_data_dirs(granule: Path | None = None) List[Tuple[int | None, Path]][source]#

Find IMG_DATA folders and return (resolution_m, path) pairs.

Parameters:

granule – Optional granule directory. If omitted, the primary granule is used.

Returns:

List of (resolution_m, path) pairs.

Raises:

S2LayoutError – If no IMG_DATA directories are found.

img_jp2_paths(meas_vars: Sequence[str] | None = None, prefer_res_m: int | None = None) Dict[str, str][source]#

Return mapping from measurement variable name to IMG_DATA JP2 filepath.

If prefer_res_m is not supplied, the variable’s default/native resolution is used where possible.

Parameters:
  • meas_vars – Requested measurement variable names. If omitted, default variables are used.

  • prefer_res_m – Optional preferred resolution in metres. This acts as an override where that resolution exists for a variable.

Returns:

Mapping {meas_var: filepath}.

Raises:

S2LayoutError – If any requested variable is not present.

jp2_files(granule: Path | None = None) List[Path][source]#

Return all JP2 files found under IMG_DATA directories.

Parameters:

granule – Optional granule directory. If omitted, the primary granule is used.

Returns:

List of IMG_DATA JP2 files.

Raises:

S2LayoutError – If no JP2 files are found.

property proc_version: Tuple[int, int]#

Return processing version number as a tuple.

Returns:

Tuple of major version and minor version.

property processing_level_guess: str#

Best-effort processing level inference from SAFE name / metadata presence.

Returns:

"L2A" when the SAFE appears to be Level-2A, otherwise "L1C".

product_metadata_xml() Path | None[source]#

Return product-level metadata XML.

Returns:

Product metadata XML path, or None if not found.

qi_data_dir(granule: Path | None = None) Path | None[source]#

Return QI_DATA directory if present under the granule.

Parameters:

granule – Optional granule directory. If omitted, the primary granule is used.

Returns:

Path to QI_DATA directory, or None if not found.

qi_jp2_files(granule: Path | None = None) List[Path][source]#

Return JP2 files found under QI_DATA.

Parameters:

granule – Optional granule directory. If omitted, the primary granule is used.

Returns:

List of QI_DATA JP2 files.

qi_jp2_paths(qi_vars: Sequence[str] | None = None) Dict[str, str][source]#

Return mapping from QI variable name to JP2 filepath.

Parameters:

qi_vars – Optional list of requested QI variable names. If omitted, all available QI variables are returned.

Returns:

Mapping {qi_var: filepath}.

Raises:

S2LayoutError – If any requested variable is not present.

property safe_dir: Path#

Return SAFE path as a pathlib Path.

Returns:

SAFE directory path.

safe_path: str#
tl_metadata_xml(granule: Path | None = None) Path[source]#

Return tile-level metadata XML.

Parameters:

granule – Optional granule directory. If omitted, the primary granule is used.

Returns:

Tile metadata XML path.

Raises:

S2LayoutError – If tile metadata cannot be found.

exception eoio.readers.sentinel2.layout.S2LayoutError[source]#

Bases: ValueError

Raised when a SAFE layout is missing expected files/structure.