Metadata

Extraction

calc_enl

Calculate the Equivalent Number of Looks (ENL) for a linear-scaled backscatter measurement GeoTIFF file.

calc_performance_estimates

Calculates the performance estimates specified in CARD4L NRB 1.6.9 for all noise power images if available.

evaluate_types

Evaluate the types of a metadata dictionary as extracted by e.g. s1ard.metadata.extract.meta_dict().

geometry_from_vec

Get geometry information for usage in STAC and XML metadata from a spatialist.vector.Vector object.

get_header_size

Gets the header size of a GeoTIFF file in bytes.

vec_from_srccoords

Creates a single Vector object from a list of footprint coordinates of source scenes.

cesard.metadata.extract.calc_enl(tif, block_size=30, return_arr=False, decimals=2)[source]

Calculate the Equivalent Number of Looks (ENL) for a linear-scaled backscatter measurement GeoTIFF file. The calculation is performed block-wise for the entire image and by default the median ENL value is returned.

Parameters:
  • tif (str) – The path to a linear-scaled backscatter measurement GeoTIFF file.

  • block_size (int) –

    The block size to use for the calculation. Remainder pixels are discarded,

    if the array dimensions are not evenly divisible by the block size. Default is 30, which calculates ENL for 30x30 pixel blocks.

  • return_arr (bool) – If True, the calculated ENL array is returned. Default is False.

  • decimals (int) – Number of decimal places to round the calculated ENL value to. Default is 2.

Raises:

RuntimeError – if the input array contains only NaN values

Return type:

float | ndarray | None

Returns:

If return_enl_arr=True, an array of ENL values is returned. Otherwise, the median ENL value is returned. If the ENL array contains only NaN and return_enl_arr=False, the return value is None.

References

[1]

cesard.metadata.extract.calc_performance_estimates(files, decimals=2)[source]

Calculates the performance estimates specified in CARD4L NRB 1.6.9 for all noise power images if available.

Parameters:
  • files (list[str]) – List of paths pointing to the noise power images the estimates should be calculated for.

  • decimals (int) – Number of decimal places to round the calculated values to. Default is 2.

Returns:

out – Dictionary containing the calculated estimates for each available polarization.

Return type:

dict

cesard.metadata.extract.evaluate_types(meta)[source]

Evaluate the types of a metadata dictionary as extracted by e.g. s1ard.metadata.extract.meta_dict(). Currently allowed:

Parameters:

meta (Any) – the metadata dictionary to be evaluated.

Raises:

TypeError

Return type:

None

cesard.metadata.extract.geometry_from_vec(vectorobject)[source]

Get geometry information for usage in STAC and XML metadata from a spatialist.vector.Vector object.

Parameters:

vectorobject (Vector) – The vector object to extract geometry information from.

Return type:

dict[str, Any]

Returns:

A dictionary containing the geometry information extracted from the vector object.

cesard.metadata.extract.get_header_size(tif)[source]

Gets the header size of a GeoTIFF file in bytes. The code used in this function and its helper function _get_block_offset were extracted from the following source:

https://github.com/OSGeo/gdal/blob/master/swig/python/gdal-utils/osgeo_utils/samples/validate_cloud_optimized_geotiff.py

Copyright (c) 2017, Even Rouault

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Parameters:

tif (str) – A path to a GeoTIFF file of the currently processed ARD product.

Returns:

The size of all IFD headers of the GeoTIFF file in bytes.

Return type:

header_size

cesard.metadata.extract.vec_from_srccoords(coord_list, crs, layername='polygon')[source]

Creates a single Vector object from a list of footprint coordinates of source scenes.

Parameters:
  • coord_list (list[list[tuple[float, float]]]) – List containing for each source scene a list of coordinate pairs as retrieved from the metadata stored in an ID object.

  • crs (int | str) – the coordinate reference system of the provided coordinates.

  • layername (str) – the layer name of the output vector object

Return type:

Vector

Returns:

the vector object

XML

parse

Wrapper for source_xml() and product_xml().

product_xml

Function to generate product-level metadata for an ARD product in OGC 10-157r4 compliant XML format.

source_xml

