Skip to content

Commit

Permalink
Fix test cases with new amp geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Broughton committed Sep 19, 2024
1 parent 9d88ca9 commit 039cf49
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
4 changes: 2 additions & 2 deletions python/lsst/ip/isr/isrMock.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ class IsrMockConfig(pexConfig.Config):
)
sourceX = pexConfig.ListField(
dtype=float,
default=[50.0],
default=[25.0],
doc="Peak position (in amplifier coordinates) of simulated 'astronomical sources'.",
)
sourceY = pexConfig.ListField(
dtype=float,
default=[25.0],
default=[35.0],
doc="Peak position (in amplifier coordinates) of simulated 'astronomical sources'.",
)
overscanScale = pexConfig.Field(
Expand Down
27 changes: 16 additions & 11 deletions python/lsst/ip/isr/isrMockLSST.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def __init__(self, **kwargs):
-8.44782871e-01, 3.54369868e-02, 5.31096720e-01,
8.10171823e-01, 4.83499829e-01]]) * 1e-10

# Spline trap coefficients and the ctiCalibDict are all taken from a
# Spline trap coefficients and the ctiCalibDict are all taken from a
# cti calibration measured from LSSTCam sensor R03_S12 during Run 5
# EO testing. These are the coefficients for the spline trap model
# used in the deferred charge calibration. The collection can be
Expand Down Expand Up @@ -816,6 +816,7 @@ def makeDeferredChargeCalib(self):
metadataDict['metadata'].add(name="OBSTYPE", value="CTI")
metadataDict['metadata'].add(name="CALIBCLS",
value="lsst.ip.isr.deferredCharge.DeferredChargeCalib")
metadataDict['metadata'].add("USEGAINS", value=False)
self.ctiCalibDict = {**metadataDict, **self.ctiCalibDict}
deferredChargeCalib = DeferredChargeCalib()
self.cti = deferredChargeCalib.fromDict(self.ctiCalibDict)
Expand All @@ -838,22 +839,27 @@ def amplifierAddBrighterFatter(self, ampImageData, rng, bfStrength, nRecalc):
"""

incidentImage = galsim.Image(ampImageData.array, scale=1)
measuredImage = galsim.ImageF(ampImageData.array.shape[1],
ampImageData.array.shape[0],
scale=1)
measuredImage = galsim.ImageF(
ampImageData.array.shape[1],
ampImageData.array.shape[0],
scale=1
)
photons = galsim.PhotonArray.makeFromImage(incidentImage)

sensorModel = galsim.SiliconSensor(strength=bfStrength,
rng=rng,
diffusion_factor=0.0,
nrecalc=nRecalc)
sensorModel = galsim.SiliconSensor(
strength=bfStrength,
rng=rng,
diffusion_factor=0.0,
nrecalc=nRecalc
)

totalFluxAdded = sensorModel.accumulate(photons, measuredImage)
ampImageData.array = measuredImage.array

return totalFluxAdded

def amplifierAddDeferredCharge(self, amp, ampImageData, ampFreeChargeData, cti, traps, driftScale, decayTime):
def amplifierAddDeferredCharge(self, amp, ampImageData, ampFreeChargeData, cti, traps, driftScale,
decayTime):
"""Add serial CTI to the ampllifier data.
Parameters
Expand Down Expand Up @@ -899,7 +905,7 @@ def flipImage(arr, readoutCorner):
# the lower left.
if readoutCorner == ReadoutCorner.LR:
return np.fliplr(arr)
elif readoutCorner == ReadoutCorner.UR:
elif readoutCorner == ReadoutCorner.UR:
return np.fliplr(np.flipud(arr))
elif readoutCorner == ReadoutCorner.UL:
return np.flipud(arr)
Expand Down Expand Up @@ -1006,7 +1012,6 @@ def amplifierAddNonlinearity(self, ampData, centers, values, offset):

ampData.array[:, :] += delta.reshape(ampData.array.shape)


