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

Updated kaguyasp2ascii to support newer (detached) data #5568

Merged
merged 3 commits into from
Jul 31, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ release.
## [Unreleased]

### Changed
- Modified kaguyasp2isis to work with new (detached) data [#5436](https://github.com/DOI-USGS/ISIS3/issues/5436)
- Added jigsaw error message for csminit'd images without csm parameters[#5486](https://github.com/DOI-USGS/ISIS3/issues/5486)
- Changed `qwt` dependency version to 6.2.0 or below [#5498](https://github.com/DOI-USGS/ISIS3/issues/5498)
- Pinned `suitesparse` dependency version to maximum not including 7.7.0 [#5496](https://github.com/DOI-USGS/ISIS3/issues/5496)
Expand Down
4 changes: 2 additions & 2 deletions isis/src/kaguya/apps/kaguyasp2ascii/kaguyasp2ascii.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
Input Kaguya SP file
</brief>
<description>
This is the input Kaguya SP file
This is the input Kaguya SP file. For an attached label, use the .spc file, or for a detached label, use the .lbl file.
</description>
<filter>
*.spc
*.lbl *.spc
</filter>
</parameter>
<parameter name="TO">
Expand Down
37 changes: 25 additions & 12 deletions isis/src/kaguya/apps/kaguyasp2ascii/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ void IsisMain() {
ProcessImportPds p;
UserInterface &ui = Application::GetUserInterface();

FileName inFile = ui.GetFileName("FROM");
Pvl lab(inFile.expanded());
QString inFile = ui.GetFileName("FROM");
Pvl lab(inFile);
QString dataFile = lab.findKeyword("FILE_NAME")[0];

// Detached labels use format keyword = "dataFile" value <unit>
int keywordIndex = 1;

if (FileName(inFile).baseName() == FileName(dataFile).baseName()){
// data files usually do not include path information. If input basename matches datafile basename, include path information
// this allows users to specify data that is not in the current directory.
dataFile = inFile;
// Attached labels use format keyword = value <units>
keywordIndex = 0;
}

ofstream os;
QString outFile = FileName(ui.GetFileName("TO")).expanded();
Expand Down Expand Up @@ -59,32 +71,32 @@ void IsisMain() {
int qaptr = 0;

if (lab.hasKeyword("^SP_SPECTRUM_WAV")) {
wavptr = toInt(lab.findKeyword("^SP_SPECTRUM_WAV")[0]) - 1;
wavptr = toInt(lab.findKeyword("^SP_SPECTRUM_WAV")[keywordIndex]) - 1;
}
if (lab.hasKeyword("^SP_SPECTRUM_RAW")) {
rawptr = toInt(lab.findKeyword("^SP_SPECTRUM_RAW")[0]) - 1;
rawptr = toInt(lab.findKeyword("^SP_SPECTRUM_RAW")[keywordIndex]) - 1;
}
if (lab.hasKeyword("^SP_SPECTRUM_RAD")) {
radptr = toInt(lab.findKeyword("^SP_SPECTRUM_RAD")[0]) - 1;
radptr = toInt(lab.findKeyword("^SP_SPECTRUM_RAD")[keywordIndex]) - 1;
}
//older-format file without calibrated NIR2 data
if (lab.hasKeyword("^SP_SPECTRUM_REF")) {
refptr1 = toInt(lab.findKeyword("^SP_SPECTRUM_REF")[0]) - 1;
refptr1 = toInt(lab.findKeyword("^SP_SPECTRUM_REF")[keywordIndex]) - 1;
}
//newer-format file with calibrated NIR2 data and 2 different Reflectances
if (lab.hasKeyword("^SP_SPECTRUM_REF1")) {
refptr1 = toInt(lab.findKeyword("^SP_SPECTRUM_REF1")[0]) - 1;
refptr1 = toInt(lab.findKeyword("^SP_SPECTRUM_REF1")[keywordIndex]) - 1;
}
if (lab.hasKeyword("^SP_SPECTRUM_REF2")) {
refptr2 = toInt(lab.findKeyword("^SP_SPECTRUM_REF2")[0]) - 1;
refptr2 = toInt(lab.findKeyword("^SP_SPECTRUM_REF2")[keywordIndex]) - 1;
}
if (lab.hasKeyword("^SP_SPECTRUM_QA")) {
qaptr = toInt(lab.findKeyword("^SP_SPECTRUM_QA")[0]) - 1;
qaptr = toInt(lab.findKeyword("^SP_SPECTRUM_QA")[keywordIndex]) - 1;
}

FILE *spcptr;
if ((spcptr = fopen(inFile.expanded().toLatin1().data(),"rb")) == 0) {
QString msg = "Error opening input Kaguya SP file [" + inFile.expanded() + "]";
if ((spcptr = fopen(dataFile.toLatin1().data(),"rb")) == 0) {
QString msg = "Error opening input Kaguya SP file [" + dataFile + "]";
throw IException(IException::User, msg, _FILEINFO_);
}

Expand All @@ -101,7 +113,7 @@ void IsisMain() {
if (!lab.hasObject("SP_SPECTRUM_WAV") || !lab.hasObject("SP_SPECTRUM_QA") ||
!lab.hasObject("SP_SPECTRUM_RAD") || !(lab.hasObject("SP_SPECTRUM_REF") ||
(lab.hasObject("SP_SPECTRUM_REF1") && lab.hasObject("SP_SPECTRUM_REF2")))) {
QString msg = "Input file [" + inFile.expanded() + "] is not a valid ";
QString msg = "Input file [" + inFile + "] is not a valid ";
msg += "Kaguya Spectral Profiler file";
throw IException(IException::User, msg, _FILEINFO_);
}
Expand Down Expand Up @@ -261,6 +273,7 @@ void IsisMain() {

PvlObject refobj;
PvlObject refobj2;

if (lab.hasKeyword("^SP_SPECTRUM_REF")) {
refobj = lab.findObject("SP_SPECTRUM_REF");
}
Expand Down