Skip to content

Commit

Permalink
Converted skypt to a callable app. Converted existing makefile tests …
Browse files Browse the repository at this point in the history
…to gtest format and removed old makefile tests and data. Addresses DOI-USGS#5443.
  • Loading branch information
Sarah Sutton committed Mar 27, 2024
1 parent ba0fe7f commit 54ff94f
Show file tree
Hide file tree
Showing 9 changed files with 437 additions and 159 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
141 changes: 15 additions & 126 deletions isis/src/base/apps/skypt/main.cpp
Original file line number Diff line number Diff line change
@@ -1,135 +1,24 @@
/** 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();
}

// 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_);
}
Pvl appLog;
skypt(ui, &appLog);
}

152 changes: 152 additions & 0 deletions isis/src/base/apps/skypt/skypt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/** 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 changes: 20 additions & 0 deletions isis/src/base/apps/skypt/skypt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** 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
3 changes: 3 additions & 0 deletions isis/src/base/apps/skypt/skypt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<change name="Kelvin Rodriguez" date="2016-06-27">
Added functionality to compute celestial north clock angle, References #2365.
</change>
<change name="Sarah Sutton" date="2024-03-26">
Converted to a callable app. References #5443.
</change>
</history>

<groups>
Expand Down
4 changes: 0 additions & 4 deletions isis/src/base/apps/skypt/tsts/Makefile

This file was deleted.

9 changes: 0 additions & 9 deletions isis/src/base/apps/skypt/tsts/default/Makefile

This file was deleted.

20 changes: 0 additions & 20 deletions isis/src/base/apps/skypt/tsts/flat/Makefile

This file was deleted.

Loading

0 comments on commit 54ff94f

Please sign in to comment.