Skip to content

Commit

Permalink
Adds archive information to chandrayaan2 template (DOI-USGS#5651)
Browse files Browse the repository at this point in the history
* Adds chandrayaan2 to isisimport

* Adds archive info to chandrayaan2

* fixes to template

* removed debugging from tests

* remove xmltojson changes

* small fixes
  • Loading branch information
amystamile-usgs authored Oct 31, 2024
1 parent fee86a1 commit cda23d6
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 18 deletions.
33 changes: 31 additions & 2 deletions isis/appdata/import/PDS4/Chandrayaan2TMC2.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set file_name = Product_Observational.File_Area_Observational.File.file_name %}
{% set sensor = FindCH2Sensor(file_name) %}
{% set sensor = CharAt(file_name, 10) %}

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

Expand Down Expand Up @@ -67,15 +67,44 @@ Object = IsisCube
End_Object

Group = Instrument
SpacecraftName = {{ Product_Observational.Observation_Area.Investigation_Area.name }}
SpacecraftName = {{ capitalize(Product_Observational.Observation_Area.Investigation_Area.name) }}
{% set inst_name = Product_Observational.Observation_Area.Observing_System.Observing_System_Component.1.name %}
{% if inst_name == "terrain mapping camera" %}
InstrumentId = TMC-2
{% endif %}
TargetName = {{ Product_Observational.Observation_Area.Target_Identification.name }}
StartTime = {{ RemoveStartTimeZ(Product_Observational.Observation_Area.Time_Coordinates.start_date_time) }}
StopTime = {{ RemoveStartTimeZ(Product_Observational.Observation_Area.Time_Coordinates.stop_date_time) }}
{% if exists("Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_line_exposure_duration") %}
LineExposureDuration = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_line_exposure_duration._text }} <ms>
{% else %}
LineExposureDuration = 3.236 <ms>
{% endif %}
End_Group

{% if exists("Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters") %}
Group = Archive
JobId = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_job_id }}
OrbitNumber = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_imaging_orbit_number }}
GainType = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_gain }}
ExposureType = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_exposure }}
DetectorPixelWidth = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_detector_pixel_width._text }} <micrometers>
FocalLength = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_focal_length._text }} <mm>
ReferenceData = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_reference_data_used }}
OrbitLimbDirection = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_orbit_limb_direction }}
SpacecraftYawDirection = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_spacecraft_yaw_direction }}
SpacecraftAltitude = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_spacecraft_altitude._text }} <km>
PixelResolution = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_pixel_resolution._text }} <meters/pixel>
Roll = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_roll._text }} <degrees>
Pitch = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_pitch._text }} <degrees>
Yaw = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_yaw._text }} <degrees>
SunAzimuth = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_sun_azimuth._text }} <degrees>
SunElevation = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_sun_elevation._text }} <degrees>
SolarIncidence = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_solar_incidence._text }} <degrees>
Projection = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_projection }}
Area = {{ Product_Observational.Observation_Area.Mission_Area.isda_Product_Parameters.isda_area }}
End_Group
{% endif %}

Group = BandBin
Center = 675
Expand Down
2 changes: 1 addition & 1 deletion isis/appdata/import/fileTemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{%- if InstrumentId == "OSINAC" or InstrumentId == "OSIWAC"-%}
{%- set InstrumentId="Osiris" -%}
{%- endif -%}
{%- else if SpacecraftName == "Chandrayaan-2"-%}
{%- else if SpacecraftName == "Chandrayaan-2" or SpacecraftName == "chandrayaan-2"-%}
{%- set SpacecraftId="Chandrayaan2" -%}
{%- if InstrumentId == "terrain mapping camera"-%}
{%- set InstrumentId="TMC2" -%}
Expand Down
12 changes: 0 additions & 12 deletions isis/src/base/apps/isisimport/isisimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,6 @@ namespace Isis {

return inputString.substr(index, 1);
});


/**
* Find sensor type from Chandrayaan2 label's file_name
*/
env.add_callback("FindCH2Sensor", 1, [](Arguments& args) {
std::string fileName = args.at(0)->get<string>();

char sensor = fileName[10];

return std::string(1, sensor);
});
// end of inja callbacks


Expand Down
3 changes: 1 addition & 2 deletions isis/src/base/objs/XmlToJson/XmlToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,4 @@ namespace Isis {
}
return output;
}
}

}
170 changes: 169 additions & 1 deletion isis/tests/FunctionalTestsIsisImportChandrayaan2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using json = nlohmann::json;

static QString APP_XML = FileName("$ISISROOT/bin/xml/isisimport.xml").expanded();

