Skip to content

Commit

Permalink
Switch to MaskedImage to pass mask to ensure match with previous code.
Browse files Browse the repository at this point in the history
  • Loading branch information
czwa committed May 17, 2022
1 parent c4307e1 commit bb26e3d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion include/lsst/ip/isr/isr.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ namespace isr {

template<typename ImagePixelT>
std::vector<double> fitOverscanImage(
lsst::afw::image::Image<ImagePixelT> const& overscan,
lsst::afw::image::MaskedImage<ImagePixelT> const& overscan,
std::vector<std::string> badPixelMask,
bool isTransposed
);

Expand Down
3 changes: 2 additions & 1 deletion python/lsst/ip/isr/isr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static void declareAll(py::module& mod, std::string const& suffix) {
declareCountMaskedPixels<PixelT>(mod, suffix);

mod.def("maskNans", &maskNans<PixelT>, "maskedImage"_a, "maskVal"_a, "allow"_a = 0);
mod.def("fitOverscanImage", &fitOverscanImage<PixelT>, "maskedImage"_a, "isTransposed"_a);
mod.def("fitOverscanImage", &fitOverscanImage<PixelT>,
"maskedImage"_a, "badPixelMask"_a, "isTransposed"_a);
}

} // namespace lsst::ip::isr::<anonymous>
Expand Down
17 changes: 12 additions & 5 deletions python/lsst/ip/isr/overscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class OverscanCorrectionTaskConfig(pexConfig.Config):
maskPlanes = pexConfig.ListField(
dtype=str,
doc="Mask planes to reject when measuring overscan",
default=['SAT'],
default=['BAD', 'SAT'],
)
overscanIsInt = pexConfig.Field(
dtype=bool,
Expand Down Expand Up @@ -479,11 +479,18 @@ def measureVectorOverscan(self, image):
masked = self.maskOutliers(calcImage)

startTime = time.perf_counter()

if self.config.fitType == 'MEDIAN_PER_ROW':
if isinstance(image, afwImage.MaskedImage):
overscanVector = fitOverscanImage(image.getImage(), isTransposed)
else:
overscanVector = fitOverscanImage(image, isTransposed)
mi = afwImage.MaskedImageI(image.getBBox())
masked = masked.astype(int)
if isTransposed:
masked = masked.transpose()

mi.getImage().getArray()[:, :] = masked.data[:, :]
if bool(masked.mask.shape):
mi.getMask().getArray()[:, :] = masked.mask[:, :]

overscanVector = fitOverscanImage(mi, self.config.maskPlanes, isTransposed)
maskArray = self.maskExtrapolated(overscanVector)
else:
collapsed = self.collapseArray(masked)
Expand Down
18 changes: 10 additions & 8 deletions src/Isr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ size_t maskNans(afw::image::MaskedImage<PixelT> const& mi, afw::image::MaskPixel

template<typename ImagePixelT>
std::vector<double> fitOverscanImage(
afw::image::Image<ImagePixelT> const& overscan,
afw::image::MaskedImage<ImagePixelT> const& overscan,
std::vector<std::string> badPixelMask,
bool isTransposed
) {
typedef afw::image::Image<ImagePixelT> Image;
typedef afw::image::MaskedImage<ImagePixelT> MaskedImage;

/**
This is transposed here to match the existing numpy-array ordering.
Expand All @@ -70,6 +71,8 @@ std::vector<double> fitOverscanImage(

std::vector<double> values(length);

afw::math::StatisticsControl statControl;
statControl.setAndMask(overscan.getMask()->getPlaneBitMask(badPixelMask));
const int x0 = overscan.getX0();
const int y0 = overscan.getY0();
for (int x = 0; x < length; ++x) {
Expand All @@ -86,10 +89,9 @@ std::vector<double> fitOverscanImage(
else {
bbox = geom::Box2I(geom::Point2I(x0,y0 + x), geom::Extent2I(width,1));
}
Image mi = Image(overscan, bbox);
afw::math::Statistics stats = afw::math::makeStatistics(mi, afw::math::MEDIAN);
MaskedImage mi = MaskedImage(overscan, bbox);

values[x] = stats.getValue(afw::math::MEDIAN);
values[x] = afw::math::makeStatistics(mi, afw::math::MEDIAN, statControl).getValue();
}
return values;
}
Expand All @@ -113,13 +115,13 @@ std::string between(std::string &s, char ldelim, char rdelim) {

template
std::vector<double> fitOverscanImage<int>(
afw::image::Image<int> const&, bool isTransposed);
afw::image::MaskedImage<int> const&, std::vector<std::string> badPixelMask, bool isTransposed);
template
std::vector<double> fitOverscanImage<float>(
afw::image::Image<float> const&, bool isTransposed);
afw::image::MaskedImage<float> const&, std::vector<std::string> badPixelMask, bool isTransposed);
template
std::vector<double> fitOverscanImage<double>(
afw::image::Image<double> const&, bool isTransposed);
afw::image::MaskedImage<double> const&, std::vector<std::string> badPixelMask, bool isTransposed);

template class CountMaskedPixels<float>;
template class CountMaskedPixels<double>;
Expand Down

0 comments on commit bb26e3d

Please sign in to comment.