Unverified Commit b03abdb6 authored by Tim Giroux's avatar Tim Giroux Committed by GitHub
Browse files

EIS wac camera model gtest (#4554)

* eis wac camera model gtest

* remove old test
parent 38755662
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ namespace Isis {
       * @return @b int The appropriate instrument code for the "Camera-matrix"
       *         Kernel Frame ID
       */
      virtual int CkFrameId() const { return (-159011); }
      virtual int CkFrameId() const { return (-159104); }


      /**
+0 −31
Original line number Diff line number Diff line
Unit Test for ClipperWacFcCamera...
Testing with test image...
FileName:  "simulated_clipper_eis_wac_rolling_shutter.cub"
CK Frame:  -159104

Kernel IDs: 
CK Frame ID =  -159011
CK Reference ID =  1
SPK Target ID =  -159
SPK Reference ID =  1

Focal Length =  150.401990000000012

For upper left corner ...
DeltaSample = ERROR
DeltaLine = ERROR

For upper right corner ...
DeltaSample = ERROR
DeltaLine = ERROR

For lower left corner ...
DeltaSample = ERROR
DeltaLine = ERROR

For lower right corner ...
DeltaSample = ERROR
DeltaLine = ERROR

For center pixel position ...
ERROR
+0 −136
Original line number Diff line number Diff line
/** This is free and unencumbered software released into the public domain.

The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

#include <QDebug>

#include <iomanip>
#include <iostream>

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

using namespace std;
using namespace Isis;

void TestLineSamp(Camera *cam, double samp, double line);

/**
 * Unit test for Clipper Wac Framing Camera
 *
 * @internal
 *   @history 2020-01-24 Kristin Berry - Original version. At the time this was written, many values
 *                       were preliminary or set to arbitrary numbers for testing reasons. These
 *                       will need to be updated in the future.
 */

// IMPORTANT NOTE: This test is believed to be failing because the test data has an arbitrary date
// for the StartTime, which means that the spice probably shows the spacecraft as not being near and
// pointed at Europa. If the spacecraft isn't near and pointed at Europa, there will be no intersection
// and SetImage will fail.
int main(void) {
  Preference::Preferences(true);

  qDebug() << "Unit Test for ClipperWacFcCamera...";
  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.
    double knownLat = 0;
    double knownLon = 0;

    qDebug() << "Testing with test image...";
    Cube c("$ISISTESTDATA/isis/src/clipper/unitTestData/simulated_clipper_eis_wac_rolling_shutter.cub", "r");
    ClipperWacFcCamera *cam = (ClipperWacFcCamera *) 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() << "";

    qDebug() << qSetRealNumberPrecision(18) << "Focal Length = " << cam->FocalLength();
    qDebug() << "";

    // Test all four corners to make sure the conversions are right
    // The actual four corners are not on the body, so shifting a little
    qDebug() << "For upper left corner ...";
    TestLineSamp(cam, 145.0, 161.0);

    qDebug() << "For upper right corner ...";
    TestLineSamp(cam, 3655.0, 157.0);

    qDebug() << "For lower left corner ...";
    TestLineSamp(cam, 289, 1767);

    qDebug() << "For lower right corner ...";
    TestLineSamp(cam, 3767, 1579);

    double samp = cam->Samples() / 2;
    double line = cam->Lines() / 2;
    qDebug() << "For center pixel position ...";

    if(!cam->SetImage(samp, line)) {
      qDebug() << "ERROR";
      return 0;
    }

    if(abs(cam->UniversalLatitude() - knownLat) < 1E-13) {
      qDebug() << "Latitude OK";
    }
    else {
      qDebug() << qSetRealNumberPrecision(18)
               << "Latitude off by: " << cam->UniversalLatitude() - knownLat;
    }

    if(abs(cam->UniversalLongitude() - knownLon) < 1E-11) {
      qDebug() << "Longitude OK";
    }
    else {
      qDebug() << qSetRealNumberPrecision(18)
               << "Longitude off by: " << cam->UniversalLongitude() - knownLon;
    }
  }
  catch(IException &e) {
    e.print();
  }
}

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

  if(success) {
    success = cam->SetUniversalGround(cam->UniversalLatitude(), cam->UniversalLongitude());
  }

  if(success) {
    double deltaSamp = samp - cam->Sample();
    double deltaLine = line - cam->Line();
    if(fabs(deltaSamp) < 1.1e-2) deltaSamp = 0.0;
    if(fabs(deltaLine) < 1.0e-2) deltaLine = 0.0;
    qDebug() << "DeltaSample = " << deltaSamp;
    qDebug() << "DeltaLine = " << deltaLine;
    qDebug() << "";
  }
  else {
    qDebug() << "DeltaSample = ERROR";
    qDebug() << "DeltaLine = ERROR";
    qDebug() << "";
  }
}
+69 −0
Original line number Diff line number Diff line
#include <gtest/gtest.h>
#include "Fixtures.h"
#include "Camera.h"
#include "CameraFactory.h"
#include "Cube.h"
#include "ClipperWacFcCamera.h"
#include "IException.h"
#include "iTime.h"
#include "TestUtilities.h"

