LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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>
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 
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
std::vector< double > parameterList
fit parameters
Definition: minimize.h:49
uint64_t * ptr
Definition: RangeSet.cc:88
std::string between(std::string &s, char ldelim, char rdelim)
Definition: Isr.cc:99
table::Key< int > b
estimate sample standard deviation
Definition: Statistics.h:68
py::object result
Definition: schema.cc:284
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
int y
Definition: SpanSet.cc:49
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)
Find the minimum of a function(x)
Definition: minimize.cc:177
template size_t maskNans< float >(afw::image::MaskedImage< float > const &, afw::image::MaskPixel, afw::image::MaskPixel)
A class to evaluate image statistics.
Definition: Statistics.h:215
STL class.
int getHeight() const
Return the number of rows in the image.
Definition: MaskedImage.h:1096
A base class for image defects.
Results from minimizing a function.
Definition: minimize.h:45
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition: Statistics.h:354
x_iterator row_begin(int y) const
Return an x_iterator to the start of the image.
Definition: MaskedImage.cc:620
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:74
A Function taking one argument.
Definition: Function.h:204
T isfinite(T... args)
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:50
table::Box2IKey bbox
Definition: Detector.cc:166
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
solver_t * s
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
Definition: Statistics.cc:1056
x_iterator row_end(int y) const
Return an x_iterator to the end of the image.
Definition: MaskedImage.cc:630
T find(T... args)
T begin(T... args)
estimate sample mean
Definition: Statistics.h:67
Implementation of the templated Instrument Signature Removal stage of the nightly LSST Image Processi...
int getWidth() const
Return the number of columns in the image.
Definition: MaskedImage.h:1094
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
An integer coordinate rectangle.
Definition: Box.h:54
template size_t maskNans< double >(afw::image::MaskedImage< double > const &, afw::image::MaskPixel, afw::image::MaskPixel)
int end