LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
Isr.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #include <cmath>
26 
27 #include "lsst/afw/math.h"
29 #include "lsst/ip/isr/isr.h"
30 
31 namespace lsst { namespace ip { namespace isr {
32 
33 template <typename PixelT>
36 {
37  typedef typename afw::image::MaskedImage<PixelT>::x_iterator x_iterator;
38  size_t nPix = 0;
39  for (int y = 0; y != mi.getHeight(); ++y) {
40  for (x_iterator ptr = mi.row_begin(y), end = mi.row_end(y); ptr != end; ++ptr) {
41  if (!(ptr.mask() & allow) && (!std::isfinite(ptr.image()) ||
42  !std::isfinite(ptr.variance()))) {
43  nPix += 1;
44  ptr.mask() |= maskVal;
45  }
46  }
47  }
48  return nPix;
49 }
50 
51 template<typename ImagePixelT, typename FunctionT>
53  std::shared_ptr< afw::math::Function1<FunctionT> > &overscanFunction,
55  double ssize,
56  int sigma
57 ) {
58  typedef afw::image::MaskedImage<ImagePixelT> MaskedImage;
59 
60 
61  const int height = overscan.getHeight();
62  const int width = overscan.getWidth();
63  std::vector<double> values(height);
64  std::vector<double> errors(height);
65  std::vector<double> positions(height);
66 
67  std::vector<double> parameters(overscanFunction->getNParameters(), 0.);
68  std::vector<double> stepsize(overscanFunction->getNParameters(), ssize);
69 
70  for (int y = 0; y < height; ++y) {
78  MaskedImage mi = MaskedImage(overscan, bbox);
80 
81  values[y] = stats.getValue(afw::math::MEAN);
82  errors[y] = stats.getValue(afw::math::STDEV);
83  positions[y] = y;
84 
85  }
87  *overscanFunction,
88  parameters,
89  stepsize,
90  values,
91  errors,
92  positions,
93  sigma
94  );
95 
96  overscanFunction->setParameters(fitResults.parameterList);
97 }
98 
99 std::string between(std::string &s, char ldelim, char rdelim) {
100  std::string::iterator b(s.begin());
101  std::string::iterator e(s.end());
102  std::string::iterator lp;
103  std::string::iterator rp;
104 
105  std::string result;
106 
107  if((lp = std::find(b, e, ldelim)) != e)
108  if((rp = std::find(++lp, e, rdelim)) != e)
109  result = std::string(lp, rp);
110 
111  return result;
112 }
113 
114 // Explicit instantiations
115 
116 template
117 void fitOverscanImage(
118  std::shared_ptr<afw::math::Function1<double> > &overscanFunction,
119  afw::image::MaskedImage<float> const& overscan,
120  double ssize,
121  int sigma);
122 
123 template
124 void fitOverscanImage(
125  std::shared_ptr<afw::math::Function1<double> > &overscanFunction,
126  afw::image::MaskedImage<double> const& overscan,
127  double ssize,
128  int sigma);
129 
130 template class CountMaskedPixels<float>;
131 template class CountMaskedPixels<double>;
132 
133 // Function to mask nans in a masked image
138 
139 }}} // namespace lsst::ip::isr
int y
x_iterator row_begin(int y) const
Return an x_iterator to the start of the image.
Definition: MaskedImage.cc:757
An include file to include the public header files for lsst::afw::math.
std::uint16_t MaskPixel
std::vector< double > parameterList
fit parameters
Definition: minimize.h:55
Ref< MaskPixelT >::type mask()
Return (a reference to) the mask part of the Pixel pointed at by the iterator.
Definition: MaskedImage.h:153
std::string between(std::string &s, char ldelim, char rdelim)
Definition: Isr.cc:99
int getHeight() const
Return the number of rows in the image.
Definition: MaskedImage.h:909
estimate sample standard deviation
Definition: Statistics.h:68
void fitOverscanImage(std::shared_ptr< lsst::afw::math::Function1< FunctionT > > &overscanFunction, lsst::afw::image::MaskedImage< ImagePixelT > const &overscan, double ssize=1., int sigma=1)
x_iterator row_end(int y) const
Return an x_iterator to the end of the image.
Definition: MaskedImage.cc:767
FitResults minimize(lsst::afw::math::Function1< ReturnT > const &function, std::vector< double > const &initialParameterList, std::vector< double > const &stepSizeList, std::vector< double > const &measurementList, std::vector< double > const &varianceList, std::vector< double > const &xPositionList, double errorDef)
template size_t maskNans< float >(afw::image::MaskedImage< float > const &, afw::image::MaskPixel, afw::image::MaskPixel)
An integer coordinate rectangle.
Definition: Box.h:53
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:43
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
Definition: Statistics.cc:1034
Results from minimizing a function.
Definition: minimize.h:51
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:78
A Function taking one argument.
Definition: Function.h:229
estimate sample mean
Definition: Statistics.h:67
int getWidth() const
Return the number of columns in the image.
Definition: MaskedImage.h:907
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1107
Implementation of the templated Instrument Signature Removal stage of the nightly LSST Image Processi...
Compute Image Statistics.
afw::table::Key< double > b
size_t maskNans(afw::image::MaskedImage< PixelT > const &mi, afw::image::MaskPixel maskVal, afw::image::MaskPixel allow=0)
Definition: Isr.cc:34
template size_t maskNans< double >(afw::image::MaskedImage< double > const &, afw::image::MaskPixel, afw::image::MaskPixel)