Isis Developer Reference
ZeroDarkRate.h
Go to the documentation of this file.
1#ifndef ZeroDarkRate_h
2#define ZeroDarkRate_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
27namespace Isis {
28
47 class ZeroDarkRate : public Module {
48
49 public:
50 // Constructors and Destructor
51 ZeroDarkRate() : Module("ZeroDarkRate") { }
52 ZeroDarkRate(const HiCalConf &conf) : Module("ZeroDarkRate") {
53 init(conf);
54 }
55
57 virtual ~ZeroDarkRate() { }
58
64 const Statistics &Stats() const { return (_stats); }
65
66 private:
67 int _tdi;
68 int _bin;
69 double _temp;
70
75 HiMatrix _coeffMat;
76
77 Statistics _stats;
78
79 void init(const HiCalConf &conf) {
81 DbProfile prof = conf.getMatrixProfile();
82 _history.add("Profile["+ prof.Name()+"]");
83 _tdi = ToInteger(prof("Tdi"));
84 _bin = ToInteger(prof("Summing"));
85 int samples = ToInteger(prof("Samples"));
86
87 // Load the coefficients
88 // The CSV files for this module are named:
89 // file: DarkRate_CCD_Ch_TDI${tdi}_BIN{$binning}_ADC{$adc}_hical_????.csv
90 // Example:
91 // DarkRate_RED1_1_TDI64_BIN2_54_hical_0002.csv
92 // The format of the file is as follows:
93 // There are three comment lines
94 // # Number of files used to generate these values = 40
95 // # exponential equation: DC_Rate = a * exp(b * FPA Temperature) + c
96 // # a, b, c
97 // Then the coefficients begin.
98 // Three columns (a, b, c), and 1024/binning rows
99 // 2.483618177203812394e+00,2.255885064806690821e-01,5.617339162650616345e+03
100 _coeffMat = LoadCSV("DarkRate", conf, prof).getMatrix();
101 if (_coeffMat.dim2() != 3) {
102 QString msg = "Zero Dark Rate coefficient CSV has [" + toString(_coeffMat.dim2()) +
103 "] columns, expected 3.";
105 }
106 if (_coeffMat.dim1() != samples) {
107 QString msg = "Zero Dark Rate coefficient CSV has [" + toString(_coeffMat.dim1()) +
108 "] rows, expected " + toString(samples) + ".";
109 throw IException(IException::User, msg, _FILEINFO_);
110 }
111
112 // Set average FPA temperature
113 double fpa_py_temp = ToDouble(prof("FpaPositiveYTemperature"));
114 double fpa_my_temp = ToDouble(prof("FpaNegativeYTemperature"));
115 _temp = (fpa_py_temp+fpa_my_temp) / 2.0;
116 _history.add("BaseTemperature[" + ToString(_temp) + "]");
117
118 // Calculate the dark rate for each column.
119 _data = HiVector(samples);
120 for (int j = 0 ; j < samples ; j++) {
121 _data[j] = _coeffMat[j][0] * exp(_coeffMat[j][1]*_temp) + _coeffMat[j][2];
122 }
123
124 // Compute statistics and record to history
125 _stats.Reset();
126 for ( int i = 0 ; i < _data.dim() ; i++ ) {
127 _stats.AddData(_data[i]);
128 }
129 _history.add("Statistics(Average["+ToString(_stats.Average())+
130 "],StdDev["+ToString(_stats.StandardDeviation())+"])");
131 return;
132 }
133
134
136 virtual void printOn(std::ostream &o) const {
137 o << "# History = " << _history << std::endl;
138 // Write out the header
139 o << std::setw(_fmtWidth+1) << "FPA_Temperature\n"
140 << std::setw(_fmtWidth+1) << "ZeroDarkRate\n";
141
142 for (int i = 0 ; i < _data.dim() ; i++) {
143 o << formatDbl(_temp) << " "
144 << formatDbl(_data[i]) << std::endl;
145 }
146 return;
147 }
148
149 };
150
151} // namespace Isis
152#endif
#define _FILEINFO_
Macro for the filename and line number.
Definition IException.h:24
A DbProfile is a container for access parameters to a database.
Definition DbProfile.h:51
void clear()
Definition HiCalTypes.h:65
void add(const QString &event)
Definition HiCalTypes.h:55
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
Provides generalized access to HiRISE calibration CSV files.
Definition LoadCSV.h:52
HiMatrix getMatrix() const
Definition LoadCSV.cpp:201
Module manages HiRISE calibration vectors from various sources.
Definition Module.h:39
HiVector _data
Data vector.
Definition Module.h:151
HiHistory _history
Hierarchial component history.
Definition Module.h:152
int _fmtWidth
Default field with of double.
Definition Module.h:153
QString formatDbl(const double &value) const
Properly format values that could be special pixels.
Definition Module.h:169
This class is used to accumulate statistics on double arrays.
Definition Statistics.h:93
double Average() const
Computes and returns the average.
Definition Statistics.cpp:451
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
Definition Statistics.cpp:292
double StandardDeviation() const
Computes and returns the standard deviation.
Definition Statistics.cpp:463
void Reset()
Reset all accumulators and counters to zero.
Definition Statistics.cpp:264
Computes a complex dark subtraction component (ZeroDarkRate module)
Definition ZeroDarkRate.h:47
const Statistics & Stats() const
Return statistics for filtered - raw Buffer.
Definition ZeroDarkRate.h:64
virtual ~ZeroDarkRate()
Destructor.
Definition ZeroDarkRate.h:57
ZeroDarkRate(const HiCalConf &conf)
Definition ZeroDarkRate.h:52
ZeroDarkRate()
Definition ZeroDarkRate.h:51
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
TNT::Array2D< double > HiMatrix
2-D buffer
Definition HiCalTypes.h:28
TNT::Array1D< double > HiVector
1-D Buffer
Definition HiCalTypes.h:27
QString ToString(const T &value)
Helper function to convert values to strings.
Definition HiCalUtil.h:236
double ToDouble(const T &value)
Helper function to convert values to doubles.
Definition HiCalUtil.h:224
int ToInteger(const T &value)
Helper function to convert values to Integers.
Definition HiCalUtil.h:212