lsst.cp.pipe  21.0.0-27-gcbf119a+ce1dbdaa8b
Classes | Functions
lsst.cp.pipe.utils Namespace Reference

Classes

class  PairedVisitListTaskRunner
 
class  SingleVisitListTaskRunner
 
class  NonexistentDatasetTaskDataIdContainer
 

Functions

def sigmaClipCorrection (nSigClip)
 
def calculateWeightedReducedChi2 (measured, model, weightsMeasured, nData, nParsModel)
 
def makeMockFlats (expTime, gain=1.0, readNoiseElectrons=5, fluxElectrons=1000, randomSeedFlat1=1984, randomSeedFlat2=666, powerLawBfParams=[], expId1=0, expId2=1)
 
def countMaskedPixels (maskedIm, maskPlane)
 
def parseCmdlineNumberString (inputString)
 
def irlsFit (initialParams, dataX, dataY, function, weightsY=None, weightType='Cauchy')
 
def fitLeastSq (initialParams, dataX, dataY, function, weightsY=None)
 
def fitBootstrap (initialParams, dataX, dataY, function, weightsY=None, confidenceSigma=1.)
 
def funcPolynomial (pars, x)
 
def funcAstier (pars, x)
 
def arrangeFlatsByExpTime (exposureList, exposureIdList)
 
def arrangeFlatsByExpId (exposureList, exposureIdList)
 
def checkExpLengthEqual (exp1, exp2, v1=None, v2=None, raiseWithMessage=False)
 
def validateIsrConfig (isrTask, mandatory=None, forbidden=None, desirable=None, undesirable=None, checkTrim=True, logName=None)
 
def ddict2dict (d)
 

Function Documentation

◆ arrangeFlatsByExpId()

def lsst.cp.pipe.utils.arrangeFlatsByExpId (   exposureList,
  exposureIdList 
)
Arrange exposures by exposure ID.

There is no guarantee that this will properly group exposures, but
allows a sequence of flats that have different illumination
(despite having the same exposure time) to be processed.

Parameters
----------
exposureList : `list`[`lsst.afw.image.exposure.exposure.ExposureF`]
    Input list of exposures.

exposureIdList : `list`[`int`]
    List of exposure ids as obtained by dataId[`exposure`].

Returns
------
flatsAtExpId : `dict` [`float`,
               `list`[(`lsst.afw.image.exposure.exposure.ExposureF`, `int`)]]
    Dictionary that groups flat-field exposures (and their IDs)
    sequentially by their exposure id.

Notes
-----

This algorithm sorts the input exposures by their exposure id, and
then assigns each pair of exposures (exp_j, exp_{j+1}) to pair k,
such that 2*k = j, where j is the python index of one of the
exposures (starting from zero).  By checking for the IndexError
while appending, we can ensure that there will only ever be fully
populated pairs.

Definition at line 622 of file utils.py.

◆ arrangeFlatsByExpTime()

def lsst.cp.pipe.utils.arrangeFlatsByExpTime (   exposureList,
  exposureIdList 
)
Arrange exposures by exposure time.

Parameters
----------
exposureList : `list`[`lsst.afw.image.exposure.exposure.ExposureF`]
    Input list of exposures.

exposureIdList : `list`[`int`]
    List of exposure ids as obtained by dataId[`exposure`].

Returns
------
flatsAtExpTime : `dict` [`float`,
                  `list`[(`lsst.afw.image.exposure.exposure.ExposureF`, `int`)]]
    Dictionary that groups flat-field exposures (and their IDs) that have
    the same exposure time (seconds).

Definition at line 594 of file utils.py.

◆ calculateWeightedReducedChi2()

def lsst.cp.pipe.utils.calculateWeightedReducedChi2 (   measured,
  model,
  weightsMeasured,
  nData,
  nParsModel 
)
Calculate weighted reduced chi2.

Parameters
----------

measured : `list`
    List with measured data.

model : `list`
    List with modeled data.

weightsMeasured : `list`
    List with weights for the measured data.

nData : `int`
    Number of data points.

nParsModel : `int`
    Number of parameters in the model.

Returns
-------

redWeightedChi2 : `float`
    Reduced weighted chi2.

Definition at line 69 of file utils.py.

◆ checkExpLengthEqual()

def lsst.cp.pipe.utils.checkExpLengthEqual (   exp1,
  exp2,
  v1 = None,
  v2 = None,
  raiseWithMessage = False 
)
Check the exposure lengths of two exposures are equal.

Parameters:
-----------
exp1 : `lsst.afw.image.exposure.ExposureF`
    First exposure to check
exp2 : `lsst.afw.image.exposure.ExposureF`
    Second exposure to check
v1 : `int` or `str`, optional
    First visit of the visit pair
v2 : `int` or `str`, optional
    Second visit of the visit pair
raiseWithMessage : `bool`
    If True, instead of returning a bool, raise a RuntimeError if exposure
times are not equal, with a message about which visits mismatch if the
information is available.

