Unverified Commit 654ee9d1 authored by Kristin Berry's avatar Kristin Berry Committed by GitHub
Browse files

Updated amicacal to use camera to calculate distance to sun continuation (#4336)



* Added capabilities for camera to get sun distance

* Update Kaitlyn's amicacal PR based on feedback

* Update AmicaCalUtils.h

Co-authored-by: default avatarKaitlyn Lee <kdl222@nau.edu>
Co-authored-by: default avatarKristin Berry <kberry@gyro.wr.usgs.gov>
parent 16abf8fd
Loading
Loading
Loading
Loading
+41 −30
Original line number Diff line number Diff line
@@ -14,8 +14,10 @@ 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"
@@ -23,14 +25,9 @@ find files of those names at the top level of this repository. **/
#include "Pvl.h"
#include "PvlGroup.h"

#include "Spice.h"



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


/**
 * @author 2016-04-04 Tyler Wilson
 *
@@ -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 {


@@ -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) {

  try {
    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;

      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);
      if (!found) return false;

      //  Convert starttime to et
      double obsStartTime;
      scs2e_c(-130, 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);
      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;
      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;
}


+3 −0
Original line number Diff line number Diff line
@@ -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>
+23 −15
Original line number Diff line number Diff line
@@ -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.
@@ -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_);
@@ -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();

@@ -656,22 +656,30 @@ QString loadCalibrationVariables(const QString &config) {


  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();

  // 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_);
    }
  }

  tsecs = obsStartTime - g_launchTime.Et();
  tdays = tsecs / 86400;
  g_bias = g_b0
+7 −0
Original line number Diff line number Diff line
@@ -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;