Skip to content

Commit

Permalink
updated lronacal to compute sun to body distance from cached ephem da…
Browse files Browse the repository at this point in the history
…ta (#3611)

* updated lronacal to compute sun -> body distance from cached ephem data

* removed forced exception

* added basic Spice test

* Added doc string to Spice::Spice(PVL, json) and removed debug print
  • Loading branch information
Kelvin Rodriguez authored and scsides committed Dec 20, 2019
1 parent 9d5f300 commit 8cda49e
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 45 deletions.
57 changes: 38 additions & 19 deletions isis/src/base/objs/Spice/Spice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace Isis {
Pvl &lab = *cube.label();
PvlGroup kernels = lab.findGroup("Kernels", Pvl::Traverse);
bool hasTables = (kernels["TargetPosition"][0] == "Table");
init(cube, !hasTables);
init(lab, !hasTables);
}

/**
Expand All @@ -90,7 +90,18 @@ namespace Isis {
* @param noTables Indicates the use of tables.
*/
Spice::Spice(Cube &cube, bool noTables) {
init(cube, noTables);
init(*cube.label(), noTables);
}


/**
* Constructs a Spice Object
*
* @param lab Isis Cube Pvl Lavel
* @param isd ALE Json ISD
*/
Spice::Spice(Pvl &lab, json isd) {
init(lab, true, isd);
}

/**
Expand All @@ -106,9 +117,9 @@ namespace Isis {
* @internal
* @history 2011-02-08 Jeannie Walldren - Initialize pointers to null.
*/
void Spice::init(Cube &cube, bool noTables) {
void Spice::init(Pvl &lab, bool noTables, json isd) {
NaifStatus::CheckErrors();

// Initialize members
m_solarLongitude = new Longitude;
m_et = NULL;
Expand Down Expand Up @@ -142,8 +153,6 @@ namespace Isis {

// m_sky = false;

Pvl &lab = *cube.label();

// Get the kernel group and load main kernels
PvlGroup kernels = lab.findGroup("Kernels", Pvl::Traverse);

Expand All @@ -166,7 +175,6 @@ namespace Isis {
m_usingNaif = !lab.hasObject("NaifKeywords") || noTables;
m_usingAle = false;

json isd;
// Modified to load planetary ephemeris SPKs before s/c SPKs since some
// missions (e.g., MESSENGER) may augment the s/c SPK with new planet
// ephemerides. (2008-02-27 (KJB))
Expand All @@ -178,15 +186,18 @@ namespace Isis {
QString msg = "Falling back to ISIS generation of nadir pointing";
throw IException(IException::Programmer, msg, _FILEINFO_);
}

if (isd == NULL){
// try using ALE
std::ostringstream kernel_pvl;
kernel_pvl << kernels;

// try using ALE
std::ostringstream kernel_pvl;
kernel_pvl << kernels;
json props;
props["kernels"] = kernel_pvl.str();

json props;
props["kernels"] = kernel_pvl.str();
isd = ale::load(lab.fileName().toStdString(), props.dump(), "isis");
}

isd = ale::load(cube.fileName().toStdString(), props.dump(), "isis");
json aleNaifKeywords = isd["NaifKeywords"];
m_naifKeywords = new PvlObject("NaifKeywords", aleNaifKeywords);

Expand Down Expand Up @@ -230,7 +241,6 @@ namespace Isis {
load(kernels["Extra"], noTables);
}
}


// Moved the construction of the Target after the NAIF kenels have been loaded or the
// NAIF keywords have been pulled from the cube labels, so we can find target body codes
Expand Down Expand Up @@ -367,7 +377,7 @@ namespace Isis {
m_sunPosition = new SpicePosition(10, m_target->naifBodyCode());

// Check to see if we have nadir pointing that needs to be computed &
// See if we have table blobs to load
// See if we have table blobs to load
if (kernels["TargetPosition"][0].toUpper() == "TABLE") {
Table t("SunPosition", lab.fileName(), lab);
m_sunPosition->LoadCache(t);
Expand All @@ -387,7 +397,6 @@ namespace Isis {
m_bodyRotation->LoadCache(isd["BodyRotation"]);
solarLongitude();
}

// We can't assume InstrumentPointing & InstrumentPosition exist, old
// files may be around with the old keywords, SpacecraftPointing &
// SpacecraftPosition. The old keywords were in existance before the
Expand Down Expand Up @@ -433,8 +442,7 @@ namespace Isis {
}

NaifStatus::CheckErrors();
}

}

/**
* Loads/furnishes NAIF kernel(s)
Expand Down Expand Up @@ -1338,6 +1346,17 @@ namespace Isis {
QString Spice::targetName() const {
return m_target->name();
}


double Spice::sunToBodyDist() const {
std::vector<double> sunPosition = m_sunPosition->Coordinate();
std::vector<double> bodyRotation = m_bodyRotation->Matrix();

double sunPosFromTarget[3];
mxv_c(&bodyRotation[0], &sunPosition[0], sunPosFromTarget);

return vnorm_c(sunPosFromTarget);
}


/**
Expand All @@ -1354,7 +1373,7 @@ namespace Isis {
return;
}

if (m_usingAle){
if (m_usingAle) {
double og_time = m_bodyRotation->EphemerisTime();
m_bodyRotation->SetEphemerisTime(et.Et());
m_sunPosition->SetEphemerisTime(et.Et());
Expand Down
7 changes: 5 additions & 2 deletions isis/src/base/objs/Spice/Spice.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ namespace Isis {
// constructors
Spice(Cube &cube);
Spice(Cube &cube, bool noTables);
Spice(Pvl &lab, nlohmann::json);

// destructor
virtual ~Spice();
Expand All @@ -306,6 +307,8 @@ namespace Isis {
void instrumentBodyFixedPosition(double p[3]) const;
void sunPosition(double p[3]) const;
double targetCenterDistance() const;
double sunToBodyDist() const;

Longitude solarLongitude();
void instrumentBodyFixedVelocity(double v[3]) const;
iTime time() const;
Expand Down Expand Up @@ -392,8 +395,8 @@ namespace Isis {
// Don't allow copies
Spice(const Spice &other);
Spice &operator=(const Spice &other);

void init(Cube &cube, bool noTables);
void init(Pvl &pvl, bool noTables, nlohmann::json isd = NULL);

void load(PvlKeyword &key, bool notab);
void computeSolarLongitude(iTime et);
Expand Down
60 changes: 36 additions & 24 deletions isis/src/lro/apps/lronaccal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,33 +196,45 @@ void IsisMain() {
Pvl radPvl(radFileName.expanded());

if(g_iof) {
iTime startTime((QString) inst["StartTime"]);

try {
iTime startTime((QString) inst["StartTime"]);
double etStart = startTime.Et();
// Get the distance between the Moon and the Sun at the given time in
// Astronomical Units (AU)
QString bspKernel1 = p.MissionData("lro", "/kernels/tspk/moon_pa_de421_1900-2050.bpc", false);
QString bspKernel2 = p.MissionData("lro", "/kernels/tspk/de421.bsp", false);
furnsh_c(bspKernel1.toLatin1().data());
furnsh_c(bspKernel2.toLatin1().data());
QString pckKernel1 = p.MissionData("base", "/kernels/pck/pck?????.tpc", true);
QString pckKernel2 = p.MissionData("lro", "/kernels/pck/moon_080317.tf", false);
QString pckKernel3 = p.MissionData("lro", "/kernels/pck/moon_assoc_me.tf", false);
furnsh_c(pckKernel1.toLatin1().data());
furnsh_c(pckKernel2.toLatin1().data());
furnsh_c(pckKernel3.toLatin1().data());
double sunpos[6], lt;
spkezr_c("sun", etStart, "MOON_ME", "LT+S", "MOON", sunpos, &lt);
g_solarDistance = vnorm_c(sunpos) / KM_PER_AU;
unload_c(bspKernel1.toLatin1().data());
unload_c(bspKernel2.toLatin1().data());
unload_c(pckKernel1.toLatin1().data());
unload_c(pckKernel2.toLatin1().data());
unload_c(pckKernel3.toLatin1().data());
Camera *cam;
cam = iCube->camera();
cam->setTime(startTime);
g_solarDistance = cam->sunToBodyDist() / KM_PER_AU;

}
catch(IException &e) {
QString msg = "Unable to find the necessary SPICE kernels for converting to IOF";
throw IException(e, IException::User, msg, _FILEINFO_);
// Failed to instantiate a camera, try furnishing kernels directly
try {

double etStart = startTime.Et();
// Get the distance between the Moon and the Sun at the given time in
// Astronomical Units (AU)
QString bspKernel1 = p.MissionData("lro", "/kernels/tspk/moon_pa_de421_1900-2050.bpc", false);
QString bspKernel2 = p.MissionData("lro", "/kernels/tspk/de421.bsp", false);
furnsh_c(bspKernel1.toLatin1().data());
furnsh_c(bspKernel2.toLatin1().data());
QString pckKernel1 = p.MissionData("base", "/kernels/pck/pck?????.tpc", true);
QString pckKernel2 = p.MissionData("lro", "/kernels/pck/moon_080317.tf", false);
QString pckKernel3 = p.MissionData("lro", "/kernels/pck/moon_assoc_me.tf", false);
furnsh_c(pckKernel1.toLatin1().data());
furnsh_c(pckKernel2.toLatin1().data());
furnsh_c(pckKernel3.toLatin1().data());
double sunpos[6], lt;
spkezr_c("sun", etStart, "MOON_ME", "LT+S", "MOON", sunpos, &lt);
g_solarDistance = vnorm_c(sunpos) / KM_PER_AU;
unload_c(bspKernel1.toLatin1().data());
unload_c(bspKernel2.toLatin1().data());
unload_c(pckKernel1.toLatin1().data());
unload_c(pckKernel2.toLatin1().data());
unload_c(pckKernel3.toLatin1().data());
}
catch(IException &e) {
QString msg = "Unable to find the necessary SPICE kernels for converting to IOF";
throw IException(e, IException::User, msg, _FILEINFO_);
}
}
g_iofLeft = radPvl["IOF_LEFT"];
g_iofRight = radPvl["IOF_RIGHT"];
Expand Down
Loading

0 comments on commit 8cda49e

Please sign in to comment.