lsst.ip.isr  13.0-15-g0af5a6c+29
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>
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
std::vector< double > parameterList
std::string between(std::string &s, char ldelim, char rdelim)
Definition: Isr.cc:99
void fitOverscanImage(std::shared_ptr< lsst::afw::math::Function1< FunctionT > > &overscanFunction, lsst::afw::image::MaskedImage< ImagePixelT > const &overscan, double ssize=1., int sigma=1)
Definition: Isr.cc:52
T end(T... args)
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)
afw::table::Key< double > sigma
STL class.
Remove all non-astronomical counts from the Chunk Exposure&#39;s pixels.
int end
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
x_iterator row_begin(int y) const
T isfinite(T... args)
std::int32_t MaskPixel
double getValue(Property const prop=NOTHING) const
x_iterator row_end(int y) const
T find(T... args)
T begin(T... args)
Implementation of the templated Instrument Signature Removal stage of the nightly LSST Image Processi...
afw::table::Key< double > b
size_t maskNans(afw::image::MaskedImage< PixelT > const &mi, afw::image::MaskPixel maskVal, afw::image::MaskPixel allow=0)
Mask NANs in an image.
Definition: Isr.cc:34
template size_t maskNans< double >(afw::image::MaskedImage< double > const &, afw::image::MaskPixel, afw::image::MaskPixel)