pypeit.core.fitting module

Module for fitting codes

class pypeit.core.fitting.PypeItFit(xval=None, yval=None, order=None, x2=None, weights=None, fitc=None, fitcov=None, func=None, minx=None, maxx=None, minx2=None, maxx2=None, gpm=None, success=None)[source]

Bases: DataContainer

General fitting class used by PypeIt.

The datamodel attributes are:

Version: 1.0.0

Attribute

Type

Array Type

Description

fitc

numpy.ndarray

numpy.floating

Fit coefficients

fitcov

numpy.ndarray

numpy.floating

Covariance of the coefficients

func

str

Fit function (polynomial, legendre, chebyshev, polynomial2d, legendre2d)

gpm

numpy.ndarray

numpy.integer

Mask (1=good)

maxx

float

maximum value in the array (or the right limit for a legendre / chebyshev polynomial)

maxx2

float

Same as maxx for the second independent variable x2

minx

float

minimum value in the array (or the left limit for a legendre / chebyshev polynomial)

minx2

float

Same as minx for the second independent variable x2

order

numpy.ndarray

numpy.integer

The order of the polynomial to be used in the fitting. This is a 2d array for 2d fits

success

int

Flag indicating whether fit was successful (success=1) or if it failed (success=0)

weights

numpy.ndarray

numpy.floating

Weights. Often the same as invvar

x2

numpy.ndarray

numpy.floating

x2 inputs, second independent variable

xval

numpy.ndarray

numpy.floating

x inputs

yval

numpy.ndarray

numpy.floating

y inputs

When written to an output-file HDU, all numpy.ndarray elements are bundled into an astropy.io.fits.BinTableHDU, and the other elements are written as header keywords. Any datamodel elements that are None are not included in the output.

_bundle(ext='PYPEITFIT')[source]

Bundle the data in preparation for writing to a fits file.

See pypeit.datamodel.DataContainer._bundle(). Data is always written to a ‘PYPEITFIT’ extension.

property bool_gpm

Generate a bool version of gpm which is int for I/O

Returns:

bool version of self.gpm or None

Return type:

numpy.ndarray or None

calc_fit_rms(apply_mask=True, x2=None)[source]

Simple RMS calculation for the fit on the data.

Parameters:
  • apply_mask (bool, optional) – If true, apply mask to data before calculating RMS.

  • x2 (numpy.ndarray, optional) – x locations for 2D fits

Returns:

Root mean square

Return type:

float

datamodel = {'fitc': {'atype': <class 'numpy.floating'>, 'descr': 'Fit coefficients', 'otype': <class 'numpy.ndarray'>}, 'fitcov': {'atype': <class 'numpy.floating'>, 'descr': 'Covariance of the coefficients', 'otype': <class 'numpy.ndarray'>}, 'func': {'descr': 'Fit function (polynomial, legendre, chebyshev, polynomial2d, legendre2d)', 'otype': <class 'str'>}, 'gpm': {'atype': <class 'numpy.integer'>, 'descr': 'Mask (1=good)', 'otype': <class 'numpy.ndarray'>}, 'maxx': {'descr': 'maximum value in the array (or the right limit for a legendre / chebyshev polynomial)', 'otype': <class 'float'>}, 'maxx2': {'descr': 'Same as maxx for the second independent variable x2', 'otype': <class 'float'>}, 'minx': {'descr': 'minimum value in the array (or the left limit for a legendre / chebyshev polynomial)', 'otype': <class 'float'>}, 'minx2': {'descr': 'Same as minx for the second independent variable x2', 'otype': <class 'float'>}, 'order': {'atype': <class 'numpy.integer'>, 'descr': 'The order of the polynomial to be used in the fitting. This is a 2d array for 2d fits', 'otype': <class 'numpy.ndarray'>}, 'success': {'descr': 'Flag indicating whether fit was successful (success=1) or if it failed (success=0)', 'otype': <class 'int'>}, 'weights': {'atype': <class 'numpy.floating'>, 'descr': 'Weights.  Often the same as invvar', 'otype': <class 'numpy.ndarray'>}, 'x2': {'atype': <class 'numpy.floating'>, 'descr': 'x2 inputs, second independent variable', 'otype': <class 'numpy.ndarray'>}, 'xval': {'atype': <class 'numpy.floating'>, 'descr': 'x inputs', 'otype': <class 'numpy.ndarray'>}, 'yval': {'atype': <class 'numpy.floating'>, 'descr': 'y inputs', 'otype': <class 'numpy.ndarray'>}}

