Background

Comparaison Matlab - Python

C’est la fonction principale de calcul du fond de ciel. Les résultats sont légèrement différents de ceux données par le programme originel en Matlab. Prenons par exemple la donnée suivante :

  • a=[3, 4, 3, 5, 2, 5, 4, 3, 1, 2, 3, 1, 2, 4, 5, 2, 1, 2, 3, 6, 5, 4, 2, 1, 5, 3, 2, 1, 4, 3, 2, 1, 4, 2, 2, 3, 6]

Pour une régression linéaire d’ordre 1, nous obtenons les résultats suivants, en fonction de la fonction utilisé :

Comparaison des valeurs de polifit entre Python et Matlab

Fonction utilisée

x0

x1

x0 error

x1 error

Matlab polyfit

-0.0085

3.1622

Matlab fitlm

-0.0085349

3.1622

0.022941

0.49998

Matlab fit

-0.0085

3.1622

0.0229

0.5

Python numpy polyfit

-0.00853485

3.16216216

0.02294058

0.49997666

A noter que la fonction polyfit de Matlab ne permet pas de calculer directement l’erreur.

Dans le cas de l’utilisation d’une fonction de poids, les outils Matlab ne permettent pas de calculer la régression polynomiale, alors qu’elle est possible avec Python et la librairie Numpy. Pour tester cela, prenons les valeurs suivantes (même que “a”, sauf une valeur qui a été changée de 1 à 100):

  • b=[3, 4, 3, 5, 2, 5, 4, 3, 1, 2, 3, 100, 2, 4, 5, 2, 1, 2, 3, 6, 5, 4, 2, 1, 5, 3, 2, 1, 4, 3, 2, 1, 4, 2, 2, 3, 6]

Comparaison des valeurs de polifit entre Python et Matlab, avec l’utilisation d’une fonction de poids (racine carrée du signal)

Fonction utilisée

x0

x1

x0 error

x1 error

Matlab fit

-0.0244

2.8749

0.0249

0.5597

Python numpy polyfit

-0.02438482

2.87488398

0.0213165

1.08084752

Main functions

SignalCreation.Pretreatment.Background.get_sky_background(ds, da_name, method=None, alt_min=None, alt_max=None, order=None, log_regression=None, method_alt_min_auto=None, method_alt_max_auto=None, method_method_auto=None, param_alt_min_auto_por=None, da_simu_name=None, param_alt_max_n=None, use_index_background_matlab_software=False)

Compute the sky background according the correction type chosen

Parameters:
  • ds (xr.Dataset) – Raw Lidar Signal on which applies saturation

  • da_name (str) – name of the data array to desaturate

  • method (str | None)

  • alt_min (int | float | str | Quantity | None)

  • alt_max (int | float | str | Quantity | None)

  • order (int | float | str | None)

  • log_regression (int | float | str | bool | None)

  • method_alt_min_auto (str | None) – methodology if alt min is None

  • method_alt_max_auto (str | None) – methodology if alt max is None

  • method_method_auto (str | None) – methodology if method is None

  • use_index_background_matlab_software (bool) – use index search for background value as Matlab software (default: False)

  • param_alt_min_auto_por (float | None)

  • da_simu_name (str | None)

  • param_alt_max_n (int | None)

Returns:

Sky Background Correction DataArray to apply to the raw signal

Return type:

xr.DataArray

SignalCreation.Pretreatment.Background.apply_pretreatment(raw_lidar_signal, desaturation=None, sky_background=None, geo_factor=None)

Apply pretreatment to raw signal. Saturation, sky-background and geometric factor can be given (ignored if not)

Parameters:
  • raw_lidar_signal (xr.DataArray) – DataArray representing raw data

  • desaturation (xr.DataArray) – DataArray filled with saturation coefficients

  • sky_background (xr.DataArray) – DataArray representing sky background

  • geo_factor (xr.DataArray) – Geometric factor

Returns:

Apply pretreatment on raw lidar signal

Return type:

xr.DataArray

Specific sky background functions

SignalCreation.Pretreatment.Background.background_process(signal, alt_min, alt_max, order=1, dim_name_time='time', dim_name_altitude='altitude', signal_unc=None, log_regression=False, use_weight=True, use_index_background_matlab_software=False)

Processes the background correction on a raw lidar signal.

Parameters:
  • signal (xr.DataArray) – The raw lidar signal to be corrected.

  • alt_min (pint.Quantity) – The minimum altitude for calculating the background correction.

  • alt_max (pint.Quantity) – The maximum altitude for calculating the background correction.

  • order (int or float, optional) – The order of the polynomial regression used for fitting the background signal. Can be 0, 1, or 2. Defaults to 1.

  • dim_name_time (str, optional) – The name of the time dimension in the DataArray. Defaults to “time”.

  • dim_name_altitude (str, optional) – The name of the altitude dimension in the DataArray. Defaults to “altitude”.

  • signal_unc (xr.DataArray or None, optional) – The uncertainty of the raw lidar signal. If provided, this uncertainty is used to weight the polynomial fit.

  • log_regression (bool, optional) – If True, performs a logarithmic regression on the signal.

  • use_weight (bool, optional) – If True, weights are used for the polynomial regression based on the signal uncertainty.

  • use_index_background_matlab_software (bool, optional) – use index search for background value as Matlab software (default: False)

Returns:

A list containing the background corrected signal, the background polynomial coefficients, the background correction uncertainty, and the attributes dict.

Return type:

list

The function performs a background correction by applying a polynomial regression (optionally logarithmic and weighted) to a specified altitude range of a lidar signal. This correction is essential for isolating the signal attributable to atmospheric particles from various sources of background noise.

Tools functions

SignalCreation.Pretreatment.Background.check_mandatory_parameters(parameters, mandatory_parameters, function_name)

Function used to check missing parameters in saturation function (Müller, Pelon, Donovan)

Parameters:
  • parameters (dict) – Parameters given by user

  • mandatory_parameters (list) – Parameters required for the saturation function

  • function_name (str) – Sky background computation method

SignalCreation.Pretreatment.Background.value_to_pint(value, unit)

Convert a float/int value to a pint.Quantity specifying unit

Parameters:
  • value (float) – Value to convert, can also be an int

  • unit (str) – unity to add to the value

Returns:

Value converted to pint object

Return type:

pint.Quantity