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

Added more template elements and callback for file size #4236

Merged
merged 9 commits into from
Jan 5, 2021
36 changes: 18 additions & 18 deletions isis/src/base/apps/topds4/20190612T090019S776_map_L0pan.xml.full
Original file line number Diff line number Diff line change
Expand Up @@ -389,63 +389,63 @@
</Observation_Area>
<File_Area_Observational>
<File>
<file_name>20190612T090019S776_map_L0pan.fits</file_name>
<creation_date_time>2020-01-17T19:16:18.256Z</creation_date_time>
<file_size unit="byte">4443840</file_size>
<file_name>{{imageFileName()}}</file_name>
<creation_date_time>{{currentTime()}}</creation_date_time>
<file_size unit="byte">{{outputFileSize()}}</file_size>
</File>
<Header>
<offset unit="byte">0</offset>
<object_length unit="byte">17280</object_length>
<parsing_standard_id>FITS 3.0</parsing_standard_id>
<object_length unit="byte">{{ int(MainLabel.IsisCube.Core.StartByte.Value) - 2}}</object_length>
<parsing_standard_id>ISIS3</parsing_standard_id>
</Header>
<Array_2D_Image>
<local_identifier>Active Area</local_identifier>
<offset unit="byte">17280</offset>
<offset unit="byte">{{ int(MainLabel.IsisCube.Core.Pixels.Multiplier.Value) - 1}}</offset>
<axes>2</axes>
<axis_index_order>Last Index Fastest</axis_index_order>
<description>OCAMS image 1024 by 1024 pixel active array.</description>
<Element_Array>
<data_type>UnsignedMSB2</data_type>
<unit>DN</unit>
<scaling_factor>1</scaling_factor>
<value_offset>32768</value_offset>
<scaling_factor>{{MainLabel.IsisCube.Core.Pixels.Multiplier.Value}}</scaling_factor>
<value_offset>{{MainLabel.IsisCube.Core.Pixels.Base.Value}}</value_offset>
</Element_Array>
<Axis_Array>
<axis_name>Line</axis_name>
<elements>1024</elements>
<elements>{{MainLabel.IsisCube.Core.Dimensions.Lines.Value}}</elements>
<sequence_number>1</sequence_number>
</Axis_Array>
<Axis_Array>
<axis_name>Sample</axis_name>
<elements>1024</elements>
<elements>{{MainLabel.IsisCube.Core.Dimensions.Samples.Value}}</elements>
<sequence_number>2</sequence_number>
</Axis_Array>
</Array_2D_Image>
<Header>
<offset unit="byte">2116800</offset>
<object_length unit="byte">2880</object_length>
<parsing_standard_id>FITS 3.0</parsing_standard_id>
<offset unit="byte">0</offset>
<object_length unit="byte">TBD</object_length>
<parsing_standard_id>ISIS3</parsing_standard_id>
</Header>
<Array_2D_Image>
<local_identifier>Active Array and Extended Pixel Regions</local_identifier>
<offset unit="byte">2119680</offset>
<offset unit="byte">TBD</offset>
<axes>2</axes>
<axis_index_order>Last Index Fastest</axis_index_order>
<description>OCAMS 1044 sample by 1112 line extended pixel array. The extended pixel array contains the detector overscan and dark pixels.</description>
<Element_Array>
<data_type>UnsignedMSB2</data_type>
<unit>DN</unit>
<scaling_factor>1</scaling_factor>
<value_offset>32768</value_offset>
<scaling_factor>TBD</scaling_factor>
<value_offset>TBD</value_offset>
</Element_Array>
<Axis_Array>
<axis_name>Line</axis_name>
<elements>{{MainLabel.IsisCube.Core.Dimensions.Lines.Value}} </elements>
<elements>TBD</elements>
<sequence_number>1</sequence_number>
</Axis_Array>
<Axis_Array>
<axis_name>Sample</axis_name>
<elements>1112{{MainLabel.IsisCube.Core.Dimensions.Samples.Value}}</elements>
<elements>TBD</elements>
<sequence_number>2</sequence_number>
</Axis_Array>
</Array_2D_Image>
Expand Down
26 changes: 19 additions & 7 deletions isis/src/base/apps/topds4/topds4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <inja/inja.hpp>

#include "md5wrapper.h"
#include "QFile.h"

