Unverified Commit e2ab8843 authored by Amy Stamile's avatar Amy Stamile Committed by GitHub
Browse files

Converted ClipperNacRollingShutterCamera unit test to Gtest (#4549)

* Converted ClipperNacRollingShutterCamera unit test to Gtest.

* Fixed bug regarding Sample and Line doubling. Updated fixture name.
parent c24b57bd
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -104,8 +104,8 @@ namespace Isis {
    p_parentSample   = (p_detectorSample - p_ss) / p_detectorSampleSumming + 1.0;
    p_parentLine     = (p_detectorLine   - p_sl) / p_detectorLineSumming   + 1.0;
    std::pair<double, double> jittered = applyJitter(p_parentSample, p_parentLine);
    p_parentSample += jittered.first;
    p_parentLine += jittered.second;
    p_parentSample = jittered.first;
    p_parentLine = jittered.second;
    return true;
  }

+0 −31
Original line number Diff line number Diff line
Unit Test for ClipperNacRollingShutterCamera...
Testing with test image...
FileName:  "simulated_clipper_eis_nac_rolling_shutter.cub"
CK Frame:  -159011

Kernel IDs: 
CK Frame ID =  -159011
CK Reference ID =  -159010
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 "ClipperNacRollingShutterCamera.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 Nac Rolling Shutter 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 ClipperNacRollingShutterCamera...";
  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("$clipper/testData/simulated_clipper_eis_nac_rolling_shutter.cub", "r");
    ClipperNacRollingShutterCamera *cam = (ClipperNacRollingShutterCamera *) 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() << "";
  }
}
+54 −0
Original line number Diff line number Diff line
#include "ClipperNacRollingShutterCamera.h"
#include "Fixtures.h"
#include "TestUtilities.h"

#include <gtest/gtest.h>

using namespace Isis;

TEST_F(ClipperNacRsCube, ClipperNacRsCameraUnitTest) {

  ClipperNacRollingShutterCamera *cam = (ClipperNacRollingShutterCamera *)testCube->camera();

  EXPECT_EQ(cam->CkFrameId(), -159011);
  EXPECT_EQ(cam->CkReferenceId(), -159010);
  EXPECT_EQ(cam->SpkTargetId(), -159);
  EXPECT_EQ(cam->SpkReferenceId(), 1);

  EXPECT_NEAR(cam->FocalLength(), 150.402, 0.0001);

  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->spacecraftNameLong(), "Europa Clipper");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->spacecraftNameShort(), "Clipper");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->instrumentNameLong(), "Europa Imaging System Rolling Shutter Narrow Angle Camera");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->instrumentNameShort(), "EIS-RSNAC");
  EXPECT_PRED_FORMAT2(AssertQStringsEqual, cam->instrumentId(), "EIS-NAC-RS");


  EXPECT_TRUE(cam->SetImage(145, 161));
  EXPECT_NEAR(cam->UniversalLatitude(), 10.248688804675723, 0.0001);
  EXPECT_NEAR(cam->UniversalLongitude(), 256.15486019464515, 0.0001);
  EXPECT_TRUE(cam->SetUniversalGround(cam->UniversalLatitude(), cam->UniversalLongitude()));
  EXPECT_NEAR(cam->Sample(), 145, 0.0001);
  EXPECT_NEAR(cam->Line(), 161, 0.0001);

  EXPECT_TRUE(cam->SetImage(3655, 157));
  EXPECT_NEAR(cam->UniversalLatitude(), 14.250132025597672, 0.0001);
  EXPECT_NEAR(cam->UniversalLongitude(), 258.44639101206752, 0.0001);
  EXPECT_TRUE(cam->SetUniversalGround(cam->UniversalLatitude(), cam->UniversalLongitude()));
  EXPECT_NEAR(cam->Sample(), 3655, 0.0001);
  EXPECT_NEAR(cam->Line(), 157, 0.0001);

  EXPECT_TRUE(cam->SetImage(289, 1767));
  EXPECT_NEAR(cam->UniversalLatitude(), 9.4776705775142567, 0.0001);
  EXPECT_NEAR(cam->UniversalLongitude(), 258.17321108594587, 0.0001);
  EXPECT_TRUE(cam->SetUniversalGround(cam->UniversalLatitude(), cam->UniversalLongitude()));
  EXPECT_NEAR(cam->Sample(), 289, 0.0001);
  EXPECT_NEAR(cam->Line(), 1767, 0.001);

  EXPECT_TRUE(cam->SetImage(3767, 1579));
  EXPECT_NEAR(cam->UniversalLatitude(), 13.641265011679993, 0.0001);
  EXPECT_NEAR(cam->UniversalLongitude(), 260.38986965108342, 0.0001);
  EXPECT_TRUE(cam->SetUniversalGround(cam->UniversalLatitude(), cam->UniversalLongitude()));
  EXPECT_NEAR(cam->Sample(), 3767, 0.0001);
  EXPECT_NEAR(cam->Line(), 1579, 0.001);
 }
+60 −0
Original line number Diff line number Diff line
@@ -1550,4 +1550,64 @@ namespace Isis {
      delete cubeList;
    }
  }

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

    delete testCube;
    testCube = new Cube();

    FileName newCube(tempDir.path() + "/testing.cub");

    testCube->fromIsd(newCube, label, isd, "rw");

    PvlGroup &kernels = testCube->label()->findObject("IsisCube").findGroup("Kernels");
    kernels.findKeyword("NaifFrameCode").setValue("-159011");

    PvlGroup &inst = testCube->label()->findObject("IsisCube").findGroup("Instrument");
    std::istringstream iss(R"(
      Group = Instrument
        SpacecraftName            = Clipper
        InstrumentId              = EIS-NAC-RS
        TargetName                = Europa
        StartTime                 = 2025-01-01T00:00:00.000
        JitterSampleCoefficients = (0.0, 0.0, 0.0)
        JitterLineCoefficients   = (0.0, 0.0, 0.0)
      End_Group
    )");

    PvlGroup newInstGroup;
    iss >> newInstGroup;
    inst = newInstGroup;

    PvlObject &naifKeywords = testCube->label()->findObject("NaifKeywords");
    std::istringstream nk(R"(
      Object = NaifKeywords
        BODY_CODE               = 502
        BODY502_RADII           = (1562.6, 1560.3, 1559.5)
        BODY_FRAME_CODE         = 10024
        INS-159011_FOCAL_LENGTH = 150.40199
        INS-159011_PIXEL_PITCH  = 0.014
        INS-159011_TRANSX       = (0.0, 0.014004651, 0.0)
        INS-159011_TRANSY       = (0.0, 0.0, 0.01399535)
        INS-159011_ITRANSS      = (0.0, 71.404849, 0.0)
        INS-159011_ITRANSL      = (0.0, 0.0, 71.4523)
      End_Object
    )");

    PvlObject newNaifKeywords;
    nk >> newNaifKeywords;
    naifKeywords = newNaifKeywords;

    QString fileName = testCube->fileName();
    delete testCube;
    testCube = new Cube(fileName, "rw");
  }

  void ClipperNacRsCube::TearDown() {
    if (testCube) {
      delete testCube;
    }
  }

}
Loading