Commit c82afe4b authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by Adam Paquette
Browse files

Hayabusa2 w1, w2 and telescopic tests (#3929)

* added tests for hayabusa2's  w1, w2 and telescopic cameras

* removed old tests

* cleaned up tests

* addressed comments

* added extra Fail

* added full instrument label to image

* Changed hyb2onccamera pointer
parent 787d72af
Loading
Loading
Loading
Loading
+0 −127
Original line number Diff line number Diff line
Unit Test for Hyb2OncCamera...

----------------------------------------------
Test for Telecopic Camera...
FileName:  "hyb2_onc_20151204_041012_tbf_l2a.cub"
CK Frame:  -37100

Kernel IDs: 
CK Frame ID      =  -37000
CK Reference ID  =  1
SPK Target ID    =  -37
SPK Reference ID =  1

Spacecraft Name Long:   "Hayabusa2"
Spacecraft Name Short:  "Hayabusa2"
Instrument Name Long:   "Optical Navigation Camera - Telescopic Camera"
Instrument Name Short:  "ONC-T"

Shutter open  =  "502474280.7291458"
Shutter close =  "502474280.7291541"

For upper left of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For upper right of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For lower left of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For lower right of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For center pixel position ...
Latitude OK
Longitude OK
Delta Sample less than 0.001
Delta Line less than 0.001


----------------------------------------------
Test for W1 Camera...
FileName:  "hyb2_onc_20151204_045429_w1f_l2a_crop.cub"
CK Frame:  -37110

Kernel IDs: 
CK Frame ID      =  -37000
CK Reference ID  =  1
SPK Target ID    =  -37
SPK Reference ID =  1

Spacecraft Name Long:   "Hayabusa2"
Spacecraft Name Short:  "Hayabusa2"
Instrument Name Long:   "Optical Navigation Camera - W1 Camera"
Instrument Name Short:  "ONC-W1"

Shutter open  =  "502476937.6921466"
Shutter close =  "502476937.6921548"

For upper left of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For upper right of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For lower left of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For lower right of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For center pixel position ...
Latitude OK
Longitude OK
Delta Sample less than 0.001
Delta Line less than 0.001


----------------------------------------------
Test for W2 Camera...
FileName:  "hyb2_onc_20151203_072958_w2f_l2a_crop.cub"
CK Frame:  -37120

Kernel IDs: 
CK Frame ID      =  -37000
CK Reference ID  =  1
SPK Target ID    =  -37
SPK Reference ID =  1

Spacecraft Name Long:   "Hayabusa2"
Spacecraft Name Short:  "Hayabusa2"
Instrument Name Long:   "Optical Navigation Camera - W2 Camera"
Instrument Name Short:  "ONC-W2"

Shutter open  =  "502399866.4151246"
Shutter close =  "502399866.4151273"

For upper left of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For upper right of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For lower left of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For lower right of target ...
Delta Sample less than 0.001
Delta Line less than 0.001

For center pixel position ...
Latitude OK
Longitude OK
Delta Sample less than 0.001
Delta Line less than 0.001
+0 −200
Original line number Diff line number Diff line
/**
 * @file
 *
 *   Unless noted otherwise, the portions of Isis written by the USGS are public
 *   domain. See individual third-party library and package descriptions for 
 *   intellectual property information,user agreements, and related information.
 *
 *   Although Isis has been used by the USGS, no warranty, expressed or implied,
 *   is made by the USGS as to the accuracy and functioning of such software 
 *   and related material nor shall the fact of distribution constitute any such 
 *   warranty, and no responsibility is assumed by the USGS in connection 
 *   therewith.
 *
 *   For additional information, launch
 *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html in a browser or see 
 *   the Privacy & Disclaimers page on the Isis website,
 *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
 *   http://www.usgs.gov/privacy.html.
 */
#include <QDebug>

#include <iomanip>
#include <iostream>

#include "Hyb2OncCamera.h"
#include "Camera.h"
#include "CameraFactory.h"
#include "IException.h"
#include "iTime.h"
#include "Preference.h"
#include "Pvl.h"
#include "PvlGroup.h"

using namespace std;
using namespace Isis;

void testCamera(Cube &c, double knownLat, double knownLon,
                double s1, double l1, 
                double s2, double l2, 
                double s3, double l3, 
                double s4, double l4);
void testLineSamp(Camera *cam, double sample, double line);


/**
 * Unit Test for the Hayabusa2 ONC camera.
 *
 * @author 2017-07-11 Kristin Berry
 *
 * @internal
 *   @history 2017-07-11 Kristin Berry
 */
int main(void) {
  Preference::Preferences(true);

  qDebug() << "Unit Test for Hyb2OncCamera...";
  try {
    // These should be lat/lon at center of image. To obtain these numbers for a new cube/camera,
    // set both the known lat and known lon to zero and copy the unit test output "Latitude off by: "
    // and "Longitude off by: " values directly into these variables.
    qDebug() << "";
    qDebug() << "----------------------------------------------";
    qDebug() << "Test for Telecopic Camera...";
    double knownLat = -39.18374913423203;
    double knownLon = 48.06875707620756;
    Cube c("$hayabusa2/testData/hyb2_onc_20151204_041012_tbf_l2a.cub", "r");
    testCamera(c, knownLat, knownLon, 357.0, 359.0, 602.0, 334.0, 378.0, 557.0, 594.0, 580.0);

    qDebug() << "";
    qDebug() << "----------------------------------------------";
    qDebug() << "Test for W1 Camera...";
    knownLat = -54.25951996619505;
    knownLon = 67.72017401996563;
    Cube w1("$hayabusa2/testData/hyb2_onc_20151204_045429_w1f_l2a_crop.cub", "r");
    testCamera(w1, knownLat, knownLon, 21.0, 20.0, 31.0, 11.0, 16.0, 29.0, 32.0, 28.0);

    qDebug() << "";
    qDebug() << "----------------------------------------------";
    qDebug() << "Test for W2 Camera...";
    knownLat = 29.68691258558313;
    knownLon = 78.57599766268363;
    Cube w2("$hayabusa2/testData/hyb2_onc_20151203_072958_w2f_l2a_crop.cub", "r");
    testCamera(w2, knownLat, knownLon, 51.0, 42.0, 173.0, 21.0, 54.0, 149.0, 174.0, 155.0);

  }
  catch (IException &e) {
    e.print();
  }

}


void testCamera(Cube &c,
                double knownLat, double knownLon,
                double s1, double l1, 
                double s2, double l2, 
                double s3, double l3, 
                double s4, double l4) {
  Hyb2OncCamera *cam = (Hyb2OncCamera *) CameraFactory::Create(c);
  qDebug() << "FileName: " << FileName(c.fileName()).name();
  qDebug() << "CK Frame: " << cam->instrumentRotation()->Frame();
  qDebug() << "";

  // Test kernel IDs
  qDebug() << "Kernel IDs: ";
  qDebug() << "CK Frame ID      = " << cam->CkFrameId();
  qDebug() << "CK Reference ID  = " << cam->CkReferenceId();
  qDebug() << "SPK Target ID    = " << cam->SpkTargetId();
  qDebug() << "SPK Reference ID = " << cam->SpkReferenceId();
  qDebug() << "";
  
  // Test name methods
  qDebug() << "Spacecraft Name Long:  " << cam->spacecraftNameLong();
  qDebug() << "Spacecraft Name Short: " << cam->spacecraftNameShort();
  qDebug() << "Instrument Name Long:  " << cam->instrumentNameLong();
  qDebug() << "Instrument Name Short: " << cam->instrumentNameShort();
  qDebug() << "";

  // Test Shutter Open/Close 
  const PvlGroup &inst = c.label()->findGroup("Instrument", Pvl::Traverse);
  double exposureDuration = ((double) inst["ExposureDuration"])/1000;
  QString stime = inst["StartTime"];
  double et; // StartTime keyword is the center exposure time
  str2et_c(stime.toLatin1().data(), &et);
  pair <iTime, iTime> shuttertimes = cam->ShutterOpenCloseTimes(et, exposureDuration);
  qDebug() << "Shutter open  = " << toString(shuttertimes.first.Et(), 16);
  qDebug() << "Shutter close = " << toString(shuttertimes.second.Et(), 16);
  qDebug() << "";

  // Test all four corners to make sure the conversions are right
  qDebug() << "For upper left of target ...";
  testLineSamp(cam, s1, l1);

  qDebug() << "For upper right of target ...";
  testLineSamp(cam, s2, l2);

  qDebug() << "For lower left of target ...";
  testLineSamp(cam, s3, l3);

  qDebug() << "For lower right of target ...";
  testLineSamp(cam, s4, l4);

  qDebug() << "For center pixel position ...";

  if (!cam->SetImage((cam->Samples()/2.0), (cam->Lines()/2.0))) {
    throw IException(IException::Unknown, "ERROR setting image to known position.", _FILEINFO_);
  }

  if (abs(cam->UniversalLatitude() - knownLat) < 1E-10) {
    qDebug() << "Latitude OK";
  }
  else {
    qDebug() << "Latitude off by:  " << toString(cam->UniversalLatitude() - knownLat, 16);
  }

  if (abs(cam->UniversalLongitude() - knownLon) < 1E-10) {
    qDebug() << "Longitude OK";
  }
  else {
    qDebug() << "Longitude off by: " << toString(cam->UniversalLongitude() - knownLon, 16);
  }

  testLineSamp( cam, (cam->Samples()/2.0), (cam->Lines()/2.0) );
}


void testLineSamp(Camera *cam, double sample, double line) {
  bool success = cam->SetImage(sample, line);

  if (success) {
    double lat = cam->UniversalLatitude();
    double lon = cam->UniversalLongitude();
    success = cam->SetUniversalGround(lat, lon);
//    success = cam->SetUniversalGround(cam->UniversalLatitude(), cam->UniversalLongitude());
  }

  if (success) {
    double deltaSamp = sample - cam->Sample();
    double deltaLine = line - cam->Line();
    if(fabs(deltaSamp) < 0.001) {
      qDebug() << "Delta Sample less than 0.001";
    }
    else {
      qDebug() << "Delta Sample larger than expected " << deltaSamp;
    }
    if(fabs(deltaLine) < 0.001) {
      qDebug() << "Delta Line less than 0.001";
    }
    else {
      qDebug() << "Delta Line larger than expected " << deltaLine;
    }
    qDebug() << "";
  }
  else {
    qDebug() << "DeltaSample = No Intersection";
    qDebug() << "DeltaLine   = No Intersection";
    qDebug() << "";
  }
}
+237 −0
Original line number Diff line number Diff line
#include <QDebug>

#include <iomanip>
#include <iostream>

#include "Hyb2OncCamera.h"
#include "Camera.h"
#include "CameraFactory.h"
#include "IException.h"
#include "iTime.h"
#include "Preference.h"
#include "Pvl.h"
#include "TestUtilities.h"
#include "PvlGroup.h"
#include "Fixtures.h"

#include "gmock/gmock.h"

using namespace std;
using namespace Isis;

void testCamera(Cube &c, double knownLat, double knownLon,
                double s1, double l1, 
                double s2, double l2, 
                double s3, double l3, 
                double s4, double l4);
void testLineSamp(Camera *cam, double sample, double line);

class Hayabusa2Cube : public DefaultCube {
  protected:
    void setInstrument(QString ikid, QString instrumentId, QString spacecraftName) {
      PvlGroup &kernels = testCube->label()->findObject("IsisCube").findGroup("Kernels");
      kernels.findKeyword("NaifFrameCode").setValue(ikid);    
      
      PvlGroup &inst = testCube->label()->findObject("IsisCube").findGroup("Instrument");
      std::istringstream iss(R"(
        Group = Instrument
         SpacecraftName                  = HAYABUSA-2
         InstrumentId                    = ONC-W2
         InstrumentName                  = "Optical Navigation Camera"
         TargetName                      = Mars
         StartTime                       = 2015-12-03T07:29:58.232
         StopTime                        = 2015-12-03T07:29:58.234
         ExposureDuration                = 0.00272 <seconds>
         RawSpacecraftClockCount         = 0x3C38845A <1/32 sec>
         Binning                         = 1
         SelectedImageAreaX1             = 1
         SelectedImageAreaY1             = 1
         SelectedImageAreaX2             = 1024
         SelectedImageAreaY2             = 1
         SelectedImageAreaX3             = 1
         SelectedImageAreaY3             = 1024
         SelectedImageAreaX4             = 1024
         SelectedImageAreaY4             = 1024
         SmearCorrection                 = NON
         OffsetCorrection                = N/A
         FlatCorrection                  = NON
         RadianceConversion              = NON
         PhotometricCorrection           = NON
         BandRegistration                = NON
         L2BFlatFileName                 = N/A
         L2BSystemEfficiencyFileName     = N/A
         L2CShapeModelFileName           = N/A
         L2DPhaseFunctionFileName        = N/A
         L2DShapeModelFileName           = N/A
         SubImageCount                   = 1
         BusLineVoltage                  = 49.28 <V>
         ONCCurrent                      = 0.52 <V>
         FLACCurrent                     = 0.00 <V>
         ONCAETemperature                = 1.53 <degC>
         ONCTOpticsTemperature           = 19.17 <degC>
         ONCTCCDTemperature              = -29.62 <degC>
         ONCTElectricCircuitTemperature  = -11.96 <degC>
         ONCW1OpticsTemperature          = 1.42 <degC>
         ONCW1CCDTemperature             = -24.98 <degC>
         ONCW1ElectricCircuitTemperature = -10.90 <degC>
         ONCW2OpticsTemperature          = 1.28 <degC>
         ONCW2CCDTemperature             = -24.67 <degC>
         ONCW2ElectricCircuitTemperature = -4.12 <degC>
         FLACTemperature                 = -15.27 <degC>
       End_Group
      )");
      
      PvlGroup newInstGroup; 
      iss >> newInstGroup; 
      
      newInstGroup.findKeyword("InstrumentId").setValue(instrumentId);
      newInstGroup.findKeyword("SpacecraftName").setValue(spacecraftName);
      inst = newInstGroup;

      PvlKeyword startcc("SpacecraftClockStartCount", "33322515");
      PvlKeyword stopcc("SpaceCraftClockStopCount", "33322516");
      inst += startcc;
      inst += stopcc; 

      PvlObject &naifKeywords = testCube->label()->findObject("NaifKeywords");
      
      json nk; 
      nk["INS"+ikid.toStdString()+"_FOCAL_LENGTH"] = 10.44;
      nk["INS"+ikid.toStdString()+"_PIXEL_PITCH"] = 0.013;
      nk["INS"+ikid.toStdString()+"_TRANSX"] = {0.0, 0.013, 0.0};
      nk["INS"+ikid.toStdString()+"_TRANSY"] = {0.0, 0.0, 0.013};
      nk["INS"+ikid.toStdString()+"_ITRANSS"] = {0.0, 76.923076923077, 0.0};
      nk["INS"+ikid.toStdString()+"_ITRANSL"] = {0.0, 0.0, 76.923076923077};
      nk["INS"+ikid.toStdString()+"_BORESIGHT_LINE"] = 490.5;
      nk["INS"+ikid.toStdString()+"_BORESIGHT_SAMPLE"] = 512.5;
      nk["INS"+ikid.toStdString()+"_OD_K"] = {1.014, 2.933e-07, -1.384e-13};
      nk["BODY499_RADII"] = {3396.19, 3396.19, 3376.2};
      nk["CLOCK_ET-37_33322515_COMPUTED"] = "8ed6ae8930f3bd41";
      nk["BODY_CODE"] = 499;
      nk["BODY_FRAME_CODE"] = 10014; 
      PvlObject newNaifKeywords("NaifKeywords", nk);
      naifKeywords = newNaifKeywords; 

      QString fileName = testCube->fileName();
      // need to remove old camera pointer 
      delete testCube;
      // This is now a Hayabusa cube
      testCube = new Cube(fileName, "rw");
    }
};


TEST_F(Hayabusa2Cube, Hayabusa2OncCameraW1CameraTest) {
  setInstrument("-37110", "ONC-W1", "HAYABUSA-2");
  Camera *cam = testCube->camera();
  EXPECT_EQ(cam->CkFrameId(), -37000);
  EXPECT_EQ(cam->CkReferenceId(), 1);
  EXPECT_EQ(cam->SpkTargetId(), -37);
  EXPECT_EQ(cam->SpkReferenceId(), 1);
   
  // Test name methods
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->spacecraftNameLong(), "Hayabusa2");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->spacecraftNameShort(), "Hayabusa2");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->instrumentNameLong(), "Optical Navigation Camera - W1 Camera");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->instrumentNameShort(), "ONC-W1");

  testCamera(*testCube, 11.215766294778371, 257.19997053715304, 51.0, 42.0, 173.0, 21.0, 54.0, 149.0, 174.0, 155.0);
}


