Skip to content

Commit

Permalink
merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelvin committed Mar 2, 2021
2 parents 144877b + b4eee50 commit 800a08d
Show file tree
Hide file tree
Showing 16 changed files with 2,264 additions and 503 deletions.
128 changes: 90 additions & 38 deletions isis/src/messenger/apps/mdiscal/MdisCalUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ find files of those names at the top level of this repository. **/
#include <string>
#include <vector>

#include "Camera.h"
#include "CSVReader.h"
#include "FileName.h"
#include "IString.h"
#include "iTime.h"
#include "NaifStatus.h"
#include "Spice.h"

/**
* @author ????-??-?? Kris Becker
*
Expand Down Expand Up @@ -65,7 +69,7 @@ namespace Isis {
static void loadNaifTiming() {
static bool naifLoaded = false;
if (!naifLoaded) {
// Load the NAIF kernels to determine timing data
// Load the NAIF kernels to determine timing data
Isis::FileName leapseconds("$base/kernels/lsk/naif????.tls");
leapseconds = leapseconds.highestVersion();

Expand All @@ -75,20 +79,21 @@ namespace Isis {
Isis::FileName pck("$base/kernels/spk/de???.bsp");
pck = pck.highestVersion();

// Load the kernels
// Load the kernels
QString leapsecondsName(leapseconds.expanded());
QString sclkName(sclk.expanded());
QString pckName(pck.expanded());
furnsh_c(leapsecondsName.toLatin1().data());
furnsh_c(sclkName.toLatin1().data());
furnsh_c(pckName.toLatin1().data());

// Ensure it is loaded only once
// Ensure it is loaded only once
naifLoaded = true;
}
return;
}


/**
* @brief Computes the distance from the Sun to the observed body
*
Expand All @@ -99,34 +104,54 @@ namespace Isis {
*/
static bool sunDistanceAU(const QString &scStartTime,
const QString &target,
double &sunDist) {

// Ensure NAIF kernels are loaded
loadNaifTiming();
sunDist = 1.0;

// Determine if the target is a valid NAIF target
SpiceInt tcode;
SpiceBoolean found;
bodn2c_c(target.toLatin1().data(), &tcode, &found);
if (!found) return (false);

// Convert starttime to et
double obsStartTime;
scs2e_c(-236, scStartTime.toLatin1().data(), &obsStartTime);

// Get the vector from target to sun and determine its length
double sunv[3];
double lt;
spkpos_c(target.toLatin1().data(), obsStartTime, "J2000", "LT+S", "sun",
sunv, &lt);
double sunkm = vnorm_c(sunv);

// Return in AU units
sunDist = sunkm / 1.49597870691E8;
double &sunDist,
Cube *cube) {
try {
Camera *cam;
cam = cube->camera();
cam->SetImage(0.5, 0.5);
sunDist = cam->sunToBodyDist() / 1.49597870691E8;
}
catch (IException &e) {
try {
// Ensure NAIF kernels are loaded
NaifStatus::CheckErrors();
loadNaifTiming();
sunDist = 1.0;

// Determine if the target is a valid NAIF target
SpiceInt tcode;
SpiceBoolean found;
bodn2c_c(target.toLatin1().data(), &tcode, &found);
if (!found) return (false);

// Convert starttime to et
double obsStartTime;
scs2e_c(-236, scStartTime.toLatin1().data(), &obsStartTime);
NaifStatus::CheckErrors();

// Get the vector from target to sun and determine its length
double sunv[3];
double lt;
spkpos_c(target.toLatin1().data(), obsStartTime, "J2000", "LT+S", "sun",
sunv, &lt);
double sunkm = vnorm_c(sunv);

// Return in AU units
sunDist = sunkm / 1.49597870691E8;
}
catch (IException &e) {
QString message = "Unable to determine the sun-target distance.";
throw IException(e, IException::Unknown, message, _FILEINFO_);
}
}
return (true);
}