Raises:
-------
RuntimeError
    Raised if the exposure lengths of the two exposures are not equal

Definition at line 673 of file utils.py.

◆ countMaskedPixels()

def lsst.cp.pipe.utils.countMaskedPixels (   maskedIm,
  maskPlane 
)
Count the number of pixels in a given mask plane.

Definition at line 200 of file utils.py.

◆ ddict2dict()

def lsst.cp.pipe.utils.ddict2dict (   d)
Convert nested default dictionaries to regular dictionaries.

This is needed to prevent yaml persistence issues.

Parameters
----------
d : `defaultdict`
    A possibly nested set of `defaultdict`.

Returns
-------
dict : `dict`
    A possibly nested set of `dict`.

Definition at line 806 of file utils.py.

◆ fitBootstrap()

def lsst.cp.pipe.utils.fitBootstrap (   initialParams,
  dataX,
  dataY,
  function,
  weightsY = None,
  confidenceSigma = 1. 
)
Do a fit using least squares and bootstrap to estimate parameter errors.

The bootstrap error bars are calculated by fitting 100 random data sets.

Parameters
----------
initialParams : `list` of `float`
    initial values for fit parameters. For ptcFitType=POLYNOMIAL, its length
    determines the degree of the polynomial.

dataX : `numpy.array` of `float`
    Data in the abscissa axis.

dataY : `numpy.array` of `float`
    Data in the ordinate axis.

function : callable object (function)
    Function to fit the data with.

weightsY : `numpy.array` of `float`, optional.
    Weights of the data in the ordinate axis.

confidenceSigma : `float`, optional.
    Number of sigmas that determine confidence interval for the bootstrap errors.

Return
------
pFitBootstrap : `list` of `float`
    List with fitted parameters.

pErrBootstrap : `list` of `float`
    List with errors for fitted parameters.

reducedChiSqBootstrap : `float`
    Reduced chi squared, unweighted if weightsY is not provided.

Definition at line 487 of file utils.py.

◆ fitLeastSq()

def lsst.cp.pipe.utils.fitLeastSq (   initialParams,
  dataX,
  dataY,
  function,
  weightsY = None 
)
Do a fit and estimate the parameter errors using using scipy.optimize.leastq.

optimize.leastsq returns the fractional covariance matrix. To estimate the
standard deviation of the fit parameters, multiply the entries of this matrix
by the unweighted reduced chi squared and take the square root of the diagonal elements.

Parameters
----------
initialParams : `list` of `float`
    initial values for fit parameters. For ptcFitType=POLYNOMIAL, its length
    determines the degree of the polynomial.

dataX : `numpy.array` of `float`
    Data in the abscissa axis.

dataY : `numpy.array` of `float`
    Data in the ordinate axis.

function : callable object (function)
    Function to fit the data with.

weightsY : `numpy.array` of `float`
    Weights of the data in the ordinate axis.

Return
------
pFitSingleLeastSquares : `list` of `float`
    List with fitted parameters.

pErrSingleLeastSquares : `list` of `float`
    List with errors for fitted parameters.

reducedChiSqSingleLeastSquares : `float`
    Reduced chi squared, unweighted if weightsY is not provided.

Definition at line 420 of file utils.py.

◆ funcAstier()

def lsst.cp.pipe.utils.funcAstier (   pars,
  x 
)
Single brighter-fatter parameter model for PTC; Equation 16 of Astier+19.

Parameters
----------
params : `list`
    Parameters of the model: a00 (brightter-fatter), gain (e/ADU), and noise (e^2).

x : `numpy.array`
    Signal mu (ADU).

Returns
-------
C_00 (variance) in ADU^2.

Definition at line 575 of file utils.py.

◆ funcPolynomial()

def lsst.cp.pipe.utils.funcPolynomial (   pars,
  x 
)
Polynomial function definition
Parameters
----------
params : `list`
    Polynomial coefficients. Its length determines the polynomial order.

x : `numpy.array`
    Abscisa array.

Returns
-------
Ordinate array after evaluating polynomial of order len(pars)-1 at `x`.

Definition at line 558 of file utils.py.

◆ irlsFit()

def lsst.cp.pipe.utils.irlsFit (   initialParams,
  dataX,
  dataY,
  function,
  weightsY = None,
  weightType = 'Cauchy' 
)
Iteratively reweighted least squares fit.

This uses the `lsst.cp.pipe.utils.fitLeastSq`, but applies weights
based on the Cauchy distribution by default.  Other weight options
are implemented.  See e.g. Holland and Welsch, 1977,
doi:10.1080/03610927708827533

Parameters
----------
initialParams : `list` [`float`]
    Starting parameters.
dataX : `numpy.array` [`float`]
    Abscissa data.
dataY : `numpy.array` [`float`]
    Ordinate data.
function : callable
    Function to fit.
weightsY : `numpy.array` [`float`]
    Weights to apply to the data.
weightType : `str`, optional
    Type of weighting to use.  One of Cauchy, Anderson, bisquare,
    box, Welsch, Huber, logistic, or Fair.

