Commit 66325293 authored by Stuart Sides's avatar Stuart Sides Committed by Jesse Mapel
Browse files

Allows user control of output bit type in hideal2pds. Added for tjwilson. #2692 #3366 (#3420)

* Allows user control of output bit type. Added for tjwilson

* Updated no global variables, indents
parent 5d4c4632
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@
    <change name="Makayla Shepherd" date="2015-10-06">
      Added stretch parameters. Fixes #1761.
    </change>
    <change name="Tyler Wilson" date="2019-02-08">
      Added an option to control the output bits.  min = 8, max =16, default = 10.  Fixes #5527.
    </change>
  </history>

  <groups>
@@ -220,5 +223,30 @@
          </greaterThanOrEqual>
        </parameter>
      </group>
      <group name="Output Controls">
        <parameter name="BITS">
          <type>integer</type>
          <default>
            <item>10</item>
          </default>
          <brief>
            Number of bits for the output DN
          </brief>
          <description>
            The number of bits to compress the input data to. The valid data as
            well as the five special pixel values (NULL, LIS, LRS, HIS, HRS) will be
            compressed into this number of bits. The output data type will be
            automaticity choosen using this value. A value of 8 will create
            unsigned byte output files. Values from 9 to 16 will create unsigned
            word output files. Unused bits in the unsigned word output file will be
            set to zero.
          </description>
          <minimum inclusive="yes">8</minimum>
          <maximum inclusive="yes">16</maximum>
        </parameter>

      </group>


  </groups>
</application>
+50 −22
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include "LineManager.h"
#include "Longitude.h"
#include "OriginalLabel.h"
#include "PixelType.h"
#include "ProcessExportPds.h"
#include "Pvl.h"
#include "PvlFormat.h"
@@ -29,8 +30,6 @@
using namespace Isis;
using namespace std;

double *g_min, *g_max;

pair<double, double> inputRange(Cube *inputCube);
void updatePdsLabelTimeParametersGroup(Pvl &pdsLabel);
void updatePdsLabelImageObject(PvlObject *isisCubeLab, Pvl &pdsLabel);
@@ -41,6 +40,9 @@ void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();  
  ProcessExportPds p;
  Process pHist;
  double *band_min, *band_max;


  Cube *inputCube = p.SetInputCube("FROM");
  PvlObject *isisCubeLab = inputCube->label();

@@ -68,8 +70,8 @@ void IsisMain() {
    throw IException(IException::Io, msg, _FILEINFO_);
  }
  
  g_min = new double[inputCube->bandCount()];
  g_max = new double[inputCube->bandCount()];
  band_min = new double[inputCube->bandCount()];
  band_max = new double[inputCube->bandCount()];

  for (int band = 1; band <= inputCube->bandCount(); ++band) {

@@ -91,21 +93,21 @@ void IsisMain() {
      }

      // get the requested cumulative percentages
      g_min[band-1] = ui.GetDouble("MINPER") == 0.0 ? hist.Minimum() : hist.Percent(ui.GetDouble("MINPER"));
      g_max[band-1] = ui.GetDouble("MAXPER") == 100.0 ? hist.Maximum() : hist.Percent(ui.GetDouble("MAXPER"));
      band_min[band-1] = ui.GetDouble("MINPER") == 0.0 ? hist.Minimum() : hist.Percent(ui.GetDouble("MINPER"));
      band_max[band-1] = ui.GetDouble("MAXPER") == 100.0 ? hist.Maximum() : hist.Percent(ui.GetDouble("MAXPER"));
    }
    else {
      g_min[band-1] = ui.GetDouble("MIN");
      g_max[band-1] = ui.GetDouble("MAX");
      band_min[band-1] = ui.GetDouble("MIN");
      band_max[band-1] = ui.GetDouble("MAX");
    }
  }

  // Find the minimum min and maximum max for all bands
  double minmin = g_min[0];
  double maxmax = g_max[0];
  double minmin = band_min[0];
  double maxmax = band_max[0];
  for (int band = 1; band < inputCube->bandCount(); ++band) {
    if (g_min[band] < minmin) minmin = g_min[band];
    if (g_max[band] > maxmax) maxmax = g_max[band];
    if (band_min[band] < minmin) minmin = band_min[band];
    if (band_max[band] > maxmax) maxmax = band_max[band];
  }

  pHist.EndProcess();