#include "topds4.h"

Expand All @@ -30,6 +31,9 @@ namespace Isis {
Process p;
p.SetInputCube(icube);

// NEED TO WRITE AND CLOSE THE OUTPUT FILE BEFORE RENDERING SO THE FILE SIZE CALLBACK CAN GET THE FINAL FILE SIZE
QString outputFile = ui.GetFileName("TO");
jessemapel marked this conversation as resolved.
Show resolved Hide resolved

json dataSource;

Pvl &cubeLabel = *icube->label();
Expand All @@ -50,13 +54,8 @@ namespace Isis {
// get the xml label and add it to the template data
}

std::cout << "=============Data================" << std::endl;
std::cout << dataSource.dump(4) << std::endl;
std::cout << "=================================" << std::endl;


Environment env;
// Call back functions
// Template engine call back functions
/**
* Renders to the current UTC time formatted as YYYY-MM-DDTHH:MM:SS
*/
Expand All @@ -76,6 +75,14 @@ namespace Isis {
return (cubeFilename.split(".")[0] + ".img").toStdString();
});

/**
* Renders to the final file size in bytes of the output cube or img
*/
env.add_callback("outputFileSize", 0, [outputFile](Arguments& args) {
FileName cubeFilename = outputFile;
return QFile(outputFile).size();
});

/**
* Renders to the MD5 hash for the input cube
*/
Expand All @@ -85,13 +92,18 @@ namespace Isis {
});

std::string inputTemplate = ui.GetFileName("TEMPLATE").toStdString();

std::string result = env.render_file(inputTemplate, dataSource);

std::ofstream outFile(ui.GetFileName("TO").toStdString());
outFile << result;
outFile.close();

if (ui.WasEntered("DATA")) {
std::ofstream jsonDataFile(FileName(ui.GetFileName("DATA")).expanded().toStdString());
jsonDataFile << dataSource.dump(4);
jsonDataFile.close();
}

std::cout << "============Result===============" << std::endl;
std::cout << result << std::endl;
std::cout << "=================================" << std::endl;
Expand Down
44 changes: 36 additions & 8 deletions isis/src/base/apps/topds4/topds4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@

<application name="topds4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Application/application.xsd">
<brief>
dummy
Convert from ISIS3 cube to PDS 4 format using template XML files
</brief>

<description>
dummy
<p>
Writes a PDS4 compatible label file and image file. The contents of the label file are
generated useing the template file specified by the TEMPLATE parameter.
</p>
<p>
The image file is generated from the input ISIS cube specified by the FROM parameter.
The format of the output image file can be either an ISIS cube or a raw binary file containing
only the image DNs (i.e., no header or trailing data).
</p>
</description>

<category>
<categoryItem>Trim and Mask</categoryItem>
<categoryItem>Import and Export</categoryItem>
</category>

<history>
<change name="Jeffrey Covington" date="2015-01-15">
Removed unreachable code.
<change name="Stuart Sides" date="2021-01-03">
Original version
</change>
</history>

Expand All @@ -28,7 +36,7 @@
Input cube
</brief>
<description>
This is the input cube that will be cropped.
This is the input cube that will be converted to PDS4 format.
</description>
<filter>
*.cub
Expand All @@ -42,7 +50,10 @@
Input template
</brief>
<description>
Input template
The file name of the input template. This file contains "inja" compatible
template syntax inside of a PDS4 XML label. The data used to replace the
template elements comes from the ISIS cube label, the original label
(PDS3, FITS, PDS4), and other input PVL, XML, or JSON files.
</description>
</parameter>

Expand All @@ -53,9 +64,26 @@
Output PDS4 label
</brief>
<description>
The.
The output file name of the PDS4 label. The output image name will be derived from this
parameter by removing the last extension and adding .cub
</description>
</parameter>

<parameter name="DATA">
<type>filename</type>
<internalDefault>None</internalDefault>
<fileMode>output</fileMode>
<brief>
Output JSON data
</brief>
<description>
The output file name to store the template data source. This is a dump of the JSON data used
by the template engine to fill in the template elements. It is a combination of the ISIS
main cube lable, the original lable, and any other data sources supplied. The purpose of this
parameter is for debugging the templates.
</description>
</parameter>

</group>
</groups>
</application>