hispecdrp.primitives.gain.fit_gain_Brandt

Functions

fit_gain_linearity(ramps_dark, ramps_illum)

Main function: fit gain, read noise, nonlinearity.

fitquad(diffs_lin, diffs_quad, covar, sigs, ...)

Fit a quadratic form to the probability distributions from marginalizing the ramps over the count rates.

gen_likelihood_map(diffs_lin, diffs_quad, ...)

Generate a 3D array of the log likelihood of the ramp fit marginalized over the count rates ramp-by-ramp (or, if the countratesidentical variable is set to True, assume that all ramps have the same count rate).

get_best_nonlinearity(diffs_lin, diffs_quad, ...)

Fit a quadratic form for three values of the nonlinearity coefficient, and then use a parzabolic fit to find the highest gain and the nonlinearity coefficient corresponding to this highest gain.

fit_gain_linearity(ramps_dark, ramps_illum, fit_nonlin=True, alpha_offset=2e-06, dalpha=2e-06, dalpha2=5e-07, gainguess=1.85, maxiter_nonlin=10, snrscalefac=1)[source]

Main function: fit gain, read noise, nonlinearity.

Parameters:
  • diffs_lin (2D array of floats) – Size nreads-1 x nramps. Differences between consecutive reads.

  • diffs_quad (2D array of floats) – Size nreads-1 x nramps. Differences between the squares of the values (from a designated pedestal) in consecutive reads

  • covar (fitramp.Covar class) – Should be appropriate for diffs_lin

  • sigs (list of floats) – Trial read noise values

  • gains (list of floats) – Trial gain values

  • alphas (list of floats) – Trial nonlinearity coefficient values

  • asig (float, optional) – Standard deviation of the read noise from other constraints. If the best-fit read noise from this other constraint is sigs[1], asig will incorporate this constraint to the likelihood.

  • countratesidentical (boolean, optional) – Assume that the count rate is the same for all ramps? Default False.

  • cguess (1D array of floats or None, optional) – Count rates for the purposes of computing a covariance matrix. Default None. If None, compute cguess from the nonlinearity-corrected ramps.

  • d2use (2D array of bools or None, optional) – Boolean mask of differences between reads to use for computing a likelihood. If None, use all read differences.

  • log (bool, optional) – Use logarithmic coordinates for the quadratic form? Default True.

Returns:
  • center (tuple of two or three floats) – Center of the quadratic form in gain, read noise, nonlinearity. The coordinates will be given in log(gain) and log(readnoise) if the argument log is True.

  • cov (2D array of floats) – The covariance matrix of the log likelihood as estimated by the quadratic form fit

  • c_2d (list of floats) – The coefficients describing the quadratic form

fitquad(diffs_lin, diffs_quad, covar, sigs, gains, alphas=[0], asig=0, countratesidentical=False, cguess=None, d2use=None, log=True)[source]

Fit a quadratic form to the probability distributions from marginalizing the ramps over the count rates. This function will return the vertex of the fit, the covariance matrix implied by the coefficients, and the coefficients themselves.

Parameters:
  • diffs_lin (2D array of float) – Size (nreads-1, nramps). Differences between consecutive reads.

  • diffs_quad (2D array of float) – Size (nreads-1, nramps). Differences between the squares of the values (from a designated pedestal) in consecutive reads.

  • covar (fitramp.Covar) – Should be appropriate for diffs_lin.

  • sigs (list of float) – Trial read noise values.

  • gains (list of float) – Trial gain values.

  • alphas (list of float) – Trial nonlinearity coefficient values.

  • asig (float, optional) – Standard deviation of the read noise from other constraints. If the best-fit read noise from this other constraint is sigs[1], asig will incorporate this constraint into the likelihood.

  • countratesidentical (bool, optional) – Assume that the count rate is the same for all ramps. Default is False.

  • cguess (1D array of float or None, optional) – Count rates for computing a covariance matrix. Default is None. If None, compute cguess from the nonlinearity-corrected ramps.

  • d2use (2D array of bool or None, optional) – Boolean mask of differences between reads to use for computing a likelihood. If None, use all read differences.

  • log (bool, optional) – Use logarithmic coordinates for the quadratic form. Default is True.