@@ -114,14 +116,40 @@ void IsisMain() {
  pair<double, double> inRange;
  inRange = inputRange(inputCube);
  p.SetInputRange(minmin, maxmax);
  // output bit type will be 16bit unsigned word

  int nbits = ui.GetInteger("BITS");
  switch (nbits) {
    case 8:
      p.SetOutputType(Isis::UnsignedWord);
  p.SetOutputNull(Isis::NULLU2);         
  p.SetOutputLrs(Isis::LOW_REPR_SATU2);  
  p.SetOutputLis(Isis::LOW_INSTR_SATU2); 
  p.SetOutputHrs(Isis::HIGH_REPR_SATU2); 
  p.SetOutputHis(Isis::HIGH_INSTR_SATU2);
      p.SetOutputRange(VALID_MIN1, VALID_MAX1);
      p.SetOutputNull(NULL1);
      p.SetOutputLis(LOW_INSTR_SAT1);
      p.SetOutputLrs(LOW_REPR_SAT1);
      p.SetOutputHis(HIGH_INSTR_SAT1);
      p.SetOutputHrs(HIGH_REPR_SAT1);
      break;

    case 16:
      p.SetOutputType(UnsignedWord);
      p.SetOutputRange(VALID_MINU2, VALID_MAXU2);
      p.SetOutputNull(NULLU2);
      p.SetOutputLis(LOW_INSTR_SATU2);
      p.SetOutputLrs(LOW_REPR_SATU2);
      p.SetOutputHis(HIGH_INSTR_SATU2);
      p.SetOutputHrs(HIGH_REPR_SATU2);
      break; 

    default:
      p.SetOutputType(UnsignedWord);
      p.SetOutputRange(3.0, pow(2.0, (double)(nbits)) - 1.0 - 2.0);
      p.SetOutputNull(0);
      p.SetOutputLrs(1);
      p.SetOutputLis(2);
      p.SetOutputHis(pow(2.0, (double)(nbits)) - 1.0 - 1.0);
      p.SetOutputHrs(pow(2.0, (double)(nbits)) - 1.0);
  }


  // output byte order will be MSB
  p.SetOutputEndian(Isis::Msb);
  p.setFormat(ProcessExport::BSQ);
@@ -273,8 +301,8 @@ void IsisMain() {
  p.EndProcess();
  outputStream.close();
  
  delete [] g_min;
  delete [] g_max;
  delete [] band_min;
  delete [] band_max;
}

/**
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ include $(ISISROOT)/make/isismake.tsts
commands:
	$(APPNAME) FROM=$(INPUT)/input.cub \
	  to=$(OUTPUT)/output.img \
	  bits=16 \
	  rationale_desc="user entered" \
	  version="2.0" type=automatic \
	  minper=.5 maxper=99.5 > /dev/null;
+54 −0
Original line number Diff line number Diff line
# This tests the following conditions:
#
# -- RationaleDescription value is entered by the user.
# -- Version Number is entered by the user.
# -- ImageJitterCorrected keyword exists in the input cube
# -- The input has been cropped (An AlphaCube group exists)
# -- Center and Length keywords in the BandBin group have no units
#
# To verify the image data, use pds2hideal to reimport to Isis. The reimported 
# cube hideal2pds2hideal.cub should be identical to input.cub
#
# To verify the table data, use table dump on the reimported cube.
#
# To verify the label data, change the lbl extension to pvl.
APPNAME = hideal2pds

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) FROM=$(INPUT)/input.cub \
	  to=$(OUTPUT)/output16.img \
	  bits=16 > /dev/null;	  
	  pds2hideal from=$(OUTPUT)/output16.lbl \
	  to=$(OUTPUT)/hideal2pds2hideal16bit.cub > /dev/null;	
	$(APPNAME) FROM=$(INPUT)/input.cub \
	  to=$(OUTPUT)/output8.img \
	  bits=8 > /dev/null;	  
	  pds2hideal from=$(OUTPUT)/output8.lbl \
	  to=$(OUTPUT)/hideal2pds2hideal8bit.cub > /dev/null;
	$(APPNAME) FROM=$(INPUT)/input.cub \
	  to=$(OUTPUT)/output10.img \
	  bits=10 > /dev/null;	  
	  pds2hideal from=$(OUTPUT)/output10.lbl \
	  to=$(OUTPUT)/hideal2pds2hideal10bit.cub > /dev/null;	    
	$(MV) $(OUTPUT)/output16.lbl $(OUTPUT)/output16.pvl;
	$(MV) $(OUTPUT)/output8.lbl $(OUTPUT)/output8.pvl;
	$(MV) $(OUTPUT)/output10.lbl $(OUTPUT)/output10.pvl;
	$(RM) $(OUTPUT)/output8.img;
	$(RM) $(OUTPUT)/output10.img;
	$(RM) $(OUTPUT)/output16.img;
	$(RM) $(OUTPUT)/output8_INSTRUMENT_POINTING_TABLE.dat;
	$(RM) $(OUTPUT)/output10_INSTRUMENT_POINTING_TABLE.dat;
	$(RM) $(OUTPUT)/output16_INSTRUMENT_POINTING_TABLE.dat;
	$(RM) $(OUTPUT)/output8_INSTRUMENT_POSITION_TABLE.dat;
	$(RM) $(OUTPUT)/output10_INSTRUMENT_POSITION_TABLE.dat;
	$(RM) $(OUTPUT)/output16_INSTRUMENT_POSITION_TABLE.dat;
	$(RM) $(OUTPUT)/output8_BODY_ROTATION_TABLE.dat;
	$(RM) $(OUTPUT)/output10_BODY_ROTATION_TABLE.dat;
	$(RM) $(OUTPUT)/output16_BODY_ROTATION_TABLE.dat;
	$(RM) $(OUTPUT)/output8_SUN_POSITION_TABLE.dat;
	$(RM) $(OUTPUT)/output10_SUN_POSITION_TABLE.dat;
	$(RM) $(OUTPUT)/output16_SUN_POSITION_TABLE.dat;

+7 −7
Original line number Diff line number Diff line
@@ -34,43 +34,43 @@ commands:
	  op=modkey grp=AlphaCube key=BetaLines val=9 > /dev/null;
	echo -e "Error Test A:" > $(OUTPUT)/error_temp.txt;
	$(APPNAME) FROM=$(OUTPUT)/input.cub \
	  to=$(OUTPUT)/output.img 2>> $(OUTPUT)/error_temp.txt > /dev/null;
	  to=$(OUTPUT)/output.img bits=16 2>> $(OUTPUT)/error_temp.txt > /dev/null;
#   TEST B: edit label to simulate using reduce program on number of samples
	editlab from=$(OUTPUT)/input.cub \
	  op=modkey grp=AlphaCube key=BetaSamples val=9 > /dev/null;
	echo -e "\nError Test B:" >> $(OUTPUT)/error_temp.txt;
	$(APPNAME) FROM=$(OUTPUT)/input.cub \
	  to=$(OUTPUT)/output.img 2>> $(OUTPUT)/error_temp.txt > /dev/null;
	  to=$(OUTPUT)/output.img bits=16 2>> $(OUTPUT)/error_temp.txt > /dev/null;
#   TEST C: edit label to simulate using enlarge program on number of lines
	editlab from=$(OUTPUT)/input.cub \
	  op=modkey grp=AlphaCube key=BetaLines val=11 > /dev/null;
	echo -e "\nError Test C:" >> $(OUTPUT)/error_temp.txt;
	$(APPNAME) FROM=$(OUTPUT)/input.cub \
	  to=$(OUTPUT)/output.img 2>> $(OUTPUT)/error_temp.txt > /dev/null;
	  to=$(OUTPUT)/output.img bits=16 2>> $(OUTPUT)/error_temp.txt > /dev/null;
#   TEST D: use edit lab to simulate using enlarge program on number of samples
	editlab from=$(OUTPUT)/input.cub \
	  op=modkey grp=AlphaCube key=BetaSamples val=20001 > /dev/null;
	echo -e "\nError Test D:" >> $(OUTPUT)/error_temp.txt;
	$(APPNAME) FROM=$(OUTPUT)/input.cub \
	  to=$(OUTPUT)/output.img 2>> $(OUTPUT)/error_temp.txt > /dev/null;
	  to=$(OUTPUT)/output.img bits=16 2>> $(OUTPUT)/error_temp.txt > /dev/null;
#   TEST E: target is not mars
	editlab from=$(OUTPUT)/input.cub \
	  op=modkey grp=Instrument key=TargetName val=Invalid > /dev/null;
	echo -e "\nError Test E:" >> $(OUTPUT)/error_temp.txt;
	$(APPNAME) FROM=$(OUTPUT)/input.cub \
	  to=$(OUTPUT)/output.img 2>> $(OUTPUT)/error_temp.txt > /dev/null;
	  to=$(OUTPUT)/output.img bits=16 2>> $(OUTPUT)/error_temp.txt > /dev/null;
#   TEST F: instrument id is not ideal
	editlab from=$(OUTPUT)/input.cub \
	  op=modkey grp=Instrument key=InstrumentId val=HIRISE > /dev/null;
	echo -e "\nError Test F:" >> $(OUTPUT)/error_temp.txt;
	$(APPNAME) FROM=$(OUTPUT)/input.cub \
	  to=$(OUTPUT)/output.img 2>> $(OUTPUT)/error_temp.txt > /dev/null;
	  to=$(OUTPUT)/output.img bits=16 2>> $(OUTPUT)/error_temp.txt > /dev/null;
#   TEST G: Original instrument is not hirise
	editlab from=$(OUTPUT)/input.cub \
	  op=modkey grp=OriginalInstrument key=InstrumentId val=Invalid > /dev/null;
	echo -e "\nError Test G:" >> $(OUTPUT)/error_temp.txt;
	$(APPNAME) FROM=$(OUTPUT)/input.cub \
	  to=$(OUTPUT)/output.img 2>> $(OUTPUT)/error_temp.txt > /dev/null;
	  to=$(OUTPUT)/output.img bits=16 2>> $(OUTPUT)/error_temp.txt > /dev/null;
#   TEST H: 
#   TEST I:

Loading