Commit d1672b59 authored by AustinSanders's avatar AustinSanders Committed by Jesse Mapel
Browse files

Tests + test data for CSM jigsaw (#4530)



* Removed debug couts

* Added csmnetwork test fixture

* Added a test for CSM test network

* Adjusted trig functions + added deg/rad conversions

* Initial CSMNetwork data

* Uncommented code

* Removed network path and control network from CSMNetwork fixture

* Removed temporary path from csv comparison

* Adjusted spacing + responded to PR feedback

Co-authored-by: default avatarAustin Sanders <arsanders@ugs.gov>
parent 0b46300a
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -1857,8 +1857,6 @@ namespace Isis {
                                     BundleMeasure &measure,
                                     BundleControlPoint &point) {

    std::cout << "Computing partials for [" << measure.cubeSerialNumber() << "] in [" << point.id() << "]." << std::endl;

    Camera *measureCamera = measure.camera();
    BundleObservationQsp observation = measure.parentBundleObservation();

@@ -1935,7 +1933,6 @@ namespace Isis {
        coeffTarget *= observationWeight;
      }
    }
    std::cout << std::endl;

    return true;
  }
+43 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#include "FileName.h"

#include "Blob.h"
#include "csminit.h"
#include "Fixtures.h"
#include "Portal.h"
#include "LineManager.h"
@@ -1507,4 +1508,46 @@ namespace Isis {
    }
  }

  void CSMNetwork::SetUp(){
    QString APP_XML = FileName("$ISISROOT/bin/xml/csminit.xml").expanded();
    QVector<QString> fNames = {"/Test_A", "/Test_B",
                               "/Test_C", "/Test_D",
                               "/Test_E", "/Test_F",
                               "/Test_G", "/Test_H",
                               "/Test_I", "/Test_J"
                              };

    cubes.fill(nullptr, 10);

    cubeList = new FileList();
    cubeListFile = tempDir.path() + "/cubes.lis";
    // Create CSMInit-ed cubes
    for (int i = 0; i < cubes.size() ; i++){
      cubes[i] = new Cube();
      cubes[i]->setDimensions(1024,1024,1);
      FileName cubName = FileName(tempDir.path()+fNames[i]+".cub");
      cubes[i]->create(cubName.expanded());
      cubeList->append(cubes[i]->fileName());
      QVector<QString> args = {"from="+cubName.expanded(),
                               "state=data/CSMNetwork/"+fNames[i]+".json",
                               "modelname=TestCsmModel",
                               "pluginname=TestCsmPlugin"
                              };
      UserInterface ui(APP_XML, args);
      csminit(ui);
    }
    cubeList->write(cubeListFile);
  }

  void CSMNetwork::TearDown() {
    for(int i = 0; i < cubes.size(); i++) {
      if(cubes[i] && cubes[i]->isOpen()) {
        delete cubes[i];
      }
    }

    if (cubeList) {
      delete cubeList;
    }
  }
}
+14 −1
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ namespace Isis {
      void TearDown() override;
  };


  class DefaultCube : public TempTestingFiles {
    protected:
      Cube *testCube;
@@ -357,6 +356,20 @@ class VikThmNetwork : public TempTestingFiles {
    void SetUp() override;
    void TearDown() override;
};

class CSMNetwork : public TempTestingFiles {
  protected:

    QVector<FileName> stateStringFiles;
    QVector<FileName> labelFiles;
    QVector<Cube*> cubes;

    FileList *cubeList;
    QString cubeListFile;

    void SetUp() override;
    void TearDown() override;
};
}

#endif
+73 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include "Latitude.h"
#include "Longitude.h"
#include "ControlPoint.h"
#include "CSMCamera.h"

#include "jigsaw.h"

@@ -1591,3 +1592,75 @@ TEST_F(MiniRFNetwork, FunctionalTestJigsawRadar) {
   "0.0,-1.5077677229935,N/A,N/A,22.723572340278,0.0,22.723572340278,N/A,N/A,-169.13683247633,"
   "0.0,-169.13683247633,N/A,N/A", 1);
}