Provides the class data model. This is undefined in the abstract class and should be overwritten in the derived classes.

The format of the datamodel needed for each implementation of a DataContainer derived class is as follows.

The datamodel itself is a class attribute (i.e., it is a member of the class, not just of an instance of the class). The datamodel is a dictionary of dictionaries: Each key of the datamodel dictionary provides the name of a given datamodel element, and the associated item (dictionary) for the datamodel element provides the type and description information for that datamodel element. For each datamodel element, the dictionary item must provide:

  • otype: This is the type of the object for this datamodel item. E.g., for a float or a numpy.ndarray, you would set otype=float and otype=np.ndarray, respectively.

  • descr: This provides a text description of the datamodel element. This is used to construct the datamodel tables in the pypeit documentation.

If the object type is a numpy.ndarray, you should also provide the atype keyword that sets the type of the data contained within the array. E.g., for a floating point array containing an image, your datamodel could be simply:

datamodel = {'image' : dict(otype=np.ndarray, atype=float, descr='My image')}

More advanced examples are given in the top-level module documentation.

Currently, datamodel components are restricted to have otype that are tuple, int, float, numpy.integer, numpy.floating, numpy.ndarray, or astropy.table.Table objects. E.g., datamodel values for otype cannot be dict.

eval(x, x2=None)[source]

Return the evaluated fit at locations x (and x2, if 2D)

Parameters:
Return type:

numpy.ndarray

fit()[source]

Perform the fit, either in 1D or 2D depending on the data and model.

Returns:

Flag indicating whether fit was successful (1) or if it failed (0)

Return type:

int

to_hdu(**kwargs)[source]

Over-ride pypeit.datamodel.DataContainer.to_hdu() to force to a BinTableHDU

See that func for Args and Returns

version = '1.0.0'

Provides the string representation of the class version.

This is currently put to minimal use so far, but will used for I/O verification in the future.

Each derived class should provide a version to guard against data model changes during development.

class pypeit.core.fitting.PypeItFitCollection(xpos, ypos, ivar=None, gpm=None, func='legendre', order=3, xmin=None, xmax=None, maxiter=10, maxdev=None, lower=None, upper=None)[source]

Bases: object

A collection of 1D fits to a set of data.

The provided data to be fit (xpos, ypos) can be provided as 1D or 2D arrays, but their shape must match.

  • If 1D, only one fit is performed, and this is effectively identical to a single instance of PypeItFit.

  • If 2D, fits are performed along the 2nd axis; i.e., a model is fit to (xpos[0],ypos[0]) vectors, then to the (xpos[1],ypos[1]) vectors, etc.

This class uses robust_fit() to perform all the fits.

Parameters:
  • xpos (numpy.ndarray) – The x positions of the data to be fit. Can be 1D or 2D; if the latter, fits are performed along the 2nd axis (see class description).

  • ypos (numpy.ndarray) – The y positions of the data to be fit. Must have the same shape as xpos.

  • ivar (numpy.ndarray, optional) – The inverse variance in the ypos data. Must have the same shape as ypos.

  • gpm (numpy.ndarray, optional) – Good pixel mask. Must have the same shape as ypos. If None and ivar is None, all pixels are considered good. If None and ivar is provided, the data with ivar > 0 are considered good.

  • func (str, optional) – The functional form to use for the fit. Must be one of ‘polynomial’, ‘legendre’, or ‘chebyshev’.

  • order (int, optional) – The order of the polynomial to be fit.

  • xmin (float, optional) – The minimum x value to be used for the fit. If None, this is set to the minimum of xpos (i.e., the entire array). Generally, you should not provide this, and just let the code determine it from xpos.

  • xmax (float, optional) – The maximum x value to be used for the fit. If None, this is set to the maximum of xpos (i.e., the entire array). Generally, you should not provide this, and just let the code determine it from xpos.

  • maxiter (int, optional) – Maximum number of rejection iterations; see robust_fit().

  • maxdev (int, float, optional) – An absolute-difference threshold for rejecting outliers; see robust_fit().

  • lower (int, float, optional) – A sigma-rejection threshold for data with values less than the model; see robust_fit().

  • upper (int, float, optional) – A sigma-rejection threshold for data with values greater than the model; see robust_fit().

