Ancillary Functions
Buffer a rectangular geometry to a minimum overlap with a second geometry. |
|
Time range buffering |
|
Check the consistency of a scene selection. |
|
Check whether the spacing fits into the MGRS tile boundaries. |
|
Combine polygon vector objects into one. |
|
Compute the (multi)hash of a file using the specified algorithm. |
|
Create data masks for a given image file. |
|
convert a date object to a UTC date string or datetime object. |
|
Convert a (nested) defaultdict to a regular dictionary. |
|
Returns a unique product identifier as a hexadecimal string. |
|
Download the Sentinel-2 MGRS grid KML file. |
|
Gets the maximum extent from a list of geometries. |
|
Get the name of a temporary file with defined suffix. |
|
Group items based on a key function. |
|
Group scenes by their acquisition time difference. |
|
Convert a pixel size from meters to degrees. |
|
Add overviews to an existing VRT file. |
- cesard.ancillary.buffer_min_overlap(geom1, geom2, percent=1, step=None)[source]
Buffer a rectangular geometry to a minimum overlap with a second geometry. The geometry is iteratively buffered until the minimum overlap is reached. If the overlap of the input geometries is already larger than the defined threshold, a copy of the original geometry is returned.
- Parameters:
- Return type:
- cesard.ancillary.buffer_time(start, stop, as_datetime=False, str_format='%Y%m%dT%H%M%S', **kwargs)[source]
Time range buffering
- Parameters:
start (
str) – the start time date object to convert; timezone-unaware dates are interpreted as UTC.stop (
str) – the stop time date object to convert; timezone-unaware dates are interpreted as UTC.as_datetime (
bool) – return datetime objects instead of strings?str_format (
str) – the output string format (ignored if as_datetime is True)kwargs – time arguments passed to
datetime.timedelta()
- Return type:
- Returns:
the buffered start and stop time as string or datetime object
- cesard.ancillary.check_scene_consistency(scenes)[source]
Check the consistency of a scene selection. The following pyroSAR object attributes must be the same:
sensor
acquisition_mode
product
frameNumber (data take ID for Sentinel-1)
- Parameters:
- Raises:
- Return type:
- cesard.ancillary.check_spacing(spacing)[source]
Check whether the spacing fits into the MGRS tile boundaries.
- cesard.ancillary.combine_polygons(vector, crs=4326, multipolygon=False, layer_name='combined')[source]
Combine polygon vector objects into one. The output is a single vector object with the polygons either stored in separate features or combined into a single multipolygon geometry.
- Parameters:
vector (
Vector|list[Vector]) – the input vector object(s). Providing only one object only makes sense when multipolygon=True.multipolygon (
bool) – combine all polygons into one multipolygon? Default False: write each polygon into a separate feature.layer_name (
str) – the layer name of the output vector object.
- Return type:
- Returns:
the combined vector object
- cesard.ancillary.compute_hash(file_path, algorithm='sha256', chunk_size=8192, multihash_encode=True)[source]
Compute the (multi)hash of a file using the specified algorithm.
- Parameters:
file_path (
str) – Path to the file.algorithm (
str) – Hash algorithm to use (default is ‘sha256’).chunk_size (
int) – Size of chunks to read from the file in bytes (default is 8192).multihash_encode (
bool) – Encode the hash according to the multihash specification (default is True)? The hash generated by hashlib will be wrapped usingmultiformats.multihash.wrap().
- Return type:
- Returns:
the hexadecimal hash string of the file.
See also
- cesard.ancillary.datamask(measurement, dm_ras, dm_vec)[source]
Create data masks for a given image file. The created raster data mask does not contain a simple mask of nodata values. Rather, a boundary vector geometry containing all valid pixels is created and then rasterized. This boundary geometry (single polygon) is saved as dm_vec. In this case dm_vec is returned. If the input image only contains nodata values, no raster data mask is created, and an empty dummy vector mask is created. In this case the function will return None.
- cesard.ancillary.date_to_utc(date, as_datetime=False, str_format='%Y%m%dT%H%M%S')[source]
convert a date object to a UTC date string or datetime object.
- Parameters:
- Return type:
- Returns:
the date string or datetime object in UTC time zone
- cesard.ancillary.defaultdict_to_dict(d)[source]
Convert a (nested) defaultdict to a regular dictionary.
- Parameters:
d (
defaultdict) – the defaultdict to convert- Return type:
- Returns:
the converted dictionary
- cesard.ancillary.generate_unique_id(encoded_str, length=4)[source]
Returns a unique product identifier as a hexadecimal string. The CRC-16 algorithm used to compute the unique identifier is CRC-CCITT (0xFFFF). The resulting CRC value is truncated to the number of hexadecimal characters specified by the length argument.
- Parameters:
encoded_str (
bytes) – A string that should be used to generate a unique id from. The string needs to be encoded; e.g.: ‘abc’.encode().length (
int) – The desired length of the output string in hexadecimal characters (max: 4). Values higher than 4 will be capped at 4, since CRC-16 only produces 16 bits.
- Return type:
- Returns:
The unique product identifier (upper-case hexadecimal string).
- cesard.ancillary.get_kml()[source]
Download the Sentinel-2 MGRS grid KML file. The target folder is ~/cesard.
- Return type:
- Returns:
the path to the KML file
- cesard.ancillary.get_max_ext(geometries, buffer=None, crs=None)[source]
Gets the maximum extent from a list of geometries.
- Parameters:
- Return type:
- Returns:
The maximum extent of the selected
Vectorgeometries including the chosen buffer.
- cesard.ancillary.get_tmp_name(suffix)[source]
Get the name of a temporary file with defined suffix. Files are placed in a subdirectory ‘cesard’ of the regular temporary directory so the latter is not flooded with too many files in case they are not properly deleted.
- cesard.ancillary.group_by_attr(items, key_fn)[source]
Group items based on a key function.
- Parameters:
- Return type:
- Returns:
A list of groups, where each group is a list of items with the same key.
Example
>>> list_in = ['abc', 'axy', 'brt', 'btk'] >>> print(group_by_attr(list_in, lambda x: x[0])) [['abc', 'axy'], ['brt', 'btk']]
>>> list_in = [{'a': 1}, {'a': 2}, {'a': 1}, {'a': 2}] >>> print(group_by_attr(list_in, lambda x: x['a'])) [[{'a': 1}, {'a': 1}], [{'a': 2}, {'a': 2}]]
- cesard.ancillary.group_by_time(scenes, time=3)[source]
Group scenes by their acquisition time difference.
- Parameters:
- Return type:
- Returns:
a list of sub-lists containing the file names of the grouped scenes
- cesard.ancillary.pixel_size_degrees(lon, lat, xres, yres)[source]
Convert a pixel size from meters to degrees.
- Parameters:
- Return type:
- Returns:
the x and y resolution in degrees
See also