TEST_F(TempTestingFiles, FunctionalTestIsisImportChandrayaan2){
TEST_F(TempTestingFiles, FunctionalTestIsisImportChandrayaan2MinimalLabel){
std::istringstream PvlInput(R"(
Object = IsisCube
Object = Core
Expand Down Expand Up @@ -57,6 +57,7 @@ TEST_F(TempTestingFiles, FunctionalTestIsisImportChandrayaan2){
TargetName = Moon
StartTime = 2019-11-28T00:35:38.9755
StopTime = 2019-11-28T00:45:17.9161
LineExposureDuration = 3.236 <ms>
End_Group
Group = BandBin
Expand Down Expand Up @@ -172,4 +173,171 @@ TEST_F(TempTestingFiles, FunctionalTestIsisImportChandrayaan2){
outGroup = outLabel->findGroup("Kernels", Pvl::Traverse);
EXPECT_PRED_FORMAT2(AssertPvlGroupEqual, outGroup, truthGroup);

}

TEST_F(TempTestingFiles, FunctionalTestIsisImportChandrayaan2FullLabel){
std::istringstream PvlInput(R"(
Object = IsisCube
Object = Core
StartByte = 65537
Format = Tile
TileSamples = 519
TileLines = 1000
Group = Dimensions
Samples = 180093
Lines = 4000
Bands = 1
End_Group
Group = Pixels
Type = UnsignedWord
ByteOrder = Lsb
Base = 0.0
Multiplier = 1.0
End_Group
End_Object
Group = Instrument
SpacecraftName = Chandrayaan-2
InstrumentId = TMC-2
TargetName = Moon
StartTime = 2024-08-08T05:32:59.6974
StopTime = 2024-08-08T05:42:42.4783
LineExposureDuration = 3.236 <ms>
End_Group
Group = Archive
JobId = TMCXXD18CHO2210300NNNN24221055326097_V2_1
OrbitNumber = 22103
GainType = g1
ExposureType = e1
DetectorPixelWidth = 7 <micrometers>
FocalLength = 140 <mm>
ReferenceData = SELENE
OrbitLimbDirection = Descending
SpacecraftYawDirection = False
SpacecraftAltitude = 89.53 <km>
PixelResolution = 4.48 <meters/pixel>
Roll = 0.009365 <degrees>
Pitch = 0.066417 <degrees>
Yaw = -0.017284 <degrees>
SunAzimuth = 116.737463 <degrees>
SunElevation = 39.932493 <degrees>
SolarIncidence = 50.067507 <degrees>
Projection = Selenographic
Area = Equatorial
End_Group
Group = BandBin
Center = 675
Width = 175
End_Group
Group = Kernels
NaifFrameCode = -152210
End_Group
End_Object
Object = Label
Bytes = 65536
End_Object
Object = OriginalXmlLabel
Name = IsisCube
StartByte = 1440809537
Bytes = 7625
ByteOrder = Lsb
End_Object
End
)");
QString dataFilePath= "data/isisimport/chan2/ch2_tmc_ncn_20240808T0532596974_d_img_d18.xml";
QString dataFileName = "ch2_tmc_ncn_20240808T0532596974_d_img_d18.xml";
QString imageFileName = "ch2_tmc_ncn_20240808T0532596974_d_img_d18.img";
QString cubeFileName = tempDir.path() + "/output.cub";

int samples = 4000;
int lines = 180093;
int bytes = 2;

// create a temp img file and write data to it
QFile tempImgFile(tempDir.path() + "/" + imageFileName);

if(!tempImgFile.open(QFile::WriteOnly | QFile::Text)){
FAIL() << " Could not open file for writing";
}
QDataStream out(&tempImgFile);

// generate lines
QByteArray writeToFile = QByteArray();
short int fill = 0;
for(int i=-1; i<(samples * bytes); i++){
writeToFile.append(fill);
}

// write the lines to the temp file
for(int i=0; i<lines; i++){
QDataStream out(&tempImgFile);
out << writeToFile;
}
tempImgFile.flush();
tempImgFile.close();

// create a temp data file and copy the contents of the xml in to it
QFile tempDataFile(tempDir.path() + "/" + dataFileName);

if(!tempDataFile.open(QFile::ReadWrite | QFile::Text)){
FAIL() << " Could not open file for writing";
}

// open xml to get data
QFile realXmlFile(dataFilePath);
if (!realXmlFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
FAIL() << "Failed to open file";
}

QTextStream xmlData(&tempDataFile);
xmlData << realXmlFile.readAll();

tempDataFile.close();
realXmlFile.close();

QFileInfo fileInfo(tempDataFile);

// testing with template
QVector<QString> args = {"from=" + fileInfo.absoluteFilePath(), "to=" + cubeFileName};
UserInterface options(APP_XML, args);
isisimport(options);

Pvl truthLabel;
PvlInput >> truthLabel;

Cube outCube(cubeFileName);
Pvl *outLabel = outCube.label();

PvlGroup truthGroup = truthLabel.findGroup("Dimensions", Pvl::Traverse);
PvlGroup &outGroup = outLabel->findGroup("Dimensions", Pvl::Traverse);
EXPECT_PRED_FORMAT2(AssertPvlGroupEqual, outGroup, truthGroup);

truthGroup = truthLabel.findGroup("Pixels", Pvl::Traverse);
outGroup = outLabel->findGroup("Pixels", Pvl::Traverse);
EXPECT_PRED_FORMAT2(AssertPvlGroupEqual, outGroup, truthGroup);

truthGroup = truthLabel.findGroup("Instrument", Pvl::Traverse);
outGroup = outLabel->findGroup("Instrument", Pvl::Traverse);
EXPECT_PRED_FORMAT2(AssertPvlGroupEqual, outGroup, truthGroup);

truthGroup = truthLabel.findGroup("BandBin", Pvl::Traverse);
outGroup = outLabel->findGroup("BandBin", Pvl::Traverse);
EXPECT_PRED_FORMAT2(AssertPvlGroupEqual, outGroup, truthGroup);

truthGroup = truthLabel.findGroup("Kernels", Pvl::Traverse);
outGroup = outLabel->findGroup("Kernels", Pvl::Traverse);
EXPECT_PRED_FORMAT2(AssertPvlGroupEqual, outGroup, truthGroup);

truthGroup = truthLabel.findGroup("Archive", Pvl::Traverse);
outGroup = outLabel->findGroup("Archive", Pvl::Traverse);
EXPECT_PRED_FORMAT2(AssertPvlGroupEqual, outGroup, truthGroup);

}
1 change: 1 addition & 0 deletions isis/tests/XmlToJsonTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,4 @@ TEST(XmlToJson, TestXMLWithNamespace) {
}



Loading

0 comments on commit cda23d6

Please sign in to comment.