using namespace Isis;

void TestLineSamp(Camera *cam, double samp, double line) {
  bool success = cam->SetImage(samp, line);
  EXPECT_TRUE(success);

  if(success) {
    success = cam->SetUniversalGround(cam->UniversalLatitude(), cam->UniversalLongitude());
  }
  EXPECT_TRUE(success);

  if(success) {
    EXPECT_NEAR(samp, cam->Sample(), 1.1e-2);
    EXPECT_NEAR(line, cam->Line(), 1.0e-2);
  }
}


TEST_F(ClipperWacFcCube, ClipperWacFcCameraUnitTest) {
  ClipperWacFcCamera *cam;
  try {
    cam = (ClipperWacFcCamera *) CameraFactory::Create(*wacFcCube);
  } catch(IException &e) {
    FAIL() << "Unable to create ClipperWacFcCamera" << std::endl;
  }

  // Camera info
  //EXPECT_EQ(cam->instrumentRotation()->Frame(), -27002);    // from the defaultcube isd
  EXPECT_EQ(cam->CkFrameId(), -159104);
  EXPECT_EQ(cam->CkReferenceId(), 1);
  EXPECT_EQ(cam->SpkTargetId(), -159);
  EXPECT_EQ(cam->SpkReferenceId(), 1);
  EXPECT_NEAR(cam->FocalLength(), 150.402, 1e-4);

  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->spacecraftNameLong(), "Europa Clipper");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->spacecraftNameShort(), "Clipper");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->instrumentNameLong(), "Europa Imaging System Framing Wide Angle Camera");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->instrumentNameShort(), "EIS-FWAC");

  
  // Check SetImage on corners
  int line, samp, nline, nsamp;
  line = 1.0;     samp = 1.0;
  nline = 1203.0; nsamp = 1055.0;
  TestLineSamp(cam, line, samp);
  TestLineSamp(cam, line, nsamp);
  TestLineSamp(cam, nline, nsamp);
  TestLineSamp(cam, nline, samp);


  // Simple test for ClipperWacFcCamera::ShutterOpenCloseTimes
  PvlGroup &inst = label.findGroup("Instrument", Pvl::Traverse);
  QString startTime = inst["StartTime"];
  iTime etStart(startTime);

  std::pair<iTime, iTime> startStop;
  startStop = cam->ShutterOpenCloseTimes(etStart.Et(), 0.00005);  // dummy value for exposure duration
  EXPECT_TRUE(startStop.first.Et() < startStop.second.Et());
}
+53 −1
Original line number Diff line number Diff line
@@ -1551,6 +1551,59 @@ namespace Isis {
    }
  }

  void ClipperWacFcCube::SetUp() {
    TempTestingFiles::SetUp();

    // Use defaultCube label and isd for now
    std::ifstream isdFile("data/defaultImage/defaultCube.isd");
    std::ifstream cubeLabel("data/defaultImage/defaultCube.pvl");
    isdFile >> isd;
    cubeLabel >> label;
    
    // Define WAC cube
    wacFcCube = new Cube();
    FileName wacFn(tempDir.path() + "/ClipperWAC.cub");
    wacFcCube->fromIsd(wacFn, label, isd, "rw");

    PvlGroup &wacKernels = wacFcCube->label()->findObject("IsisCube").findGroup("Kernels");
    wacKernels.findKeyword("NaifFrameCode").setValue("-159104");

      // Instruments Group
    PvlGroup &realWacInst = wacFcCube->label()->findObject("IsisCube").findGroup("Instrument");
    std::istringstream newWacInst(R"(
      Group = Instrument
        SpacecraftName            = Clipper
        InstrumentId              = EIS-WAC-FC
        TargetName                = Europa
        StartTime                 = 2025-01-01T00:00:00.000
      End_Group
    )");
    PvlGroup newWacInstPvl; newWacInst >> newWacInstPvl;
    realWacInst = newWacInstPvl;

      // NaifKeywords Group
    PvlObject &realWacNk = wacFcCube->label()->findObject("NaifKeywords");
    std::istringstream newWacNk(R"(
        INS-159104_FOCAL_LENGTH = 150.40199
        INS-159104_PIXEL_PITCH  = 0.014
        INS-159104_TRANSX       = (0.0, 0.014004651, 0.0)
        INS-159104_TRANSY       = (0.0, 0.0, 0.01399535)
        INS-159104_ITRANSS      = (0.0, 71.404849, 0.0)
        INS-159104_ITRANSL      = (0.0, 0.0, 71.4523)
      End_Object
    )");
    PvlObject newWacNkPvl; newWacNk >> newWacNkPvl;
    realWacNk = newWacNkPvl;

    wacFcCube->reopen("rw");
  }

  void ClipperWacFcCube::TearDown() {
    if (wacFcCube) {
      delete wacFcCube;
    }
  }

  void ClipperNacRsCube::SetUp() {
    DefaultCube::SetUp();

@@ -1610,5 +1663,4 @@ namespace Isis {
      delete testCube;
    }
  }

}
Loading