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 amicacal to use camera to calculate distance to sun continuation #4336

Merged
merged 3 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
71 changes: 41 additions & 30 deletions isis/src/hayabusa/apps/amicacal/AmicaCalUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ find files of those names at the top level of this repository. **/
#include <vector>
#include <QString>

#include "Camera.h"
#include "CSVReader.h"
#include "IException.h"
#include "iTime.h"
#include "FileName.h"
#include "LineManager.h"
#include "NaifStatus.h"
#include "IString.h"
#include "Pvl.h"
#include "PvlGroup.h"

#include "Spice.h"



// OpenCV libraries
#include <opencv2/opencv.hpp>


/**
* @author 2016-04-04 Tyler Wilson
*
Expand All @@ -39,6 +36,8 @@ find files of those names at the top level of this repository. **/
using namespace cv;
using namespace std;

#define KM_PER_AU 149597871

namespace Isis {


Expand Down Expand Up @@ -96,42 +95,54 @@ static void loadNaifTiming() {
*
* @return @b double Distance in AU between Sun and observed body.
*/
static bool sunDistanceAU(const QString &scStartTime,
static bool sunDistanceAU(Cube *iCube,
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);
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment above goes with the catch

Camera *cam;
cam = iCube->camera();
cam->SetImage (0.5, 0.5);
sunDist = cam->sunToBodyDist() / KM_PER_AU;
}
catch(IException &e) {
try {
// Ensure NAIF kernels are loaded
loadNaifTiming();
sunDist = 1.0;

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

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

if (!found) return false;

// 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);
NaifStatus::CheckErrors();
// Convert starttime to et
double obsStartTime;
scs2e_c(-130, scStartTime.toLatin1().data(), &obsStartTime);

double sunkm = vnorm_c(sunv);
// 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);
NaifStatus::CheckErrors();

double sunkm = vnorm_c(sunv);

// Return in AU units
sunDist = sunkm / 1.49597870691E8;
// Return in AU units
sunDist = sunkm / KM_PER_AU;
}
catch (IException &e) {
QString message = "Failed to calculate the sun-target distance.";
throw IException(e, IException::User, message, _FILEINFO_);
}
}

//cout << "sunDist = " << sunDist << endl;
return (true);
return true;
}


Expand Down
3 changes: 3 additions & 0 deletions isis/src/hayabusa/apps/amicacal/amicacal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
Added DN/S as an output option. Apply dark current current as it was disabled
in earlier versions.
</change>
<change name="Kaitlyn Lee" date="2021-02-24">
Added ability to get the sun distance from the camera.
</change>
</history>

<groups>
Expand Down
38 changes: 23 additions & 15 deletions isis/src/hayabusa/apps/amicacal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using namespace std;
FileName determineFlatFieldFile(const QString &filter, const bool nullPolarPix);
void calibrate(vector<Buffer *>& in, vector<Buffer *>& out);

QString loadCalibrationVariables(const QString &config);
QString loadCalibrationVariables(const QString &config, Cube *iCube);

#if 0
// PSF correction is currently not working and has been removed as an option.
Expand Down Expand Up @@ -299,14 +299,14 @@ void IsisMain() {
//nb = inputCube->bandCount();
#endif

QString calfile = loadCalibrationVariables(ui.GetAsString("CONFIG"));
QString calfile = loadCalibrationVariables(ui.GetAsString("CONFIG"), inputCube);

g_timeRatio = g_tvct / (g_exposureTime + g_tvct);
g_darkCurrent = g_d0 * exp(g_d1 * g_temperature);
g_calibrationScale = 1.0;
QString g_units = "DN";

if ( !sunDistanceAU(startTime, target, g_solarDist) ) {
if ( !sunDistanceAU(inputCube, startTime, target, g_solarDist) ) {
throw IException(IException::Programmer,
"Cannot calculated distance to sun!",
_FILEINFO_);
Expand Down Expand Up @@ -600,7 +600,7 @@ void psfCorrection(vector<Buffer *> &in, vector<Buffer *> &out) {
* @brief Loads the calibration variables into the program.
*/

QString loadCalibrationVariables(const QString &config) {
QString loadCalibrationVariables(const QString &config, Cube *iCube) {

// UserInterface& ui = Application::GetUserInterface();

Expand Down Expand Up @@ -655,23 +655,31 @@ QString loadCalibrationVariables(const QString &config) {
g_b2 = biasGroup["B"][2].toDouble();


g_launchTimeStr=QString(biasGroup["launchTime"]);

//cout << g_launchTimeStr << endl;

//static iTime g_launchTime("2003-05-09T04:29:25");
g_launchTime =g_launchTimeStr;
//iTime g_t0(g_startTime);
//cout << "g_t0" << g_t0.EtString();
g_launchTimeStr = QString(biasGroup["launchTime"]);
g_launchTime = g_launchTimeStr;

// Compute BIAS correction factor (it's a constant so do it once!)
double obsStartTime;
double tsecs;
double tdays;

try{
Camera *cam;
cam = iCube->camera();
cam->SetImage (0.5, 0.5);
obsStartTime = cam->time().Et();
}
catch(IException &e) {
try{
loadNaifTiming(); // Ensure the proper kernels are loaded
scs2e_c(g_hayabusaNaifCode, g_startTime.toLatin1().data(), &obsStartTime);
}
catch (IException &e) {
QString message = "IOF option does not work with non-spiceinited cubes.";
throw IException(e, IException::User, message, _FILEINFO_);
}
}

loadNaifTiming(); // Ensure the proper kernels are loaded

scs2e_c(g_hayabusaNaifCode, g_startTime.toLatin1().data(), &obsStartTime);
tsecs = obsStartTime - g_launchTime.Et();
tdays = tsecs / 86400;
g_bias = g_b0
Expand Down
7 changes: 7 additions & 0 deletions isis/src/hayabusa/apps/amicacal/tsts/iof/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ commands:
TO=$(OUTPUT)/corrected_noiof_st_2459265790_w.cub \
units=dn \
> /dev/null;

# Test spiceinited data
$(APPNAME) \
FROM=$(INPUT)/st_2459265790_w.spice.cub \
TO=$(OUTPUT)/corrected_iof_st_2459265790_w.spice.cub \
> /dev/null;