plesty.fss.line_fit

Finding and fitting the lines of one spectrum, for plesty.fss.tracking.LineTracker.

Both steps are the analysis’s own: lines are found with find_peaks() and fitted with SpectrumFit, so a line the tracker follows during a sweep is found and fitted as the analysis does after it.

Functions

saved_fit(→ Any)

Load the line fit an analysis saved, given the path of its document.

check_fit_options(→ None)

Refuse fit options SpectrumFit would refuse.

find_lines(→ numpy.ndarray)

Return the positions of the lines in reference, shortest wavelength first.

fit_line_positions(→ numpy.ndarray)

Fit the lines of one spectrum, starting from seeds, and return their positions.

Module Contents

plesty.fss.line_fit.saved_fit(path: Any) → Any

Load the line fit an analysis saved, given the path of its document.

Here rather than beside the tracker because this module is where a line fit is produced, and a fit read back is the same thing arriving another way — the tracker itself reaches for nothing outside this package.

Parameters:

path (Any) – The document’s path.

Returns:

The analyzer’s fit output.

Raises:

Exception – Whatever reading it raises — a document still being written, or one from a version that saved a different shape.

Return type:

Any

plesty.fss.line_fit.check_fit_options(fit_options: Mapping[str, Any]) → None

Refuse fit options SpectrumFit would refuse.

Raises:

ValueError – If an option is invalid.

Parameters:

fit_options (Mapping[str, Any])

Return type:

None

plesty.fss.line_fit.find_lines(wavelength: numpy.ndarray, reference: numpy.ndarray, prominence: float | None, distance: int) → numpy.ndarray

Return the positions of the lines in reference, shortest wavelength first.

Parameters:
  • wavelength (numpy.ndarray) – The axis, in nm.

  • reference (numpy.ndarray) – The spectrum to search, e.g. the median of the spectra so far.

  • prominence (Optional[float]) – Minimum height of a line above its surroundings, in counts.

  • distance (int) – Minimum separation of two lines, in pixels.

Return type:

numpy.ndarray

plesty.fss.line_fit.fit_line_positions(wavelength: numpy.ndarray, counts: numpy.ndarray, seeds: numpy.ndarray, fit_options: Mapping[str, Any]) → numpy.ndarray

Fit the lines of one spectrum, starting from seeds, and return their positions.

Fit-quality warnings are not raised: one spectrum at a time says little, and the analysis reports them for the whole sweep.

Parameters:
  • wavelength (numpy.ndarray) – The axis, in nm.

  • counts (numpy.ndarray) – The spectrum.

  • seeds (numpy.ndarray) – Starting position of each line, in nm.

  • fit_options (Mapping[str, Any]) – SpectrumFit options other than peaks.

Returns:

The fitted position of each line, nan for all when the fit fails.

Raises:

ImportError – If the fitting extra is not installed. A spectrum that cannot be fitted is ordinary and becomes nan; an environment that cannot fit anything is not, and swallowing it means every line of every spectrum silently reads as unfittable — a viewer drawing no markers at all, with nothing to say why.

Return type:

numpy.ndarray