allowed_functions = ['polynomial', 'legendre', 'chebyshev']

Allowed functional forms for fitting.

eval(xpos=None, copy=True)[source]

Evaluate the fits at the provided coordinates.

Parameters:
  • xpos (array-like, optional) – Positions at which to evaluate the fits. This can be 1D or 2D. If 1D, the same positions will be used for all fits. If 2D, the length of the first axis must be the same as nfit. If None, the x positions are the same as xpos and the fit values are identically yfit.

  • copy (bool, optional) – Only relevant if xpos is None. If True, the returned x and y positions are copies of the internal attributes; otherwise, the attributes themselves are returned.

Returns:

pypeit.core.fitting.bspline_qa(xdata, ydata, sset, gpm, yfit, xlabel=None, ylabel=None, title=None, show=True)[source]

Construct a QA plot of the B-spline fit.

Warning

This function has not been tested with BSpline2D fits. The call to value() at the breakpoints may fail or produce unexpected results for 2D fits.

Parameters:
  • xdata (numpy.ndarray) – Independent variable. Regardless of shape, data is treated as one-dimensional.

  • ydata (numpy.ndarray) – Dependent variable. Regardless of shape, data is treated as one-dimensional.

  • sset (BSpline) – Fitted B-spline object, as returned by iterative_bspline_fit().

  • gpm (numpy.ndarray) – Boolean array with the same size as xdata. Points rejected during the fit have gpm=False.

  • yfit (numpy.ndarray) – Best-fitting model sampled at xdata, as returned by iterative_bspline_fit().

  • xlabel (str, optional) – Label for the abscissa. If None, no label is added.

  • ylabel (str, optional) – Label for the ordinate. If None, no label is added.

  • title (str, optional) – Title for the plot. If None, no title is added.

  • show (bool, optional) – If True, display the plot with the legend, axis labels, and title applied. If False, return the Axes instance immediately, before the legend, axis labels, or title are added.

Returns:

ax – Axes instance with the data, model, and breakpoints plotted. Only returned when show is False.

Return type:

matplotlib.axes.Axes

pypeit.core.fitting.evaluate_fit(fitc, func, x, x2=None, minx=None, maxx=None, minx2=None, maxx2=None)[source]

Return the evaluated fit at the x locations

Parameters:
  • fitc (numpy.ndarray) – Fit coefficients

  • func (str) – Name of the functional form to fit

  • x (numpy.ndarray) – x locations for the evaluation

  • x2 (numpy.ndarray, optional) – x2 locations for 2D fits

  • minx (float, optional) – Minimum x value for the fit used to normalise the x values

  • maxx (float, optional) – Maximum x value for the fit used to normalise the x values

  • minx2 (float, optional) – Minimum x value for the fit used to normalise the x2 values

  • maxx2 (float, optional) – Maximum x value for the fit used to normalise the x2 values

Returns:

Evaluated fit at the x (and x2) locations

Return type:

numpy.ndarray

pypeit.core.fitting.fit_gauss(x_out, y_out, guesses=None, w_out=None, nparam=3, maxfev=0)[source]

Fit a 3 or 4 parameter gaussian

