SOFIARedux:docs
  • Index
  • Modules

Navigation

  • next »
  • « previous |
  • sofia_redux v1.3.4.dev38+g92ea2f4 »
  • SOFIA Redux »
  • EXES Redux Developer’s Manual »
  • initial_search

initial_search¶

sofia_redux.toolkit.fitting.fitpeaks1d.initial_search(fitter, model, x, y, npeaks=1, xpeak_parname=None, ypeak_parname=None, baseline_func=<function medabs_baseline>, guess_func=<function guess_xy_mad>, guess=None, fitopts=None)[source]¶

Perform an initial search for peaks in the data

The procedure is:

  1. Take the original (x, y) data and optionally modify it to some form where it is easier to fit a more accurate peak. In the default case, the median is subtracted from y before taking the absolute value. At this stage we do not typically fit the background level so instead try to center most of the data around zero and then take the absolute value. This is sensible for stable baselines with positive and negative peaks, but may not be so for other flavours of data. Different baseline removal and data modification functions may be specified with the baseline_func argument.

  2. Start a loop of npeaks iterations. On each interation:

    1. Identify the most prominent peak in the modified y data. This is done via the guess_func function. In the default case this simply finds the (x, y) position of the maximum y value. Optionally, the user may parse in specified x values using the guess argument.

    2. Fit the data to the search model using the x and y guesses obtained in the previous step.

    3. Store the parameters obtained from the fit, then subtract a fit of the peak from the data and begin the next iteration. If successful, the most prominent peak was removed and we can move on to fitting the next most prominent peak.

  3. After npeaks iterations take the x values of the fit and use interpolation to get an estimate of y on the original unmodified data set. This y estimate is added to the other stored peak parameters which are then used as a more accurate starting point for a refined search later.

Parameters:
fitterfitting object

Typically a “solver” from scipy.optimize or astropy.modeling that performs the function:

fitted_model = solver(model, x, y)
modelastropy.modeling.Fittable1DModel

The model to fit. Typically from get_search_model.

xarray_like of float

(N,) array of independent data to fit

yarray_like of float

(N,) array of dependent data to fit

xpeak_parnamestr, optional

Name of the parameter in the peak model governing the location of the peak along the x-axis. If None, will attempt to autodetect.

ypeak_parnamestr, optional

Name of the parameter in the peak model governing the location of the peak along the y-axis. If None, will attempt to autodetect.

npeaksint, optional

The number of peaks to find

guess_funcfunction

A function of the form:

x_guess, y_guess = guess_func(x, y_modified)

Here x_guess and y_guess are the x (position) and y (amplitude) estimates of the most prominent peak in the data. Here we use the output from baseline_func as the dependent values which allows the user to do things such as smoothing, filtering, or whatever other ideas they may have. The default function, guess_xy_mad simply finds the x and y coordinate of the maximum value in y_modified.

guessarray_like of float, optional

An array where each element gives a guess at an initial x position for the peak. If there are less guesses than npeaks, guess_func will be used after the inital guesses have been taken. If there are more guesses than npeaks, then only guess[:npeaks] will be used.

baseline_funcfunction, optional

A function of the form:

y_modified, baseline = baseline_func(x, y)

Here y_modified may be the original y data, or the y data modified such that the combination of model and solver is able to identify peaks. In the default case, the medabs_baseline function is used which returns y_modified = abs(y - median(y)) and baseline = y - median(y).

fitoptsdict, optional

Optional arguments to pass into the solver at runtime.

Returns:
numpy.ndarray of numpy.float64

(npeaks, n_parameters) array of the initial guesses for the model parameters of each peak. Note that this contains the peak only portion of parameters and not the filtering parameters of the optional box_model that may have been appended to the peak model at get_search_model.

Page Contents

  • initial_search
    • initial_search()

Page Source   Back to Top

© Copyright 2024, SOFIA-USRA.
Created using Sphinx 7.2.6.   Last built 05 Feb 2024.