Isis 3 Programmer Reference
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 <QString>
28 
29 //#include "CrismCameraGroundMap.h"
30 //#include "CrismDistortionMap.h"
31 #include "CameraFocalPlaneMap.h"
34 #include "LineScanCameraSkyMap.h"
35 #include "Constants.h"
36 #include "FileName.h"
37 #include "IException.h"
38 #include "IString.h"
39 #include "iTime.h"
40 #include "NaifStatus.h"
41 #include "SpecialPixel.h"
42 
43 using namespace std;
44 
45 namespace Isis {
55  CrismCamera::CrismCamera(Cube &cube) : LineScanCamera(cube), m_lineRates(),
56  m_isBandDependent(true) {
57  m_instrumentNameLong = "Compact Reconnaissance Imaging Spectrometer for Mars";
58  m_instrumentNameShort = "CRISM";
59  m_spacecraftNameLong = "Mars Reconnaissance Orbiter";
60  m_spacecraftNameShort = "MRO";
62 
63  Pvl &lab = *cube.label();
64 
65  PvlGroup inst = lab.findGroup("Instrument", Pvl::Traverse);
66 
67  // SensorId = S (VNIR), = L (IR) = J (JOINT)
68  QString sensor = (QString) inst ["SensorId"];
69 
70  // Prepare instrument code
71  QString ikCode(toString(naifIkCode()));
72 
73  // Set Frame mounting. Same for both (VNIR, IR) detectors
75  SetPixelPitch();
76 
77  // Get the start and end time in et
78  double etStart = getEtTime((QString) inst ["SpacecraftClockStartCount"]);
79  double etStop = getEtTime((QString) inst ["SpacecraftClockStopCount"]);
80 
81 
82  // Compute the exposure time of the first line and the line rate. This
83  // algorithm is taken from the CRISM instrument kernel, mro_crism_v10.ti,
84  // at the time of development.
85 // double framesPerSec = (double) inst["FrameRate"];
86  int exposure = (int) inst["ExposureParameter"];
87 
88  // calculate seconds for a full frame
89 // double frame_time = 1.0 / framesPerSec;
90 
91  // calculate seconds per pixel clock
92 // double pixel_clock_time = frame_time / 83333.0;
93 
94  // This is what John Hayes does in the DPU (Data Processing Unit), to write
95  // register to FPU (Focal Plane Unit) specifying how long NOT to integrate,
96  // in pixel clocks [0..83333]
97  int reg = ((480 - exposure) * 83333) / 480;
98 
99  // Actual integration starts 3 line-times later, rounded up to next line
100  // time
101  int start_clocks = reg + (3 * 166);
102  if (start_clocks % 166) start_clocks += 166 - (start_clocks % 166);
103 
104  // integration continues 4 line-times after de-assertion
105 // int stop_clocks = 83333 + (4 * 166);
106 
107 // double start_time = start_clocks * pixel_clock_time;
108 // double stop_time = stop_clocks * pixel_clock_time;
109 
110  // Start of first line exposure time. This is the start time of the
111  // frame time plus the itegration delay start time - constant for all
112  // frames
113 // double obsStartTime(etStart+start_time);
114 // double obsStopTime(obsStartTime+(stop_time*ParentLines())-start_time);
115 // double obsEndTime(obsStartTime+(frame_time*(ParentLines()))-start_time);
116 
117  double frameStartTime(etStart);
118 // double frameStopTime(frameStartTime+(stop_time*(ParentLines())));
119 // double frameEndTime(frameStartTime+(frame_time*(ParentLines())));
120 
121 // double lineTime((etStop-etStart+frame_time)/(ParentLines()));
122 
123 
124  // Compute the sclk and UTC of the specifed line for cropping purposes
125 #if 0
126  iTime myLineStartTime(etStart + ((25.0 - 1.0) * frame_time));
127 // cout << "\nLine 25 Start Times...\n";
128  SpiceChar sclk[80];
129  (void) sce2s_c(naifSclkCode(), myLineStartTime.Et(), sizeof(sclk), sclk);
130 // cout << "UTC@Line 25: " << myLineStartTime.UTC() << "\n";
131 // cout << "SCLK@Line 25: " << sclk << "\n";
132 
133 #endif
134  // Setup detector map
135 #if 1
136  double jaTime = (etStop-etStart)/ParentLines();
137  new LineScanCameraDetectorMap(this, frameStartTime, jaTime);
138 // new LineScanCameraDetectorMap(this, frameStartTime, frame_time);
139 #else
140  // Have to use variable line scan detector mapping due to how line scans
141  // are performed. This is currently segfaulting...
142 
143  double stime(obsStartTime);
144  double scanTime(stop_time-start_time);
145  m_lineRates.clear();
146  for (int i = 0 ; i < ParentLines() ; i++) {
147  m_lineRates.push_back(LineRateChange(i+1, stime, scanTime));
148  stime += frame_time;
149  }
150  m_lineRates.push_back(LineRateChange(ParentLines()+1,stime-start_time,start_time));
151  double endTime(stime-frame_time+scanTime);
152  new VariableLineScanCameraDetectorMap(this, m_lineRates);
153 #endif
154 
155  int binning = inst["PixelAveragingWidth"];
157  DetectorMap()->SetDetectorLineSumming(1.0); // Line dimension never binned
158 
159  // Setup focal plane map
161 
162  // lines and samples added to the pvl in the order you
163  // call getDouble()
164  double bLine = getDouble("INS"+ikCode+"_BORESIGHT_LINE");
165  double bSample = getDouble("INS"+ikCode+"_BORESIGHT_SAMPLE");
166 
167  fmap->SetDetectorOrigin(bSample, bLine);
168  fmap->SetDetectorOffset(0.0, 0.0);
169 
170  // Setup distortion map
171  //new CrismDistortionMap(this);
172  new CameraDistortionMap(this);
173 
174 
175  // Setup the ground and sky map
176  new LineScanCameraGroundMap(this);
177 // new CrismCameraGroundMap(this);
178  new LineScanCameraSkyMap(this);
179 
180  setTime(iTime(frameStartTime));
181  double tol = 0.0; //PixelResolution();
182  if(tol < 0.) {
183  // Alternative calculation of .01*ground resolution of a pixel
184  tol = PixelPitch() * SpacecraftAltitude() / FocalLength() / 1000. / 100.;
185  }
186 
187 // cout << "\nCreateCache(" << frameStartTime << ", " << frameEndTime << ")...\n";
188 #if 0
189 // cout << "CacheSize: " << CacheSize(obsStartTime, obsStopTime) << "\n";
190  createCache(obsStartTime, obsStopTime, ParentLines(), tol);
191 
192 #else
193 // cout << "LoadCache()...\n";
194  LoadCache();
195 #endif
196 // cout << "Done.\n";
198  return;
199  }
200 
201  void CrismCamera::SetBand (const int physicalBand) {
202  return;
203  }
204 
206  return (m_isBandDependent);
207  }
208 
209 
210  double CrismCamera::getEtTime(const QString &sclk) {
211  return (getClockTime(sclk, -74999).Et());
212  }
213 }
214 
215 
216 // Plugin
226  return new Isis::CrismCamera(cube);
227 }
bool IsBandIndependent()
This is a band-dependant instrument.
void SetFocalLength()
Reads the focal length from the instrument kernel.
Definition: Camera.cpp:1430
void SetBand(const int physicalBand)
Virtual method that sets the band number.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
void SetDetectorOffset(const double sampleOffset, const double lineOffset)
Set the detector offset.
Parse and return pieces of a time string.
Definition: iTime.h:78
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
QString m_instrumentNameLong
Full instrument name.
Definition: Camera.h:507
void SetDetectorSampleSumming(const double summing)
Set sample summing mode.
void SetPixelPitch()
Reads the Pixel Pitch from the instrument kernel.
Definition: Camera.cpp:1437
Namespace for the standard library.
Generic class for Line Scan Cameras.
Search child objects.
Definition: PvlObject.h:170
SpiceInt naifSclkCode() const
This returns the NAIF SCLK code to use when reading from instrument kernels.
Definition: Spice.cpp:903
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
void createCache(iTime startTime, iTime endTime, const int size, double tol)
This method creates an internal cache of spacecraft and sun positions over a specified time range...
Definition: Spice.cpp:574
void SetDetectorOrigin(const double sample, const double line)
Set the detector origin.
void SetDetectorLineSumming(const double summing)
Set line summing mode.
int ParentLines() const
Returns the number of lines in the parent alphacube.
Definition: Camera.cpp:2818
MRO CRISM camera model.
Definition: CrismCamera.h:57
Convert between undistorted focal plane and ground coordinates.
Container class for storing timing information for a section of an image.
Convert between distorted focal plane and detector coordinates.
QString m_instrumentNameShort
Shortened instrument name.
Definition: Camera.h:508
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
SpiceInt naifIkCode() const
This returns the NAIF IK code to use when reading from instrument kernels.
Definition: Spice.cpp:893
double FocalLength() const
Returns the focal length.
Definition: Camera.cpp:2744
iTime getClockTime(QString clockValue, int sclkCode=-1, bool clockTicks=false)
This converts the spacecraft clock ticks value (clockValue) to an iTime.
Definition: Spice.cpp:977
Distort/undistort focal plane coordinates.
double PixelPitch() const
Returns the pixel pitch.
Definition: Camera.cpp:2754
void setTime(const iTime &time)
By setting the time you essential set the position of the spacecraft and body as indicated in the cla...
Definition: Sensor.cpp:112
Convert between parent image coordinates and detector coordinates.
Container for cube-like labels.
Definition: Pvl.h:135
double SpacecraftAltitude()
Returns the distance from the spacecraft to the subspacecraft point in km.
Definition: Sensor.cpp:712
Convert between undistorted focal plane and ra/dec coordinates.
void LoadCache()
This loads the spice cache big enough for this image.
Definition: Camera.cpp:2432
QString m_spacecraftNameLong
Full spacecraft name.
Definition: Camera.h:509
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition: Cube.cpp:1346
Isis::Camera * CrismCameraPlugin(Isis::Cube &cube)
This is the function that is called in order to instantiate a CrismCamera object. ...
LineScanCameraDetectorMap * DetectorMap()
Returns a pointer to the LineScanCameraDetectorMap object.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Definition: NaifStatus.cpp:43
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QString m_spacecraftNameShort
Shortened spacecraft name.
Definition: Camera.h:510
Convert between parent image coordinates and detector coordinates.
double Et() const
Returns the ephemeris time (TDB) representation of the time as a double.
Definition: iTime.h:139
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition: Spice.cpp:963
IO Handler for Isis Cubes.
Definition: Cube.h:170