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
ImageStatistics.h
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 
35 #ifndef LSST_IP_DIFFIM_IMAGESTATISTICS_H
36 #define LSST_IP_DIFFIM_IMAGESTATISTICS_H
37 
38 #include <cmath>
39 #include <limits>
40 #include <memory>
41 
42 #include "lsst/afw/image.h"
43 #include "lsst/log/Log.h"
44 #include "lsst/pex/policy/Policy.h"
45 
46 namespace lsst {
47 namespace ip {
48 namespace diffim {
49 
58  template <typename PixelT>
60  public:
63 
65  _xsum(0.), _x2sum(0.), _npix(0), _bpMask(0) {
66 
67  std::vector<std::string> detBadMaskPlanes = policy.getStringArray("badMaskPlanes");
68  for (std::vector<std::string>::iterator mi = detBadMaskPlanes.begin();
69  mi != detBadMaskPlanes.end(); ++mi){
70 
71  try {
73  } catch (pexExcept::Exception& e) {
74  LOGL_DEBUG("TRACE4.ip.diffim.ImageStatistics",
75  "Cannot update bad bit mask with %s", (*mi).c_str());
76  LOGL_DEBUG("TRACE5.ip.diffim.ImageStatistics",
77  e.what());
78  }
79  }
80  } ;
81  virtual ~ImageStatistics() {} ;
82 
83  // Clear the accumulators
84  void reset() { _xsum = _x2sum = 0.; _npix = 0;}
85 
86  // Work your magic
88  apply(image, -1);
89  }
90 
92  reset();
93  int y0, y1, x0, x1;
94  if (core == -1) {
95  y0 = 0;
96  y1 = image.getHeight();
97  x0 = 0;
98  x1 = image.getWidth();
99  }
100  else {
101  y0 = std::max(0, image.getHeight()/2 - core);
102  y1 = std::min(image.getHeight(), image.getHeight()/2 + core + 1);
103  x0 = std::max(0, image.getWidth()/2 - core);
104  x1 = std::min(image.getWidth(), image.getWidth()/2 + core + 1);
105  }
106 
107  for (int y = y0; y != y1; ++y) {
108  for (x_iterator ptr = image.x_at(x0, y), end = image.x_at(x1, y);
109  ptr != end; ++ptr) {
110  if (!((*ptr).mask() & _bpMask)) {
111  double const ivar = 1. / (*ptr).variance();
112  if (std::isfinite(ivar)) {
113  _xsum += (*ptr).image() * sqrt(ivar);
114  _x2sum += (*ptr).image() * (*ptr).image() * ivar;
115  _npix += 1;
116  }
117  }
118  }
119  }
120  if ((!std::isfinite(_xsum)) || (!std::isfinite(_x2sum))) {
122  "Nan/Inf in ImageStatistics.apply");
123  }
124  }
125 
126  void setBpMask(lsst::afw::image::MaskPixel bpMask) {_bpMask = bpMask;}
128 
129  // Mean of distribution
130  double getMean() const {
131  return (_npix > 0) ? _xsum/_npix : std::numeric_limits<double>::quiet_NaN();
132  }
133  // Variance of distribution
134  double getVariance() const {
135  return (_npix > 1) ? (_x2sum/_npix - _xsum/_npix * _xsum/_npix) * _npix/(_npix-1.) :
137  }
138  // RMS
139  double getRms() const {
140  return sqrt(getVariance());
141  }
142  // Return the number of good pixels
143  int getNpix() const { return _npix; }
144 
145  // Return Sdqa rating
147  if ( fabs(getMean()) > policy.getDouble("maximumFootprintResidualMean") ) return false;
148  if ( getRms() > policy.getDouble("maximumFootprintResidualStd") ) return false;
149  return true;
150  }
151 
152  private:
153  double _xsum;
154  double _x2sum;
155  int _npix;
157  };
158 
159 
160 }}} // end of namespace lsst::ip::diffim
161 
162 
163 #endif
164 
165 
166 
uint64_t * ptr
Definition: RangeSet.cc:88
void apply(lsst::afw::image::MaskedImage< PixelT > const &image)
std::shared_ptr< ImageStatistics > Ptr
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
int y
Definition: SpanSet.cc:49
T end(T... args)
Provides consistent interface for LSST exceptions.
Definition: Exception.h:107
void setBpMask(lsst::afw::image::MaskPixel bpMask)
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:489
lsst::afw::image::MaskedImage< PixelT >::x_iterator x_iterator
x_iterator x_at(int x, int y) const
Return an x_iterator at the point (x, y)
Definition: MaskedImage.h:1220
LSST DM logging module built on log4cxx.
T min(T... args)
virtual char const * what(void) const noexcept
Return a character string summarizing this exception.
Definition: Exception.cc:99
int getHeight() const
Return the number of rows in the image.
Definition: MaskedImage.h:1096
A base class for image defects.
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:74
T isfinite(T... args)
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR&#39;d together.
Definition: Mask.cc:383
T max(T... args)
Class to calculate difference image statistics.
double getDouble(const std::string &name) const
return a double value associated with the given name.
Definition: Policy.h:617
ImageStatistics(lsst::pex::policy::Policy const &policy)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
bool evaluateQuality(lsst::pex::policy::Policy const &policy)
T begin(T... args)
void apply(lsst::afw::image::MaskedImage< PixelT > const &image, int core)
int getWidth() const
Return the number of columns in the image.
Definition: MaskedImage.h:1094
T quiet_NaN(T... args)
lsst::afw::image::MaskPixel getBpMask()
int end
StringArray getStringArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:1027