Skip to content

Commit

Permalink
Merge pull request #222 from lsst/tickets/DM-42024
Browse files Browse the repository at this point in the history
DM-42024: Allow for low gains and allow initial outlier cutoff to have units of electrons.
  • Loading branch information
erykoff committed Dec 6, 2023
2 parents 83e0762 + c0e6461 commit 2f39c65
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 26 additions & 5 deletions python/lsst/cp/pipe/ptc/cpSolvePtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,17 @@ class PhotonTransferCurveSolveConfig(pipeBase.PipelineTaskConfig,
maxSignalInitialPtcOutlierFit = pexConfig.Field(
dtype=float,
doc="Maximum signal considered for intial outlier fit. This should be below "
"the PTC turnoff to ensure accurate outlier rejection.",
default=30_000.,
"the PTC turnoff to ensure accurate outlier rejection. If "
"scaleMaxSignalInitialPtcOutlierFit=True then the units are electrons; "
"otherwise ADU.",
default=50_0000.,
)
scaleMaxSignalInitialPtcOutlierFit = pexConfig.Field(
dtype=bool,
doc="Scale maxSignalInitialPtcOutlierFit by approximate gain? If yes then "
"maxSignalInitialPtcOutlierFit is assumed to have units of electrons, "
"otherwise ADU.",
default=True,
)
minVarPivotSearch = pexConfig.Field(
dtype=float,
Expand Down Expand Up @@ -1005,8 +1014,8 @@ def errFunc(p, x, y):
if self.config.binSize > 1:
bounds = self._boundsForAstier(parsIniPtc)
else:
bounds = self._boundsForAstier(parsIniPtc, lowers=[-1e-4, 0.5, -2000],
uppers=[1e-4, 2.5, 2000])
bounds = self._boundsForAstier(parsIniPtc, lowers=[-1e-4, 0.1, -2000],
uppers=[1e-4, 10.0, 2000])
if ptcFitType == 'POLYNOMIAL':
ptcFunc = funcPolynomial
parsIniPtc = self._initialParsForPolynomial(self.config.polynomialFitDegree + 1)
Expand All @@ -1022,6 +1031,18 @@ def errFunc(p, x, y):
# This algorithm was initially developed by Seth Digel for
# the EO Testing pipeline.

if self.config.scaleMaxSignalInitialPtcOutlierFit:
approxGain = np.nanmedian(meanVecOriginal/varVecOriginal)
maxADUInitialPtcOutlierFit = self.config.maxSignalInitialPtcOutlierFit/approxGain
self.log.info(
"Using approximate gain %.3f and ADU signal cutoff of %.1f for amplifier %s",
approxGain,
maxADUInitialPtcOutlierFit,
ampName,
)
else:
maxADUInitialPtcOutlierFit = self.config.maxSignalInitialPtcOutlierFit

if maxIterationsPtcOutliers == 0:
# We are not doing any outlier rejection here, but we do want
# an initial fit.
Expand All @@ -1034,7 +1055,7 @@ def errFunc(p, x, y):
pars = res.x
newMask = mask.copy()
else:
newMask = (mask & (meanVecOriginal <= self.config.maxSignalInitialPtcOutlierFit))
newMask = (mask & (meanVecOriginal <= maxADUInitialPtcOutlierFit))

count = 0
lastMask = mask.copy()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_linearity.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _create_ptc(self, amp_names, exp_times, means, ccobcurr=None, photo_charges=
inputExpIdPair=exp_id_pairs[i],
rawExpTime=exp_times[i],
rawMean=raw_mean,
rawVar=1.0,
rawVar=raw_mean,
kspValue=1.0,
expIdMask=exp_id_mask,
photoCharge=photo_charges[i],
Expand Down

0 comments on commit 2f39c65

Please sign in to comment.