USGS

Isis 3.0 Object Programmers' Reference

Home

CrismCamera.cpp
Go to the documentation of this file.
1 
21 #include "CrismCamera.h"
22 
23 #include <fstream>
24 #include <iostream>
25 #include <iomanip>
26 
27 //#include "CrismCameraGroundMap.h"
28 //#include "CrismDistortionMap.h"
29 #include "CameraFocalPlaneMap.h"
32 #include "LineScanCameraSkyMap.h"
33 #include "Constants.h"
34 #include "FileName.h"
35 #include "IException.h"
36 #include "IString.h"
37 #include "iTime.h"
38 #include "NaifStatus.h"
39 #include "SpecialPixel.h"
40 
41 using namespace std;
42 
43 namespace Isis {
53  CrismCamera::CrismCamera(Cube &cube) : LineScanCamera(cube), m_lineRates(),
54  m_isBandDependent(true) {
56 
57  Pvl &lab = *cube.label();
58 
59  PvlGroup inst = lab.findGroup("Instrument", Pvl::Traverse);
60 
61  // SensorId = S (VNIR), = L (IR) = J (JOINT)
62  QString sensor = (QString) inst ["SensorId"];
63 
64  // Prepare instrument code
65  QString ikCode(toString(naifIkCode()));
66 
67  // Set Frame mounting. Same for both (VNIR, IR) detectors
69  SetPixelPitch();
70 
71  // Get the start and end time in et
72  double etStart = getEtTime((QString) inst ["SpacecraftClockStartCount"]);
73  double etStop = getEtTime((QString) inst ["SpacecraftClockStopCount"]);
74 
75 
76  // Compute the exposure time of the first line and the line rate. This
77  // algorithm is taken from the CRISM instrument kernel, mro_crism_v10.ti,
78  // at the time of development.
79 // double framesPerSec = (double) inst["FrameRate"];
80  int exposure = (int) inst["ExposureParameter"];
81 
82  // calculate seconds for a full frame
83 // double frame_time = 1.0 / framesPerSec;
84 
85  // calculate seconds per pixel clock
86 // double pixel_clock_time = frame_time / 83333.0;
87 
88  // This is what John Hayes does in the DPU (Data Processing Unit), to write
89  // register to FPU (Focal Plane Unit) specifying how long NOT to integrate,
90  // in pixel clocks [0..83333]
91  int reg = ((480 - exposure) * 83333) / 480;
92 
93  // Actual integration starts 3 line-times later, rounded up to next line
94  // time
95  int start_clocks = reg + (3 * 166);
96  if (start_clocks % 166) start_clocks += 166 - (start_clocks % 166);
97 
98  // integration continues 4 line-times after de-assertion
99 // int stop_clocks = 83333 + (4 * 166);
100 
101 // double start_time = start_clocks * pixel_clock_time;
102 // double stop_time = stop_clocks * pixel_clock_time;
103 
104  // Start of first line exposure time. This is the start time of the
105  // frame time plus the itegration delay start time - constant for all
106  // frames
107 // double obsStartTime(etStart+start_time);
108 // double obsStopTime(obsStartTime+(stop_time*ParentLines())-start_time);
109 // double obsEndTime(obsStartTime+(frame_time*(ParentLines()))-start_time);
110 
111  double frameStartTime(etStart);
112 // double frameStopTime(frameStartTime+(stop_time*(ParentLines())));
113 // double frameEndTime(frameStartTime+(frame_time*(ParentLines())));
114 
115 // double lineTime((etStop-etStart+frame_time)/(ParentLines()));
116 
117 
118  // Compute the sclk and UTC of the specifed line for cropping purposes
119 #if 0
120  iTime myLineStartTime(etStart + ((25.0 - 1.0) * frame_time));
121 // cout << "\nLine 25 Start Times...\n";
122  SpiceChar sclk[80];
123  (void) sce2s_c(naifSclkCode(), myLineStartTime.Et(), sizeof(sclk), sclk);
124 // cout << "UTC@Line 25: " << myLineStartTime.UTC() << "\n";
125 // cout << "SCLK@Line 25: " << sclk << "\n";
126 
127 #endif
128  // Setup detector map
129 #if 1
130  double jaTime = (etStop-etStart)/ParentLines();
131  new LineScanCameraDetectorMap(this, frameStartTime, jaTime);
132 // new LineScanCameraDetectorMap(this, frameStartTime, frame_time);
133 #else
134  // Have to use variable line scan detector mapping due to how line scans
135  // are performed. This is currently segfaulting...
136 
137  double stime(obsStartTime);
138  double scanTime(stop_time-start_time);
139  m_lineRates.clear();
140  for (int i = 0 ; i < ParentLines() ; i++) {
141  m_lineRates.push_back(LineRateChange(i+1, stime, scanTime));
142  stime += frame_time;
143  }
144  m_lineRates.push_back(LineRateChange(ParentLines()+1,stime-start_time,start_time));
145  double endTime(stime-frame_time+scanTime);
146  new VariableLineScanCameraDetectorMap(this, m_lineRates);
147 #endif
148 
149  int binning = inst["PixelAveragingWidth"];
151  DetectorMap()->SetDetectorLineSumming(1.0); // Line dimension never binned
152 
153  // Setup focal plane map
155  fmap->SetDetectorOrigin(getDouble("INS"+ikCode+"_BORESIGHT_SAMPLE"),
156  getDouble("INS"+ikCode+"_BORESIGHT_LINE"));
157  fmap->SetDetectorOffset(0.0, 0.0);
158 
159  // Setup distortion map
160  //new CrismDistortionMap(this);
161  new CameraDistortionMap(this);
162 
163 
164  // Setup the ground and sky map
165  new LineScanCameraGroundMap(this);
166 // new CrismCameraGroundMap(this);
167  new LineScanCameraSkyMap(this);
168 
169  setTime(iTime(frameStartTime));
170  double tol = 0.0; //PixelResolution();
171  if(tol < 0.) {
172  // Alternative calculation of .01*ground resolution of a pixel
173  tol = PixelPitch() * SpacecraftAltitude() / FocalLength() / 1000. / 100.;
174  }
175 
176 // cout << "\nCreateCache(" << frameStartTime << ", " << frameEndTime << ")...\n";
177 #if 0
178 // cout << "CacheSize: " << CacheSize(obsStartTime, obsStopTime) << "\n";
179  createCache(obsStartTime, obsStopTime, ParentLines(), tol);
180 
181 #else
182 // cout << "LoadCache()...\n";
183  LoadCache();
184 #endif
185 // cout << "Done.\n";
187  return;
188  }
189 
190  void CrismCamera::SetBand (const int physicalBand) {
191  return;
192  }
193 
195  return (m_isBandDependent);
196  }
197 
198 
199  double CrismCamera::getEtTime(const QString &sclk) {
200  return (getClockTime(sclk, -74999).Et());
201  }
202 
203 }
204 
205 
206 // Plugin
216  return new Isis::CrismCamera(cube);
217 }
218