Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kaguyami App and Test Update #4190

Merged
merged 6 commits into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 54 additions & 172 deletions isis/notebooks/crop_kaguya.ipynb

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions isis/src/kaguya/apps/kaguyami2isis/kaguyami2isis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#include "kaguyami2isis.h"

#include <cstdio>
#include <string>
#include <sstream>
#include <iomanip>
#include <iostream>

#include "ProcessImportPds.h"
#include "ProgramLauncher.h"

#include "UserInterface.h"
#include "FileName.h"
#include "IString.h"

using namespace std;

static double range(double x);

namespace Isis {

void kaguyami2isis(UserInterface &ui) {
ProcessImportPds p;
Pvl label;

FileName inFile = ui.GetFileName("FROM");
QString id;
Pvl lab(inFile.expanded());

if (lab.hasObject("IMAGE_MAP_PROJECTION")) {
QString msg = "Unsupported projected file [" + inFile.expanded() + "]";
throw IException(IException::User, msg, _FILEINFO_);
}

try {
id = (QString) lab.findKeyword("DATA_SET_ID");
}
catch(IException &e) {
QString msg = "Unable to read [DATA_SET_ID] from input file [" +
inFile.expanded() + "]";
throw IException(e, IException::Unknown, msg, _FILEINFO_);
}

p.SetPdsFile(inFile.expanded(), "", label);
CubeAttributeOutput &att = ui.GetOutputAttribute("TO");
Cube *outcube = p.SetOutputCube(ui.GetFileName("TO"), att);

// Get user entered special pixel ranges
if(ui.GetBoolean("SETNULLRANGE")) {
p.SetNull(ui.GetDouble("NULLMIN"), ui.GetDouble("NULLMAX"));
}
if(ui.GetBoolean("SETHRSRANGE")) {
p.SetHRS(ui.GetDouble("HRSMIN"), ui.GetDouble("HRSMAX"));
}
if(ui.GetBoolean("SETHISRANGE")) {
p.SetHIS(ui.GetDouble("HISMIN"), ui.GetDouble("HISMAX"));
}
if(ui.GetBoolean("SETLRSRANGE")) {
p.SetLRS(ui.GetDouble("LRSMIN"), ui.GetDouble("LRSMAX"));
}
if(ui.GetBoolean("SETLISRANGE")) {
p.SetLIS(ui.GetDouble("LISMIN"), ui.GetDouble("LISMAX"));
}

p.SetOrganization(Isis::ProcessImport::BSQ);

p.StartProcess();

// Get the directory where the Kaguya MI translation tables are.
QString transDir = "$ISISROOT/appdata/translations/";
Pvl inputLabel(inFile.expanded());
Pvl *outputLabel = outcube->label();
FileName transFile;

// Translate the Archive group
transFile = transDir + "KaguyaMiArchive.trn";
PvlToPvlTranslationManager archiveXlater(inputLabel, transFile.expanded());
archiveXlater.Auto(*(outputLabel));

// Translate the Instrument group
transFile = transDir + "KaguyaMiInstrument.trn";
PvlToPvlTranslationManager instrumentXlater(inputLabel, transFile.expanded());
instrumentXlater.Auto(*(outputLabel));
//trim trailing z's from the time strings
PvlGroup &instGroup(outputLabel->findGroup("Instrument",Pvl::Traverse));
QString timeString;
//StartTime
PvlKeyword &startTimeKeyword=instGroup["StartTime"];
timeString = startTimeKeyword[0];
startTimeKeyword.setValue( timeString.mid(0,timeString.lastIndexOf("Z")) );
//StartTimeRaw
PvlKeyword &startTimeRawKeyword=instGroup["StartTimeRaw"];
timeString = startTimeRawKeyword[0];
startTimeRawKeyword.setValue( timeString.mid(0,timeString.lastIndexOf("Z")) );
//StopTime
PvlKeyword &stopTimeKeyword=instGroup["StopTime"];
timeString = stopTimeKeyword[0];
stopTimeKeyword.setValue( timeString.mid(0,timeString.lastIndexOf("Z")) );
//StopTimeRaw
PvlKeyword &stopTimeRawKeyword=instGroup["StopTimeRaw"];
timeString = stopTimeRawKeyword[0];
stopTimeRawKeyword.setValue( timeString.mid(0,timeString.lastIndexOf("Z")) );


// Translate the BandBin group
transFile = transDir + "KaguyaMiBandBin.trn";
PvlToPvlTranslationManager bandBinXlater(inputLabel, transFile.expanded());
bandBinXlater.Auto(*(outputLabel));

//Set up the Kernels group
PvlGroup kern("Kernels");
QString baseBand = lab.findKeyword("BASE_BAND")[0];
if (lab.findKeyword("INSTRUMENT_ID")[0] == "MI-VIS") {
if (baseBand.contains("MV")) {
kern += PvlKeyword("NaifFrameCode", toString(-13133) + baseBand[2]);
}
kern += PvlKeyword("NaifCkCode", toString(-131330));
}
else if (lab.findKeyword("INSTRUMENT_ID")[0] == "MI-NIR") {
if (baseBand.contains("MN")) {
kern += PvlKeyword("NaifFrameCode", toString(-13134) + baseBand[2]);
}
kern += PvlKeyword("NaifCkCode", toString(-131340));
}
acpaquette marked this conversation as resolved.
Show resolved Hide resolved

//At the time of this writing there was no expectation that Kaguya ever did any binning
// so this is check to make sure an error is thrown if an image was binned
if (lab.findKeyword("INSTRUMENT_ID")[0] == "MI-VIS" && outcube->sampleCount() != 962 ) {
QString msg = "Input file [" + inFile.expanded() + "]" + " appears to be binned. Binning was "
"unexpected, and is unsupported by the camera model";
throw IException(IException::Unknown, msg, _FILEINFO_);
}
if (lab.findKeyword("INSTRUMENT_ID")[0] == "MI-NIR" && outcube->sampleCount() != 320 ) {
QString msg = "Input file [" + inFile.expanded() + "]" + " appears to be binned. Binning was "
"unexpected, and is unsupported by the camera model";
throw IException(IException::Unknown, msg, _FILEINFO_);
}

outcube->putGroup(kern);

p.EndProcess();
}

double range(double x) {
double a,b,c;
b = x / 360;
if(b > 0) {
c = floor(b);
}
else {
c = ceil(b);
}
a = 360 * (b - c);
if(a < 0) {
a = a + 360;
}
return a;
}
}
10 changes: 10 additions & 0 deletions isis/src/kaguya/apps/kaguyami2isis/kaguyami2isis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef kaguyami2isis_h
#define kaguyami2isis_h

