LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 
26 #include "lsst/pex/logging/Trace.h"
27 #include "lsst/afw/math.h"
29 #include "lsst/ip/isr.h"
30 
31 namespace lsst { namespace ip { namespace isr {
32 
33 // Functions
34 template <typename ImageT>
36  double igain = 1.0 / gain;
37  int nPixTooHigh = 0;
38  int nPixTooLow = 0;
39  for (int y = 0; y != image.getHeight(); ++y) {
40  for (x_iterator ptr = image.row_begin(y), end = image.row_end(y); ptr != end; ++ptr) {
41  int ind = static_cast<int>(ptr.image() + 0.5); // Rounded pixel value
42  if (ind < 0) {
43  ind = 0;
44  ++nPixTooLow;
45  } else if (ind >= _max) {
46  ind = _max - 1;
47  ++nPixTooHigh;
48  }
49  PixelT p = PixelT(_table[ind], (*ptr).mask(), _table[ind] * igain);
50  *ptr = p;
51  }
52  }
53  if ((nPixTooHigh > 0) || (nPixTooLow > 0)) {
54  // log message
55  pex::logging::TTrace<1>("lsst.ip.isr.LookupTableReplace.apply",
56  "Data truncated; %d pixels were < 0; %d pixels were >= %d", nPixTooLow, nPixTooHigh, _max);
57  }
58 }
59 
60 template <typename PixelT>
63 {
64  typedef typename afw::image::MaskedImage<PixelT>::x_iterator x_iterator;
65  size_t nPix = 0;
66  for (int y = 0; y != mi.getHeight(); ++y) {
67  for (x_iterator ptr = mi.row_begin(y), end = mi.row_end(y); ptr != end; ++ptr) {
68  if (!(ptr.mask() & allow) && (!utils::lsst_isfinite(ptr.image()) ||
69  !utils::lsst_isfinite(ptr.variance()))) {
70  nPix += 1;
71  ptr.mask() |= maskVal;
72  }
73  }
74  }
75  return nPix;
76 }
77 
78 template<typename ImagePixelT, typename FunctionT>
80  boost::shared_ptr< afw::math::Function1<FunctionT> > &overscanFunction,
82  double ssize,
83  int sigma
84 ) {
85  typedef afw::image::MaskedImage<ImagePixelT> MaskedImage;
86 
87 
88  const int height = overscan.getHeight();
89  const int width = overscan.getWidth();
90  std::vector<double> values(height);
91  std::vector<double> errors(height);
92  std::vector<double> positions(height);
93 
94  std::vector<double> parameters(overscanFunction->getNParameters(), 0.);
95  std::vector<double> stepsize(overscanFunction->getNParameters(), ssize);
96 
97  for (int y = 0; y < height; ++y) {
105  MaskedImage mi = MaskedImage(overscan, bbox);
107 
108  values[y] = stats.getValue(afw::math::MEAN);
109  errors[y] = stats.getValue(afw::math::STDEV);
110  positions[y] = y;
111 
112  }
114  *overscanFunction,
115  parameters,
116  stepsize,
117  values,
118  errors,
119  positions,
120  sigma
121  );
122 
123  overscanFunction->setParameters(fitResults.parameterList);
124 }
125 
126 std::string between(std::string &s, char ldelim, char rdelim) {
127  std::string::iterator b(s.begin());
128  std::string::iterator e(s.end());
129  std::string::iterator lp;
130  std::string::iterator rp;
131 
132  std::string result;
133 
134  if((lp = std::find(b, e, ldelim)) != e)
135  if((rp = std::find(++lp, e, rdelim)) != e)
136  result = std::string(lp, rp);
137 
138  return result;
139 }
140 
141 // Explicit instantiations
142 
143 template
144 void fitOverscanImage(
145  boost::shared_ptr<afw::math::Function1<double> > &overscanFunction,
146  afw::image::MaskedImage<float> const& overscan,
147  double ssize,
148  int sigma);
149 
150 template
151 void fitOverscanImage(
152  boost::shared_ptr<afw::math::Function1<double> > &overscanFunction,
153  afw::image::MaskedImage<double> const& overscan,
154  double ssize,
155  int sigma);
156 
157 template class CountMaskedPixels<float>;
158 template class CountMaskedPixels<double>;
159 
160 // Integer classes make no sense for multiplicative table
161 // unless you change the image type
162 template class LookupTableMultiplicative<float>;
163 template class LookupTableMultiplicative<double>;
164 
165 // Only integer images make sense for a replacement table
166 template class LookupTableReplace<int>;
167 // But we turn our images into floats immediately, so use it
168 template class LookupTableReplace<float>;
169 // Function to mask nans in a masked image
174 
175 }}} // namespace lsst::ip::isr
int y
An include file to include the public header files for lsst::afw::math.
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
Definition: Statistics.cc:1009
boost::uint16_t MaskPixel
int getWidth() const
Return the number of columns in the image.
Definition: MaskedImage.h:901
estimate sample mean
Definition: Statistics.h:67
std::string between(std::string &s, char ldelim, char rdelim)
Definition: Isr.cc:126
Implementation of the templated Instrument Signature Removal stage of the nightly LSST Image Processi...
void fitOverscanImage(boost::shared_ptr< lsst::afw::math::Function1< FunctionT > > &overscanFunction, lsst::afw::image::MaskedImage< ImagePixelT > const &overscan, double ssize=1., int sigma=1)
definition of the Trace messaging facilities
estimate sample standard deviation
Definition: Statistics.h:68
void apply(lsst::afw::image::MaskedImage< ImageT > &image, float gain=1.0) const
Definition: Isr.cc:35
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)
x_iterator row_end(int y) const
Return an x_iterator to the end of the image.
Definition: MaskedImage.cc:752
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
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
Ref< MaskPixelT >::type mask()
Return (a reference to) the mask part of the Pixel pointed at by the iterator.
Definition: MaskedImage.h:152
An iterator to the MaskedImage.
Definition: MaskedImage.h:109
Results from minimizing a function.
Definition: minimize.h:51
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
A Function taking one argument.
Definition: Function.h:229
std::vector< double > parameterList
fit parameters
Definition: minimize.h:55
A pixel of a MaskedImage.
Definition: Pixel.h:137
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082
Compute Image Statistics.
afw::table::Key< double > b
x_iterator row_begin(int y) const
Return an x_iterator to the start of the image.
Definition: MaskedImage.cc:742
size_t maskNans(afw::image::MaskedImage< PixelT > const &mi, afw::image::MaskPixel maskVal, afw::image::MaskPixel allow=0)
Definition: Isr.cc:61
int getHeight() const
Return the number of rows in the image.
Definition: MaskedImage.h:903
template size_t maskNans< double >(afw::image::MaskedImage< double > const &, afw::image::MaskPixel, afw::image::MaskPixel)