TEST_F(Hayabusa2Cube, Hayabusa2OncCameraW2CameraTest) {
  setInstrument("-37120", "ONC-W2", "HAYABUSA-2");
   
  Camera *cam = testCube->camera();
  EXPECT_EQ(cam->CkFrameId(), -37000);
  EXPECT_EQ(cam->CkReferenceId(), 1);
  EXPECT_EQ(cam->SpkTargetId(), -37);
  EXPECT_EQ(cam->SpkReferenceId(), 1);
   
  // Test name methods
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->spacecraftNameLong(), "Hayabusa2");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->spacecraftNameShort(), "Hayabusa2");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->instrumentNameLong(), "Optical Navigation Camera - W2 Camera");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->instrumentNameShort(), "ONC-W2");

  testCamera(*testCube, 11.215766294778371, 257.19997053715304, 51.0, 42.0, 173.0, 21.0, 54.0, 149.0, 174.0, 155.0);

  
}

TEST_F(Hayabusa2Cube, Hayabusa2OncCameraTelecopicCameraTest) {
  setInstrument("-37100", "ONC-T", "HAYABUSA-2");

  Camera *cam = testCube->camera(); 
  EXPECT_EQ(cam->CkFrameId(), -37000);
  EXPECT_EQ(cam->CkReferenceId(), 1);
  EXPECT_EQ(cam->SpkTargetId(), -37);
  EXPECT_EQ(cam->SpkReferenceId(), 1);
   
  // Test name methods
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->spacecraftNameLong(), "Hayabusa2");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->spacecraftNameShort(), "Hayabusa2");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->instrumentNameLong(), "Optical Navigation Camera - Telescopic Camera");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual,cam->instrumentNameShort(), "ONC-T");

  testCamera(*testCube, 11.215766294778371, 257.19997053715304, 51.0, 42.0, 173.0, 21.0, 54.0, 149.0, 174.0, 155.0);
}

