Skip to content

Commit

Permalink
Added ability to get sun distance from the camera Ref #4303 (#4307)
Browse files Browse the repository at this point in the history
  • Loading branch information
scsides authored Feb 23, 2021
1 parent fe149f5 commit 28d62c4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 29 deletions.
61 changes: 42 additions & 19 deletions isis/src/viking/apps/vikcal/CalParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ find files of those names at the top level of this repository. **/
#include <SpiceZmc.h>

#include "CalParameters.h"
#include "Camera.h"
#include "Cube.h"
#include "FileName.h"
#include "IException.h"
#include "IString.h"
#include "iTime.h"
#include "LeastSquares.h"
#include "Pvl.h"
#include "TextFile.h"
Expand All @@ -26,7 +29,7 @@ find files of those names at the top level of this repository. **/
using namespace std;
namespace Isis {

CalParameters::CalParameters(const QString &fname) {
CalParameters::CalParameters(const QString &fname, Cube *icube) {
try {
// Extract Pvl Information from the file
Pvl pvl(fname.toLatin1().data());
Expand Down Expand Up @@ -76,7 +79,7 @@ namespace Isis {
}

QString startTime = instrument["STARTTIME"];
CalcSunDist(startTime);
p_dist1 = CalcSunDist(startTime, icube);
p_labexp = (double)instrument["EXPOSUREDURATION"] * 1000.0; // convert to msec
QString target = " ";
PvlKeyword cs1 = instrument["FLOODMODEID"];
Expand Down Expand Up @@ -360,24 +363,44 @@ namespace Isis {
}

/**
* Calculates the distance from the sun at the specified time
* Calculates the distance from Mars to the sun at the specified time.
* Try to useing the camera assiciated with the cube first, if that
* doesn't work fall back to using the SPICE data.
*
* @param t iTime
* @param t The UTC time at which the sun distance is being requested
* @param iCube The cube we are calibrating
*
* @return Distance from the Sun to Mars in km
*/
void CalParameters::CalcSunDist(QString t) {
NaifStatus::CheckErrors();
double sunv[3];
SpiceDouble lt, et;
FileName fname1 = (FileName)"$base/kernels/lsk/naif0007.tls";
FileName fname2 = (FileName)"$base/kernels/spk/de405.bsp";
QString tempfname1 = fname1.expanded();
QString tempfname2 = fname2.expanded();
furnsh_c(tempfname1.toLatin1().data());
furnsh_c(tempfname2.toLatin1().data());
utc2et_c(t.toLatin1().data(), &et);
spkezp_c(10, et, "J2000", "LT+S", 499, sunv, &lt);
p_dist1 = sqrt(sunv[0] * sunv[0] + sunv[1] * sunv[1] + sunv[2] * sunv[2]);
NaifStatus::CheckErrors();
double CalParameters::CalcSunDist(QString t, Cube *iCube) {
try {
Camera *cam;
cam = iCube->camera();
iTime startTime(t);
cam->setTime(startTime);
return cam->sunToBodyDist();
}
catch(IException &e) {
// Failed to instantiate a camera, try furnishing kernels directly
try {
NaifStatus::CheckErrors();
double sunv[3];
SpiceDouble lt, et;
FileName fname1 = (FileName)"$base/kernels/lsk/naif0007.tls";
FileName fname2 = (FileName)"$base/kernels/spk/de405.bsp";
QString tempfname1 = fname1.expanded();
QString tempfname2 = fname2.expanded();
furnsh_c(tempfname1.toLatin1().data());
furnsh_c(tempfname2.toLatin1().data());
utc2et_c(t.toLatin1().data(), &et);
spkezp_c(10, et, "J2000", "LT+S", 499, sunv, &lt);
return sqrt(sunv[0] * sunv[0] + sunv[1] * sunv[1] + sunv[2] * sunv[2]);
NaifStatus::CheckErrors();
}
catch(IException &e) {
QString msg = "Unable to determine the distance from Mars to the Sun";
throw IException(e, IException::User, msg, _FILEINFO_);
}
}
}

} // end namespace isis
8 changes: 5 additions & 3 deletions isis/src/viking/apps/vikcal/CalParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ namespace Isis {
* were signaled. References #2248
*
*/

class Cube;
class CalParameters {
public:
// Constructor
CalParameters(const QString &fname);
CalParameters(const QString &fname, Cube *icube);

/**
* Calculates and returns time based offset at specified line and sample
Expand All @@ -62,7 +64,7 @@ namespace Isis {
}

/**
* Returns distance value found in the vikcal.sav file
* Returns estimated distance from Mars to the Sun found in the vikcal.sav file
*
* @return double Approximate distance from the sun
*/
Expand Down Expand Up @@ -221,7 +223,7 @@ namespace Isis {
int cam, QString wav, int cs1, int cs2, int cs3, int cs4);
void vikoffSetup(QString mission, int spn, QString target,
int cam, double clock, int cs3);
void CalcSunDist(QString t);
double CalcSunDist(QString t, Cube *icube);

double p_labexp; //!<Exposure Duration from cube label
double p_w0; //!<Omega0 from vikcal.sav file
Expand Down
7 changes: 2 additions & 5 deletions isis/src/viking/apps/vikcal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ void IsisMain() {
// linear = ui.GetBoolean("LINEAR");
const QString in = ui.GetFileName("FROM");

calParam = new CalParameters(in);

// Open the input cube
Cube icube;
icube.open(in, "r");
calParam = new CalParameters(in, &icube);
Progress prog;

// If the file has already been calibrated, throw an error
Expand Down Expand Up @@ -98,15 +97,13 @@ void IsisMain() {
p.EndProcess();
}

void cal(vector<Buffer *> &in,
vector<Buffer *> &out) {
void cal(vector<Buffer *> &in, vector<Buffer *> &out) {

Buffer &inp = *in[0]; // Input Cube
Buffer &dcf = *in[1]; // Dark Current File
Buffer &fff = *in[2]; // Flat Field File
Buffer &outp = *out[0]; // Output Cube


// Loop for each pixel in the line.
for(int i = 0; i < inp.size(); i++) {
if(IsSpecial(inp[i])) {
Expand Down
2 changes: 2 additions & 0 deletions isis/src/viking/apps/vikcal/tsts/default/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ include $(ISISROOT)/make/isismake.tsts
commands:
$(APPNAME) from=$(INPUT)/f387a06.cub \
to=$(OUTPUT)/vikcalTruth.cub > /dev/null;
$(APPNAME) from=$(INPUT)/f319b18.cub \
to=$(OUTPUT)/vikcalCameraTruth.cub > /dev/null;
7 changes: 5 additions & 2 deletions isis/src/viking/apps/vikcal/vikcal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
Fixed poutput pvl to not have spaces in the keyword names
</change>
<change name="Steven Lambright" date="2008-05-13">
Removed references to CubeInfo
Removed references to CubeInfo
</change>
<change name="Christopher Austin" date="2010-06-16">
Fixed pvl comments
</change>
<change name="Stuart Sides" date="2021-02-22">
Added ability to calibrate using the camera instead of direcly using SPICE kernels
</change>
</history>

<groups>
Expand All @@ -57,7 +60,7 @@
Input cube file name
</brief>
<description>
The cube to be calibrated.
The cube to be calibrated.
</description>
<filter>
*.cub
Expand Down

0 comments on commit 28d62c4

Please sign in to comment.