Isis 3 Programmer Reference
ZeroDark.h
Go to the documentation of this file.
1 #ifndef ZeroDark_h
2 #define ZeroDark_h
3 
26 #include <cmath>
27 #include <string>
28 #include <vector>
29 
30 #include "IString.h"
31 #include "HiCalTypes.h"
32 #include "HiCalUtil.h"
33 #include "HiCalConf.h"
34 #include "Module.h"
35 #include "FileName.h"
36 #include "LoadCSV.h"
37 #include "LowPassFilter.h"
38 #include "Statistics.h"
39 #include "IException.h"
40 
41 namespace Isis {
42 
62  class ZeroDark : public Module {
63 
64  public:
65  // Constructors and Destructor
66  ZeroDark() : Module("ZeroDark") { }
67  ZeroDark(const HiCalConf &conf) : Module("ZeroDark") {
68  init(conf);
69  }
70 
72  virtual ~ZeroDark() { }
73 
79  const Statistics &Stats() const { return (_stats); }
80 
81  private:
82  int _tdi;
83  int _bin;
84 
85  HiVector _BM;
86  HiVector _slope;
87  HiVector _intercept;
88  HiVector _tempProf;
89 
90  double _refTemp;
91 
92  Statistics _stats;
93 
94  void init(const HiCalConf &conf) {
95  _history.clear();
96  DbProfile prof = conf.getMatrixProfile();
97  _history.add("Profile["+ prof.Name()+"]");
98  _tdi = ToInteger(prof("Tdi"));
99  _bin = ToInteger(prof("Summing"));
100  int samples = ToInteger(prof("Samples"));
101 
102  // Get dark current (B) matrix, slope and intercept CSV files
103  _BM = loadCsv("DarkCurrent", conf, prof, samples);
104  _slope = loadCsv("DarkSlope", conf, prof, 256);
105  _intercept = loadCsv("DarkIntercept", conf, prof, 256);
106 
107  // Get temperation normalization factor
108  _refTemp = toDouble(ConfKey(prof, "FpaReferenceTemperature", toString(21.0)));
109 
110  // Smooth/filter if requested
111  int width = toInt(ConfKey(prof,"ZeroDarkFilterWidth",toString(3)));
112  int iters = toInt(ConfKey(prof,"ZerDarkFilterIterations",toString(0)));
113  LowPassFilter smooth(width, iters);
114  _history.add("Smooth(Width["+ToString(width)+"],Iters["+ToString(iters)+"])");
115 
116  // Set average tempuratures
117  double fpa_py_temp = ToDouble(prof("FpaPositiveYTemperature"));
118  double fpa_my_temp = ToDouble(prof("FpaNegativeYTemperature"));
119  double temp = (fpa_py_temp+fpa_my_temp) / 2.0;
120  _history.add("BaseTemperature[" + ToString(temp) + "]");
121 
122  // Filter the slope/intercept
123  smooth.Process(_slope);
124  _slope = smooth.ref();
125 
126  smooth.Process(_intercept);
127  _intercept = smooth.ref();
128 
129  HiVector t_prof(_slope.dim());
130  for (int i = 0 ; i < _slope.dim() ; i++) {
131  t_prof[i] = _intercept[i] + _slope[i] * temp;
132  }
133 
134  _tempProf = rebin(t_prof, samples);
135  _history.add("Rebin(T_Profile," + ToString(t_prof.dim()) + "," +
136  ToString(samples) +")");
137 
138  HiVector dc(samples);
139  double linetime = ToDouble(prof("ScanExposureDuration"));
140  double scale = linetime * 1.0E-6 * (_bin*_bin) *
141  (20.0*103.0/89.0 + _tdi);
142  double baseT = HiTempEqn(_refTemp);
143  for (int j = 0 ; j < samples ; j++) {
144  dc[j] = _BM[j] * scale * HiTempEqn(_tempProf[j]) / baseT;
145  }
146 
147  // Filter it yet again
148  smooth.Process(dc);
149  _data = smooth.ref();
150 
151  // Compute statistics and record to history
152  _stats.Reset();
153  for ( int i = 0 ; i < _data.dim() ; i++ ) {
154  _stats.AddData(_data[i]);
155  }
156  _history.add("Statistics(Average["+ToString(_stats.Average())+
157  "],StdDev["+ToString(_stats.StandardDeviation())+"])");
158  return;
159  }
160 
161 
163  virtual void printOn(std::ostream &o) const {
164  o << "# History = " << _history << std::endl;
165  // Write out the header
166  o << std::setw(_fmtWidth) << "DarkMatrix"
167  << std::setw(_fmtWidth+1) << "TempNorm"
168  << std::setw(_fmtWidth+1) << "ZeroDark\n";
169 
170  for (int i = 0 ; i < _data.dim() ; i++) {
171  o << formatDbl(_BM[i]) << " "
172  << formatDbl(_tempProf[i]) << " "
173  << formatDbl(_data[i]) << std::endl;
174  }
175  return;
176  }
177 
178  };
179 
180 } // namespace Isis
181 #endif
double StandardDeviation() const
Computes and returns the standard deviation.
Definition: Statistics.cpp:325
int _fmtWidth
Default field with of double.
Definition: Module.h:168
HiVector _data
Data vector.
Definition: Module.h:166
double HiTempEqn(const double temperature, const double napcm2=2.0, const double px=12.0)
Implements (classic) HiRISE temperature equation.
Definition: HiCalUtil.h:405
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
HiHistory _history
Hierarchial component history.
Definition: Module.h:167
HiVector loadCsv(const QString &csvBase, const HiCalConf &conf, const DbProfile &prof, const int &elements=0)
Provide generic loading of CSV file for all modules.
Definition: Module.h:116
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:65
QString formatDbl(const double &value) const
Properly format values that could be special pixels.
Definition: Module.h:184
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:107
Computes a complex dark subtraction component (ZeroDark module)
Definition: ZeroDark.h:62
int ToInteger(const T &value)
Helper function to convert values to Integers.
Definition: HiCalUtil.h:236
void Reset()
Reset all accumulators and counters to zero.
Definition: Statistics.cpp:126
Compute a low pass filter from a Module class content.
Definition: LowPassFilter.h:45
Module manages HiRISE calibration vectors from various sources.
Definition: Module.h:54
virtual void printOn(std::ostream &o) const
Virtualized data dump method.
Definition: ZeroDark.h:163
$Revision $Date$ $Id$
HiVector rebin(const HiVector &v, int n)
Rebins a vector to a different size.
Definition: HiCalUtil.h:430
double ToDouble(const T &value)
Helper function to convert values to doubles.
Definition: HiCalUtil.h:248
virtual ~ZeroDark()
Destructor.
Definition: ZeroDark.h:72
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
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:219
QString Name() const
Returns the name of this property.
Definition: DbProfile.h:118
const Statistics & Stats() const
Return statistics for filtered - raw Buffer.
Definition: ZeroDark.h:79
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
Definition: Statistics.cpp:154
QString ToString(const T &value)
Helper function to convert values to strings.
Definition: HiCalUtil.h:260
double Average() const
Computes and returns the average.
Definition: Statistics.cpp:313
TNT::Array1D< double > HiVector
1-D Buffer
Definition: HiCalTypes.h:40