ppcpy.calibration.rayleighfit#

Functions

DP_algorithm

Recursive implementation of the Douglas-Peucker algorithm.

DouglasPeucker

Simplify signal according to Douglas-Peucker algorithm.

chi2fit

CHI2FIT Chi-2 fitting.

fit_profile

Search the clean region with rayleigh fit algorithm.

my_dist

Calculate the perpendicular distance between pointM and the line connecting pointS and pointE.

rayleighfit

Rayleighfit ...

smooth_signal

Uniformly smooth the input signal

ppcpy.calibration.rayleighfit.rayleighfit(data_cube) list[source]#

Rayleighfit …

Parameters:

data_cube (object) – Main PicassoProc object.

Returns:

refH – Reference heights per channel per cloud free period.

Return type:

list of dicts

Notes

  • TODO: Write docstring.

ppcpy.calibration.rayleighfit.smooth_signal(signal: ndarray, window_len: int) ndarray[source]#

Uniformly smooth the input signal

Parameters:
  • singal (ndarray) – Signal to be smooth

  • window_len (int) – Width of the applied uniform filter

Returns:

  • ndarray – Smoothed signal

  • History

  • ——-

  • - 2026-02-04 (Changed from scipy.ndimage.uniform_filter1d to ppcpy.misc.helper.uniform_filter)

ppcpy.calibration.rayleighfit.DouglasPeucker(signal: ndarray, height: ndarray, epsilon: float, heightBase: float, heightTop: float, maxHThick: float, window_size: int = 1) ndarray[source]#

Simplify signal according to Douglas-Peucker algorithm.

Parameters:
  • signal (ndarray) – Molecule corrected signal. [MHz]

  • height (ndarray) – Height. [m]

  • epsilon (float) – Maximum distance.

  • heightBase (float) – Minimum height for the algorithm. [m]

  • heightTop (float) – Maximum height for the algorithm. [m]

  • maxHThick (float) – Maximum spatial thickness of each segment. [m]

  • window_size (int) – Size of the average smooth window.

Returns:

sigIndx – Index of the signal that stands for different segments of the signal.

Return type:

array

References

https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm

History#

  • 2017-12-29: First edition by Zhenping.

  • 2018-07-29: Add the height range for the searching instead of SNR restriction.

  • 2018-07-31: Add the maxHThick argument to control the maximum thickness of each output segment.

  • 2024-12-20: Direct translated from matlab with ai

ppcpy.calibration.rayleighfit.DP_algorithm(pointList: list, epsilon: float, maxHThick: float) list[source]#

Recursive implementation of the Douglas-Peucker algorithm.

Parameters:
  • pointList (list) – List of points [[x1, y1], [x2, y2], …].

  • epsilon (float) – Maximum distance.

  • maxHThick (float) – Maximum thickness for each segment.

Returns:

sigIndx – Indices of simplified points.

Return type:

list

ppcpy.calibration.rayleighfit.my_dist(pointM: list, pointS: list, pointE: list) float[source]#

Calculate the perpendicular distance between pointM and the line connecting pointS and pointE.

Parameters:
  • pointM (list) – Middle point [x, y].

  • pointS (list) – Start point [x, y].

  • pointE (list) – End point [x, y].

Returns:

d – Distance.

Return type:

float

ppcpy.calibration.rayleighfit.chi2fit(x: ndarray, y: ndarray, measure_error: ndarray) tuple[source]#

CHI2FIT Chi-2 fitting. All the code are translated from the exemplified code in Numerical Recipes in C (2nd Edition). Great help comes from Birgit Heese.

Usage#

a, b, sigmaA, sigmaB, chi2, Q = chi2fit(x, y, measure_error)

param x:

The length of x should be larger than 1.

type x:

ndarray

param y:

The measured signal.

type y:

ndarray

param measure_error:

Measurement errors for the y values.

type measure_error:

ndarray

returns:
  • a (float) – Intercept of the linear regression.

  • b (float) – Slope of the linear regression.

  • sigmaA (float) – Uncertainty of the intercept.

  • sigmaB (float) – Uncertainty of the slope.

  • chi2 (float) – Chi-square value.

  • Q (float) – Goodness of fit.

  • History

  • ——-

  • - 2018-08-03 (First edition by Zhenping.)

  • Authors (- zhenping@tropos.de)

ppcpy.calibration.rayleighfit.fit_profile(height: ndarray, sig_aer: ndarray, pc: ndarray, bg: ndarray, sig_mol: ndarray, dpIndx: ndarray, layerThickConstrain: float, slopeConstrain: float, SNRConstrain: float, flagShowDetail: bool = False) tuple[source]#

Search the clean region with rayleigh fit algorithm.

Parameters:
  • height (array_like) – height [m]

  • sig_aer (array_like) – range corrected signal

  • pc (array_like) – photon count signal

  • bg (array_like) – background

  • sig_mol (array_like) – range corrected molecular signal

  • dpIndx (array_like) – index of the region calculated by Douglas-Peucker algorithm

  • layerThickConstrain (float) – constrain for the reference layer thickness [m]

  • slopeConstrain (float) – constrain for the uncertainty of the regressed extinction coefficient

  • SNRConstrain (float) – minimum SNR for the signal at the reference height

  • flagShowDetail (bool, optional) – if True, calculation information will be printed (default: False)

Returns:

(hBIndx, hTIndx) - indices of bottom and top of searched region Returns (nan, nan) if region not found

Return type:

tuple