Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated lronacal to compute sun to body distance from cached ephem data #3611

Merged
merged 4 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 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,11 @@ namespace Isis {
* @param noTables Indicates the use of tables.
*/
Spice::Spice(Cube &cube, bool noTables) {
init(cube, noTables);
init(*cube.label(), noTables);
}

Spice::Spice(Pvl &lab, json isd) {
Kelvinrr marked this conversation as resolved.
Show resolved Hide resolved
init(lab, true, isd);
}

/**
Expand All @@ -106,9 +110,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 +146,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 +168,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 +179,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 +234,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 +370,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 +390,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 +435,7 @@ namespace Isis {
}

NaifStatus::CheckErrors();
}

}

/**
* Loads/furnishes NAIF kernel(s)
Expand Down Expand Up @@ -1338,6 +1339,21 @@ 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();

for(size_t i = 0; i < bodyRotation.size(); i++) {
std::cout << bodyRotation[i] << std::endl;
Kelvinrr marked this conversation as resolved.
Show resolved Hide resolved
}

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

return vnorm_c(sunPosFromTarget);
}


/**
Expand All @@ -1354,7 +1370,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