sisppeo.utils package

Submodules

sisppeo.utils.algos module

Contains various useful functions used by algorithms.

sisppeo.utils.algos.load_calib(calibration, default_calibration_file, default_calibration_name)[source]

Loads parameters for a given calibration name/file.

Parameters
  • calibration – calibration name or path. 1. If ‘calibration’ is a string, it refers to a calibration included in SISPPEO (this calibration name is an entry of the ‘default_calibration_file’). 2. If ‘calibration’ is a path, it refers to a calibration given by the user, embedded in a standalone file (see the docs for the detailed structure of this file).

  • default_calibration_file – path of the default calibration file (for a given algorithm).

  • default_calibration_name – name of the default calibration (for a given algorithm).

Returns

A dict of parameters (model coefficients) and the name of the chosen calibration.

sisppeo.utils.algos.producttype_to_sat(product_type)[source]

Returns the satellite for the given product_type.

Parameters

product_type – The type of the input satellite product (e.g. S2_ESA_L2A or L8_USGS_L1)

Returns

The name of the satellite that matches the input product_type.

sisppeo.utils.builders module

Contains a useful function used in main.py.

sisppeo.utils.builders.get_variables(algo_config, algo_name)[source]

Read variable (=output of a given algorithm) (long_)names from config.

Parameters
  • algo_config – A configuration dict (loaded from a YAML file, e.g. wc_algo_config.yaml).

  • algo_name – The name of the algorithm.

sisppeo.utils.cli module

Contains various useful functions and classes used in the CLI.

class sisppeo.utils.cli.Mutex(*args, **kwargs)[source]

Bases: click.core.Option

Mutually exclusive options (with at least one required).

handle_parse_result(ctx, opts, args)[source]
class sisppeo.utils.cli.Mutin(*args, **kwargs)[source]

Bases: click.core.Option

Mutually inclusive options.

handle_parse_result(ctx, opts, args)[source]
class sisppeo.utils.cli.PathPath(exists=False, file_okay=True, dir_okay=True, writable=False, readable=True, resolve_path=False, allow_dash=False, path_type=None)[source]

Bases: click.types.Path

A Click path argument that returns a pathlib Path, not a string

convert(value, param, ctx)[source]

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters
  • value – The value to convert.

  • param – The parameter that is using this type to convert its value. May be None.

  • ctx – The current context that arrived at this value. May be None.

name

the descriptive name of this type

sisppeo.utils.cli.read_algos_list(path)[source]

Parse a text file and return a config dictionnary.

sisppeo.utils.cli.read_masks_list(path)[source]

Parse a text file and return a config dictionnary.

sisppeo.utils.cli.read_products_list(path, is_ts=False)[source]

Parse a text file and return a config dictionnary.

sisppeo.utils.config module

Contains paths and configs used in other parts of the code.

sisppeo.utils.exceptions module

Contains custom exceptions used in other parts of the code.

exception sisppeo.utils.exceptions.GeometryError[source]

Bases: Exception

Exception raised for errors related to geometry objects.

exception sisppeo.utils.exceptions.InputError[source]

Bases: Exception

Exception raised for errors in inputs.

exception sisppeo.utils.exceptions.ProductError[source]

Bases: Exception

Exception raised for errors with the input product.

sisppeo.utils.lazy_loader module

A LazyLoader class.

Slightly adapted from the one of TensorFlow, see: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/lazy_loader.py

class sisppeo.utils.lazy_loader.LazyLoader(local_name, parent_module_globals, name)[source]

Bases: module

Lazily import a module, mainly to avoid pulling in large dependencies.

sisppeo.utils.main module

Contains various useful functions used in main.py.

sisppeo.utils.main.parse_params(key, params)[source]

Parse and verify params given to the function generate (main.py).

sisppeo.utils.main.series_to_batch(args, n)[source]
sisppeo.utils.main.str_to_path(path_str, exists=True)[source]

Converts a path string to a pathlib.Path object.

Parameters
  • path_str – a path string.

  • exists – a boolean whether to check if this path exists or not.

sisppeo.utils.naming module

Contains various useful functions used for naming products.

sisppeo.utils.naming.extract_info_from_input_product(input_product, product_type, code_site=None, geom=None)[source]

Extracts some information from the given input product.

sisppeo.utils.naming.generate_l3_filename(l3prod, code_image, source, roi)[source]

Returns a filename for a L3 product based on the provided arguments.

sisppeo.utils.naming.generate_ts_filename(ts, sat, source, roi)[source]

Returns a filename for time series based on the provided arguments.

sisppeo.utils.naming.geom_to_str(geom_dict)[source]