Parameters:
  • x_out (numpy.ndarray) – x values to be fit

  • y_out (numpy.ndarray) – y values to be fit

  • guesses (tuple, optional) – ampl, cent, sigma, [floor] guesses for the Gaussian; each as floats

  • w_out (numpy.ndarray_) – Weights. 1./sqrt(ivar) is expected

  • nparam (int, optional) – Number of parameters in the Gaussian Only options are 3 or 4 where the latter includes a floor in the fit.

  • maxfev (int, optional) – Maximum number of function evaluations. Passed directly to scipy.optimize.curve_fit. Note that setting maxfev to 0 uses the default value set by scipy.optimize.leastsq.

Returns:

Fit coefficients, fit covariance from numpy’s curve_fit

Return type:

tuple

pypeit.core.fitting.gauss_3deg(x, ampl, cent, sigm)[source]

Generate a simple 3-parameter Gaussian

Parameters:
Returns:

Evaluated Gausssian

Return type:

float or numpy.ndarray

pypeit.core.fitting.gauss_4deg(x, b, ampl, cent, sigm)[source]

Generate a simple 4-parameter Gaussian

Parameters:
Returns:

Evaluated Gausssian

Return type:

float or numpy.ndarray

pypeit.core.fitting.guess_gauss(x, y)[source]

Guesses Gaussian parameters with basic stats

Parameters:
Returns:

Amplitude, centroid, sigma, floor all as float

Return type:

tuple

pypeit.core.fitting.iterative_bspline_fit(x, y, ivar=None, gpm=None, nord=4, basis=None, npoly=1, basis_x=None, xmin=None, xmax=None, kwargs_knots={}, relative=None, upper=5, lower=5, maxiter=25, kwargs_reject={})[source]

Fit a B-spline with iterative sigma-clipping rejection.

Parameters:
  • x (numpy.ndarray) – Independent variable. Should be sorted in ascending order; fit() sorts internally, but the default stride knot strategy places breakpoints at evenly-spaced indices of x, which is only meaningful when x is sorted.

  • y (numpy.ndarray) – Dependent variable.

  • ivar (numpy.ndarray, optional) – Inverse variance of y. Points with ivar <= 0 are excluded from the fit regardless of gpm.

  • gpm (numpy.ndarray of bool, optional) – Additional input mask; True for pixels to include in the fit. When None (default), all pixels with positive ivar are used; if ivar is also None, all pixels are used.

  • nord (int, optional) – B-spline order.

  • basis (str or numpy.ndarray or None, optional) – Polynomial basis specification for the second variable. When a string, it must be one of 'legendre', 'chebyshev', 'poly', or 'poly1'; basis_x must also be provided. When a numpy.ndarray, it is used directly as the pre-built polynomial basis matrix; a 1D array of size x.size * npoly is reshaped to (x.size, npoly) automatically. When None (default), a 1D BSpline fit is performed.

  • npoly (int, optional) – Number of polynomial terms; forwarded to fit() and ignored when basis is an array or None.

  • basis_x (numpy.ndarray or None, optional) – Second variable. Required when basis is a string; ignored when basis is None or a pre-built array.

  • xmin (float, optional) – Minimum value of basis_x for normalisation; forwarded to fit() and ignored when basis is an array or None.

  • xmax (float, optional) – Maximum value of basis_x for normalisation; forwarded to fit() and ignored when basis is an array or None.

  • kwargs_knots (dict, optional) – Keyword arguments forwarded to Knots to control knot placement. See Knots for the available strategies and their default values.

  • relative (array-like or None, optional) – Index array for computing the relative chi-squared used to rescale the rejection thresholds. When None (default) the thresholds are not rescaled.

  • upper (float, optional) – Upper sigma-clipping threshold.

  • lower (float, optional) – Lower sigma-clipping threshold.

  • maxiter (int, optional) – Maximum number of fit-reject iterations.

  • kwargs_reject (dict, optional) – Additional keyword arguments forwarded to djs_reject().

