## This template is made up of usable macros for PDS4 Velocity Templates.
## This file must be placed in the same directory as the Velocity Templates
## to be used, otherwise the VelocityEngine will not be able to find it.
##
## To include this file in your template and use the macros, add the following
## at the top of your Velocity template:
##
## #parse ( "pds_velocity_macros.txt" )
##
#set ( $DEBUG = 1 )
#################################
## PDS3 to PDS4 Data Type Mapping
##
## This macro will return a PDS4 data type based on a PDS3 data type
## More specifically, this macro provides a mapping from the PDS3 Keywords
## DATA_TYPE, SAMPLE_TYPE, among others, to PDS4 data_type attribute in
## accordance with the number of BITS for the data_type (i.e. SAMPLE_BITS).
## The values in PDS4 are based on PDS SCH 1.4.0.0
## The following mappings are TBD
## "ComplexLSB16",
## "ComplexLSB8",
## "ComplexMSB16",
## "ComplexMSB8",
## "IEEE754LSBDouble",
## "IEEE754LSBSingle",
## "IEEE754MSBDouble",
## "IEEE754MSBSingle",
## "SignedBitString",
## "SignedByte",
## "UnsignedBitString",
## "UnsignedByte",
#set ($PDS3_PDS4_DTYPE_MAP = {
"LSB_SIGNED_INTEGER" : "SignedLSB",
"MSB_SIGNED_INTEGER" : "SignedMSB",
"LSB_UNSIGNED_INTEGER" : "UnsignedLSB",
"MSB_UNSIGNED_INTEGER" : "UnsignedMSB",
"UNSIGNED_INTEGER" : "UnsignedMSB"
})
#macro(getPds4DataType $pds3_dtype $bits)
$PDS3_PDS4_DTYPE_MAP.get($pds3_dtype)$bits##
#end
#################################
#################################
## PDS3 Bit Mask Trimmer
##
## In PDS3, the value for BIT_MASK and SAMPLE_BIT_MASK look like the following:
## SAMPLE_BIT_MASK = 2#0000111111111111#
##
## In PDS4, these values should be just the binary portion "0000111111111111"
##
## This macro extracts the binary portion of the bit mask string. Dependent on the
## the number of bits for the array/sample/object.
##
#macro(trimBitMask $bit_mask)
#set ( $dataType = $label.PDS4_IMAGE.pds4_data_type.toString() )
#if ($bit_mask)
##
#if ( !($dataType.startsWith("IEEE") || $dataType.startsWith("Complex")) )
$bit_mask.replace('2', '').replace('#', '')##
#end
##
#end
#end
#################################
#################################
## Convert PDS3 Bit Mask to PDS4 Sample Bits
##
## In PDS3, the value for BIT_MASK and SAMPLE_BIT_MASK look like the following:
## SAMPLE_BIT_MASK = 2#0000111111111111#
##
## In PDS4, these values should be just the binary portion "0000111111111111"
##
## This macro extracts the binary portion of the bit mask string. Dependent on the
## the number of bits for the array/sample/object.
##
#macro(bitMaskToSampleBits $bit_mask)
#set ( $dataType = $label.PDS4_IMAGE.pds4_data_type.toString() )
#if ($bit_mask)
##
#if ( !($dataType.startsWith("IEEE") || $dataType.startsWith("Complex")) )
#set ( $bit_mask = $bit_mask.replace('2', '').replace('#', '').trim() )
#set ( $bit_mask_chars = $bit_mask.toCharArray() )
#set ( $bit_count = 0 )
#set ( $length = $bit_mask.length() - 1 )
#foreach ( $i in [ 0..$length ] )
#if( $bit_mask_chars[$i] == '1')
#set ( $bit_count = $bit_count + 1 )
#end
#end
#end
$!bit_count##
##
#end
#end
#################################
##################################
## Target vs. Target Type Mapping
##
## These are explicit mappings between target names and target types
## These may need to be applied at a mission-specific level, but for now
## will just leave in here.
##
##
#set ($TARGET_MAP = {
"ALTAIR" : "Star",
"APXSSITE" : "Equipment",
"ARCTURUS" : "Star",
"CALIMG" : "Calibration",
"CALLISTO" : "Satellite",
"DEIMOS" : "Satellite",
"EARTH" : "Planet",
"GANYMEDE" : "Satellite",
"IO" : "Satellite",
"JUPITER" : "Planet",
"LANDER" : "Equipment",
"MAG" : "Equipment",
"MARS" : "Planet",
"MOON" : "Satellite",
"PHOBOS" : "Satellite",
"ROVER" : "Equipment",
"SKY" : "null",
"SPACE" : "Calibration Field",
"SUN" : "Sun",
"VEGA" : "Star",
"WINDSOCK" : "null"
})
#macro(getTargetType $target)
$TARGET_MAP.get($target)##
#end
##################################
##################################
## Science Facets
##
##
#macro(getScienceFacets $target)
#if ($target == "SPACE")
#set ($domain = "Interstellar")
#else
#set ($domain = "Surface")
Visible
$domain
Imaging
#end
#end
##################################
##################################
#macro ( print_string_if_exist $field $default )
#if($field && "$field" != "")
"$field"
#else
"$default"
#end
#end
##################################
##################################
## Set Image Compression Parameters
##
##
#macro(getImageCompressionParameters $compressionType)
#set ($compressionType = $compressionType)
#if ( $compressionType.equals("JPEG") )
#set ($COLOR_MODE_MAP = {
"COLOR_MODE_422" : "4:2:2",
"COLOR_MODE_444" : "4:4:4",
"GRAYSCALE" : "Grayscale"
})
#set ($colorMode = $COLOR_MODE_MAP.get($label.COMPRESSION_PARMS.INST_CMPRS_COLOR_MODE[0]))
#set ($compressionClass = "Lossy")
#elseif ( $compressionType.equals("INTEGER COSINE TRANSFORM") )
#set ($compressionType = $compressionType.replace("INTEGER COSINE TRANSFORM", "ICT"))
#set ($compressionClass = "Lossy")
#end
$!compressionClass
#debug("COMPRESSION_PARMS.INST_CMPRS_NAME")
$compressionType.replace("NONE", "None")
#debug("COMPRESSION_PARMS.INST_CMPRS_RATE")
#checkNA($label.COMPRESSION_PARMS.INST_CMPRS_RATE)
#debug("COMPRESSION_PARMS.INST_CMPRS_RATIO")
#checkNA($label.COMPRESSION_PARMS.INST_CMPRS_RATIO)
#set ($quality = "Null")
#if (! $label.COMPRESSION_PARMS.INST_CMPRS_NAME.toString.equals("NONE") )
#set ($quality = $!label.INST_CMPRS_QUALITY/100)
#end
#if ( ! $quality.equals("Null") )
$quality
#end
$!label.COMPRESSION_PARMS.ERROR_PIXELS
#if ( $compressionType.equals("JPEG") )
#debug("COMPRESSION_PARMS.INST_CMPRS_COLOR_MODE")
$!colorMode
#debug("COMPRESSION_PARMS.INST_CMPRS_QUALITY")
$!label.COMPRESSION_PARMS.INST_CMPRS_QUALITY
#end
#end
##################################
##################################
## Dynamically populate Coordinate_System_Definition class
##
#macro(getCoordinateSystemDefinition $coordSys)
#if ($label.get($coordSys))
#debug($coordSys)
#debug($coordSys.concat(".COORDINATE_SYSTEM_NAME"))
#debug($coordSys.concat(".COORDINATE_SYSTEM_INDEX"))
#getCoordSysId($label.get($coordSys).COORDINATE_SYSTEM_NAME $label.get($coordSys).COORDINATE_SYSTEM_INDEX)
#debug($coordSys.concat(".SOLUTION_ID"))
## SOLUTION_ID is optional
#if ($label.get($coordSys).SOLUTION_ID)
#getCoordSysIdWithSolutionId( $label.get($coordSys).COORDINATE_SYSTEM_NAME $label.get($coordSys).COORDINATE_SYSTEM_INDEX $label.get($coordSys).SOLUTION_ID )
#end
#debug ($coordSys.concat(".POSITIVE_AZIMUTH_DIRECTION"))
$text.capitalize($!label.get($coordSys).POSITIVE_AZIMUTH_DIRECTION[0])
#debug ($coordSys.concat(".POSITIVE_ELEVATION_DIRECTION"))
$text.capitalize($!label.get($coordSys).POSITIVE_ELEVATION_DIRECTION[0])
#debug($coordSys.concat(".COORDINATE_SYSTEM_INDEX"))
#getCoordinateSpacePresent( $coordSys )
#debug ($coordSys.concat(".ORIGIN_OFFSET_VECTOR"))
$!label.get($coordSys).ORIGIN_OFFSET_VECTOR[0]
$!label.get($coordSys).ORIGIN_OFFSET_VECTOR[1]
$!label.get($coordSys).ORIGIN_OFFSET_VECTOR[2]
#debug ($coordSys.concat("ORIGIN_ROTATION_QUATERNION"))
$!label.get($coordSys).ORIGIN_ROTATION_QUATERNION[0]
$!label.get($coordSys).ORIGIN_ROTATION_QUATERNION[1]
$!label.get($coordSys).ORIGIN_ROTATION_QUATERNION[2]
$!label.get($coordSys).ORIGIN_ROTATION_QUATERNION[3]
Forward
#set ( $coordSystemName = $label.get($coordSys).REFERENCE_COORD_SYSTEM_NAME )
#set ( $coordSystemIndex = $label.get($coordSys).REFERENCE_COORD_SYSTEM_INDEX )
#getCoordinateSpaceReference( $coordSystemName $coordSystemIndex "geom" $coordSys )
#end
#end
##################################
##################################
## Dynamically populate Coordinate Space Present class
##
#macro(getCoordinateSpacePresent $coordSystemObjectName)
$label.get(${coordSystemObjectName}).COORDINATE_SYSTEM_NAME
#set($count = $label.get(${coordSystemObjectName}).COORDINATE_SYSTEM_INDEX_NAME.size() - 1)
#foreach ( $i in [ 0..$count ] )
$label.get(${coordSystemObjectName}).COORDINATE_SYSTEM_INDEX_NAME.get($foreach.index)
$label.get(${coordSystemObjectName}).COORDINATE_SYSTEM_INDEX.get($foreach.index)
#end
## SOLUTION_ID is optional
#if ($label.get(${coordSystemObjectName}).SOLUTION_ID)
$label.get(${coordSystemObjectName}).SOLUTION_ID
#end
#end
##################################
##################################
## Dynamically populate Coordinate Space Reference class
##
#macro(getCoordinateSpaceReference $name $index $dictName $labelSection)
#if ( $name.toString().equals("SITE_FRAME") )
<$dictName:Coordinate_Space_Reference>
${name}
SITE
${index}
$dictName:Coordinate_Space_Reference>
#elseif ( $name.toString().equals("LANDER_FRAME") && $mosaic ) ## TODO - Hack for InSight Peer Review. Needs to be removed
<$dictName:Coordinate_Space_Reference>
LANDER_FRAME
SITE
1
DRIVE
0
$dictName:Coordinate_Space_Reference>
#else
<$dictName:Coordinate_Space_Reference>
#getCoordSysId( $name $index )
to_reference_coordinate_space
$dictName:Coordinate_Space_Reference>
#end
#end
##################################
##################################
## Builds the local identifier based on the COORDINATE_SYSTEM_NAME and COORDINATE_SYSTEM_INDEX
##
#macro(getCoordSysId $name $index)
#if ($name && $index)
#set ( $refindex = "" )
#foreach ( $i in $index )
#set ( $refindex = $refindex + $i + "_" )
#end
#set ( $refindexLength = $refindex.length() - 1 )
#set ( $refindex = $refindex.substring(0, $refindexLength) )
##
${name}_${refindex}##
#end
#end
##################################
##################################
## Builds the local identifier based on the COORDINATE_SYSTEM_NAME, COORDINATE_SYSTEM_INDEX,
## and SOLUTION_ID.
##
#macro(getCoordSysIdWithSolutionId $name $index $solnId)
#getCoordSysId( $name $index )_${solnId}##
#end
##################################
##################################
## Transform VICAR units
##
#set ($UNIT_MAP = {
"WATT*M**-2*SR**-1*HZ**-1" : "W*m**-2*sr**-1*Hz**-1",
"WATT*M**-2*SR**-1*NM**-1" : "W*m**-2*sr**-1*nm**-1",
"WATT*M**-2*SR**-1*UM**-1" : "W*m**-2*sr**-1*um**-1",
"WATT*M**-3*SR**-1" : "W*m**-3*sr**-1",
"WATT/M**2/SR/HZ" : "W/m**2/sr/Hz",
"WATT/M**2/SR/NM" : "W/m**2/sr/nm",
"?" : "W/m**2/sr/μm",
"WATT*M**3/SR" : "W/m**3/sr",
"??" : "uW*cm**-2*sr**-1*um**-1",
"???" : "μW/cm**2/sr/μm",
"DEGREES" : "deg",
"PIXELS/DEGREE" : "pixel/deg",
"METER" : "m",
"M" : "m",
"M/PIXEL" : "m/pixel"
})
#macro(transformUnits $unit)
#if ( $UNIT_MAP.containsKey($unit.toString()) )
$UNIT_MAP.get($unit.toString())##
#else
$unit##
#end
#end
##################################
##################################
## Get data correction parameters
##
## not using this yet
##
#macro(getDataCorrectionParameters)
#set ( $shutter_mode = $label.INSTRUMENT_STATE_PARMS.SHUTTER_CORRECTION_MODE.toString().toLowerCase() )
#if ( $shutter_mode )
Shutter Subtraction
$shutter_mode
#end
#set ( $radiometric_correction_type = $label.DERIVED_IMAGE_PARMS.RADIOMETRIC_CORRECTION_TYPE.toString() )
#if ( $radiometric_correction_type )
Radiometric
true
$!label.DERIVED_IMAGE_PARMS.RADIOMETRIC_CORRECTION_TYPE
$label.DERIVED_IMAGE_PARMS.RADIANCE_OFFSET
$label.DERIVED_IMAGE_PARMS.RADIANCE_SCALING_FACTOR
#end
$text.capitalize($label.IDENTIFICATION.GEOMETRY_PROJECTION_TYPE.toString())
#end
##################################
##################################
## Check NA
##
## Simple macro that checks if value is equal to "NULL" string
## or "N/A" and if so, returns default value given as second argument
##
#macro(checkNA $value $default)
#set ($val = $value.toString().toLowerCase())
##
#if (! $default)
#set ($default = "")
#end
#if ( ! $val or $val.equals("null") or $val.equals("n/a") or $val.equals("unk") )
$default##
#else
$value##
#end
#end
##################################
##################################
## defaultDisplaySettings
##
## This function will set the default
## display settings information based
## on the most common cases.
##
##
#macro(defaultDisplaySettings $bands $id )
#set($axes = $label.PDS4_IMAGE.axes[0])
#if ( $axes == 2 )
$id
display_settings_to_array
Sample
Left to Right
Line
Top to Bottom
#elseif ( $axes == 3 )
$id
display_settings_to_array
Sample
Left to Right
Line
Top to Bottom
#set( $derived_img_type = $label.DERIVED_IMAGE_PARMS.DERIVED_IMAGE_TYPE.toString() )
#set ( $img_type = $label.IDENTIFICATION.IMAGE_TYPE.toString() )
#if ( ($derived_img_type && $derived_img_type.equals("IMAGE")) || (!$derived_img_type && ( $img_type.equals("REGULAR") || $img_type.equals("THUMBNAIL") ) ) )
Band
1
2
3
#end
#end
#end
##################################
##################################
## cartMapProjTagOpen
##
## This function will return the opening tag
## for the CART DD's map projection class.
##
#macro(cartMapProjTagOpen $mapProjection)
#end
##################################
##################################
## cartMapProjTagClose
##
## This function will return the closing tag
## for the CART DD's map projection class.
##
#macro(cartMapProjTagClose $mapProjection)
#end
##################################
##################################
## geomModelTypeTagOpen
##
## This function will return the opening tag
## for the GEOM DD's model type class.
##
#macro(geomModelTypeTagOpen $modelType)
#end
##################################
##################################
## geomModelTypeTagClose
##
## This function will return the closing tag
## for the GEOM DD's model type class.
##
#macro(geomModelTypeTagClose $modelType)
#end
##################################
##################################
## debug macro
##
## Using DEBUG variable set at top of this files,
## determine whether or not to output the input
## string as an XML comment
##
##
#macro(debug $var )
#if ( $DEBUG == 1 && $label.get($var) )
#end
#end