Function to generate source-level metadata for an ARD product in OGC 10-157r4 compliant XML format.

cesard.metadata.xml.parse(meta, target, assets, exist_ok=False)[source]

Wrapper for source_xml() and product_xml().

Parameters:
  • meta (dict[str, dict[str, Any]]) – Metadata dictionary generated by the satellite-specific ARD packages, e.g. s1ard.metadata.extract.meta_dict().

  • target (str) – A path pointing to the root directory of a product scene.

  • assets (list[str]) – List of paths to all GeoTIFF and VRT assets of the currently processed ARD product.

  • exist_ok (bool) – Do not create files if they already exist?

Return type:

None

cesard.metadata.xml.product_xml(meta, target, assets, nsmap, ard_ns, exist_ok=False)[source]

Function to generate product-level metadata for an ARD product in OGC 10-157r4 compliant XML format.

Parameters:
  • meta (dict[str, dict[str, Any]]) – Metadata dictionary generated by the satellite-specific ARD packages, e.g. s1ard.metadata.extract.meta_dict().

  • target (str) – A path pointing to the root directory of a product scene.

  • assets (list[str]) – List of paths to all GeoTIFF and VRT assets of the currently processed ARD product.

  • nsmap (dict[str, str]) – Dictionary listing abbreviation (key) and URI (value) of all necessary XML namespaces.

  • ard_ns (str) – Abbreviation of the ARD namespace. E.g., s1-nrb for the NRB ARD product.

  • exist_ok (bool) – Do not create files if they already exist?

Return type:

None

cesard.metadata.xml.source_xml(meta, target, nsmap, ard_ns, exist_ok=False)[source]

Function to generate source-level metadata for an ARD product in OGC 10-157r4 compliant XML format.

Parameters:
  • meta (dict[str, dict[str, Any]]) – Metadata dictionary generated by the satellite-specific ARD packages, e.g. s1ard.metadata.extract.meta_dict().

  • target (str) – A path pointing to the root directory of a product scene.

  • nsmap (dict[str, str]) – Dictionary listing abbreviation (key) and URI (value) of all necessary XML namespaces.

  • ard_ns (str) – Abbreviation of the ARD namespace. E.g., s1-nrb for the NRB ARD product.

  • exist_ok (bool) – Do not create files if they already exist?

Return type:

None

STAC

parse

Wrapper for source_json() and product_json().

product_json

Function to generate product-level metadata for an ARD product in STAC compliant JSON format.

source_json

Function to generate source-level metadata for an ARD product in STAC compliant JSON format.

cesard.metadata.stac.parse(meta, target, assets, exist_ok=False)[source]

Wrapper for source_json() and product_json().

Parameters:
  • meta (dict[str, dict[str, Any]]) – Metadata dictionary generated by the satellite-specific ARD packages, e.g. s1ard.metadata.extract.meta_dict().

  • target (str) – A path pointing to the root directory of a product scene.

  • assets (list[str]) – List of paths to all GeoTIFF and VRT assets of the currently processed ARD product.

  • exist_ok (bool) – Do not create files if they already exist?

Return type:

None

cesard.metadata.stac.product_json(meta, target, assets, exist_ok=False)[source]

Function to generate product-level metadata for an ARD product in STAC compliant JSON format.

Parameters:
  • meta (dict[str, dict[str, Any]]) – Metadata dictionary generated by the satellite-specific ARD packages, e.g. s1ard.metadata.extract.meta_dict().

  • target (str) – A path pointing to the root directory of a product scene.

  • assets (list[str]) – List of paths to all GeoTIFF and VRT assets of the currently processed ARD product.

  • exist_ok (bool) – Do not create files if they already exist?

Return type:

None

cesard.metadata.stac.source_json(meta, target, exist_ok=False)[source]

Function to generate source-level metadata for an ARD product in STAC compliant JSON format.

Parameters:
  • meta (dict[str, dict[str, Any]]) – Metadata dictionary generated by the satellite-specific ARD packages, e.g. s1ard.metadata.extract.meta_dict().

  • target (str) – A path pointing to the root directory of a product scene.

  • exist_ok (bool) – Do not create files if they already exist?

Return type:

None