Returns:

  • bspl (BSpline, BSpline2D) – Fitted spline object. A BSpline2D is returned when basis is provided; a BSpline is returned otherwise. None is returned on catastrophic failure (exit status 4 with no valid input points).

  • outmask (numpy.ndarray of bool) – Final good-pixel mask after all rejection iterations.

  • yfit (numpy.ndarray) – Best-fit model values at x.

  • reduced_chi (float) – Reduced chi-squared of the final fit.

  • exit_status (int) –

    Convergence status code that will be one of the following:

    • 0 — converged normally

    • 1 — maximum iterations reached

    • 2 — too few good points during iteration

    • 3 — singular or degenerate fit (all breakpoints lost)

    • 4 — fewer good points than nord on entry

pypeit.core.fitting.moffat(x, p0, p1, p2)[source]

Moffat profile This 3 parameter formulation assumes the trace is known

Parameters:
Returns:

Evaluated Moffat

Return type:

float or numpy.ndarray

pypeit.core.fitting.polyfit2d_general(x, y, z, deg, w=None, function='polynomial', minx=None, maxx=None, miny=None, maxy=None)[source]

2D Polynomimal fit

Parameters:
  • x (numpy.ndarray) – x-values

  • y (numpy.ndarray) – y-values

  • z (numpy.ndarray) – value of data at each (x,y) coordinate

  • deg (tuple) – degree of polynomial fit in the form [nx,ny]

  • w (numpy.ndarray, optional) – weights. Often invvar

  • function (str, optional) – 2D function to fit. Options are ‘polynomial’, ‘chebyshev’ or ‘legendre’

  • minx (float, optional) – Minimum x value for the fit used to normalise the x values

  • maxx (float, optional) – Maximum x value for the fit used to normalise the x values

  • miny (float, optional) – Minimum value for the fit used to normalise the y values

  • maxy (float, optional) – Maximum value for the fit used to normalise the y values

Returns:

  • The coefficients of the polynomial fit as a numpy.ndarray

  • minx, maxx, miny, maxy: min and max values for the fit as float

Return type:

tuple

pypeit.core.fitting.robust_fit(xarray, yarray, order, x2=None, function='polynomial', minx=None, maxx=None, minx2=None, maxx2=None, maxiter=10, in_gpm=None, weights=None, invvar=None, lower=None, upper=None, maxdev=None, maxrej=None, groupdim=None, groupsize=None, groupbadpix=False, grow=0, sticky=True, use_mad=True, verbose=True, show_fit=False)[source]

A robust fit is performed to the xarray, yarray pairs mask[i] = 1 are good values, if provided.

The underlying method(s) are the numpy fitting routines, e.g. polyfit, legfit.

