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

mimap2isis app and tests conversion #4186

Merged
merged 21 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 19 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
400 changes: 160 additions & 240 deletions isis/notebooks/crop_mimap.ipynb

Large diffs are not rendered by default.

115 changes: 14 additions & 101 deletions isis/src/kaguya/apps/mimap2isis/main.cpp
Original file line number Diff line number Diff line change
@@ -1,114 +1,27 @@
#include "Isis.h"
#include "ProcessImportPds.h"

#include "UserInterface.h"
#include "FileName.h"
#include "mimap2isis.h"

#include <QFile>
#include "Application.h"
#include "Pvl.h"

using namespace std;
using namespace Isis;

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

QString labelFile = ui.GetFileName("FROM");
QString imageFile("");
if(ui.WasEntered("IMAGE")) {
imageFile = ui.GetFileName("IMAGE");
}

// The Kaguya MI MAP files have an incorrect SAMPLE_PROJECTION_OFFSET
// keyword value in their labels. The following code creates a temporary
// detached PDS label with the correct (negated) keyword value.
ptmp.SetPdsFile(labelFile, imageFile, label);
PvlObject obj = label.findObject("IMAGE_MAP_PROJECTION");
double soff = toDouble(obj.findKeyword("SAMPLE_PROJECTION_OFFSET")[0]);
soff = -soff;
label.findObject("IMAGE_MAP_PROJECTION").addKeyword(PvlKeyword("SAMPLE_PROJECTION_OFFSET",toString(soff)),Pvl::Replace);
FileName tempFileName = FileName::createTempFile("TEMPORARYlabel.pvl").name();
QString fn(tempFileName.expanded());
label.write(fn);
p.SetPdsFile(label, labelFile);
QFile::remove(fn);

Cube *ocube = 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"));
Pvl appLog;
try {
mimap2isis(ui, &appLog);
}
if(ui.GetBoolean("SETLRSRANGE")) {
p.SetLRS(ui.GetDouble("LRSMIN"), ui.GetDouble("LRSMAX"));
catch (...) {
for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
Application::Log(*grpIt);
}
throw;
}
if(ui.GetBoolean("SETLISRANGE")) {
p.SetLIS(ui.GetDouble("LISMIN"), ui.GetDouble("LISMAX"));

for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
Application::Log(*grpIt);
}

// Export the cube
p.StartProcess();

// Translate the mapping labels
Pvl otherLabels;
p.TranslatePdsProjection(otherLabels);

// Translate the remaining MI MAP labels
QString transDir = "$ISISROOT/appdata/translations/";

FileName transFile(transDir + "KaguyaMiMapBandBin.trn");
PvlToPvlTranslationManager bandBinXlater(label, transFile.expanded());
bandBinXlater.Auto(otherLabels);

transFile = transDir + "KaguyaMiMapInstrument.trn";
PvlToPvlTranslationManager instXlater(label, transFile.expanded());
instXlater.Auto(otherLabels);

PvlKeyword processId = label.findKeyword("PROCESS_VERSION_ID");

if (processId[0] == "L3C") {
transFile = transDir + "KaguyaMil3cArchive.trn";;
}
else {
transFile = transDir + "KaguyaMiMapArchive.trn";
}
PvlToPvlTranslationManager archiveXlater(label, transFile.expanded());
archiveXlater.Auto(otherLabels);

if(otherLabels.hasGroup("Mapping") &&
(otherLabels.findGroup("Mapping").keywords() > 0)) {
ocube->putGroup(otherLabels.findGroup("Mapping"));
}
if(otherLabels.hasGroup("Instrument") &&
(otherLabels.findGroup("Instrument").keywords() > 0)) {
ocube->putGroup(otherLabels.findGroup("Instrument"));
}
if(otherLabels.hasGroup("BandBin") &&
(otherLabels.findGroup("BandBin").keywords() > 0)) {
ocube->putGroup(otherLabels.findGroup("BandBin"));
}
if(otherLabels.hasGroup("Archive") &&
(otherLabels.findGroup("Archive").keywords() > 0)) {
ocube->putGroup(otherLabels.findGroup("Archive"));
}

// Check for and log any change from the default projection offsets and multipliers
if (p.GetProjectionOffsetChange()) {
PvlGroup results = p.GetProjectionOffsetGroup();
results.setName("Results");
results[0].addComment("Projection offsets and multipliers have been changed from");
results[0].addComment("defaults. New values are below.");
Application::Log(results);
}