Returns
-------
polyFit : `list` [`float`]
    Final best fit parameters.
polyFitErr : `list` [`float`]
    Final errors on fit parameters.
chiSq : `float`
    Reduced chi squared.
weightsY : `list` [`float`]
    Final weights used for each point.

Raises
------
RuntimeError :
    Raised if an unknown weightType string is passed.

Definition at line 327 of file utils.py.

◆ makeMockFlats()

def lsst.cp.pipe.utils.makeMockFlats (   expTime,
  gain = 1.0,
  readNoiseElectrons = 5,
  fluxElectrons = 1000,
  randomSeedFlat1 = 1984,
  randomSeedFlat2 = 666,
  powerLawBfParams = [],
  expId1 = 0,
  expId2 = 1 
)
Create a pair or mock flats with isrMock.

Parameters
----------
expTime : `float`
    Exposure time of the flats.

gain : `float`, optional
    Gain, in e/ADU.

readNoiseElectrons : `float`, optional
    Read noise rms, in electrons.

fluxElectrons : `float`, optional
    Flux of flats, in electrons per second.

randomSeedFlat1 : `int`, optional
    Random seed for the normal distrubutions for the mean signal and noise (flat1).

randomSeedFlat2 : `int`, optional
    Random seed for the normal distrubutions for the mean signal and noise (flat2).

powerLawBfParams : `list`, optional
    Parameters for `galsim.cdmodel.PowerLawCD` to simulate the brightter-fatter effect.

expId1 : `int`, optional
    Exposure ID for first flat.

expId2 : `int`, optional
    Exposure ID for second flat.

Returns
-------

flatExp1 : `lsst.afw.image.exposure.exposure.ExposureF`
    First exposure of flat field pair.

flatExp2 : `lsst.afw.image.exposure.exposure.ExposureF`
    Second exposure of flat field pair.

Notes
-----
The parameters of `galsim.cdmodel.PowerLawCD` are `n, r0, t0, rx, tx, r, t, alpha`. For more
information about their meaning, see the Galsim documentation
https://galsim-developers.github.io/GalSim/_build/html/_modules/galsim/cdmodel.html
and Gruen+15 (1501.02802).

Example: galsim.cdmodel.PowerLawCD(8, 1.1e-7, 1.1e-7, 1.0e-8, 1.0e-8, 1.0e-9, 1.0e-9, 2.0)

Definition at line 101 of file utils.py.

◆ parseCmdlineNumberString()

def lsst.cp.pipe.utils.parseCmdlineNumberString (   inputString)
Parse command line numerical expression sytax and return as list of int

Take an input of the form "'1..5:2^123..126'" as a string, and return
a list of ints as [1, 3, 5, 123, 124, 125, 126]

Definition at line 242 of file utils.py.

◆ sigmaClipCorrection()

def lsst.cp.pipe.utils.sigmaClipCorrection (   nSigClip)
Correct measured sigma to account for clipping.

If we clip our input data and then measure sigma, then the
measured sigma is smaller than the true value because real
points beyond the clip threshold have been removed.  This is a
small (1.5% at nSigClip=3) effect when nSigClip >~ 3, but the
default parameters for measure crosstalk use nSigClip=2.0.
This causes the measured sigma to be about 15% smaller than
real.  This formula corrects the issue, for the symmetric case
(upper clip threshold equal to lower clip threshold).

Parameters
----------
nSigClip : `float`
    Number of sigma the measurement was clipped by.

Returns
-------
scaleFactor : `float`
    Scale factor to increase the measured sigma by.

Definition at line 42 of file utils.py.

◆ validateIsrConfig()

def lsst.cp.pipe.utils.validateIsrConfig (   isrTask,
  mandatory = None,
  forbidden = None,
  desirable = None,
  undesirable = None,
  checkTrim = True,
  logName = None 
)
Check that appropriate ISR settings have been selected for the task.

Note that this checks that the task itself is configured correctly rather
than checking a config.

Parameters
----------
isrTask : `lsst.ip.isr.IsrTask`
    The task whose config is to be validated

mandatory : `iterable` of `str`
    isr steps that must be set to True. Raises if False or missing

forbidden : `iterable` of `str`
    isr steps that must be set to False. Raises if True, warns if missing

desirable : `iterable` of `str`
    isr steps that should probably be set to True. Warns is False, info if
missing

undesirable : `iterable` of `str`
    isr steps that should probably be set to False. Warns is True, info if
missing

checkTrim : `bool`
    Check to ensure the isrTask's assembly subtask is trimming the images.
This is a separate config as it is very ugly to do this within the
normal configuration lists as it is an option of a sub task.

Raises
------
RuntimeError
    Raised if ``mandatory`` config parameters are False,
    or if ``forbidden`` parameters are True.

TypeError
    Raised if parameter ``isrTask`` is an invalid type.

Notes
-----
Logs warnings using an isrValidation logger for desirable/undesirable
options that are of the wrong polarity or if keys are missing.

Definition at line 710 of file utils.py.