Skip to content

Commit

Permalink
Check values in PTC per amp
Browse files Browse the repository at this point in the history
  • Loading branch information
plazas committed Nov 6, 2023
1 parent ae4b54f commit 79eb980
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
5 changes: 3 additions & 2 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1878,9 +1878,10 @@ def defineEffectivePtc(self, ptcDataset, detector, bfGains, overScans, metadata)

effectivePtc.gain[ampName] = gain
effectivePtc.noise[ampName] = noise

print ("before ampName: ", effectivePtc.gain[ampName], effectivePtc.noise[ampName])

Check failure on line 1881 in python/lsst/ip/isr/isrTask.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E211

whitespace before '('
# Make sure noise,turnoff, and gain make sense
effectivePtc.validateGainNoiseTurnoffValues()
effectivePtc.validateGainNoiseTurnoffValues(ampName)
print ("After ampName: ", effectivePtc.gain[ampName], effectivePtc.noise[ampName])

Check failure on line 1884 in python/lsst/ip/isr/isrTask.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E211

whitespace before '('

metadata[f"LSST GAIN {amp.getName()}"] = effectivePtc.gain[ampName]
metadata[f"LSST READNOISE {amp.getName()}"] = effectivePtc.noise[ampName]
Expand Down
53 changes: 26 additions & 27 deletions python/lsst/ip/isr/ptcDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,33 +776,32 @@ def getGoodPoints(self, ampName):
"""
return self.expIdMask[ampName]

def validateGainNoiseTurnoffValues(self):
def validateGainNoiseTurnoffValues(self, ampName):
"""Ensure the gain, read noise, and PTC turnoff have
sensible values."""

for ampName in self.ampNames:
gain = self.gain[ampName]
noise = self.noise[ampName]
ptcTurnoff = self.ptcTurnoff[ampName]

# Check if gain is not positive or is np.nan
if not (isinstance(gain, (int, float)) and gain > 0) or math.isnan(gain):
self.log.warning(f"Invalid gain value for {ampName}: {gain}"
" Setting to default: Gain=1")
gain = 1

# Check if noise is not positive or is np.nan
if not (isinstance(noise, (int, float)) and noise > 0) or math.isnan(noise):
self.log.warning(f"Invalid noise value for {ampName}: {noise}"
" Setting to default: Noise=1")
noise = 1

# Check if ptcTurnoff is not positive or is np.nan
if not (isinstance(ptcTurnoff, (int, float)) and ptcTurnoff > 0) or math.isnan(ptcTurnoff):
self.log.warning(f"Invalid PTC turnoff value for {ampName}: {ptcTurnoff}"
" Setting to default: PTC Turnoff=2e19")
ptcTurnoff = 2e19

self.gain[ampName] = gain
self.noise[ampName] = noise
self.ptcTurnoff[ampName] = ptcTurnoff
gain = self.gain[ampName]
noise = self.noise[ampName]
ptcTurnoff = self.ptcTurnoff[ampName]

# Check if gain is not positive or is np.nan
if not (isinstance(gain, (int, float)) and gain > 0) or math.isnan(gain):
self.log.warning(f"Invalid gain value for {ampName}: {gain}"
" Setting to default: Gain=1")
gain = 1

# Check if noise is not positive or is np.nan
if not (isinstance(noise, (int, float)) and noise > 0) or math.isnan(noise):
self.log.warning(f"Invalid noise value for {ampName}: {noise}"
" Setting to default: Noise=1")
noise = 1

# Check if ptcTurnoff is not positive or is np.nan
if not (isinstance(ptcTurnoff, (int, float)) and ptcTurnoff > 0) or math.isnan(ptcTurnoff):
self.log.warning(f"Invalid PTC turnoff value for {ampName}: {ptcTurnoff}"
" Setting to default: PTC Turnoff=2e19")
ptcTurnoff = 2e19

self.gain[ampName] = gain
self.noise[ampName] = noise
self.ptcTurnoff[ampName] = ptcTurnoff
2 changes: 1 addition & 1 deletion tests/test_flatAndIlluminationCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def testGainAndReadnoise(self):
effectivePtc = PhotonTransferCurveDataset([ampName], "TEST_PTC", 1)
effectivePtc.gain[ampName] = gain
effectivePtc.noise[ampName] = readNoise
effectivePtc.validateGainNoiseTurnoffValues()
effectivePtc.validateGainNoiseTurnoffValues(ampName)
isrTask.updateVariance(raw, testAmp, effectivePtc)
if gain <= 0: # behave the same way as amp.setGain
gain = 1
Expand Down

0 comments on commit 79eb980

Please sign in to comment.