sisppeo.products package

Submodules

sisppeo.products.l3 module

This module gathers classes related to L3 products.

In this module are defined L3 products : the abstract class L3Product and its child classes L3AlgoProduct and L3MaskProduct. Basically, these classes wrap a well formated xarray Dataset and offer a few useful methods.

Example:

S2_ndvi = L3AlgoProduct(dataset)
S2_ndvi.plot()
S2_ndvi.save(path_to_file)

s2cloudless_mask = L3MaskProduct(dataset)
s2cloudless_mask.save(path_to_file)
class sisppeo.products.l3.L3AlgoProduct(dataset)[source]

Bases: sisppeo.products.l3.L3Product

An L3Product embedding data obtained by using a wc/land algorithm.

dataset

A dataset containing processed data.

Type

xarray.core.dataset.Dataset

property algo

Returns the name of the algorithm used to get this dataset.

classmethod from_file(filename)[source]
save(filename)[source]

See base class.

class sisppeo.products.l3.L3MaskProduct(dataset)[source]

Bases: sisppeo.products.l3.L3Product

An L3Product embedding data obtained by using a mask algorithm.

dataset

A dataset containing processed data.

Type

xarray.core.dataset.Dataset

classmethod from_file(filename)[source]
property mask

Returns the name of the mask used to get this dataset.

save(filename)[source]

See base class.

class sisppeo.products.l3.L3Product(dataset)[source]

Bases: abc.ABC, sisppeo.utils.products.CoordinatesMixin

Abstract class inherited by both L3AlgoProduct and L3MaskProduct.

dataset

A dataset containing processed data.

Type

xarray.core.dataset.Dataset

property data_vars

Returns a list of DataArrays corresponding to variables.

dataset
abstract classmethod from_file(filename)[source]

Loads and returns a L3Product from file.

Parameters

filename – The path to the L3Product (saved as a netCDF file).

plot(data_var)[source]

Plots a given variable.

data_var: The name of the variable/DataArray of interest (e.g., a

band, aCDOM, etc).

property product_type

Returns the product_type of the product used to get this dataset.

abstract save(filename)[source]

Saves this product into a netCDF file.

Parameters

filename – Path of the output file.

property title

Returns the title of the underlying dataset.

sisppeo.products.l3.mask_product(l3_algo, l3_masks, lst_mask_type, inplace=False)[source]

Masks an L3AlgoProduct.

Masks an L3AlgoProduct with one or more L3MaskProducts. It can be used for instance to get rid of clouds or to extract only water areas.

Parameters
  • l3_algo – The L3AlgoProduct to be masked.

  • l3_masks – The mask or list of masks to use.

  • lst_mask_type – The type of the input mask (or the list of the types of input masks). Can either be ‘IN’ or ‘OUT’, indicating if the corresponding mask is inclusive or exclusive.

  • inplace – If True, do operation inplace and return None.

Returns

A masked L3AlgoProduct.

sisppeo.products.timeseries module

This module contains the TimeSeries class.

A TimeSeries object is a new kind of product, made from either L1, L2, or L3 products, and allowing one to build a time series:

  • Masks can be used to clip data.

  • Basic statistics can be calculated.

  • Generic plots can easily be made.

Example:

paths = [<first S2_ESA_L2A product>, <second S2_ESA_L2A product>, ...,
       <n-th S2_ESA_L2A product>]
