Skip to content

Commit

Permalink
EIS Import Fixes (DOI-USGS#5630)
Browse files Browse the repository at this point in the history
* Fixed small typo in isisimport.cpp

* Added support for writing clipper line time tables for pushbroom images

* Adjust Clipper EIS plugin name

* Fixed clipper line time import function

* Minor Clipper PB camera adjustments

* Address breaking change

* Capture detector offset in isisimport and the ClipperPushBroomCamera

* Adjusted detector offset

* Reverted detector origin

* Updated Clipper pushbroom camera tests

* Fixed detector center and offset

* Fixes EIS Import Tests

* Fixes ClipperPushBroomTests

* Fix "Failed to open file" failures

---------

Co-authored-by: amystamile-usgs <[email protected]>
  • Loading branch information
acpaquette and amystamile-usgs authored Nov 22, 2024
1 parent 3793da6 commit b224a0f
Show file tree
Hide file tree
Showing 19 changed files with 923 additions and 1,586 deletions.
45 changes: 25 additions & 20 deletions isis/appdata/import/PDS4/ClipperEIS.tpl
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
{% set sub_sensor = Product_Observational.Label_TBD.Observation_Area.Observing_System.Observing_System_Component.0.name %}
{% if sub_sensor == "WAC FC" or sub_sensor == "WAC PB" %}
{% set sensor="WAC" %}
{% else if sub_sensor == "NAC FC" or sub_sensor == "NAC PB" %}
{% set sensor="NAC" %}
{% else %}
{% set sensor="UNK" %}
{% endif %}
{% set sensor = Product_Observational.Observation_Area.Observing_System.Observing_System_Component.1.name %}
{% set sub_sensor = Product_Observational.Observation_Area.Mission_Area.clipper_Observation_Information.clipper_EIS_Parameters.clipper_mode %}

{% set ImageArray = Product_Observational.File_Area_Observational.0.Array_2D_Image %}

{% set ImageArray = Product_Observational.File_Area_Observational.Array_2D_Image %}

Object = IsisCube
Object = Core
Group = Dimensions
Samples = {{ ImageArray.Axis_Array.0.elements }}
Lines = {{ ImageArray.Axis_Array.1.elements }}
Samples = {{ ImageArray.Axis_Array.1.elements }}
Lines = {{ ImageArray.Axis_Array.0.elements }}
Bands = 1
End_Group



Group = Pixels
{% set pixelType = ImageArray.Element_Array.data_type %}
{% if exists("Product_Observational.File_Area_Observational.0.Array_2D_Image.Element_Array.data_type") %}
{% if exists("Product_Observational.File_Area_Observational.Array_2D_Image.Element_Array.data_type") %}
Type = {% if pixelType == "IEEE754LSBDouble" %} Double
{% else if pixelType == "IEEE754LSBSingle" %} Real
{% else if pixelType == "IEEE754MSBDouble" %} Double
Expand Down Expand Up @@ -59,14 +54,14 @@ Object = IsisCube
ByteOrder = Lsb
{% endif %}

Base = {% if exists("Product_Observational.File_Area_Observational.0.Array_2D_Image.Element_Array.value_offset") %}
Base = {% if exists("Product_Observational.File_Area_Observational.Array_2D_Image.Element_Array.value_offset") %}
{{ ImageArray.Element_Array.value_offset }}
{% else if exists("Product_Observational.File_Area_Observational.0.Array_2D_Image.offset._text") %}
{% else if exists("Product_Observational.File_Area_Observational.Array_2D_Image.offset._text") %}
{{ ImageArray.offset._text }}
{% else %}
0
{% endif %}
Multiplier = {% if exists("Product_Observational.File_Area_Observational.0.Array_2D_Image.Element_Array.scaling_factor") %}
Multiplier = {% if exists("Product_Observational.File_Area_Observational.Array_2D_Image.Element_Array.scaling_factor") %}
{{ ImageArray.Element_Array.scaling_factor._text }}
{% else %}
1
Expand All @@ -75,14 +70,19 @@ Object = IsisCube
End_Object

Group = Instrument
SpacecraftName = "{{ Product_Observational.Observation_Area.Investigation_Area.name }}"
InstrumentId = "{{ Product_Observational.Observation_Area.Observing_System.Observing_System_Component.1.name }} {{ Product_Observational.Label_TBD.Observation_Area.Observing_System.Observing_System_Component.0.name }}"
TargetName = {{ at(splitOnChar(Product_Observational.Observation_Area.Target_Identification.name, " "), 1) }}
SpacecraftName = "{{ Product_Observational.Observation_Area.Observing_System.Observing_System_Component.0.name }}"
InstrumentId = "{{ sensor }}-{{ sub_sensor }}"
TargetName = {{ Product_Observational.Observation_Area.Target_Identification.name }}
StartTime = {{ RemoveStartTimeZ(Product_Observational.Observation_Area.Time_Coordinates.start_date_time) }}
ExposureDuration = {{ Product_Observational.Observation_Area.Discipline_Area.img_Exposure.img_exposure_duration._text }}<seconds>
ExposureDuration = {{ Product_Observational.Observation_Area.Discipline_Area.img_Exposure.img_exposure_duration._text }} <{{ Product_Observational.Observation_Area.Discipline_Area.img_Exposure.img_exposure_duration.attrib_unit }}>
DetectorLineOffset = {% if exists("Product_Observational.Observation_Area.Mission_Area.clipper_Observation_Information.clipper_EIS_Parameters.clipper_Detector_Region.clipper_readout_start_row") %}
{{ Product_Observational.Observation_Area.Mission_Area.clipper_Observation_Information.clipper_EIS_Parameters.clipper_Detector_Region.clipper_readout_start_row }}
{% else %}
{{ Product_Observational.Observation_Area.Mission_Area.clipper_Observation_Information.clipper_EIS_Parameters.clipper_Detector_Region.0.clipper_readout_start_row }}
{% endif %}
End_Group

{% set filter=Product_Observational.Label_TBD.Observation_Area.Observing_System.Observing_System_Component.1.name %}
{% set filter=Product_Observational.Observation_Area.Mission_Area.clipper_Observation_Information.clipper_EIS_Parameters.clipper_filter_used %}
Group = BandBin
FilterName = {{ filter }}
Center = {% if filter == "CLEAR" %}
Expand Down Expand Up @@ -154,5 +154,10 @@ Object = IsisCube
End_Object

Object = Translation
{% if sub_sensor == "PUSHBROOM" %}
Object = AncillaryProcess
ProcessFunction = clipperEisPBCreateLineTable
End_Object
{% endif %}
End_Object
End
58 changes: 58 additions & 0 deletions isis/src/base/apps/isisimport/ClipperImportUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef CLIPPER_H
#define CLIPPER_H

#include "iTime.h"
#include "Pvl.h"
#include "PvlGroup.h"
#include "PvlKeyword.h"
#include "Table.h"
#include "TableField.h"
#include "TableRecord.h"

using namespace std;

namespace Isis {

void clipperEisPBCreateLineTable(Cube *cube) {
TableField ephTimeField("EphemerisTime", TableField::Double);
TableField expTimeField("ExposureTime", TableField::Double);
TableField lineStartField("LineStart", TableField::Integer);

TableRecord timesRecord;
timesRecord += ephTimeField;
timesRecord += expTimeField;
timesRecord += lineStartField;

Table timesTable("LineScanTimes", timesRecord);

Pvl *inputCubeLabel = cube->label();

PvlGroup instGroup;
try {
instGroup = inputCubeLabel->findGroup("Instrument", PvlObject::FindOptions::Traverse);
}
catch(IException &e) {
QString msg = "Unable to find instrument group in [" + cube->fileName() + "]";
throw IException(e, IException::User, msg, _FILEINFO_);
}

QString startTime = QString(instGroup.findKeyword("StartTime"));
iTime time(startTime);
PvlKeyword exposureDuration = instGroup.findKeyword("ExposureDuration");
double lineDuration = (double)exposureDuration;
if (exposureDuration.unit() == "ms") {
lineDuration /= 1000;
}
lineDuration /= cube->lineCount();

timesRecord[0] = time.Et();
timesRecord[1] = lineDuration;
timesRecord[2] = 1;
timesTable += timesRecord;

cube->write(timesTable);
}

}

#endif
10 changes: 8 additions & 2 deletions isis/src/base/apps/isisimport/importUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Stretch.h"

#include "CassiniImportUtils.h"
#include "ClipperImportUtils.h"

using namespace std;

Expand All @@ -24,7 +25,8 @@ std::map<std::string, int> processMap = {

std::map<std::string, int> ancillaryProcessMap = {
{"cassiniIssCreateLinePrefixTable", 1},
{"cassiniIssFixLabel", 2}
{"cassiniIssFixLabel", 2},
{"clipperEisPBCreateLineTable", 3}
};

namespace Isis {
Expand All @@ -48,14 +50,18 @@ namespace Isis {
QString processFunction,
PvlObject translation,
ProcessImport *process) {
vector<vector<char *>> prefixData = process->DataPrefix();
vector<vector<char *>> prefixData;
switch (ancillaryProcessMap[processFunction.toStdString()]) {
case 1:
prefixData = process->DataPrefix();
return cassiniIssCreateLinePrefixTable(cube,
prefixData.at(0),
translation);
case 2:
return cassiniIssFixLabel(cube, translation, process);

case 3:
return clipperEisPBCreateLineTable(cube);
}

throw IException(IException::Programmer, "Unable to find prefix/suffix function [" + processFunction.toStdString() + "]", _FILEINFO_);
Expand Down
4 changes: 2 additions & 2 deletions isis/src/base/apps/isisimport/isisimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace Isis {
words.push_back(text.substr(0, pos));
words.push_back(text.substr(pos + 1));
text.erase(0, pos + delimiter.length());
}
}
return words;
});

Expand Down Expand Up @@ -587,7 +587,7 @@ namespace Isis {
importer.EndProcess();

if (translation.hasObject("PostProcess")) {
// Expand for potentially more than one prefix process
// Expand for potentially more than one postfix process
// See AncillaryProcess section above
runProcess(ui.GetCubeName("TO"), translation.findObject("PostProcess"));
}
Expand Down
50 changes: 23 additions & 27 deletions isis/src/base/objs/XmlToJson/XmlToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,24 @@ namespace Isis {
while (!element.isNull()) {
std::string cleanTagName = element.tagName().replace(":", "_").toStdString();
QDomElement next = element.firstChildElement();
if (next.isNull()){
if (next.isNull()) {
json converted = convertLastChildNodeToJson(element);
// Simple case with no repeated tags at the same level
if (!output.contains(cleanTagName)){
output.update(converted);
}
else {
// There is a repeated tag at the same level in the XML, i.e: <a>val1</a><a>val2</a>
// Translated json goal: a:[val1, val2]
// If the converted json has an array already, append, else make it an array
if (!output[cleanTagName].is_array()) {
json repeatedArray;
repeatedArray.push_back(output[element.tagName().toStdString()]);
output[cleanTagName] = repeatedArray;
if (!converted.is_null()) {
// Simple case with no repeated tags at the same level
if (!output.contains(cleanTagName)) {
output[cleanTagName] = converted[cleanTagName];
}
else {
// There is a repeated tag at the same level in the XML, i.e: <a>val1</a><a>val2</a>
// Translated json goal: a:[val1, val2]
// If the converted json has an array already, append, else make it an array
if (!output[cleanTagName].is_array()) {
json repeatedArray = json::array();
repeatedArray.push_back(output[cleanTagName]);
output[cleanTagName] = repeatedArray;
}
output[cleanTagName].push_back(converted[cleanTagName]);
}
output[cleanTagName].push_back(converted[cleanTagName]);
}
}
else {
Expand All @@ -174,33 +176,27 @@ namespace Isis {
// overwriting. This is the following situation:
// XML: <a> <first>value1</first> </a> <a> <second>value2</second></a>
// JSON: a: [ {first:value1, second:value2} ]
json temporaryJson;
convertXmlToJson(next, temporaryJson);

if (output.contains(cleanTagName)) {
// If it's an array already, append, else make it an array
json temporaryJson;
convertXmlToJson(next, temporaryJson);
if (!output[cleanTagName].is_array()) {
json repeatedArray;
repeatedArray.push_back(output[element.tagName().toStdString()]);
json repeatedArray = json::array();
repeatedArray.push_back(output[cleanTagName]);
output[cleanTagName] = repeatedArray;
}
output[cleanTagName].push_back(temporaryJson);
}
else {
if (element.hasAttributes()) {
json tempArea;
QDomNamedNodeMap attrMap = element.attributes();
for (int j=0; j < attrMap.size(); j++) {
QDomAttr attr = attrMap.item(j).toAttr();
tempArea["attrib_"+attr.name().toStdString()] = attr.value().toStdString();
temporaryJson["attrib_"+attr.name().toStdString()] = attr.value().toStdString();
}
tempArea.update(
convertXmlToJson(next, output[cleanTagName]));
output[cleanTagName] = tempArea;
}
else {
output[cleanTagName] =
convertXmlToJson(next, output[cleanTagName]);
}
output[cleanTagName] = temporaryJson;
}
}
element = element.nextSiblingElement();
Expand Down
4 changes: 2 additions & 2 deletions isis/src/clipper/objs/ClipperPushBroomCamera/Camera.plugin
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Group = Clipper/EIS-NAC-PB
Group = Clipper/NAC-PUSHBROOM
Version = 1
Library = ClipperPushBroomCamera
Routine = ClipperPushBroomCameraPlugin
EndGroup

Group = Clipper/EIS-WAC-PB
Group = Clipper/WAC-PUSHBROOM
Version = 1
Library = ClipperPushBroomCamera
Routine = ClipperPushBroomCameraPlugin
Expand Down
Loading

0 comments on commit b224a0f

Please sign in to comment.