-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathcamstats.cpp
227 lines (199 loc) · 7.33 KB
/
camstats.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "camstats.h"
#include "Camera.h"
#include "CameraStatistics.h"
#include "Cube.h"
#include "Distance.h"
#include "IString.h"
#include "UserInterface.h"
#include "Process.h"
#include "Progress.h"
#include "Statistics.h"
using namespace std;
using namespace Isis;
namespace Isis {
//function to build stats data
void buildStats(Camera *cam, int &sample, int &line);
void writeFlat(ofstream &os, const Statistics *s);
string valueToString(const double &value);
/**
* Outputs camera statistics for a cube specified in ui parameters.
*
* @param ui UserInterface object containing camstats parameters
* @param(out) log the Pvl that camstat results log to
*/
void camstats(UserInterface &ui, Pvl *log) {
Process p;
CubeAttributeInput cai;
Cube *icube = p.SetInputCube(ui.GetCubeName("FROM"), cai, ReadWrite);
camstats(icube, ui, log);
p.EndProcess();
}
void camstats(Cube *icube, UserInterface &ui, Pvl *log) {
Process p;
p.SetInputCube(icube);
Camera *cam = icube->camera();
QString from = icube->fileName();
int sinc = ui.GetInteger("SINC");
int linc = ui.GetInteger("LINC");
CameraStatistics camStats(cam, sinc, linc, from);
// Send the Output to the log area
Pvl statsPvl = camStats.toPvl();
for (int i = 0; i < statsPvl.groups(); i++) {
log->addLogGroup(statsPvl.group(i));
}
if(ui.WasEntered("TO")) {
QString outfile = FileName(ui.GetFileName("TO")).expanded();
bool exists = FileName(outfile).fileExists();
bool append = ui.GetBoolean("APPEND");
// If the user chose a format of PVL, then write to the output file ("TO")
if(ui.GetString("FORMAT") == "PVL") {
(append) ? statsPvl.append(outfile) : statsPvl.write(outfile);
}
else {
// Create a flatfile of the data with columhn headings the flatfile is
// comma-delimited and can be imported in to spreadsheets
ofstream os;
bool writeHeader = true;
if(append) {
os.open(outfile.toLatin1().data(), ios::app);
if(exists) {
writeHeader = false;
}
}
else {
os.open(outfile.toLatin1().data(), ios::out);
}
// if new file or append and no file exists then write header
if(writeHeader) {
os << "Filename," <<
"LatitudeMinimum," <<
"LatitudeMaximum," <<
"LatitudeAverage," <<
"LatitudeStandardDeviation," <<
"LongitudeMinimum," <<
"LongitudeMaximum," <<
"LongitudeAverage," <<
"LongitudeStandardDeviation," <<
"SampleResolutionMinimum," <<
"SampleResolutionMaximum," <<
"SampleResolutionAverage," <<
"SampleResolutionStandardDeviation," <<
"LineResolutionMinimum," <<
"LineResolutionMaximum," <<
"LineResolutionAverage," <<
"LineResolutionStandardDeviation," <<
"ResolutionMinimum," <<
"ResolutionMaximum," <<
"ResolutionAverage," <<
"ResolutionStandardDeviation," <<
"AspectRatioMinimum," <<
"AspectRatioMaximum," <<
"AspectRatioAverage," <<
"AspectRatioStandardDeviation," <<
"PhaseMinimum," <<
"PhaseMaximum," <<
"PhaseAverage," <<
"PhaseStandardDeviation," <<
"EmissionMinimum," <<
"EmissionMaximum," <<
"EmissionAverage," <<
"EmissionStandardDeviation," <<
"IncidenceMinimum," <<
"IncidenceMaximum," <<
"IncidenceAverage," <<
"IncidenceStandardDeviation," <<
"LocalSolarTimeMinimum," <<
"LocalSolarTimeMaximum," <<
"LocalSolarTimeAverage," <<
"LocalSolarTimeStandardDeviation," <<
"LocalRadiusMaximum," <<
"LocalRadiusMaximum," <<
"LocalRadiusAverage," <<
"LocalRadiusStandardDeviation," <<
"NorthAzimuthMinimum," <<
"NorthAzimuthMaximum," <<
"NorthAzimuthAverage," <<
"NorthAzimuthStandardDeviation," <<
"ObliqueResolutionMinimum," <<
"ObliqueResolutionMaximum," <<
"ObliqueResolutionAverage," <<
"ObliqueResolutionStandardDeviation," <<
"ObliqueLineResolutionMinimum," <<
"ObliqueLineResolutionMaximum," <<
"ObliqueLineResolutionAverage," <<
"ObliqueLineResolutionStandardDeviation," <<
"ObliqueSampleResolutionMinimum," <<
"ObliqueSampleResolutionMaximum," <<
"ObliqueSampleResolutionAverage," <<
"ObliqueSampleResolutionStandardDeviation," << endl;
}
os << FileName(from).expanded() << ",";
//call the function to write out the values for each group
writeFlat(os, camStats.getLatStat());
writeFlat(os, camStats.getLonStat());
writeFlat(os, camStats.getSampleResStat());
writeFlat(os, camStats.getLineResStat());
writeFlat(os, camStats.getResStat());
writeFlat(os, camStats.getAspectRatioStat());
writeFlat(os, camStats.getPhaseStat());
writeFlat(os, camStats.getEmissionStat());
writeFlat(os, camStats.getIncidenceStat());
writeFlat(os, camStats.getLocalSolarTimeStat());
writeFlat(os, camStats.getLocalRaduisStat());
writeFlat(os, camStats.getNorthAzimuthStat());
writeFlat(os,camStats.getObliqueResStat());
writeFlat(os,camStats.getObliqueLineResStat());
writeFlat(os,camStats.getObliqueSampleResStat());
os << endl;
}
}
if(ui.GetBoolean("ATTACH")) {
QString cam_name = "CameraStatistics";
//Creates new CameraStatistics Table
TableField fname("Name", Isis::TableField::Text, 45);
TableField fmin("Minimum", Isis::TableField::Double);
TableField fmax("Maximum", Isis::TableField::Double);
TableField favg("Average", Isis::TableField::Double);
TableField fstd("StandardDeviation", Isis::TableField::Double);
TableRecord record;
record += fname;
record += fmin;
record += fmax;
record += favg;
record += fstd;
Table table(cam_name, record);
// Place all the gathered camera statistics in a table and attach it to the
// cube. Skip "User Parameters" group.
for (int i = 1; i < statsPvl.groups(); i++) {
PvlGroup &group = statsPvl.group(i);
int entry = 0;
record[entry] = group.name();
entry++;
for (int j = 0; j < group.keywords(); j++) {
record[entry] = toDouble(group[j][0]);
entry++;
}
table += record;
}
icube->reopen("rw");
icube->write(table);
p.WriteHistory(*icube);
icube->close();
}
}
//function to write the stats values to flat file
void writeFlat(ofstream &os, const Statistics *s) {
os << valueToString(s->Minimum()) << "," <<
valueToString(s->Maximum()) << "," <<
valueToString(s->Average()) << "," <<
valueToString(s->StandardDeviation()) << ",";
}
string valueToString(const double &value) {
if(IsSpecial(value)) {
return (string("NULL"));
}
else {
return ((string) IString(value));
}
}
}