Unverified Commit 3812ae2c authored by Kristin Berry's avatar Kristin Berry Committed by GitHub
Browse files

Update gllssical to work without local spice kernels (#4306)



* Update gllssical to work without local spice kernels

* getClockTime doesn't furnsh missing kernels

* Move into try

* Updated to work on old spiceinited data and add test

* A bit of cleanup

* Forgot first naif status

* Update to use setImage to set the time of the camera

* Updated based on feedback

Co-authored-by: default avatarKristin Berry <kberry@gyro.wr.usgs.gov>
parent 24ac6f74
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -163,6 +163,9 @@
      Modified code that it doesn't require a camera model to calculate the I/F.
      Fixes #1740.
    </change>
    <change name="Kristin Berry" date="2021-02-23">
      Modified code to try to use the camera to get the target-sun distance to calculate the IOF.
    </change>
  </history>

  <groups>     
+51 −25
Original line number Diff line number Diff line
@@ -9,10 +9,12 @@ find files of those names at the top level of this repository. **/
#include "Isis.h"
#include "ProcessByLine.h"
#include "Buffer.h"
#include "Camera.h"
#include "iTime.h"
#include "SpecialPixel.h"
#include "Spice.h"
#include "TextFile.h"
#include "NaifStatus.h"

using namespace Isis;
using namespace std;
@@ -444,13 +446,31 @@ void calculateScaleFactor0(Cube *icube, Cube *gaincube) {
  gainConversion = toDouble(conversionFactors["GainRatios"][getGainModeID(gaincube)-1]);

  if (iof) {
    try {
      Camera *cam;
      cam = icube->camera();
      cam->instrumentPosition()->SetAberrationCorrection("LT+S");
      // Set time to the starting time of the image by setting image.
      cam->SetImage(0.5, 0.5);

      // rsun converted to AU
      rsun = cam->sunToBodyDist() / 1.49597870691E8 / 5.2;
    } 
    catch (IException &e) {
      // try original fallback for previously spiceinited data 
      try {
        Pvl *label = icube->label();
        QString startTime = label->findGroup("Instrument",Pvl::Traverse)["SpacecraftClockStartCount"][0];

        Spice spicegll(*icube);
        spicegll.instrumentPosition()->SetAberrationCorrection("LT+S");
    QString startTime = label->findGroup("Instrument",Pvl::Traverse)["SpacecraftClockStartCount"][0];
        Isis::FileName sclk(label->findGroup("Kernels",Pvl::Traverse)["SpacecraftClock"][0]);
        QString sclkName(sclk.expanded());

        NaifStatus::CheckErrors();
        furnsh_c(sclkName.toLatin1().data());
        NaifStatus::CheckErrors();

        double obsStartTime;
        scs2e_c(-77, startTime.toLatin1().data(), &obsStartTime);
        spicegll.setTime(obsStartTime);
@@ -461,6 +481,12 @@ void calculateScaleFactor0(Cube *icube, Cube *gaincube) {
        
        //  Convert to AU units
        rsun = sunkm / 1.49597870691E8 / 5.2;
      } 
      catch (IException &e) {
        QString message = "IOF option does not work with non-spiceinited cubes.";
        throw IException(e, IException::User, message, _FILEINFO_);
      }
    }
        
   /*
    * We are calculating I/F, so scaleFactor0 is:
+23 −0
Original line number Diff line number Diff line
@@ -3,7 +3,30 @@ APPNAME = gllssical
include $(ISISROOT)/make/isismake.tsts

commands:
	# Test old spiceinited data
	$(APPNAME) FROM=$(INPUT)/3439R.cub TO=$(OUTPUT)/3439R.cal.cub > /dev/null;
	catlab FROM=$(OUTPUT)/3439R.cal.cub TO=$(OUTPUT)/3439R.cal.pvl > /dev/null;
	$(APPNAME) FROM=$(INPUT)/1213r.cub TO=$(OUTPUT)/1213r.cal.cub > /dev/null;
	catlab FROM=$(OUTPUT)/1213r.cal.cub TO=$(OUTPUT)/1213r.cal.pvl > /dev/null;

	# Test newly re-spiceinited data
	$(APPNAME) FROM=$(INPUT)/3439R.respiceinit.cub TO=$(OUTPUT)/3439R.respiceinit.cub > /dev/null;
	catlab FROM=$(OUTPUT)/3439R.respiceinit.cub TO=$(OUTPUT)/3439R.respiceinit.pvl > /dev/null;
	$(APPNAME) FROM=$(INPUT)/1213r.respiceinit.cub TO=$(OUTPUT)/1213r.respiceinit.cub > /dev/null;
	catlab FROM=$(OUTPUT)/1213r.respiceinit.cub TO=$(OUTPUT)/1213r.respiceinit.pvl > /dev/null;

	# Test non-spiceinited data: throws an error
	if [ `$(APPNAME) \
	  FROM=$(INPUT)/3439R.nospice.cub TO=$(OUTPUT)/broken.cub 2>> $(OUTPUT)/errors_temp.txt > /dev/null` ]; \
	  then true; \
	  fi;

	# Remove everything in brackets like filenames/paths from error messages
	$(SED) 's/\[\([^"]*\)\]//g' $(OUTPUT)/errors_temp.txt \
	  > $(OUTPUT)/errors.txt; 

	# Cleanup
	$(RM) $(OUTPUT)/errors_temp.txt;
	$(RM) $(OUTPUT)/broken.cub;