void testCamera(Cube &c,
                double knownLat, double knownLon,
                double s1, double l1, 
                double s2, double l2, 
                double s3, double l3, 
                double s4, double l4) {
  
  FramingCamera *cam = (FramingCamera*) CameraFactory::Create(c);
  
  // Test Shutter Open/Close 
  const PvlGroup &inst = c.label()->findGroup("Instrument", Pvl::Traverse);
  double exposureDuration = ((double) inst["ExposureDuration"])/1000;
  QString stime = inst["StartTime"];
  double et; // StartTime keyword is the center exposure time
  str2et_c(stime.toLatin1().data(), &et);
  pair <iTime, iTime> shuttertimes = cam->ShutterOpenCloseTimes(et, exposureDuration);
  
  EXPECT_DOUBLE_EQ(shuttertimes.first.Et(), 502399866.4151246);
  EXPECT_DOUBLE_EQ(shuttertimes.second.Et(), 502399866.41512734);

  // Test all four corners to make sure the conversions are right
  testLineSamp(cam, s1, l1);
  testLineSamp(cam, s2, l2);
  testLineSamp(cam, s3, l3);
  testLineSamp(cam, s4, l4);
  
  if (!cam->SetImage((cam->Samples()/2.0), (cam->Lines()/2.0))) {
    throw IException(IException::Unknown, "ERROR setting image to known position.", _FILEINFO_);
  }

  EXPECT_NEAR(cam->UniversalLatitude(), knownLat,  1E-10);
  EXPECT_NEAR(cam->UniversalLongitude(), knownLon,  1E-10);
  testLineSamp( cam, (cam->Samples()/2.0), (cam->Lines()/2.0) );
}


void testLineSamp(Camera *cam, double sample, double line) {
  bool success = cam->SetImage(sample, line);
  double lat;
  double lon;

  if (success) {
    lat = cam->UniversalLatitude();
    lon = cam->UniversalLongitude();
    success = cam->SetUniversalGround(lat, lon);
  }
  else {
    FAIL() << "Failed to set sample/line (Line: " << line << ", Sample: " << sample << ")." ;
  }

  if (success) {
    EXPECT_NEAR(sample, cam->Sample(), .001); 
    EXPECT_NEAR(line, cam->Line(), .001);
  }
  else {
    FAIL() << "Failed to set lat/lon (Lat: " << lat << ", Lon: " << lon << ")." ;
  }
}