/**
* Load WAC CSV.
*/
std::vector<double> loadWACCSV(const QString &fname, int filter,
int nvalues, bool header=true, int skip=0) {
// Open the CSV file
Expand Down Expand Up @@ -159,6 +184,9 @@ namespace Isis {
}


/**
* Load NAC CSV.
*/
std::vector<double> loadNACCSV(const QString &fname, int nvalues,
bool header=true, int skip=0) {
// Open the CSV file
Expand All @@ -180,6 +208,9 @@ namespace Isis {
}


/**
* Load responsivity
*/
std::vector<double> loadResponsivity(bool isNAC, bool binned, int filter,
QString &fname) {

Expand All @@ -205,6 +236,9 @@ namespace Isis {
}


/**
* Load solar irradiation
*/
std::vector<double> loadSolarIrr(bool isNAC, bool binned, int filter,
QString &fname) {

Expand All @@ -225,6 +259,10 @@ namespace Isis {
}
}


/**
* Loads the smear component
*/
double loadSmearComponent(bool isNAC, int filter, QString &fname) {

FileName smearfile(fname);
Expand All @@ -246,6 +284,7 @@ namespace Isis {
return (smear[0]);
}


/**
* @brief Load and retrieve empirical correction factor
*
Expand Down Expand Up @@ -319,7 +358,7 @@ namespace Isis {
* to WAC filter data.
*/
double loadEmpiricalCorrection(const QString &scStartTime, const int filter,
QString &ename, QString &eDate) {
QString &ename, QString &eDate, Cube *cube) {

// This table maps the filter number extracted from BandBin/Number keyword
// to the columns (index) in the empirical correction table
Expand Down Expand Up @@ -363,12 +402,27 @@ namespace Isis {
throw IException(IException::User, mess, _FILEINFO_);
}

// Ensure NAIF kernels are loaded for NAIF time computations
loadNaifTiming();

// Convert s/c clock start time to et
double obsStartTime;
scs2e_c(-236, scStartTime.toLatin1().data(), &obsStartTime);
double obsStartTime = 0.0;
try {
Camera *cam = cube->camera();
obsStartTime = cam->getClockTime(scStartTime, -236).Et();
}
catch (IException &e) {
try {
// Ensure NAIF kernels are loaded for NAIF time computations
NaifStatus::CheckErrors();
loadNaifTiming();

// Convert s/c clock start time to et
scs2e_c(-236, scStartTime.toLatin1().data(), &obsStartTime);
NaifStatus::CheckErrors();

}
catch (IException &e) {
QString message = "Could not convert spacecraft clock start count to ET.";
throw IException(e, IException::Unknown, message, _FILEINFO_);
}
}

// Set initial conditions and loop through all rows in the event table
double evalue = 1.0;
Expand All @@ -378,8 +432,7 @@ namespace Isis {
CSVReader::CSVAxis eRow = csv.getRow(i);
QString utcTime = eRow[0];
double eTime;
utc2et_c(utcTime.toLatin1().data(), &eTime);

eTime = iTime(utcTime.toLatin1().data()).Et();
// If current time is greater than start time this is the post event case
if (eTime > obsStartTime) {
// Get closest pre or post event correction factor
Expand All @@ -402,6 +455,5 @@ namespace Isis {
return (evalue);
}


};
#endif
4 changes: 2 additions & 2 deletions isis/src/messenger/apps/mdiscal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void IsisMain() {
empiricalCorrectionFile = "";
g_empiricalCorrectionFactor = loadEmpiricalCorrection(startTime, g_filterNumber + 1,
empiricalCorrectionFile,
empiricalCorrectionDate);
empiricalCorrectionDate, icube);
empiricalCorrectionFactor = toString(g_empiricalCorrectionFactor);
}
else {
Expand All @@ -335,7 +335,7 @@ void IsisMain() {
PvlGroup& inst = icube->group("Instrument");
QString target = inst["TargetName"];
QString startTime = inst["SpacecraftClockCount"];
if (sunDistanceAU(startTime, target, g_solarDist)) {
if (sunDistanceAU(startTime, target, g_solarDist, icube)) {
vector<double> sol = loadSolarIrr(g_isNarrowAngleCamera, g_isBinnedData,
g_filterNumber + 1, solirrfile);
g_Ff = sol[2];
Expand Down
4 changes: 4 additions & 0 deletions isis/src/messenger/apps/mdiscal/mdiscal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,10 @@
was applied. This will change the output DNs for any images where FLATFIELD=false.
Updated documentation. Fixes #2338
</change>
<change name="Kristin Berry" date="2021-02-26">
Updated to use camera for the target-sun distance and clock time to ET conversion, if possible.
This enables the program to be run without local spice kernels (the spice server can be used for spiceinit.)
</change>
</history>

<groups>
Expand Down
15 changes: 15 additions & 0 deletions isis/src/messenger/apps/mdiscal/tsts/contamination/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ commands:
catlab \
from=$(OUTPUT)/pre_contamination.cub \
to=$(OUTPUT)/pre_contamination_label.pvl > /dev/null;

# contamination day 1, iof=true
$(APPNAME) from=$(INPUT)/EW0217136166F.cub \
to=$(OUTPUT)/contamination_day_1.cub \
iof=true > /dev/null;
catlab from=$(OUTPUT)/contamination_day_1.cub \
to=$(OUTPUT)/contamination_day_1_label.pvl > /dev/null;

# more contamination, iof=true
$(APPNAME) \
from=$(INPUT)/EW0217310049F.cub \
Expand All @@ -25,6 +27,7 @@ commands:
catlab \
from=$(OUTPUT)/contamination_jun_2011_iof.cub \
to=$(OUTPUT)/contamination_jun_2011_iof_label.pvl > /dev/null;

# more contamination, iof=false
$(APPNAME) \
from=$(INPUT)/EW0217310055G.cub \
Expand All @@ -33,6 +36,7 @@ commands:
catlab \
from=$(OUTPUT)/contamination_jun_2011_ra.cub \
to=$(OUTPUT)/contamination_jun_2011_ra_label.pvl > /dev/null;

# even more contamination, iof=true
$(APPNAME) \
from=$(INPUT)/EW0234069364C.cub \
Expand All @@ -41,6 +45,7 @@ commands:
catlab \
from=$(OUTPUT)/contamination_jan_2012_last_day.cub \
to=$(OUTPUT)/contamination_jan_2012_last_day_label.pvl > /dev/null;

# post contamination, iof=true
$(APPNAME) \
from=$(INPUT)/EW0234155897G.cub \
Expand All @@ -49,13 +54,15 @@ commands:
catlab \
from=$(OUTPUT)/post_contamination.cub \
to=$(OUTPUT)/post_contamination_label.pvl > /dev/null;

# contamination day 1, iof=true, no empirical correction performed
$(APPNAME) from=$(INPUT)/EW0217136166F.cub \
to=$(OUTPUT)/contamination_day_1_no_ec.cub \
iof=true \
ecf=false > /dev/null;
catlab from=$(OUTPUT)/contamination_day_1_no_ec.cub \
to=$(OUTPUT)/contamination_day_1_no_ec_label.pvl > /dev/null;

# post contamination, iof=true, no empirical correction performed
$(APPNAME) \
from=$(INPUT)/EW0234155897G.cub \
Expand All @@ -65,6 +72,7 @@ commands:
catlab \
from=$(OUTPUT)/post_contamination_no_ec.cub \
to=$(OUTPUT)/post_contamination_no_ec_label.pvl > /dev/null;

# NAC contamination, iof=true, no empirical correction (because NAC)
$(APPNAME) \
from=$(INPUT)/EN0228199579M.cub \
Expand All @@ -74,4 +82,11 @@ commands:
from=$(OUTPUT)/contamination_NAC.cub \
to=$(OUTPUT)/contamination_NAC_label.pvl > /dev/null;

# Test going through the camera model for sun distance and start time
$(APPNAME) from=$(INPUT)/EW0217136166F.spiceinited.cub \
to=$(OUTPUT)/contamination_day_1.spiceinited.cub \
iof=true > /dev/null;
catlab from=$(OUTPUT)/contamination_day_1.spiceinited.cub \
to=$(OUTPUT)/contamination_day_1_label.spiceinited.pvl > /dev/null;


Loading

0 comments on commit 800a08d

Please sign in to comment.