mask_paths = [
    [<first water_mask>, <second water_mask>, ..., <n-th water_mask>],
    [<first mask2>
config = {
    'paths': paths,
    'product_type': 'S2_ESA_L2A',
    'requested_bands': ['B2', 'B3', 'B4', 'B5', 'B6'],
    'wkt': wkt,
    'srid': 4326,
}
S2L2A_ts = factory.create('TS', **config)
S2L2A_ts.compute_stats(<filename>)
S2L2A_ts.plot()
class sisppeo.products.timeseries.TimeSeries(dataset)[source]

Bases: sisppeo.utils.products.CoordinatesMixin

A ‘L4’ product, made from either L1, L2, or L3 products.

This product contain one or more DataArrays (e.g., one for ndwi, one for each band extracted…). Each DataArrays is a data cube (i.e. 3D: x, y, time). It allows one to study time series of data, and compute and plot statistics over time and/or space.

dataset

A dataset containing one or more 3D-dataarrays.

Type

xarray.core.dataset.Dataset

compute_stats(filename, plot=True)[source]

Computes (and save on disk) statistics about embedded data at each date.

Parameters
  • filename – The path of the output product (a CSV file).

  • plot – A boolean flag that indicates if computed statistics should be plotted or not.

property data_vars

Returns a list of DataArrays corresponding to variables.

dataset
property end_date

Return the end date.

classmethod from_file(filename)[source]

Load a TimeSeries object from disk.

Parameters

filename – The path of the netCDF file.

Returns

time, x, y).

Return type

A TimeSeries object (i.e. a 3D dataset

classmethod from_files(paths)[source]

Load and merge a list of L3 products from disk.

Parameters

paths – A list of paths (to L3 products saved as netCDF files).

Returns

time, x, y).

Return type

A TimeSeries object (i.e. a 3D dataset

classmethod from_l3products(lst)[source]

Load and merge a list of L3 products.

Parameters

lst – A list of L3 products (loaded in memory).

Returns

time, x, y).

Return type

A TimeSeries object (i.e. a 3D dataset

get_max_map(var, plot=True, filename=None, save=False, savefig=False, fmt='jpeg')[source]

Gets the map of (temporal) max values for a given data_var.

Compute a map (a dataarray of dimension N * M) from a dataarray of dimension t * N * M. Each pixel of this map is the max value of the N * M t-vectors.

Parameters
  • var – The name of the dataarray to use.

  • plot – A boolean flag that indicates if the figure should be plotted or not.

  • filename – Optional; The path of the output product (a figure and/or a netCDF file).

  • save – Optional; A boolean flag that indicates if the mean map should be saved on disk or not.

  • savefig – Optional; A boolean flag that indicates if the figure should be saved or not.

  • fmt – The format of the static image that is saved on disk. Can be either “png”, “jpeg”, “webp”, “svg” or “pdf”.

Returns

A map (a dataarray of dimension N * M) of max values for a given data_var.

get_mean_map(var, plot=True, filename=None, save=False, savefig=False, fmt='jpeg')[source]

Gets the map of (temporal) mean values for a given data_var.

Compute a map (a DataArray of dimension N * M) from a DataArray of dimension t * N * M. Each pixel of this map is the mean value of the N * M t-vectors.

Parameters
  • var – The name of the DataArray to use.

  • plot – A boolean flag that indicates if the figure should be plotted or not.

  • filename – Optional; The path of the output product (a figure and/or a netCDF file).

  • save – Optional; A boolean flag that indicates if the mean map should be saved on disk or not.

  • savefig – Optional; A boolean flag that indicates if the figure should be saved or not.

  • fmt – The format of the static image that is saved on disk. Can be either “png”, “jpeg”, “webp”, “svg” or “pdf”.

Returns

A map (a dataarray of dimension N * M) of mean values for a given data_var.

get_min_map(var, plot=True, filename=None, save=False, savefig=False, fmt='jpeg')[source]

Gets the map of (temporal) min values for a given data_var.

Compute a map (a dataarray of dimension N * M) from a dataarray of dimension t * N * M. Each pixel of this map is the min value of the N * M t-vectors.

Parameters
  • var – The name of the dataarray to use.

  • plot – A boolean flag that indicates if the figure should be plotted or not.

  • filename – Optional; The path of the output product (a figure and/or a netCDF file).

  • save – Optional; A boolean flag that indicates if the mean map should be saved on disk or not.

  • savefig – Optional; A boolean flag that indicates if the figure should be saved or not.

  • fmt – The format of the static image that is saved on disk. Can be either “png”, “jpeg”, “webp”, “svg” or “pdf”.

Returns

A map (a dataarray of dimension N * M) of min values for a given data_var.

plot_1d(lst_coordinates, data_var='all', buffer=None, epsg=4326, mode='xy', filename=None, fmt='jpeg')[source]

Plots time series of data_var(s) for one or more given points.

Parameters
  • lst_coordinates – A tuple of coordinates (x, y) that locates the point to extract (/a list of tuples of coordinates, locating points of interest).

  • data_var – Optional; A variable (e.g. “aCDOM”) or a list of variables to plot.

  • buffer

  • epsg

  • mode

  • filename – Optional; If a filename is provided, the figure will be saved using this path.

  • fmt – The format of the exported figure. Can be either “png”, “jpeg”, “webp”, “svg” or “pdf”.

plot_2d(data_vars='all', filename=None, fmt='jpeg')[source]

Plots timelapse as a mosaic (one per data_var).

For each data_var, create a figure composed of multiples subplots, each one of them being a image of the given data_var at a given date.

Parameters
  • data_vars – A variable (e.g. “aCDOM”) or a list for variables to plot. If ‘all’, creates a figure for each variable (i.e. DataArray) embedded into this dataset.

  • filename – Optional; If a filename is provided, the figure will be saved using this path.

  • fmt – The format of the exported figure. Can be either “png”, “jpeg”, “webp”, “svg” or “pdf”.

plot_hists(data_vars='all', dates='all', plot=True, filename=None, fmt='jpeg')[source]

Plots an histogram (per data_var, per date).

For each data_var, at each date, plots an histogram using the right array of values.

Parameters
  • data_vars – The name of the dataarray to plot. If ‘all’, create a figure for each dataarray (i.e. for each data_var in data_vars).

  • dates – The wanted date. If ‘all’, create a histogram for each date.

  • plot – A boolean flag that indicates if the figure should be plotted or not.

  • filename – Optional; The path of the output figure.

  • fmt – The format of the static image that is saved on disk. Can be either “png”, “jpeg”, “webp”, “svg” or “pdf”.

plot_stats_maps(data_vars='all', filename=None, savefig=False, fmt='jpeg')[source]

Plots a figure of stats (temporal mean/min/max) map (one per data_var).

For each data_var, create a figure composed of 3 subplots : a mean-, min-, and max-map. See ‘get_mean_map’, ‘get_min_map’, and ‘get_max_map’ for more information about what the so-called maps are.

Parameters
  • data_vars – The name of the dataarray to plot. If ‘all’, create a figure for each dataarray (i.e. for each data_var in data_vars).

  • filename – Optional; The path of the output figure.

  • savefig – Optional; A boolean flag that indicates if the figure should be saved or not.

  • fmt – The format of the static image that is saved on disk. Can be either “png”, “jpeg”, “webp”, “svg” or “pdf”.

save(filename)[source]

See base class.

property start_date

Return the start date.

timelapse(data_vars, filename, out_res=None, write_time=True)[source]

Creates a timelapse and save it on disk (as a GIF file).

Parameters
  • data_vars – The data_var(s) to plot; 1 for a grayscale image, and a list of 3 for a RGB one.

  • filename – The path of the output gif.

  • out_res – The resolution of the timelapse; must be coarser than the one of the time series.

  • write_time – If True, the corresponding date will be written on each frame.

property title

Returns the title of the underlying dataset.

sisppeo.products.timeseries.cond_resample(arr, in_res, out_res)[source]

See resample_band_array(…).

sisppeo.products.timeseries.mask_time_series(ts_algo, ts_masks, lst_mask_type, inplace=False)[source]

Masks time series of L3AlgoProducts.

Masks a TimeSeries made of L3AlgoProducts with one (or multiple ones) made of L3MaskProducts. It can be used for instance to get rid of clouds or to extract only water areas.

Parameters
  • ts_algo – The TimeSeries to be masked.

  • ts_masks – The TimeSeries or list of TimeSeries to use as mask (/list of masks).

  • lst_mask_type – The type of the input mask (or the list of the types of input masks). Can either be ‘IN’ or ‘OUT’, indicating if the corresponding mask is inclusive or exclusive.

  • inplace – If True, do operation inplace and return None.

Returns

A masked TimeSeries.

Module contents