Skip to content

Commit

Permalink
Fix handling of mask in node computation and initial linearizer fit.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff committed Jul 13, 2023
1 parent 39039ac commit 4283018
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/lsst/cp/pipe/linearity.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def run(self, inputPtc, dummy, camera, inputDims,
# fits deviations from linearity, rather than the linear
# function itself which is degenerate with the gain.

nodes = np.linspace(0.0, inputOrdinate.max(), self.config.splineKnots)
nodes = np.linspace(0.0, np.max(inputOrdinate[mask]), self.config.splineKnots)

fitter = AstierSplineLinearityFitter(
nodes,
Expand Down
10 changes: 6 additions & 4 deletions python/lsst/cp/pipe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def estimate_p0(self):
p0 = np.zeros(npt)

# Do a simple linear fit and set all the constants to this.
linfit = np.polyfit(self._pd, self._mu, 1)
linfit = np.polyfit(self._pd[self.mask], self._mu[self.mask], 1)
p0[-self.ngroup:] = linfit[0]

# Look at the residuals...
Expand All @@ -867,7 +867,7 @@ def estimate_p0(self):
self._mu,
)
# ...and adjust the linear parameters accordingly.
p0[-self.ngroup:] *= np.median(ratio_model)
p0[-self.ngroup:] *= np.median(ratio_model[self.mask])

# Re-compute the residuals.
ratio_model2 = self.compute_ratio_model(
Expand All @@ -879,10 +879,10 @@ def estimate_p0(self):
)

# And compute a first guess of the spline nodes.
bins = np.searchsorted(self._nodes, self._mu)
bins = np.searchsorted(self._nodes, self._mu[self.mask])
tot_arr = np.zeros(len(self._nodes))
n_arr = np.zeros(len(self._nodes), dtype=int)
np.add.at(tot_arr, bins, ratio_model2)
np.add.at(tot_arr, bins, ratio_model2[self.mask])
np.add.at(n_arr, bins, 1)

ratio = np.ones(len(self._nodes))
Expand Down Expand Up @@ -1014,6 +1014,8 @@ def __call__(self, pars):
)

resid = self._w*(ratio_model - 1.0)
# Ensure masked points have 0 residual.
resid[~self.mask] = 0.0

constraint = [1e3 * np.mean(spl.interpolate(self._x_regularize))]
# 0 should transform to 0
Expand Down
6 changes: 6 additions & 0 deletions tests/test_linearity.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ def _check_linearity_spline(self, do_pd_offsets=False):
pd_values_offset[group2] *= pd_offset_factors[2]
pd_values_offset[group3] *= pd_offset_factors[3]

# Add one bad photodiode value, but don't put it at the very
# end because that would change the spline node positions
# and make comparisons to the "truth" here in the tests
# more difficult.
pd_values_offset[-2] = np.nan

ptc = self._create_ptc(
self.amp_names,
time_values,
Expand Down

0 comments on commit 4283018

Please sign in to comment.