def amplifierMultiplyFlat(self, amp, ampData, fracDrop, u0=100.0, v0=100.0):
"""Multiply an amplifier's image data by a flat-like pattern.
Expand Down
3 changes: 1 addition & 2 deletions python/lsst/ip/isr/isrTaskLSST.py
Original file line number Diff line number Diff line change
Expand Up @@ -1633,15 +1633,14 @@ def run(self, ccdExposure, *, dnlLUT=None, bias=None, deferredChargeCalib=None,
# (to make it simpler!)
# Output units: electron (adu if doBootstrap=True)
if self.config.doDeferredCharge:
self.log.info("Applying deferred charge/CTI correction.")
if exposureMetadata["LSST ISR UNITS"] == "electron":
self.deferredChargeCorrection.config.useGains = False
else:
self.deferredChargeCorrection.config.useGains = True
self.deferredChargeCorrection.run(
ccdExposure,
deferredChargeCalib,
gains=gains
gains=gains,
)

# Assemble/trim
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fringes.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ def test_multiFringes(self):
stdAfter = np.nanstd(exp.getImage().getArray())

self.assertLess(medianAfter, medianBefore)
self.assertFloatsAlmostEqual(medianAfter, 3000.925, atol=1e-4)
self.assertFloatsAlmostEqual(stdAfter, 3549.9885, atol=1e-4)
self.assertFloatsAlmostEqual(medianAfter, 3000.5981, atol=1e-3)
self.assertFloatsAlmostEqual(stdAfter, 3551.2116, atol=1e-3)

deviation = np.abs(solution - config.fringeScale)
self.assertTrue(np.all(deviation / rms < 1.0))
Expand Down
18 changes: 9 additions & 9 deletions tests/test_isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_updateVariance(self):
statAfter = computeImageMedianAndStd(self.inputExp.variance[self.amp.getBBox()])
self.assertGreater(statAfter[0], statBefore[0])
self.assertFloatsAlmostEqual(statBefore[0], 0.0, atol=1e-2)
self.assertFloatsAlmostEqual(statAfter[0], 8170.0195, atol=1e-2)
self.assertFloatsAlmostEqual(statAfter[0], 8171.2099, atol=1e-2)

def test_defineEffectivePtc(self):
ampName = self.amp.getName()
Expand Down Expand Up @@ -200,8 +200,8 @@ def test_darkCorrection(self):
self.task.darkCorrection(self.inputExp, darkIm)
statAfter = computeImageMedianAndStd(self.inputExp.image[self.amp.getBBox()])
self.assertLess(statAfter[0], statBefore[0])
self.assertFloatsAlmostEqual(statBefore[0], 8070.0195, atol=1e-2)
self.assertFloatsAlmostEqual(statAfter[0], 8045.7773, atol=1e-2)
self.assertFloatsAlmostEqual(statBefore[0], 8071.2099, atol=1e-2)
self.assertFloatsAlmostEqual(statAfter[0], 8046.7207, atol=1e-2)

def test_darkCorrection_noVisitInfo(self):
"""Expect the median image value should decrease after this operation.
Expand All @@ -213,8 +213,8 @@ def test_darkCorrection_noVisitInfo(self):
self.task.darkCorrection(self.inputExp, darkIm)
statAfter = computeImageMedianAndStd(self.inputExp.image[self.amp.getBBox()])
self.assertLess(statAfter[0], statBefore[0])
self.assertFloatsAlmostEqual(statBefore[0], 8070.0195, atol=1e-2)
self.assertFloatsAlmostEqual(statAfter[0], 8045.7773, atol=1e-2)
self.assertFloatsAlmostEqual(statBefore[0], 8071.2099, atol=1e-2)
self.assertFloatsAlmostEqual(statAfter[0], 8046.7207, atol=1e-2)

def test_flatCorrection(self):
"""Expect the image median should increase (divide by < 1).
Expand All @@ -225,8 +225,8 @@ def test_flatCorrection(self):
self.task.flatCorrection(self.inputExp, flatIm)
statAfter = computeImageMedianAndStd(self.inputExp.image[self.amp.getBBox()])
self.assertGreater(statAfter[1], statBefore[1])
self.assertFloatsAlmostEqual(statAfter[1], 147407.02, atol=1e-2)
self.assertFloatsAlmostEqual(statBefore[1], 147.55304, atol=1e-2)
self.assertFloatsAlmostEqual(statAfter[1], 147611.1875, atol=1e-2)
self.assertFloatsAlmostEqual(statBefore[1], 110.8648, atol=1e-2)

def test_saturationDetection(self):
"""Expect the saturation level detection/masking to scale with
Expand All @@ -242,8 +242,8 @@ def test_saturationDetection(self):
countAfter = countMaskedPixels(self.mi, "SAT")

self.assertLessEqual(countBefore, countAfter)
self.assertEqual(countBefore, 43)
self.assertEqual(countAfter, 136)
self.assertEqual(countBefore, 26)
self.assertEqual(countAfter, 116)

def test_measureBackground(self):
"""Expect the background measurement runs successfully and to save
Expand Down
12 changes: 12 additions & 0 deletions tests/test_isrTaskLSST.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,17 @@ def test_isrDark(self):

delta = result2.exposure.image.array - result.exposure.image.array
exp_time = input_exp.getInfo().getVisitInfo().getExposureTime()

# One pixel breaks the next test due to rounding error
# since mock_config.doRoundAdu=True. Let's remove it
# from the list of good pixels.
x = good_pixels[0]
y = good_pixels[1]
ind = np.argwhere((x == 110) * (y == 171))
x = np.delete(x, ind)
y = np.delete(y, ind)
good_pixels = (x, y)

self.assertFloatsAlmostEqual(
delta[good_pixels],
self.dark.image.array[good_pixels] * exp_time,
Expand Down Expand Up @@ -526,6 +537,7 @@ def test_isrNoise(self):
bias=self.bias,
crosstalk=self.crosstalk,
ptc=self.ptc,
deferredChargeCalib=self.cti,
linearizer=self.linearizer,
)

Expand Down

0 comments on commit 039cf49

Please sign in to comment.