Isis 3 Programmer Reference
ZeroBufferSmooth.h
1 #ifndef ZeroBufferSmooth_h
2 #define ZeroBufferSmooth_h
3 
10 /* SPDX-License-Identifier: CC0-1.0 */
11 
12 #include <cmath>
13 #include <string>
14 #include <vector>
15 #include <iostream>
16 #include <sstream>
17 
18 
19 #include "IString.h"
20 #include "HiCalTypes.h"
21 #include "HiCalUtil.h"
22 #include "HiCalConf.h"
23 #include "Module.h"
24 #include "SplineFill.h"
25 #include "LowPassFilter.h"
26 #include "Statistics.h"
27 #include "SpecialPixel.h"
28 #include "IException.h"
29 
30 namespace Isis {
31 
53  class ZeroBufferSmooth : public Module {
54 
55  public:
56  // Constructors and Destructor
57  ZeroBufferSmooth() : Module("ZeroBufferSmooth") { }
67  ZeroBufferSmooth(HiCalData &cal, const HiCalConf &conf) :
68  Module("ZeroBufferSmooth") {
69  init(cal, conf);
70  }
71 
73  virtual ~ZeroBufferSmooth() { }
74 
80  const Statistics &Stats() const { return (_stats); }
81 
82  private:
83  HiVector _buffer;
84  Statistics _stats;
85 
97  void init(HiCalData &cal, const HiCalConf &conf) {
98  DbProfile prof = conf.getMatrixProfile();
99  _history.clear();
100  _history.add("Profile["+ prof.Name()+"]");
101 
102  int samp0 = toInt(ConfKey(prof,"ZeroBufferSmoothFirstSample",QString("0")));
103  int sampN = toInt(ConfKey(prof,"ZeroBufferSmoothLastSample",QString("11")));
104  _buffer = averageSamples(cal.getBuffer(), samp0, sampN);
105  _history.add("AveCols(Buffer["+ToString(samp0)+","+ToString(sampN)+"])");
106 
107  // Smooth/filter the averages
108  LowPassFilter bufter(_buffer, _history,
109  toInt(ConfKey(prof,"ZeroBufferSmoothFilterWidth",QString("201"))),
110  toInt(ConfKey(prof,"ZeroBufferSmoothFilterIterations",QString("2"))));
111  // If need be, fill the data with a cubic spline
112  SplineFill spline(bufter);
113  _data = spline.ref();
114  _history = spline.History();
115 
116  // Compute statistics and record to history
117  _stats.Reset();
118  for ( int i = 0 ; i < _data.dim() ; i++ ) {
119  // Spline guarantees _data is non-null!
120  if ( !IsSpecial(_buffer[i]) ) {
121  _stats.AddData(_data[i] - _buffer[i]);
122  }
123  }
124  _history.add("Statistics(Average["+ToString(_stats.Average())+
125  "],StdDev["+ToString(_stats.StandardDeviation())+"])");
126  return;
127  }
128 
136  virtual void printOn(std::ostream &o) const {
137  o << "# History = " << _history << std::endl;
138  // Write out the header
139  o << std::setw(_fmtWidth) << "RawBuffer"
140  << std::setw(_fmtWidth+1) << "Filtered\n";
141 
142  for (int i = 0 ; i < _data.dim() ; i++) {
143  o << formatDbl(_buffer[i]) << " "
144  << formatDbl(_data[i]) << std::endl;
145  }
146  return;
147  }
148 
149  };
150 
151 } // namespace Isis
152 #endif
Isis::Module::_history
HiHistory _history
Hierarchial component history.
Definition: Module.h:152
Isis::ZeroBufferSmooth::Stats
const Statistics & Stats() const
Return statistics for filtered - raw Buffer.
Definition: ZeroBufferSmooth.h:80
Isis::Module::_fmtWidth
int _fmtWidth
Default field with of double.
Definition: Module.h:153
Isis::Statistics
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:94
Isis::Statistics::AddData
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
Definition: Statistics.cpp:141
Isis::DbProfile::Name
QString Name() const
Returns the name of this property.
Definition: DbProfile.h:104
Isis::ToString
QString ToString(const T &value)
Helper function to convert values to strings.
Definition: HiCalUtil.h:246
Isis::Module
Module manages HiRISE calibration vectors from various sources.
Definition: Module.h:39
Isis::ZeroBufferSmooth::ZeroBufferSmooth
ZeroBufferSmooth(HiCalData &cal, const HiCalConf &conf)
Construct with data parameters.
Definition: ZeroBufferSmooth.h:67
Isis::Module::ref
const HiVector & ref() const
Return data via a const reference.
Definition: Module.h:111
Isis::ConfKey
T ConfKey(const DbProfile &conf, const QString &keyname, const T &defval, int index=0)
Find a keyword in a profile using default for non-existant keywords.
Definition: HiCalUtil.h:205
Isis::ZeroBufferSmooth
Processes Buffer calibration data (ZeroBufferSmooth Module)
Definition: ZeroBufferSmooth.h:53
Isis::Module::History
const HiHistory & History() const
Return recorded history of events.
Definition: Module.h:116
Isis::Statistics::Reset
void Reset()
Reset all accumulators and counters to zero.
Definition: Statistics.cpp:113
Isis::SplineFill
Compute a low pass filter from a Module class content.
Definition: SplineFill.h:32
Isis::IsSpecial
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:197
Isis::LowPassFilter
Compute a low pass filter from a Module class content.
Definition: LowPassFilter.h:30
Isis::Module::_data
HiVector _data
Data vector.
Definition: Module.h:151
Isis::Module::formatDbl
QString formatDbl(const double &value) const
Properly format values that could be special pixels.
Definition: Module.h:169
Isis::averageSamples
HiVector averageSamples(const HiMatrix &m, int ssamp=0, int esamp=-1)
Reduces by averaging specified samples from a buffer.
Definition: HiCalUtil.h:182
Isis::ZeroBufferSmooth::printOn
virtual void printOn(std::ostream &o) const
Virtualized parameter reporting method.
Definition: ZeroBufferSmooth.h:136
Isis::toInt
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:93
Isis::Statistics::StandardDeviation
double StandardDeviation() const
Computes and returns the standard deviation.
Definition: Statistics.cpp:312
Isis::DbProfile
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:51
Isis::HiVector
TNT::Array1D< double > HiVector
1-D Buffer
Definition: HiCalTypes.h:27
Isis::ZeroBufferSmooth::init
void init(HiCalData &cal, const HiCalConf &conf)
Workhorse of the zero buffer computation.
Definition: ZeroBufferSmooth.h:97
Isis::Statistics::Average
double Average() const
Computes and returns the average.
Definition: Statistics.cpp:300
Isis::ZeroBufferSmooth::~ZeroBufferSmooth
virtual ~ZeroBufferSmooth()
Destructor.
Definition: ZeroBufferSmooth.h:73
Isis::HiCalData
Container for HiRISE calibration data.
Definition: HiCalData.h:35
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16