SENTINEL2

apply_qa(ds, var)

Mask SENTINEL2 data using a qa variable.

Parameters
  • ds (xr.Dataset) – Input data, should contain “qa” and var as variables.

  • var (str) – Variable name in ds to be masked.

Returns

Masked dataset.

Return type

xr.Dataset

mask_invalid(ds, var, valid_range=(1, 65534))

Mask invalid data.

Parameters
  • ds (xr.Dataset) – Input data.

  • var (str) – Variable to mask.

  • valid_range (tuple, optional) – Range of valid values in var, by default (1, 65534).

Returns

Masked data.

Return type

xr.Dataset

scale_data(ds, var)

Apply a scale and offset factor to ds.

Parameters
  • ds (xr.Dataset) – Input dataset.

  • var (str) – Variable to scale and offset.

Returns

Output data.

Return type

xr.Dataset

calc_normalized_difference(ds, var, bands=['nir', 'red'])

Calculate the normalized difference of two bands.

Parameters
  • ds (xr.Dataset) – Input data.

  • var (str) – Name of the variable in which to store the normalized difference.

  • bands (list, optional) – The two bands to use to calculate the norm. difference, by default [“nir”, “red”].

Returns

Output data.

Return type

xr.Dataset

calc_psri(ds, var)

Calculate the PSRI as (“red” - “blue)/”red_edge_740”.

Parameters
  • ds (xr.Dataset) – Input data.

  • var (str) – Name of the variable in which to store the normalized difference.

Returns

Output data.

Return type

xr.Dataset

calc_nmdi(ds, var)

Calculate the NMDI.

Parameters
  • ds (xr.Dataset) – Input data.

  • var (str) – Name of the variable in which to store the normalized difference.

Returns

Output data.

Return type

xr.Dataset

calc_bsi(ds, var)

Calculate the BSI.

Parameters
  • ds (xr.Dataset) – Input data.

  • var (str) – Name of the variable in which to store the normalized difference.

Returns

Output data.

Return type

xr.Dataset

calc_vari_red_egde(ds, var)

Calculate the VARI_RED_EDGE.

Parameters
  • ds (xr.Dataset) – Input data.

  • var (str) – Name of the variable in which to store the normalized difference.

Returns

Output data.

Return type

xr.Dataset

calc_r0(ds, var)

Calculate the Albedo.

Parameters
  • ds (xr.Dataset) – Input data.

  • var (str) – Name of the variable in which to store the normalized difference.

Returns

Output data.

Return type

xr.Dataset

default_vars(product_name, req_vars)

Given a product_name and a list of requested variables, returns a dictionary with metadata on which exact layers need to be requested from the server, how they should be renamed, and how their dimensions are defined.

Parameters
  • product_name (str) – Name of the product.

  • req_vars (list) – List of variables to be collected.

Returns

Metadata on which exact layers need to be requested from the server.

Return type

dict

default_post_processors(product_name, req_vars)

Given a product_name and a list of requested variables, returns a dictionary with a list of functions per variable that should be applied after having collected the data from a server.

Parameters
  • product_name (str) – Name of the product.

  • req_vars (list) – List of variables to be collected.

Returns

Functions per variable that should be applied to the variable.

Return type

dict

time_func(fn)

Return a np.datetime64 given a filename.

Parameters

fn (str) – Filename.

Returns

Date as described in the filename.

Return type

np.datetime64

download(folder, latlim, lonlim, timelim, product_name, req_vars, variables=None, post_processors=None, extra_search_kwargs={'cloudcoverpercentage': (0, 30)})

Download SENTINEL2 data and store it in a single netCDF file.

Parameters
  • folder (str) – Path to folder in which to store results.

  • latlim (list) – Latitude limits of area of interest.

  • lonlim (list) – Longitude limits of area of interest.

  • timelim (list) – Period for which to prepare data.

  • product_name (str) – Name of the product to download.

  • req_vars (list) – Which variables to download for the selected product.

  • variables (dict, optional) – Metadata on which exact layers need to be requested from the server, by default None.

  • post_processors (dict, optional) – Functions per variable that should be applied to the variable, by default None.

  • extra_search_kwargs (dict) – Extra search kwargs passed to SentinelAPI, by default {“cloudcoverpercentage”: (0, 30)}.

Returns

Downloaded data.

Return type

xr.Dataset