TEST_F(CSMNetwork, FunctionalTestCSMNetwork) {
  QTemporaryDir prefix;
  QString outCnetFileName = prefix.path() + "/outTemp.net";

  // solving for position only, with error propagation
  QVector<QString> args1 = {"fromlist="+cubeListFile,
                            "cnet=data/CSMNetwork/test.net",
                            "onet="+outCnetFileName,
                            "maxits=10",
                            "errorprop=yes",
                            "bundleout_txt=yes",
                            "csmsolveset=adjustable",
                            "POINT_LATITUDE_SIGMA=1125",
                            "POINT_LONGITUDE_SIGMA=1125",
                            "file_prefix="+tempDir.path()+"/"
                         };

  UserInterface options1(APP_XML, args1);
  try {
   jigsaw(options1);

  }
  catch (IException &e) {
   FAIL() << "Failed to bundle: " << e.what() << std::endl;
  }

  CSVReader line = CSVReader(tempDir.path() + "/bundleout_points.csv", false, 0,
                              ',', false, true);

  compareCsvLine(line.getRow(25),
                 "csm_test_019,	FREE,	5,	0, 0,	1.5,	358.5,	1000,	0,	0,	0,"
                 "	950.4447199,	-1195.518876,	0,	999.3147674,	-26.16797812,	26.17694831", 1);
  compareCsvLine(line.getRow(28),
                 "csm_test_022,	FREE,	5,	0,	0,	1.5,	1.5,	1000, 0, 0, 0,"
                 "	288.1013812,	-1391.568893,	0,	999.3147674,"
                 " 26.16797812,	26.17694831", 1);
  compareCsvLine(line.getRow(49),
                 "csm_test_043,	FREE,	5,	0,	0,	-1.5,	358.5,	1000, 0, 0, 0,"
                 "	1392.108941,	-833.2591342,	0,	999.3147674,	-26.16797812,"
                 "	-26.17694831", 1);
  compareCsvLine(line.getRow(52),
                 "csm_test_046,	FREE,	5,	0,	0,	-1.5,	1.5,	1000, 0, 0, 0,	51.85037177,"
                 "	-597.070682,	0,	999.3147674,	26.16797812,	-26.17694831", 1);
  compareCsvLine(line.getRow(11),
                 "csm_test_005,	FREE,	2,	0,	0,	3.5,	0.5,	1000, 0, 0, 0,	684.8038438,"
                 "	233.517266,	0,	998.0967925,	8.71025875,	61.04853953", 1);


  line = CSVReader(tempDir.path() + "/bundleout_images.csv", false, 0, ',', false, true);
  compareCsvLine(line.getRow(3),
                 "Test_B.cub,	6.65E-12,	1.41E-13,	4.70E-12,	2.875,	0.125,	3,	0.004162598,	0,"
                 "	-0.0078125,	0.0078125,	6.29E-15,	0.004162598,	0,	258,	-2,	256,	68.2,	0",
                 1);

  compareCsvLine(line.getRow(5),
                 "Test_D.cub, 3.96E-12,	1.31E-13,	2.80E-12,	-0.125,	0.125,	2.23E-17,"
                 "	0.004162598,	0,	-2.875,	-0.125,	-3,	0.004162598,	0,	254,"
                 "	2,	256,	68.2,	0", 1);
  compareCsvLine(line.getRow(7),
                 "Test_F.cub,	1.55E-13,	8.46E-14,	1.25E-13,	0,	1.39E-17,	1.39E-17,"
                 "	0.004162598,	0,	3.03125,	-0.03125,	3,	0.004162598,	0,"
                 "	272,	-16,	256,	68.2,	0", 1);
  compareCsvLine(line.getRow(9),
                 "Test_H.cub, 6.65E-12,	1.10E-13,	4.70E-12,	-3.03125,	0.03125,"
                 "	-3,	0.004162598,	0,	0,	6.17E-15,"
                 "	6.17E-15,	0.004162598",1);
  compareCsvLine(line.getRow(11),
                 "Test_J.cub, 2.76E-12,	9.95E-14,	1.96E-12,	-0.0625,	0.0625,"
                 "-2.63E-17,	0.016650391, 0,	-0.03125,	0.03125, 6.23E-15,	0.016650391", 1);
}
+84 −99
Original line number Diff line number Diff line
#include "TestCsmModel.h"
#include <math.h>
#include <fstream>
#include <iostream>
#include <string>
@@ -538,8 +539,8 @@ csm::ImageCoord TestCsmModel::groundToImage(const csm::EcefCoord& groundPt, cons
  double scale = getValue(2, adjustments);

  double R = 1000000;
  double lat = asin(groundPt.z/R);
  double lon = acos(groundPt.x/(R*cos(lat)));
  double lat = asin(groundPt.z/R)*(180/M_PI);
  double lon = atan2(groundPt.y, groundPt.x)*(180/M_PI);

  imageCoord.samp = (lon - center_longitude)*scale + getImageSize().samp/2.0;
  imageCoord.line = (lat - center_lat)*scale + getImageSize().line/2.0;
@@ -568,6 +569,8 @@ csm::EcefCoord TestCsmModel::imageToGround(const csm::ImageCoord& imagePt,

  double lon = center_longitude + (imagePt.samp - getImageSize().samp/2.0)/scale;
  double lat = center_lat + (imagePt.line - getImageSize().line/2.0)/scale;
  lon *= M_PI/180;
  lat *= M_PI/180;

  double R = 1000000.0; // TODO: getfromElliposid?
  groundPt.x = R * cos(lat) * cos(lon);
@@ -607,20 +610,7 @@ csm::EcefLocus TestCsmModel::imageToRemoteImagingLocus(
  csm::WarningList* warnings) const {

  // Convert: center lat, lon, radius+altitude to x,y,z and use that for s/c position
  csm::EcefCoord sensorPosition;

  double center_lat = m_param_values[0];
  double center_longitude = m_param_values[1];
  double scale = m_param_values[2];
  
  double lon = center_longitude + (imagePt.samp - getImageSize().samp/2.0)/scale;
  double lat = center_lat + (imagePt.line - getImageSize().line/2.0)/scale;
  
  double altitude = 10000; // TODO: more realistic value?     
  double R = 1000000.0 + altitude; // TODO: getfromElliposid?  // only line different from imageToGround. 
  sensorPosition.x = R * cos(lat) * cos(lon);
  sensorPosition.y = R * cos(lat) * sin(lon);
  sensorPosition.z = R * sin(lat);
  csm::EcefCoord sensorPosition = getSensorPosition(imagePt);

  // Look vector = scale_to_unit_vector(groundPt - sensorPosition)
  csm::EcefCoord groundPt = imageToGround(imagePt);
@@ -671,12 +661,8 @@ csm::EcefCoord TestCsmModel::getSensorPosition(const csm::ImageCoord& imagePt) c
  // Convert: center lat, lon, radius+altitude to x,y,z and use that for s/c position
  csm::EcefCoord sensorPosition;

  double center_lat = m_param_values[0];
  double center_longitude = m_param_values[1];
  double scale = m_param_values[2];
  
  double lon = center_longitude + (imagePt.samp - getImageSize().samp/2.0)/scale;
  double lat = center_lat + (imagePt.line - getImageSize().line/2.0)/scale;
  double lon = m_param_values[1] * M_PI/180;
  double lat = m_param_values[0] * M_PI/180;

  double altitude = 10000; // TODO: more realistic value?
  double R = 1000000.0 + altitude; // TODO: getfromElliposid?  // only line different from imageToGround.
@@ -761,7 +747,6 @@ std::vector<double> TestCsmModel::computeGroundPartials(const csm::EcefCoord& gr
  double dz = nextPoint.z - z;

  double pixelGroundSize = sqrt((dx * dx + dy * dy + dz * dz) / 2.0);

  // If the ground size is too small, try the opposite direction
  if (pixelGroundSize < 1e-10) {
    nextPoint = imageToGround(csm::ImageCoord(ipB.line - 1, ipB.samp - 1));
Loading