LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Classes | Functions
lsst.ip.isr.measureCrosstalk Namespace Reference

Classes

class  MeasureCrosstalkConfig
 
class  MeasureCrosstalkTask
 

Functions

def extractCrosstalkRatios (exposure, threshold=30000, badPixels=["SAT", BAD, INTRP)
 
def measureCrosstalkCoefficients (ratios, rejIter=3, rejSigma=2.0)
 

Function Documentation

◆ extractCrosstalkRatios()

def lsst.ip.isr.measureCrosstalk.extractCrosstalkRatios (   exposure,
  threshold = 30000,
  badPixels = ["SAT",
  BAD,
  INTRP 
)
Extract crosstalk ratios between different amplifiers

For pixels above ``threshold``, we calculate the ratio between each
target amp and source amp. We return a list of ratios for each pixel
for each target/source combination, as a matrix of lists.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    Exposure for which to measure crosstalk.
threshold : `float`
    Lower limit on pixels for which we measure crosstalk.
badPixels : `list` of `str`
    Mask planes indicating a pixel is bad.

Returns
-------
ratios : `list` of `list` of `numpy.ndarray`
    A matrix of pixel arrays. ``ratios[i][j]`` is an array of
    the fraction of the ``j``-th amp present on the ``i``-th amp.
    The value is `None` for the diagonal elements.

Definition at line 42 of file measureCrosstalk.py.

42 def extractCrosstalkRatios(exposure, threshold=30000, badPixels=["SAT", "BAD", "INTRP"]):
43  """Extract crosstalk ratios between different amplifiers
44 
45  For pixels above ``threshold``, we calculate the ratio between each
46  target amp and source amp. We return a list of ratios for each pixel
47  for each target/source combination, as a matrix of lists.
48 
49  Parameters
50  ----------
51  exposure : `lsst.afw.image.Exposure`
52  Exposure for which to measure crosstalk.
53  threshold : `float`
54  Lower limit on pixels for which we measure crosstalk.
55  badPixels : `list` of `str`
56  Mask planes indicating a pixel is bad.
57 
58  Returns
59  -------
60  ratios : `list` of `list` of `numpy.ndarray`
61  A matrix of pixel arrays. ``ratios[i][j]`` is an array of
62  the fraction of the ``j``-th amp present on the ``i``-th amp.
63  The value is `None` for the diagonal elements.
64  """
65  mi = exposure.getMaskedImage()
66  FootprintSet(mi, Threshold(threshold), "DETECTED")
67  detected = mi.getMask().getPlaneBitMask("DETECTED")
68  bad = mi.getMask().getPlaneBitMask(badPixels)
69  bg = calculateBackground(mi, badPixels + ["DETECTED"])
70 
71  ccd = exposure.getDetector()
72 
73  ratios = [[None for iAmp in ccd] for jAmp in ccd]
74 
75  for ii, iAmp in enumerate(ccd):
76  iImage = mi[iAmp.getBBox()]
77  iMask = iImage.mask.array
78  select = (iMask & detected > 0) & (iMask & bad == 0) & np.isfinite(iImage.image.array)
79  for jj, jAmp in enumerate(ccd):
80  if ii == jj:
81  continue
82  jImage = extractAmp(mi.image, jAmp, iAmp.getReadoutCorner(), isTrimmed=True)
83  ratios[jj][ii] = (jImage.array[select] - bg)/iImage.image.array[select]
84 
85  return ratios
86 
87 
def calculateBackground(mi, badPixels=["BAD"])
Definition: crosstalk.py:154
def extractCrosstalkRatios(exposure, threshold=30000, badPixels=["SAT", BAD, INTRP)
def extractAmp(image, amp, corner, isTrimmed=False)
Definition: crosstalk.py:122

◆ measureCrosstalkCoefficients()

def lsst.ip.isr.measureCrosstalk.measureCrosstalkCoefficients (   ratios,
  rejIter = 3,
  rejSigma = 2.0 
)
Measure crosstalk coefficients from the ratios

Given a list of ratios for each target/source amp combination,
we measure a robust mean and error.

The coefficient errors returned are the (robust) standard deviation of
the input ratios.

Parameters
----------
ratios : `list` of `list` of `numpy.ndarray`
    Matrix of arrays of ratios.
rejIter : `int`
    Number of rejection iterations.
rejSigma : `float`
    Rejection threshold (sigma).

Returns
-------
coeff : `numpy.ndarray`
    Crosstalk coefficients.
coeffErr : `numpy.ndarray`
    Crosstalk coefficient errors.
coeffNum : `numpy.ndarray`
    Number of pixels for each measurement.

Definition at line 88 of file measureCrosstalk.py.

88 def measureCrosstalkCoefficients(ratios, rejIter=3, rejSigma=2.0):
89  """Measure crosstalk coefficients from the ratios
90 
91  Given a list of ratios for each target/source amp combination,
92  we measure a robust mean and error.
93 
94  The coefficient errors returned are the (robust) standard deviation of
95  the input ratios.
96 
97  Parameters
98  ----------
99  ratios : `list` of `list` of `numpy.ndarray`
100  Matrix of arrays of ratios.
101  rejIter : `int`
102  Number of rejection iterations.
103  rejSigma : `float`
104  Rejection threshold (sigma).
105 
106  Returns
107  -------
108  coeff : `numpy.ndarray`
109  Crosstalk coefficients.
110  coeffErr : `numpy.ndarray`
111  Crosstalk coefficient errors.
112  coeffNum : `numpy.ndarray`
113  Number of pixels for each measurement.
114  """
115  numAmps = len(ratios)
116  assert all(len(rr) == numAmps for rr in ratios)
117 
118  coeff = np.zeros((numAmps, numAmps))
119  coeffErr = np.zeros((numAmps, numAmps))
120  coeffNum = np.zeros((numAmps, numAmps), dtype=int)
121 
122  for ii, jj in itertools.product(range(numAmps), range(numAmps)):
123  if ii == jj:
124  values = [0.0]
125  else:
126  values = np.array(ratios[ii][jj])
127  values = values[np.abs(values) < 1.0] # Discard unreasonable values
128 
129  coeffNum[ii][jj] = len(values)
130 
131  if len(values) == 0:
132  coeff[ii][jj] = np.nan
133  coeffErr[ii][jj] = np.nan
134  else:
135  if ii != jj:
136  for rej in range(rejIter):
137  lo, med, hi = np.percentile(values, [25.0, 50.0, 75.0])
138  sigma = 0.741*(hi - lo)
139  good = np.abs(values - med) < rejSigma*sigma
140  if good.sum() == len(good):
141  break
142  values = values[good]
143 
144  coeff[ii][jj] = np.mean(values)
145  coeffErr[ii][jj] = np.nan if coeffNum[ii][jj] == 1 else np.std(values)
146 
147  return coeff, coeffErr, coeffNum
148 
149 
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.
def measureCrosstalkCoefficients(ratios, rejIter=3, rejSigma=2.0)