Returns:
  • center (tuple of float) – Center of the quadratic form in gain, read noise, nonlinearity. The coordinates are given in log(gain) and log(readnoise) if log is True.

  • cov (2D array of float) – Covariance matrix of the log likelihood as estimated by the quadratic form fit.

  • c_2d (list of float) – Coefficients describing the quadratic form.

gen_likelihood_map(diffs_lin, diffs_quad, covar, sigs, gains, alphas, countratesidentical=False, asig=0, cguess=None, d2use=None, readtime=None)[source]

Generate a 3D array of the log likelihood of the ramp fit marginalized over the count rates ramp-by-ramp (or, if the countratesidentical variable is set to True, assume that all ramps have the same count rate). Returns a 3D array of the size of len(sigs) x len(gains) x len(alphas), where sig is the read noise, gain is the gain in electrons/DN, and alpha is the nonlinearity coefficient. Chi squared is equal to this returned array times -2.

Parameters:
  • diffs_lin (2D array of floats) – Size nreads-1 x nramps. Differences between consecutive reads.

  • diffs_quad (2D array of floats) – Size nreads-1 x nramps. Differences between the squares of the values (from a designated pedestal) in consecutive reads

  • covar (fitramp.Covar class) – Should be appropriate for diffs_lin

  • sigs (list of floats) – Trial read noise values

  • gains (list of floats) – Trial gain values

  • alphas (list of floats) – Trial nonlinearity coefficient values

  • asig (float, optional) – Standard deviation of the read noise from other constraints. If the best-fit read noise from this other constraint is sigs[1], asig will incorporate this constraint to the likelihood.

  • countratesidentical (boolean, optional) – Assume that the count rate is the same for all ramps? Default False.

  • cguess (1D array of floats or None, optional) – Count rates for the purposes of computing a covariance matrix. Default None. If None, compute cguess from the nonlinearity-corrected ramps.

  • d2use (2D array of bools or None, optional) – Boolean mask of differences between reads to use for computing a likelihood. If None, use all read differences.

Returns:

logL (3D array of floats) – log likelihood, shape (len(sigs), len(gains), len(alphas))

get_best_nonlinearity(diffs_lin, diffs_quad, covar, sigs, gains, alpha_offset, dalpha, asig, cguess=None, d2use=None)[source]

Fit a quadratic form for three values of the nonlinearity coefficient, and then use a parzabolic fit to find the highest gain and the nonlinearity coefficient corresponding to this highest gain.

Parameters:
  • diffs_lin (2D array of float) – Size (nreads-1, nramps). Differences between consecutive reads.

  • diffs_quad (2D array of float) – Size (nreads-1, nramps). Differences between the squares of the values (from a designated pedestal) in consecutive reads.

  • covar (fitramp.Covar) – Should be appropriate for diffs_lin.

  • sigs (list of float) – Trial read noise values.

  • gains (list of float) – Trial gain values.

  • alpha_offset (float) – Trial nonlinearity coefficient value.

  • dalpha (float) – Offset in nonlinearity coefficient to try to fit a parabola to maximize the gain.

  • asig (float, optional) – Standard deviation of the read noise from other constraints. If the best-fit read noise from this other constraint is sigs[1], asig will incorporate this constraint into the likelihood.

  • cguess (1D array of float or None, optional) – Count rates for computing a covariance matrix. Default is None. If None, compute cguess from the nonlinearity-corrected ramps.

  • d2use (2D array of bool or None, optional) – Boolean mask of differences between reads to use for computing a likelihood. If None, use all read differences.

Returns:
  • bestloggain (float) – Best-fit log gain.

  • alphabest (float) – Best nonlinearity coefficient (the one that yields the highest best-fit gain).

  • alpha_inc (float) – Offset between alphabest and the input alpha_offset. Can be used to assess convergence.