Isis Developer Reference
ZeroDark.h
Go to the documentation of this file.
1 #ifndef ZeroDark_h
2 #define ZeroDark_h
3 
10 /* SPDX-License-Identifier: CC0-1.0 */
11 
12 #include <cmath>
13 #include <string>
14 #include <vector>
15 
16 #include "IString.h"
17 #include "HiCalTypes.h"
18 #include "HiCalUtil.h"
19 #include "HiCalConf.h"
20 #include "Module.h"
21 #include "FileName.h"
22 #include "LoadCSV.h"
23 #include "LowPassFilter.h"
24 #include "Statistics.h"
25 #include "IException.h"
26 
27 namespace Isis {
28 
48  class ZeroDark : public Module {
49 
50  public:
51  // Constructors and Destructor
52  ZeroDark() : Module("ZeroDark") { }
53  ZeroDark(const HiCalConf &conf) : Module("ZeroDark") {
54  init(conf);
55  }
56 
58  virtual ~ZeroDark() { }
59 
65  const Statistics &Stats() const { return (_stats); }
66 
67  private:
68  int _tdi;
69  int _bin;
70 
71  HiVector _BM;
72  HiVector _slope;
73  HiVector _intercept;
74  HiVector _tempProf;
75 
76  double _refTemp;
77 
78  Statistics _stats;
79 
80  void init(const HiCalConf &conf) {
81  _history.clear();
82  DbProfile prof = conf.getMatrixProfile();
83  _history.add("Profile["+ prof.Name()+"]");
84  _tdi = ToInteger(prof("Tdi"));
85  _bin = ToInteger(prof("Summing"));
86  int samples = ToInteger(prof("Samples"));
87 
88  // Get dark current (B) matrix, slope and intercept CSV files
89  _BM = loadCsv("DarkCurrent", conf, prof, samples);
90  _slope = loadCsv("DarkSlope", conf, prof, 256);
91  _intercept = loadCsv("DarkIntercept", conf, prof, 256);
92 
93  // Get temperation normalization factor
94  _refTemp = toDouble(ConfKey(prof, "FpaReferenceTemperature", toString(21.0)));
95 
96  // Smooth/filter if requested
97  int width = toInt(ConfKey(prof,"ZeroDarkFilterWidth",toString(3)));
98  int iters = toInt(ConfKey(prof,"ZerDarkFilterIterations",toString(0)));
99  LowPassFilter smooth(width, iters);
100  _history.add("Smooth(Width["+ToString(width)+"],Iters["+ToString(iters)+"])");
101 
102  // Set average tempuratures
103  double fpa_py_temp = ToDouble(prof("FpaPositiveYTemperature"));
104  double fpa_my_temp = ToDouble(prof("FpaNegativeYTemperature"));
105  double temp = (fpa_py_temp+fpa_my_temp) / 2.0;
106  _history.add("BaseTemperature[" + ToString(temp) + "]");
107 
108  // Filter the slope/intercept
109  smooth.Process(_slope);
110  _slope = smooth.ref();
111 
112  smooth.Process(_intercept);
113  _intercept = smooth.ref();
114 
115  HiVector t_prof(_slope.dim());
116  for (int i = 0 ; i < _slope.dim() ; i++) {
117  t_prof[i] = _intercept[i] + _slope[i] * temp;
118  }
119 
120  _tempProf = rebin(t_prof, samples);
121  _history.add("Rebin(T_Profile," + ToString(t_prof.dim()) + "," +
122  ToString(samples) +")");
123 
124  HiVector dc(samples);
125  double linetime = ToDouble(prof("ScanExposureDuration"));
126  double scale = linetime * 1.0E-6 * (_bin*_bin) *
127  (20.0*103.0/89.0 + _tdi);
128  double baseT = HiTempEqn(_refTemp);
129  for (int j = 0 ; j < samples ; j++) {
130  dc[j] = _BM[j] * scale * HiTempEqn(_tempProf[j]) / baseT;
131  }
132 
133  // Filter it yet again
134  smooth.Process(dc);
135  _data = smooth.ref();
136 
137  // Compute statistics and record to history
138  _stats.Reset();
139  for ( int i = 0 ; i < _data.dim() ; i++ ) {
140  _stats.AddData(_data[i]);
141  }
142  _history.add("Statistics(Average["+ToString(_stats.Average())+
143  "],StdDev["+ToString(_stats.StandardDeviation())+"])");
144  return;
145  }
146 
147 
149  virtual void printOn(std::ostream &o) const {
150  o << "# History = " << _history << std::endl;
151  // Write out the header
152  o << std::setw(_fmtWidth) << "DarkMatrix"
153  << std::setw(_fmtWidth+1) << "TempNorm"
154  << std::setw(_fmtWidth+1) << "ZeroDark\n";
155 
156  for (int i = 0 ; i < _data.dim() ; i++) {
157  o << formatDbl(_BM[i]) << " "
158  << formatDbl(_tempProf[i]) << " "
159  << formatDbl(_data[i]) << std::endl;
160  }
161  return;
162  }
163 
164  };
165 
166 } // namespace Isis
167 #endif
Isis::Module::_history
HiHistory _history
Hierarchial component history.
Definition: Module.h:152
Isis::ZeroDark::~ZeroDark
virtual ~ZeroDark()
Destructor.
Definition: ZeroDark.h:58
Isis::HiHistory::clear
void clear()
Definition: HiCalTypes.h:65
FileName.h
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::rebin
HiVector rebin(const HiVector &v, int n)
Rebins a vector to a different size.
Definition: HiCalUtil.h:416
Isis::Module
Module manages HiRISE calibration vectors from various sources.
Definition: Module.h:39
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::ZeroDark::Stats
const Statistics & Stats() const
Return statistics for filtered - raw Buffer.
Definition: ZeroDark.h:65
LoadCSV.h
Isis::ZeroDark
Computes a complex dark subtraction component (ZeroDark module)
Definition: ZeroDark.h:48
HiCalConf.h
Isis::Statistics::Reset
void Reset()
Reset all accumulators and counters to zero.
Definition: Statistics.cpp:113
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
IString.h
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
LowPassFilter.h
Isis::Module::formatDbl
QString formatDbl(const double &value) const
Properly format values that could be special pixels.
Definition: Module.h:169
Isis::Module::loadCsv
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:101
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::ToInteger
int ToInteger(const T &value)
Helper function to convert values to Integers.
Definition: HiCalUtil.h:222
HiCalUtil.h
Isis::HiTempEqn
double HiTempEqn(const double temperature, const double napcm2=2.0, const double px=12.0)
Implements (classic) HiRISE temperature equation.
Definition: HiCalUtil.h:391
Isis::DbProfile
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:51
HiCalTypes.h
Isis::HiVector
TNT::Array1D< double > HiVector
1-D Buffer
Definition: HiCalTypes.h:27
Isis::ZeroDark::ZeroDark
ZeroDark()
Definition: ZeroDark.h:52
Isis::ZeroDark::ZeroDark
ZeroDark(const HiCalConf &conf)
Definition: ZeroDark.h:53
Isis::HiHistory::add
void add(const QString &event)
Definition: HiCalTypes.h:55
Isis::Statistics::Average
double Average() const
Computes and returns the average.
Definition: Statistics.cpp:300
Isis::ToDouble
double ToDouble(const T &value)
Helper function to convert values to doubles.
Definition: HiCalUtil.h:234
Statistics.h
IException.h
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
Module.h
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16