Unverified Commit 1663b190 authored by Sarah Sutton's avatar Sarah Sutton Committed by GitHub
Browse files

Converted skypt to a callable app. Converted existing Makefile tests to...


Converted skypt to a callable app. Converted existing Makefile tests to gtests. Removed existing Makefile tests.  (#5444)

* Converted skypt to a callable app. Converted existing makefile tests to gtest format and removed old makefile tests and data. Addresses #5443.

* Updated contributor list to add Sarah S. Sutton. Addresses #5443.

---------

Co-authored-by: default avatarSarah Sutton <ssutton@dhcp-10-142-214-177.uawifi.arizona.edu>
parent 95bc4100
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -437,6 +437,10 @@
    {
      "name": "Sucharski, Tracie"
    },
    {
      "affiliation": "University of Arizona, Lunar and Planetary Laboratory",
      "name": "Sutton, Sarah S."
    },
    {
      "name": "Takir, Driss"
    },
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ release.

### Changed
- Changed the default spiceinit url to https://astrogeology.usgs.gov/apis/ale/v0.9.1/spiceserver/ and added deprecation warning for use of https://services.isis.astrogeology.usgs.gov/cgi-bin/spiceinit.cgi url. [#5327](https://github.com/USGS-Astrogeology/ISIS3/issues/5327)
- Skypt has been refactored to be callable; old Makefile tests have been removed and replaced by gtests. Issue: [#5443](https://github.com/USGS-Astrogeology/ISIS3/issues/5443)


### Fixed
+15 −126
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 "Isis.h"

#include "Brick.h"
#include "Camera.h"
#include "CSMCamera.h"
#include "IException.h"
#include "iTime.h"
#include "UserInterface.h"
#include "Application.h"
#include "skypt.h"

using namespace std;
using namespace Isis;


void IsisMain() {
  // Get user interface
  UserInterface &ui = Application::GetUserInterface();

  // Get input cube and get camera model for it
  QString channel = ui.GetCubeName("FROM");
  Cube cube;
  cube.open(channel);
  Camera *cam = cube.camera();

  // Get the type of conversion that we are doing
  QString type = ui.GetString("TYPE");
  double samp, line;

  // Do conversion from samp/line to ra/dec
  if (type == "IMAGE") {
    // Get users sample & line values and do a setImage for the camera
    samp = ui.GetDouble("SAMPLE");
    line = ui.GetDouble("LINE");
    cam->SetImage(samp, line);
  }
  // Do conversion from ra/dec to samp/line
  else {
    double ra = ui.GetDouble("RA");
    double dec = ui.GetDouble("DEC");
    if (!cam->SetRightAscensionDeclination(ra, dec)) {
      QString msg = "Invalid Ra/Dec coordinate";
      throw IException(IException::User, msg, _FILEINFO_);
    }
    samp = cam->Sample();
    line = cam->Line();
  Pvl appLog;
  skypt(ui, &appLog);
}
  // Create Brick on samp, line to get the dn value of the pixel
  Brick b(3, 3, 1, cube.pixelType());
  int intSamp = (int)(samp + 0.5);
  int intLine = (int)(line + 0.5);
  b.SetBasePosition(intSamp, intLine, 1);
  cube.read(b);
  
  double rot;
  if (cube.hasBlob("CSMState", "String")) {
    rot = ((CSMCamera*)cam)->CelestialNorthClockAngle();
  } else {
    rot = cam->CelestialNorthClockAngle();
  }

  // Create group with sky position
  PvlGroup sp("SkyPoint");
  {
    sp += PvlKeyword("Filename", FileName(channel).expanded());
    sp += PvlKeyword("Sample", toString(cam->Sample()));
    sp += PvlKeyword("Line", toString(cam->Line()));
    sp += PvlKeyword("RightAscension", toString(cam->RightAscension()));
    sp += PvlKeyword("Declination", toString(cam->Declination()));
    sp += PvlKeyword("EphemerisTime", toString(cam->time().Et()));
    sp += PvlKeyword("PixelValue", PixelToString(b[0]));
    sp += PvlKeyword("CelestialNorthClockAngle", toString(rot), "degrees");
  }

  //Write the group to the screen
  Application::Log(sp);

  // Write an output label file if necessary
  if (ui.WasEntered("TO")) {
    // Get user params from ui
    QString outFile = FileName(ui.GetFileName("TO")).expanded();
    bool exists = FileName(outFile).fileExists();
    bool append = ui.GetBoolean("APPEND");

    // Write the pvl group out to the file
    if (ui.GetString("FORMAT") == "PVL") {
      Pvl temp;
      temp.setTerminator("");
      temp.addGroup(sp);
      if (append) {
        temp.append(ui.GetAsString("TO"));
      }
      else {
        temp.write(ui.GetAsString("TO"));
      }
    }
    // Create a flatfile of the same data
    // The flatfile is comma delimited and can be imported into Excel
    else {
      ofstream os;
      bool writeHeader = false;
      if (append) {
        os.open(outFile.toLatin1().data(), ios::app);
        if (!exists) {
          writeHeader = true;
        }
      }
      else {
        os.open(outFile.toLatin1().data(), ios::out);
        writeHeader = true;
      }

      if (writeHeader) {
        for(int i = 0; i < sp.keywords(); i++) {
          os << sp[i].name();

          if (i < sp.keywords() - 1) {
            os << ",";
          }
        }
        os << endl;
      }

      for(int i = 0; i < sp.keywords(); i++) {
        os << (QString)sp[i];

        if (i < sp.keywords() - 1) {
          os << ",";
        }
      }
      os << endl;
    }
  }
  else if (ui.GetString("FORMAT") == "FLAT") {
    QString msg = "Flat file must have a name.";
    throw IException(IException::User, msg, _FILEINFO_);
  }
}
+152 −0
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 "skypt.h"

#include <string>
#include <iomanip>

#include "Brick.h"
#include "Camera.h"
#include "IException.h"
#include "iTime.h"
#include "PvlGroup.h"

using namespace std;
using namespace Isis;

namespace Isis{

  void skypt(UserInterface &ui, Pvl *log) {
    Cube *cube = new Cube(ui.GetCubeName("FROM"));
    skypt(cube, ui, log);
  }

  void skypt(Cube *cube, UserInterface &ui, Pvl *log){
    // Get camera model for the input cube.
    QString channel = ui.GetCubeName("FROM");
    Camera *cam = cube->camera();

    // Get the type of conversion that we are doing
    QString type = ui.GetString("TYPE");
    double samp, line;

    // Do conversion from samp/line to ra/dec
    if (type == "IMAGE") {
      // Get users sample & line values and do a setImage for the camera
      samp = ui.GetDouble("SAMPLE");
      line = ui.GetDouble("LINE");
      cam->SetImage(samp, line);
    }
  
    // Do conversion from ra/dec to samp/line
    else {
      double ra = ui.GetDouble("RA");
      double dec = ui.GetDouble("DEC");
      if (!cam->SetRightAscensionDeclination(ra, dec)) {
        QString msg = "Invalid Ra/Dec coordinate";
        throw IException(IException::User, msg, _FILEINFO_);
      }
      samp = cam->Sample();
      line = cam->Line();
    }

    // Create Brick on samp, line to get the dn value of the pixel
    Brick b(3, 3, 1, cube->pixelType());
    int intSamp = (int)(samp + 0.5);
    int intLine = (int)(line + 0.5);
    b.SetBasePosition(intSamp, intLine, 1);
    cube->read(b);

    double rot = cam->CelestialNorthClockAngle();

    // Create group with sky position
    PvlGroup sp("SkyPoint");
     {
        sp += PvlKeyword("Filename", FileName(channel).expanded());
        sp += PvlKeyword("Sample", toString(cam->Sample()));
        sp += PvlKeyword("Line", toString(cam->Line()));
        sp += PvlKeyword("RightAscension", toString(cam->RightAscension()));
        sp += PvlKeyword("Declination", toString(cam->Declination()));
        sp += PvlKeyword("EphemerisTime", toString(cam->time().Et()));
        sp += PvlKeyword("PixelValue", PixelToString(b[0]));
        sp += PvlKeyword("CelestialNorthClockAngle", toString(rot), "degrees");
     }

    //Write the group to the screen
    log->addLogGroup(sp);

    // Write an output label file if necessary
    if (ui.WasEntered("TO")) {
      // Get user params from ui
      QString outFile = FileName(ui.GetFileName("TO")).expanded();
      bool exists = FileName(outFile).fileExists();
      bool append = ui.GetBoolean("APPEND");

      // Write the pvl group out to the file
      if (ui.GetString("FORMAT") == "PVL") {
        Pvl temp;
        temp.setTerminator("");
        temp.addGroup(sp);
        if (append) {
          temp.append(ui.GetAsString("TO"));
        }
        else {
          temp.write(ui.GetAsString("TO"));
        }
      }
  
      // Create a flatfile of the same data
      // The flatfile is comma delimited and can be imported into Excel
      else {
        ofstream os;
        bool writeHeader = false;
        if (append) {
          os.open(outFile.toLatin1().data(), ios::app);
          if (!exists) {
            writeHeader = true;
          }
        }
        else {
          os.open(outFile.toLatin1().data(), ios::out);
          writeHeader = true;
        }

        if (writeHeader) {
          for(int i = 0; i < sp.keywords(); i++) {
            os << sp[i].name();
            if (i < sp.keywords() - 1) {
              os << ",";
            }
          }
          os << endl;
        }

        for(int i = 0; i < sp.keywords(); i++) {
          os << (QString)sp[i];
          if (i < sp.keywords() - 1) {
            os << ",";
          }
        }
        os << endl;
      }
    }
    else if (ui.GetString("FORMAT") == "FLAT") {
      QString msg = "Flat file must have a name.";
      throw IException(IException::User, msg, _FILEINFO_);
    }
  }

}






+20 −0
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 */

#ifndef skypt_h
#define skypt_h

#include "Pvl.h"
#include "UserInterface.h"

namespace Isis{
  extern void skypt(UserInterface &ui, Pvl *log);
  extern void skypt(Cube *cube, UserInterface &ui, Pvl *log);
}

#endif
Loading