Metadata
Extraction
Calculate the Equivalent Number of Looks (ENL) for a linear-scaled backscatter measurement GeoTIFF file. |
|
Calculates the radial root mean square error, which is a target requirement of the CARD4L NRB specification (Item 4.3). |
|
Calculates the performance estimates specified in CARD4L NRB 1.6.9 for all noise power images if available. |
|
Extracts all values for Peak Side Lobe Ratio (PSLR) and Integrated Side Lobe Ratio (ISLR) from the annotation metadata of a scene and calculates the mean value for all swaths. |
|
Copies the original metadata of the source scenes to the ARD product directory. |
|
Search for a pattern in all XML annotation files provided and return a dictionary of results. |
|
Get geometry information for usage in STAC and XML metadata from a |
|
Gets the header size of a GeoTIFF file in bytes. |
|
Get information about the used OSV file. |
|
Returns a metadata dictionary, which is generated from the name of a product scene using a regular expression pattern and from a measurement GeoTIFF file of the same product scene using the |
|
Retrieve the manifest and annotation XML data of a scene as a dictionary using an |
|
Creates a dictionary containing metadata for a product scene, as well as its source scenes. |
- s1ard.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, optional) –
- 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, optional) – If True, the calculated ENL array is returned. Default is False.
decimals (int, optional) – Number of decimal places to round the calculated ENL value to. Default is 2.
- Raises:
RuntimeError – if the input array contains only NaN values
- 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.
- Return type:
float or None or numpy.ndarray
References
[2]
- s1ard.metadata.extract.calc_geolocation_accuracy(swath_identifier, ei_tif, etad, decimals=2)[source]
Calculates the radial root mean square error, which is a target requirement of the CARD4L NRB specification (Item 4.3). For more information see: https://s1ard.readthedocs.io/en/latest/general/geoaccuracy.html. Currently only the Copernicus DEM is supported.
- Parameters:
swath_identifier (str) – Swath identifier dependent on acquisition mode.
ei_tif (str) – Path to the annotation GeoTIFF layer ‘Ellipsoidal Incident Angle’ of the current product.
etad (bool) – Was the ETAD correction applied?
decimals (int, optional) – Number of decimal places to round the calculated rRMSE value to. Default is 2.
- Returns:
rmse_planar – The calculated rRMSE value rounded to two decimal places or None if a DEM other than Copernicus is used.
- Return type:
float or None
- s1ard.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:
- Returns:
out – Dictionary containing the calculated estimates for each available polarization.
- Return type:
- s1ard.metadata.extract.calc_pslr_islr(annotation_dict, decimals=2)[source]
Extracts all values for Peak Side Lobe Ratio (PSLR) and Integrated Side Lobe Ratio (ISLR) from the annotation metadata of a scene and calculates the mean value for all swaths.
- Parameters:
- Returns:
a tuple with the following values:
pslr: Mean PSLR value for all swaths of the scene.
islr: Mean ISLR value for all swaths of the scene.
- Return type:
- s1ard.metadata.extract.calc_wm_ref_stats(wm_ref_files, epsg, bounds, resolution=915)[source]
Calculates the mean wind model reference speed and direction for the wind model annotation layer.
- Parameters:
- Returns:
a tuple with the following values in the following order:
Mean wind model reference speed.
Mean wind model reference direction.
- Return type:
- s1ard.metadata.extract.copy_src_meta(ard_dir, src_ids)[source]
Copies the original metadata of the source scenes to the ARD product directory.
- Parameters:
ard_dir (str) – A path pointing to the current ARD product directory.
src_ids (list[pyroSAR.drivers.ID]) – List of
IDobjects of all source scenes that overlap with the current MGRS tile.
- Return type:
None
- s1ard.metadata.extract.find_in_annotation(annotation_dict, pattern, single=False, out_type='str')[source]
Search for a pattern in all XML annotation files provided and return a dictionary of results.
- Parameters:
annotation_dict (dict) – A dict of annotation files in the form: {‘swath ID’: lxml.etree._Element object}
pattern (str) – The pattern to search for in each annotation file.
single (bool) – If True, the results found in each annotation file are expected to be the same and therefore only a single value will be returned instead of a dict. If the results differ, an error is raised. Default is False.
out_type (str) –
Output type to convert the results to. Can be one of the following:
’str’ (default)
’float’
’int’
- Returns:
out – A dictionary of the results containing a list for each of the annotation files. E.g., {‘swath ID’: list[str or float or int]}
- Return type:
- s1ard.metadata.extract.geometry_from_vec(vectorobject)[source]
Get geometry information for usage in STAC and XML metadata from a
spatialist.vector.Vectorobject.- Parameters:
vectorobject (spatialist.vector.Vector) – The vector object to extract geometry information from.
- Returns:
out – A dictionary containing the geometry information extracted from the vector object.
- Return type:
- s1ard.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:
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.
- s1ard.metadata.extract.get_osv_info(sid)[source]
Get information about the used OSV file. First, this function attempts to find an auxiliary OSV file matching the scene. If found, its name is returned. If not, it is assumed that it is not yet available and processing was performed using the OSVs found in the source product. In this case, the metadata is searched for the name of an auxiliary OSV file used during L1 generation. If found, its name is returned.
- Parameters:
sid (pyroSAR.drivers.ID) – The pyroSAR scene ID object
- Returns:
the OSV file’s basename and the OSV type description. None is returned if no OSV file is found.
- Return type:
See also
- s1ard.metadata.extract.get_prod_meta(product_id, tif, src_ids, sar_dir, processor_name)[source]
Returns a metadata dictionary, which is generated from the name of a product scene using a regular expression pattern and from a measurement GeoTIFF file of the same product scene using the
Rasterclass.- Parameters:
product_id (str) – The top-level product folder name.
tif (str) – The path to a measurement GeoTIFF file of the product scene.
src_ids (list[pyroSAR.drivers.ID]) – List of
IDobjects of all source SLC scenes that overlap with the current MGRS tile.sar_dir (str) – A path pointing to the processed SAR datasets of the product.
processor_name (str) – The name of the SAR processor. Needed for reading processing metadata.
- Returns:
A dictionary containing metadata for the product scene.
- Return type:
- s1ard.metadata.extract.get_src_meta(sid)[source]
Retrieve the manifest and annotation XML data of a scene as a dictionary using an
pyroSAR.drivers.IDobject.- Parameters:
sid (pyroSAR.drivers.ID) – A pyroSAR
IDobject generated with e.g.pyroSAR.drivers.identify().- Returns:
A dictionary containing the parsed etree.ElementTree objects for the manifest and annotation XML files.
- Return type:
- s1ard.metadata.extract.meta_dict(config, target, src_ids, sar_dir, proc_time, start, stop, compression, product_type, wm_ref_files=None)[source]
Creates a dictionary containing metadata for a product scene, as well as its source scenes. The dictionary can then be used by
parse()andparse()to generate OGC XML and STAC JSON metadata files, respectively.- Parameters:
config (dict) – Dictionary of the parsed config parameters for the current process.
target (str) – A path pointing to the current ARD product directory.
src_ids (list[pyroSAR.drivers.ID]) – List of
IDobjects of all source scenes that overlap with the current MGRS tile.sar_dir (str) – The SAR processing output directory.
proc_time (datetime.datetime) – The processing time object used to generate the unique product identifier.
start (datetime.datetime) – The product start time.
stop (datetime.datetime) – The product stop time.
compression (str) – The compression type applied to raster files of the product.
product_type (str) – The type of ARD product that is being created. Either ‘NRB’ or ‘ORB’.
wm_ref_files (list[str], optional) – A list of paths pointing to wind model reference files. Default is None.
- Returns:
meta – A dictionary containing a collection of metadata for product as well as source scenes.
- Return type:
XML
Wrapper for |
|
Function to generate product-level metadata for an ARD product in OGC 10-157r4 compliant XML format. |
|
Function to generate source-level metadata for an ARD product in OGC 10-157r4 compliant XML format. |
- s1ard.metadata.xml.parse(meta, target, assets, exist_ok=False)[source]
Wrapper for
source_xml()andproduct_xml().- Parameters:
meta (dict) – Metadata dictionary generated with
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?
- s1ard.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) – Metadata dictionary generated with
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) – 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?
- s1ard.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) – Metadata dictionary generated with
meta_dict()target (str) – A path pointing to the root directory of a product scene.
nsmap (dict) – 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?
STAC
Wrapper for |
|
Function to generate product-level metadata for an ARD product in STAC compliant JSON format. |
|
Function to generate source-level metadata for an ARD product in STAC compliant JSON format. |
|
For a given directory of Sentinel-1 ARD products, this function will create a high-level STAC |
- s1ard.metadata.stac.make_catalog(directory, product_type, recursive=True, silent=False)[source]
For a given directory of Sentinel-1 ARD products, this function will create a high-level STAC
Catalogobject serving as the STAC endpoint and lower-level STACCollectionobjects for each subdirectory corresponding to a unique MGRS tile ID.WARNING: The directory content will be reorganized into subdirectories based on the ARD type and unique MGRS tile IDs if this is not yet the case.
- Parameters:
directory (str) – Path to a directory that contains ARD products.
product_type (str) – Type of ARD products. Options: ‘NRB’ or ‘ORB’.
recursive (bool, optional) – Search directory recursively? Default is True.
silent (bool, optional) – Should the output during directory reorganization be suppressed? Default is False.
- Returns:
nrb_catalog – STAC Catalog object
- Return type:
Notes
The returned STAC Catalog object contains Item asset hrefs that are absolute, whereas the actual on-disk files contain relative asset hrefs corresponding to the self-contained Catalog-Type. The returned in-memory STAC Catalog object deviates in this regard to ensure compatibility with the stackstac library: https://github.com/gjoseph92/stackstac/issues/20
- s1ard.metadata.stac.parse(meta, target, assets, exist_ok=False)[source]
Wrapper for
source_json()andproduct_json().- Parameters:
- s1ard.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) – Metadata dictionary generated with
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?
- s1ard.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) – Metadata dictionary generated with
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?