Returns the (lat, lon) of top-left point of a geometry.

sisppeo.utils.naming.topleftlatlon_from_wkt(wkt_string)[source]

Returns the (lat, lon) of the top-left point of a WKT string.

sisppeo.utils.products module

Contains useful stuff for products.

class sisppeo.utils.products.CoordinatesMixin[source]

Bases: object

A Mixin which adds extra properties and methods related to coordinates.

property bounds

(xmin, ymin, xmax, ymax).

Type

Returns the boundaries of this product

extract_point(data_var, coordinates, buffer=None, epsg=4326, mode='xy')[source]

Returns value(s) at the given coordinates.

Parameters
  • data_var – The name of the variable/DataArray of interest (e.g., a band, aCDOM, etc).

  • coordinates – A tuple of geographic or projected coordinates; see “mode”.

  • buffer – Optional; The radius (in pixels) of the circle (centered on coordinates) to extract. Defaults to None.

  • epsg – Optional; The EPSG code. Defaults to 4326.

  • mode – Optional; Either ‘xy’ or ‘latlon’. Defaults to ‘xy’.

Returns

An xr.DataArray containing the wanted information.

extract_points(data_var, lst_coordinates, buffer=None, epsg=4326, mode='xy')[source]

Returns value(s) at each tuple of coordinates of the given list.

Parameters
  • data_var – The name of the variable/DataArray of interest (e.g., a band, aCDOM, etc).

  • lst_coordinates – A list of tuples of geographic or projected coordinates; see “mode”.

  • buffer – Optional; The radius (in pixels) of the circle (centered on coordinates) to extract. Defaults to None.

  • epsg – Optional; The EPSG code. Defaults to 4326.

  • mode – Optional; Either ‘xy’ or ‘latlon’. Defaults to ‘xy’.

Returns

A list of xr.DataArray (one per coordinates tuple) containing the wanted information.

index(x, y)[source]

Gets (i, j) from (x, y)

property res

Returns the spatial resolution of this product.

property x

Returns x-coords.

xy(i, j)[source]

Gets (x, y) from (i, j).

property y

Returns y-coords.

sisppeo.utils.products.get_enc(array, scale_factor, compression=False)[source]
sisppeo.utils.products.get_grid(n)[source]

Gets the number of rows and columns needed according the number of subplots.

sisppeo.utils.products.normalize_arr(arr, min_, max_, new_max=255)[source]

Normalize an array between 0 and new_max.

Parameters
  • arr – The input array.

  • min – The value to consider as being the min of the array.

  • max – The value to consider as being the min of the array.

  • new_max – The maximum value of the output array.

sisppeo.utils.readers module

Contains various useful functions used by readers.

sisppeo.utils.readers.decode_data(arr, scale_factor, fill_value, offset=0)[source]

Reads and decodes encoded data.

Parameters
  • arr – The input encoded array of values.

  • scale_factor – coefficient.

  • fill_value ([type]) – coefficient.

  • offset – Optional; coefficient.

Returns

The decoded array.

sisppeo.utils.readers.get_ij_bbox(subdataset, geom)[source]

Clips the subdataset with the geometry.

Parameters
  • subdataset – An open rasterio.io DatasetReader.

  • geom – A shapley geometry object.

Returns

The corresponding bbox.

sisppeo.utils.readers.resample_band_array(arr, in_res, out_res, tqdm_=True)[source]

Resamples an array.

Parameters
  • arr – An array of (radiometric) values.

  • in_res – The input resolution.

  • out_res – The output resolution.

  • tqdm – Optional; True if in a tqdm loop.

Returns

The resampled array.

sisppeo.utils.readers.resize_and_resample_band_array(arr, ij_bbox, in_res, out_res, _tqdm=True)[source]

Resamples and resizes an array.

Parameters
  • arr – An array of (radiometric) values.

  • ij_bbox – The bbox of the ROI.

  • in_res – The input resolution.

  • out_res – The output resolution.

  • _tqdm – Optional; True if in a tqdm loop.

Returns

The resampled ROI.

sisppeo.utils.registration module

Contains functions related to algorithm&mask registration.

sisppeo.utils.registration.check_algoconfig()[source]

Print a warning message if an algorithm lacks its configuration file.

sisppeo.utils.registration.register_algos(catalog)[source]

Register each algorithm into a dictionary.

Parameters

catalog – the dictionary in which will be stored algorithms.

sisppeo.utils.registration.register_masks(catalog)[source]

Register each mask into a dictionary.

Parameters

catalog – the dictionary in which will be stored masks.

Module contents