#include "UserInterface.h"

namespace Isis {
extern void kaguyami2isis(UserInterface &ui);
}

#endif
171 changes: 4 additions & 167 deletions isis/src/kaguya/apps/kaguyami2isis/main.cpp
Original file line number Diff line number Diff line change
@@ -1,177 +1,14 @@
#include "Isis.h"

#include <cstdio>
#include <string>
#include <sstream>
#include <iomanip>
#include <iostream>
#include "kaguyami2isis.h"

#include "ProcessImportPds.h"
#include "ProgramLauncher.h"

#include "UserInterface.h"
#include "FileName.h"
#include "IString.h"

double range(double x);
#include "Application.h"
#include "Pvl.h"

using namespace std;
using namespace Isis;

void IsisMain() {
ProcessImportPds p;
Pvl label;
UserInterface &ui = Application::GetUserInterface();

FileName inFile = ui.GetFileName("FROM");
QString id;
Pvl lab(inFile.expanded());

if (lab.hasObject("IMAGE_MAP_PROJECTION")) {
QString msg = "Unsupported projected file [" + inFile.expanded() + "]";
throw IException(IException::User, msg, _FILEINFO_);
}

try {
id = (QString) lab.findKeyword("DATA_SET_ID");
}
catch(IException &e) {
QString msg = "Unable to read [DATA_SET_ID] from input file [" +
inFile.expanded() + "]";
throw IException(e, IException::Unknown, msg, _FILEINFO_);
}

p.SetPdsFile(inFile.expanded(), "", label);
Cube *outcube = p.SetOutputCube("TO");

// Get user entered special pixel ranges
if(ui.GetBoolean("SETNULLRANGE")) {
p.SetNull(ui.GetDouble("NULLMIN"), ui.GetDouble("NULLMAX"));
}
if(ui.GetBoolean("SETHRSRANGE")) {
p.SetHRS(ui.GetDouble("HRSMIN"), ui.GetDouble("HRSMAX"));
}
if(ui.GetBoolean("SETHISRANGE")) {
p.SetHIS(ui.GetDouble("HISMIN"), ui.GetDouble("HISMAX"));
}
if(ui.GetBoolean("SETLRSRANGE")) {
p.SetLRS(ui.GetDouble("LRSMIN"), ui.GetDouble("LRSMAX"));
}
if(ui.GetBoolean("SETLISRANGE")) {
p.SetLIS(ui.GetDouble("LISMIN"), ui.GetDouble("LISMAX"));
}

p.SetOrganization(Isis::ProcessImport::BSQ);

p.StartProcess();

// Get the directory where the Kaguya MI translation tables are.
QString transDir = "$ISISROOT/appdata/translations/";
Pvl inputLabel(inFile.expanded());
Pvl *outputLabel = outcube->label();
FileName transFile;

// Translate the Archive group
transFile = transDir + "KaguyaMiArchive.trn";
PvlToPvlTranslationManager archiveXlater(inputLabel, transFile.expanded());
archiveXlater.Auto(*(outputLabel));

// Translate the Instrument group
transFile = transDir + "KaguyaMiInstrument.trn";
PvlToPvlTranslationManager instrumentXlater(inputLabel, transFile.expanded());
instrumentXlater.Auto(*(outputLabel));
//trim trailing z's from the time strings
PvlGroup &instGroup(outputLabel->findGroup("Instrument",Pvl::Traverse));
QString timeString;
//StartTime
PvlKeyword &startTimeKeyword=instGroup["StartTime"];
timeString = startTimeKeyword[0];
startTimeKeyword.setValue( timeString.mid(0,timeString.lastIndexOf("Z")) );
//StartTimeRaw
PvlKeyword &startTimeRawKeyword=instGroup["StartTimeRaw"];
timeString = startTimeRawKeyword[0];
startTimeRawKeyword.setValue( timeString.mid(0,timeString.lastIndexOf("Z")) );
//StopTime
PvlKeyword &stopTimeKeyword=instGroup["StopTime"];
timeString = stopTimeKeyword[0];
stopTimeKeyword.setValue( timeString.mid(0,timeString.lastIndexOf("Z")) );
//StopTimeRaw
PvlKeyword &stopTimeRawKeyword=instGroup["StopTimeRaw"];
timeString = stopTimeRawKeyword[0];
stopTimeRawKeyword.setValue( timeString.mid(0,timeString.lastIndexOf("Z")) );


// Translate the BandBin group
transFile = transDir + "KaguyaMiBandBin.trn";
PvlToPvlTranslationManager bandBinXlater(inputLabel, transFile.expanded());
bandBinXlater.Auto(*(outputLabel));

//Set up the Kernels group
PvlGroup kern("Kernels");
if (lab.findKeyword("INSTRUMENT_ID")[0] == "MI-VIS") {
if (lab.findKeyword("BASE_BAND")[0] == "MV1") {
kern += PvlKeyword("NaifFrameCode", toString(-131331));
}
else if (lab.findKeyword("BASE_BAND")[0] == "MV2") {
kern += PvlKeyword("NaifFrameCode", toString(-131332));
}
else if (lab.findKeyword("BASE_BAND")[0] == "MV3") {
kern += PvlKeyword("NaifFrameCode", toString(-131333));
}
else if (lab.findKeyword("BASE_BAND")[0] == "MV4") {
kern += PvlKeyword("NaifFrameCode", toString(-131334));
}
else if (lab.findKeyword("BASE_BAND")[0] == "MV5") {
kern += PvlKeyword("NaifFrameCode", toString(-131335));
}
kern += PvlKeyword("NaifCkCode", toString(-131330));
}
else if (lab.findKeyword("INSTRUMENT_ID")[0] == "MI-NIR") {
if (lab.findKeyword("BASE_BAND")[0] == "MN1") {
kern += PvlKeyword("NaifFrameCode", toString(-131341));
}
else if (lab.findKeyword("BASE_BAND")[0] == "MN2") {
kern += PvlKeyword("NaifFrameCode", toString(-131342));
}
else if (lab.findKeyword("BASE_BAND")[0] == "MN3") {
kern += PvlKeyword("NaifFrameCode", toString(-131343));
}
else if (lab.findKeyword("BASE_BAND")[0] == "MN4") {
kern += PvlKeyword("NaifFrameCode", toString(-131344));
}
kern += PvlKeyword("NaifCkCode", toString(-131340));
}

//At the time of this writing there was no expectation that Kaguya ever did any binning
// so this is check to make sure an error is thrown if an image was binned
if (lab.findKeyword("INSTRUMENT_ID")[0] == "MI-VIS" && outcube->sampleCount() != 962 ) {
QString msg = "Input file [" + inFile.expanded() + "]" + " appears to be binned. Binning was "
"unexpected, and is unsupported by the camera model";
throw IException(IException::Unknown, msg, _FILEINFO_);
}
if (lab.findKeyword("INSTRUMENT_ID")[0] == "MI-NIR" && outcube->sampleCount() != 320 ) {
QString msg = "Input file [" + inFile.expanded() + "]" + " appears to be binned. Binning was "
"unexpected, and is unsupported by the camera model";
throw IException(IException::Unknown, msg, _FILEINFO_);
}

outcube->putGroup(kern);

p.EndProcess();
}

double range(double x) {
double a,b,c;
b = x / 360;
if(b > 0) {
c = floor(b);
}
else {
c = ceil(b);
}
a = 360 * (b - c);
if(a < 0) {
a = a + 360;
}
return a;
kaguyami2isis(ui);
}
4 changes: 0 additions & 4 deletions isis/src/kaguya/apps/kaguyami2isis/tsts/Makefile

This file was deleted.

12 changes: 0 additions & 12 deletions isis/src/kaguya/apps/kaguyami2isis/tsts/default/Makefile

This file was deleted.

18 changes: 0 additions & 18 deletions isis/src/kaguya/apps/kaguyami2isis/tsts/level2b2/Makefile

This file was deleted.

Loading