p.EndProcess();

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

#include "FileName.h"
#include "ProcessImportPds.h"

#include <QFile>

using namespace std;

namespace Isis {
void mimap2isis(UserInterface &ui, Pvl *log) {
ProcessImportPds p, ptmp;
Pvl label;

QString labelFile = ui.GetFileName("FROM");
QString imageFile("");
if(ui.WasEntered("IMAGE")) {
imageFile = ui.GetFileName("IMAGE");
}

// The Kaguya MI MAP files have an incorrect SAMPLE_PROJECTION_OFFSET
// keyword value in their labels. The following code creates a temporary
// detached PDS label with the correct (negated) keyword value.
ptmp.SetPdsFile(labelFile, imageFile, label);
PvlObject obj = label.findObject("IMAGE_MAP_PROJECTION");
double soff = toDouble(obj.findKeyword("SAMPLE_PROJECTION_OFFSET")[0]);
soff = -soff;
label.findObject("IMAGE_MAP_PROJECTION").addKeyword(PvlKeyword("SAMPLE_PROJECTION_OFFSET",toString(soff)),Pvl::Replace);
FileName tempFileName = FileName::createTempFile("TEMPORARYlabel.pvl").name();
QString fn(tempFileName.expanded());
label.write(fn);
p.SetPdsFile(label, labelFile);
QFile::remove(fn);

Cube *ocube = p.SetOutputCube("TO", ui);

// 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"));
}

// Export the cube
p.StartProcess();

// Translate the mapping labels
Pvl otherLabels;
p.TranslatePdsProjection(otherLabels);

// Translate the remaining MI MAP labels
QString transDir = "$ISISROOT/appdata/translations/";

FileName transFile(transDir + "KaguyaMiMapBandBin.trn");
PvlToPvlTranslationManager bandBinXlater(label, transFile.expanded());
bandBinXlater.Auto(otherLabels);

transFile = transDir + "KaguyaMiMapInstrument.trn";
PvlToPvlTranslationManager instXlater(label, transFile.expanded());
instXlater.Auto(otherLabels);

PvlKeyword processId = label.findKeyword("PROCESS_VERSION_ID");

if (processId[0] == "L3C") {
transFile = transDir + "KaguyaMil3cArchive.trn";;
}
else {
transFile = transDir + "KaguyaMiMapArchive.trn";
}
PvlToPvlTranslationManager archiveXlater(label, transFile.expanded());
archiveXlater.Auto(otherLabels);

if(otherLabels.hasGroup("Mapping") &&
(otherLabels.findGroup("Mapping").keywords() > 0)) {
ocube->putGroup(otherLabels.findGroup("Mapping"));
}
if(otherLabels.hasGroup("Instrument") &&
(otherLabels.findGroup("Instrument").keywords() > 0)) {
ocube->putGroup(otherLabels.findGroup("Instrument"));
}
if(otherLabels.hasGroup("BandBin") &&
(otherLabels.findGroup("BandBin").keywords() > 0)) {
ocube->putGroup(otherLabels.findGroup("BandBin"));
}
if(otherLabels.hasGroup("Archive") &&
(otherLabels.findGroup("Archive").keywords() > 0)) {
ocube->putGroup(otherLabels.findGroup("Archive"));
}

// Check for and log any change from the default projection offsets and multipliers
if (log && p.GetProjectionOffsetChange()) {
PvlGroup results = p.GetProjectionOffsetGroup();
results.setName("Results");
results[0].addComment("Projection offsets and multipliers have been changed from");
results[0].addComment("defaults. New values are below.");
log->addGroup(results);
}

p.EndProcess();

return;
}
}

11 changes: 11 additions & 0 deletions isis/src/kaguya/apps/mimap2isis/mimap2isis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef mimap2isis_h
#define mimap2isis_h

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

namespace Isis{
extern void mimap2isis(UserInterface &ui, Pvl *log=nullptr);
}

#endif
8 changes: 0 additions & 8 deletions isis/src/kaguya/apps/mimap2isis/tsts/L3Cdataset/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions isis/src/kaguya/apps/mimap2isis/tsts/Makefile

This file was deleted.

14 changes: 0 additions & 14 deletions isis/src/kaguya/apps/mimap2isis/tsts/default/Makefile

This file was deleted.

Loading