Parameters:
  • xarray (numpy.ndarray) – independent variable values

  • yarray (numpy.ndarray) – dependent variable values

  • order (int or numpy.ndarray`_) – the order of the polynomial to be used in the fitting. This is an integer for 1d fits and must be a tuple or 2d array for 2d fits (i.e. using x2 as the second independent variable).

  • x2 (numpy.ndarray, optional) – Do a 2d fit? This is the second independent variable for 2d fits.

  • function (str) – which function should be used in the fitting. (valid inputs are: ‘polynomial’, ‘legendre’, ‘chebyshev’, ‘polynomial2d’, ‘legendre2d’)

  • minx (float, optional) – minimum value in the array (or the left limit for a legendre/chebyshev polynomial)

  • maxx (float, optional) – maximum value in the array (or the right limit for a legendre/chebyshev polynomial)

  • minx2 (float, optional) – Same as minx for second independent variable x2.

  • maxx2 (float, optional) – Same as maxx for second independent variable x2.

  • maxiter (int, optional) – Maximum number of rejection iterations, default 10. Set this to zero to disable rejection and simply do a fit.

  • in_gpm (numpy.ndarray, optional) – Input mask. Bad points are marked with a value that evaluates to False. Must have the same number of dimensions as data. Points masked as bad “False” in the inmask will also always evaluate to “False” in the outmask.

  • invvar (float, numpy.ndarray, optional) – Inverse variance of the data, used to reject points based on the values of upper and lower. This can either be a single float for the entire yarray or a ndarray with the same shape as the yarray.

  • weights (numpy.ndarray, optional) –

    shape same as xarray and yarray If input the code will do a weighted fit. If not input, the code will use invvar as the weights. If both invvar and weights are input. The fit will be done with weights, but the rejection will be based on:

    chi = (data-model) * np.sqrt(invvar)
    

  • lower (int or float, optional) – If set, reject points with data < model - lower * sigma, where sigma = 1.0/sqrt(invvar).

  • upper (int or float, optional) – If set, reject points with data > model + upper * sigma, where sigma = 1.0/sqrt(invvar).

  • maxdev (int or float, optional) – If set, reject points with abs(data-model) > maxdev. It is permitted to set all three of lower, upper and maxdev.

  • maxrej (int, numpy.ndarray, optional) – Maximum number of points to reject in this iteration. If groupsize or groupdim are set to arrays, this should be an array as well.

  • groupdim (int, optional) – Dimension along which to group the data; set to 1 to group along the 1st dimension, 2 for the 2nd dimension, etc. If data has shape [100,200], then setting GROUPDIM=2 is equivalent to grouping the data with groupsize=100. In either case, there are 200 groups, specified by [*,i]. NOT WELL TESTED IN PYTHON!

  • groupsize (int, optional) – If this and maxrej are set, then reject a maximum of maxrej points per group of groupsize points. If groupdim is also set, then this specifies sub-groups within that. NOT WELL TESTED IN PYTHON!!

  • groupbadpix (bool, optional) – If set to True, consecutive sets of bad pixels are considered groups, overriding the values of groupsize.

  • grow (int, optional, default = 0) – If set to a non-zero integer, N, the N nearest neighbors of rejected pixels will also be rejected.

  • sticky (bool, optional, default is True) – If set to True, pixels rejected in one iteration remain rejected in subsequent iterations, even if the model changes. If

  • use_mad (bool, optional, default = False) – It set to True, compute the median of the maximum absolute deviation between the data and use this for the rejection instead of the default which is to compute the standard deviation of the yarray - modelfit. Note that it is not possible to specify use_mad=True and also pass in values invvar, and the code will return an error if this is done.

  • verbose (bool, optional, default = True) – If set to True, increase the verbosity to print additional messages.

  • show_fit (bool, optional, default = False) – If set to True, show the final fit and the data in a plot. This is only for debugging purposes and should not be used regularly.

Returns:

Object containing the inputs to the fit and the fit itself

Return type:

PypeItFit or None

pypeit.core.fitting.robust_optimize(ydata, fitfunc, arg_dict, maxiter=10, inmask=None, invvar=None, lower=None, upper=None, maxdev=None, maxrej=None, groupdim=None, groupsize=None, groupbadpix=False, grow=0, sticky=True, use_mad=False, verbose=False, **kwargs_optimizer)[source]

A routine to perform robust optimization. It is completely analogous to robust_fit(), but is more general in that it allows one to fit a more general model using the optimizer of the users choice. If you are fitting simple functions like Chebyshev or Legednre polynomials using a linear least-squares algorithm, you should use robust_fit() instead of this function.

Parameters:
  • ydata (numpy.ndarray) – Data to fit.

  • fitfunc (callable) –

    The callable object used to perform the fitting. The calling sequence must be:

    ret_tuple = fitfunc(ydata, inmask, arg_dict, **kwargs_optimizer)
    

    See the descriptions of ydata, inmask, arg_dict, and kwargs_optimizer. The returned object ret_tuple that can have two or three elements. If it has two elements (result, ymodel):

    • result: Object returned by the specific scipy.optimize method used to perform the fit.

    • ymodel: A numpy.ndarray with the model fit to ydata and with the same shape.

    If it has three elements (result, ymodel, newivar):

    • newivar: new inverse variance for the ydata ymodel comparison, in other words chi = (ydata - ymodel)*np.sqrt(newivar). This functionality allows one to deal with cases where the noise of the data-model comaprison is model dependent.

  • arg_dict (dict) – Dictionary containing the other variables needed to evaluate the model fit.

  • maxiter (int, optional) – Maximum number of rejection iterations. Set this to zero to disable rejection and simply do a fit.

  • inmask (numpy.ndarray, optional) – Input mask. Bad points are marked with a value that evaluates to False. Must have the same number of dimensions as ydata. Points masked as False in inmask will also always evaluate to False in the output mask.

  • invvar (float, numpy.ndarray, optional) – Inverse variance of the data, used to reject points based on the values of upper and lower. This can either be a single float for the entire yarray or a ndarray with the same shape as the yarray.

  • lower (int, float, optional) – If set, reject points with data < model - lower * sigma, where sigma = 1/sqrt(invvar)

  • upper (int, float, optional) – If set, reject points with data > model + upper * sigma, where sigma = 1/sqrt(invvar).

  • maxdev (int or float, optional) – If set, reject points with abs(data-model) > maxdev. It is permitted to set all three of lower, upper and maxdev.

  • maxrej (int, numpy.ndarray, optional) – Maximum number of points to reject in this iteration. If groupsize or groupdim are set to arrays, this should be an array, as well.

  • groupdim (int, optional) – Dimension along which to group the data. Set to 1 to group along the 1st dimension, 2 for the 2nd dimension, etc. For example, if data has shape [100,200], then setting groupdim=2 is equivalent to grouping the data with groupsize=100. In either case, there are 200 groups, specified by [*,i]. This functionality is not well tested in python!

  • groupsize (int, optional) – If this and maxrej are set, then reject a maximum of maxrej points per group of groupsize points. If groupdim is also set, then this specifies sub-groups within that. This functionality is not well tested in python!

  • groupbadpix (bool, optional) – If True, consecutive sets of bad pixels are considered groups, overriding the values of groupsize.

  • grow (int, optional) – If set to a non-zero integer, N, the N nearest neighbors of rejected pixels will also be rejected.

  • sticky (bool, optional) – If True, pixels rejected in one iteration remain rejected in subsequent iterations, even if the model changes.

  • use_mad (bool, optional) – It True, compute the median of the maximum absolute deviation between the data and use this for the rejection instead of the default, which is to compute the standard deviation of ydata - modelfit. Note that it is not possible to specify use_mad=True and also pass in a value for invvar, and the code will return an error if this is done.

  • **kwargs_optimizer – Optional parameters passed to the optimizer.

Returns:

  • The object returned by the scipy.optimize function used by the fitter. See fitfunc.

  • A numpy.ndarray with the model value fit to ydata and has its same shape.

  • Boolean numpy.ndarray with the same shape as data indicating which pixels were masked in the final fit. Convention is that True are good values where False indicates bad values.

Return type:

tuple

pypeit.core.fitting.scale_minmax(x, minx=None, maxx=None)[source]

Scale in the input array

Parameters:
  • x (numpy.ndarray) – x values to be scaled

  • minx (float, optional) – Minimum value for scaling

  • maxx (float, optional) – Maximum value for scaling

Returns:

  • the scaled x-values in a numpy.ndarray

  • xmin as a float

  • xmax as a float

Return type:

tuple

pypeit.core.fitting.twoD_Gaussian(tup, amplitude, xo, yo, sigma_x, sigma_y, theta, offset)[source]

A 2D Gaussian to be used to fit the cross-correlation

Parameters:
  • tup (tuple) – A two element tuple containing the (x,y) coordinates where the 2D Gaussian will be evaluated

  • amplitude (float) – The amplitude of the 2D Gaussian

  • xo (float) – The centre of the Gaussian in the x direction

  • yo (float) – The centre of the Gaussian in the y direction

  • sigma_x (float) – The dispersion of the Gaussian in the x direction

  • sigma_y (float) – The dispersion of the Gaussian in the y direction

  • theta (float) – The angle of the major axis relative to the horizontal

  • offset (float) – Constant additive term

Returns:

The value of the 2D Gaussian at the given coordinates

Return type:

numpy.ndarray