Skip to content

Commit

Permalink
PDS4 - Fix template search and targetGroup template variable for tgoc…
Browse files Browse the repository at this point in the history
…assis.tpl (#4494)

* fix template search and targetGroup template variable for tgocassis.tpl

* remove accidental extra tag

* address feedback from amy
  • Loading branch information
tgiroux committed May 27, 2021
1 parent 38a20b3 commit 5af40f1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 36 deletions.
60 changes: 35 additions & 25 deletions isis/appdata/export/TGOCaSSIS.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
<?xml-model href="http://pds.nasa.gov/pds4/disp/v1/PDS4_DISP_1B00.sch" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<?xml-model href="http://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1B00.sch" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<Product_Observational xmlns:psa="http://psa.esa.int/psa/v1" xmlns:cas="http://psa.esa.int/psa/em16/cas/v1" xmlns:img="http://pds.nasa.gov/pds4/img/v1" xmlns="http://pds.nasa.gov/pds4/pds/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pds.nasa.gov/pds4/pds/v1 http://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1B00.xsd http://pds.nasa.gov/pds4/disp/v1 http://pds.nasa.gov/pds4/disp/v1/PDS4_DISP_1B00.xsd http://pds.nasa.gov/pds4/img/v1 http://pds.nasa.gov/pds4/img/v1/PDS4_IMG_1A10_1510.xsd http://pds.nasa.gov/pds4/cart/v1 http://pds.nasa.gov/pds4/cart/v1/PDS4_CART_1900.xsd http://psa.esa.int/psa/v1 http://psa.esa.int/psa/v1/PDS4_PSA_1000.xsd http://psa.esa.int/psa/em16/cas/v1 http://psa.esa.int/psa/em16/cas/v1/PDS4_PSA_EM16_CAS_1000.xsd http://pds.nasa.gov/pds4/geom/v1 http://pds.nasa.gov/pds4/geom/v1/PDS4_GEOM_1B00_1610.xsd" xmlns:disp="http://pds.nasa.gov/pds4/disp/v1" xmlns:cart="http://pds.nasa.gov/pds4/cart/v1" xmlns:geom="http://pds.nasa.gov/pds4/geom/v1">
{% if exists("MainLabel.IsisCube.Mosaic") -%}
{% set productId = MainLabel.IsisCube.Mosaic.ObservationId -%}
{% else if exists("MainLabel.IsisCube.Archive") -%}
{% set productId = MainLabel.IsisCube.Archive.ObservationId -%}
{% if exists("MainLabel.IsisCube.Mosaic.ObservationId.Value") -%}
{% set productId = MainLabel.IsisCube.Mosaic.ObservationId.Value -%}
{% set sProductId = "MainLabel.IsisCube.Mosaic.ObservationId.Value" -%}
{% else if exists("MainLabel.IsisCube.Archive.ObservationId.Value") -%}
{% set productId = MainLabel.IsisCube.Archive.ObservationId.Value -%}
{% set sProductId = "MainLabel.IsisCube.Archive.ObservationId.Value" -%}
{% else -%}
{% set sProductId = "None" -%}
{% endif -%}
<CaSSIS_Header>
<IDENTIFICATION_DATA/>
Expand All @@ -35,29 +39,33 @@
</DERIVED_HEADER_DATA>
</CaSSIS_Header>
<Identification_Area>
<logical_identifier>urn:esa:psa:em16_tgo_cas:
{% if exists("MainLabel.IsisCube.Instrument") -%}
{% set targetGroup = MainLabel.IsisCube.Instrument -%}
{% if exists("MainLabel.IsisCube.Mapping") -%}
data_projected:
{% else -%}
data_raw:
{% endif -%}
{% else if exists("MainLabel.IsisCube.Mosaic") -%}
{% set targetGroup = MainLabel.IsisCube.Mosaic -%}
data_derived:
{% else -%}
TBD:
{% endif -%}
{{lower("productId")}}
<logical_identifier>urn:esa:psa:em16_tgo_cas:{% if exists("MainLabel.IsisCube.Instrument") -%}
{% set targetGroup = MainLabel.IsisCube.Instrument -%}
{% set sTargetGroup = "MainLabel.IsisCube.Instrument" -%}
{% if exists("MainLabel.IsisCube.Mapping") -%}
data_projected:
{% else -%}
data_raw:
{% endif -%}
{% else if exists("MainLabel.IsisCube.Mosaic") -%}
{% set targetGroup = MainLabel.IsisCube.Mosaic -%}
{% set sTargetGroup = "MainLabel.IsisCube.Mosaic" -%}
data_derived:
{% else -%}
{% set sTargetGroup = "None" -%}
TBD:
{% endif -%}
{% if exists(sProductId) -%}{{lower(productId)-}}{% endif -%}

</logical_identifier>
<version_id>1.0</version_id>
<title>PDS4 product exported from ISIS3 cube.</title>
<information_model_version>1.8.0.0</information_model_version>
<product_class>Product_Observational</product_class>
<Alias_List>
<Alias>
<alternate_id>{{productId}}</alternate_id>
<alternate_id>{% if exists(sProductId) -%}{{productId}}{% endif -%}
</logical_identifier></alternate_id>
<comment>CaSSIS Internal Identifier</comment>
</Alias>
</Alias_List>
Expand All @@ -73,16 +81,16 @@
<Observation_Area>
<Time_Coordinates>
<start_date_time>{{targetGroup.StartTime.Value}}Z</start_date_time>
{% if exists("targetGroup.StopTime") %}
{% if exists(sTargetGroup + ".StopTime") %}
<stop_date_time>{{targetGroup.StopTime.Value}}Z</stop_date_time>
{% else %}
<stop_date_time>{{targetGroup.StartTime.Value}}Z</stop_date_time>
{% endif %}
{% if exists("targetGroup.LocalTime") %}
{% if exists(sTargetGroup + ".LocalTime") %}
<local_true_solar_time>{{targetGroup.LocalTime.Value}}</local_true_solar_time>
{% endif %}
{% if exists("targetGroup.SolarLongitude") %}
<solar_longitude unit="{{targetGroup.SolarLongitude.Units}}">{{targetGroup.SolarLongitude.Value}}</solar_longitude>
{% if exists(sTargetGroup + ".SolarLongitude") %}
<solar_longitude unit="deg">{{targetGroup.SolarLongitude.Value}}</solar_longitude>
{% endif %}
</Time_Coordinates>
<Investigation_Area>
Expand All @@ -109,6 +117,7 @@
<name>{{targetGroup.TargetName.Value}}</name>
<type>Planet</type>
</Target_Identification>
{# TODO - seems like none of these values are consistently included in the Archive group. May require coordination with isisimport
{% if exists("MainLabel.IsisCube.Archive") -%}
<Mission_Area>
<psa:Mission_Information>
Expand Down Expand Up @@ -154,6 +163,7 @@
</cas:CASSIS_Data>
</Mission_Area>
{% endif -%}
#}
<Discipline_Area>
<disp:Display_Settings>
<Local_Internal_Reference>
Expand Down Expand Up @@ -234,7 +244,7 @@
<File>
<file_name>{{MainLabel.IsisCube.Archive.FileName.Value}}.img</file_name>
</File>
<Array_3D_Image> {# TODO - This can be 2D if there are no Bands -#}
<Array_3D_Image> {# TODO - Can this be 2D if there are no Bands ?? #}
<local_identifier>Array_3D_Image</local_identifier>
<offset unit="byte">0</offset>
<axes>3</axes>
Expand Down
17 changes: 17 additions & 0 deletions isis/appdata/export/pvl2template.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% if exists("MainLabel.IsisCube.Instrument.InstrumentId.Value") -%}
{% set InstrumentId=MainLabel.IsisCube.Instrument.InstrumentId.Value -%}
{% endif -%}

{% if exists("MainLabel.IsisCube.Instrument.SpacecraftName.Value") -%}
{% set SpacecraftName=MainLabel.IsisCube.Instrument.SpacecraftName.Value -%}
{% else if exists("MainLabel.IsisCube.Mosaic.SpacecraftName.Value") -%}
{% set SpacecraftName=MainLabel.IsisCube.Mosaic.SpacecraftName.Value -%}
{% endif -%}

{% if SpacecraftName == "TRACE GAS ORBITER" -%}
{% set SpacecraftId="TGO" -%}
{% else -%}
{% set SpacecraftId=SpacecraftName -%}
{% endif -%}

{% if SpacecraftId -%}$ISISROOT/appdata/export/{{- SpacecraftId -}}{{- InstrumentId -}}.tpl{% endif -%}
17 changes: 6 additions & 11 deletions isis/src/base/apps/isisexport/isisexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace Isis {

// Name for output image
FileName outputFileName(outputFile);
FileName genDefaultTemplate = ("$ISISROOT/appdata/export/pvl2template.tpl");
QString path(outputFileName.originalPath());
QString name(outputFileName.baseName());
QString outputCubePath = path + "/" + name + ".cub";
Expand All @@ -56,6 +57,8 @@ namespace Isis {

json dataSource;

Environment env;

Pvl &cubeLabel = *icube->label();

// Add the input cube PVL label to template engine data
Expand All @@ -68,16 +71,9 @@ namespace Isis {
templateFn = ui.GetFileName("TEMPLATE");
}
else {
if(cubeLabel.hasGroup("Instrument")) {
PvlGroup &inst = cubeLabel.findGroup("Instrument", Pvl::Traverse);
templateFn = FileName( "$ISISROOT/appdata/export/" +
inst["SpacecraftId"][0] +
inst["InstrumentId"][0] + ".tpl" );
}
else {
QString msg = "Cannot locate a template because Input Cube label has no Instrument group. Provide a template file to use.";
throw IException(IException::User, msg, _FILEINFO_);
}
std::string templateFnStd = env.render_file(genDefaultTemplate.expanded().toStdString(), dataSource);
templateFn = FileName(QString::fromStdString(templateFnStd));

}

if(!templateFn.fileExists()) {
Expand Down Expand Up @@ -177,7 +173,6 @@ namespace Isis {
}
}

Environment env;
env.set_trim_blocks(true);
env.set_lstrip_blocks(true);

Expand Down

0 comments on commit 5af40f1

Please sign in to comment.