Commit 5c200a0b authored by Kristin Berry's avatar Kristin Berry
Browse files

Removed the APPLYSMEAR and PSF options from the amicacal application. The...

Removed the APPLYSMEAR and PSF options from the amicacal application. The smear correction is still automatically applied when appropriate. Fixes #4609

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7575 41f8697f-d340-4b68-9986-7bafba869bb8
parent 143c65c5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ static void loadNaifTiming() {
 * @description Computes the distance from the Sun to the observed body.
 * This method requires the appropriate NAIK kernels to be loaded that
 * provides instrument time support, leap seconds and planet body ephemeris.
 *  
 * @return @b double Distance in AU between Sun and observed body.
 */
static bool sunDistanceAU(const QString &scStartTime,
+86 −127
Original line number Diff line number Diff line
@@ -41,8 +41,8 @@ FileName DetermineFlatFieldFile(const QString &filter, const bool nullPolarPix);
void Calibrate(vector<Buffer *>& in, vector<Buffer *>& out);

QString loadCalibrationVariables(const QString &config);
void psfCorrection(vector<Buffer *>& in, vector<Buffer *>& out);
void psfCorrectionBoxcar(Buffer &in, double &result);
//void psfCorrection(vector<Buffer *>& in, vector<Buffer *>& out);
//void psfCorrectionBoxcar(Buffer &in, double &result);

// Temporary cube file pointer deleter
struct TemporaryCubeDeleter {
@@ -83,7 +83,6 @@ static double g_temp(0);
static double g_darkCurrent(0);

//Smear calculation variables
static bool g_smear(false);
static double g_Tvct(0);       //!< Vertical charge-transfer period (in seconds).
static double g_texp(1);       //!< Exposure time.
static double g_timeRatio(1.0);
@@ -117,16 +116,14 @@ static double g_v_standard(3.42E-3);//!< Base conversion for all filters (Tbl. 9
static QVector<Pixel> hotPixelVector;  //!< A pixel vector that contains the Hot Pixel locations

// PSF variables 
static bool g_applyPSF(false);
static int ns,nl,nb;     //!< Number of samples, lines, bands of the input cube
static int g_size(23);   //!< The size of the Boxcar used for calculating the light diffusion model.


static const int g_N = 6;
static double g_alpha(0.0);
static double * g_psfFilter;
static double g_sigma[g_N];
static double g_A[g_N];
//static bool g_applyPSF(false);
//static int ns,nl,nb;     //!< Number of samples, lines, bands of the input cube
//static int g_size(23);   //!< The size of the Boxcar used for calculating the light diffusion model.
//static const int g_N = 6;
//static double g_alpha(0.0);
//static double * g_psfFilter;
//static double g_sigma[g_N];
//static double g_A[g_N];


void IsisMain() {
@@ -144,8 +141,7 @@ void IsisMain() {
  ProcessBySample p;

  Cube *icube = p.SetInputCube("FROM");  
  g_smear = ui.GetBoolean("APPLYSMEAR");
  g_applyPSF = ui.GetBoolean("APPLYPSF");
//  g_applyPSF = ui.GetBoolean("APPLYPSF");


  // Basic assurances...
@@ -175,12 +171,9 @@ void IsisMain() {
  alpha=&myAlpha;

  try {

    g_texp = inst["ExposureDuration"] ; 

  }
  catch(IException &e) {

    QString msg = "Unable to read [ExposureDuration] keyword in the Instrument group "
                  "from input file [" + icube->fileName() + "]";
    throw IException(e, IException::Io,msg, _FILEINFO_);
@@ -188,12 +181,9 @@ void IsisMain() {


  try {

    g_temp = inst["CcdTemperature"] ;

  }
  catch(IException &e) {

    QString msg = "Unable to read [CcdTemperature] keyword in the Instrument group "
                  "from input file [" + icube->fileName() + "]";
    throw IException(e, IException::Io,msg, _FILEINFO_);
@@ -227,16 +217,13 @@ void IsisMain() {

  QString reducedFlat(flatfile.expanded());


  // Image is not cropped
  if (startline ==0 && startsample == 0){


    if (binning > 1) {
      QString scale(toString(binning));
      FileName newflat = FileName::createTempFile("$TEMPORARY/" +
                                                  flatfile.baseName() + "_reduced.cub");

      reducedFlat = newflat.expanded();
      QString parameters = "FROM=" + flatfile.expanded() +
         " TO="   + newflat.expanded() +
@@ -258,12 +245,8 @@ void IsisMain() {
    // Set up processing for flat field as a second input file
    CubeAttributeInput att;
    p.SetInputCube(reducedFlat, att);

  }

  else {


    // Image is cropped so we have to deal with it
    FileName transFlat =
      FileName::createTempFile("$TEMPORARY/" + flatfile.baseName() + "_translated.cub");
@@ -282,16 +265,14 @@ void IsisMain() {
    
    CubeAttributeInput att;
    p.SetInputCube(transFlat.expanded(),att);

  }

  Cube *ocube  = p.SetOutputCube("TO");
  QString fname = ocube->fileName();

  ns = icube->sampleCount();
  nl = icube->lineCount();
  nb = icube->bandCount();

  //ns = icube->sampleCount();
  //nl = icube->lineCount();
  //nb = icube->bandCount();

  QString calfile = loadCalibrationVariables(ui.GetAsString("CONFIG"));

@@ -300,11 +281,12 @@ void IsisMain() {
  g_darkCurrent = g_d0*exp(g_d1*g_temp);

  g_iof = 1.0;  // Units of DN

  QString g_units = "DN";
  if ( "radiance" == g_iofCorrection.toLower() ) {
    // Units of RADIANCE 
    g_iof = g_iof * g_v_standard * g_iofScale; 
    g_units = "W / (m**2 micrometer sr) / (DN / sec)";
    g_units = "W / (m**2 micrometer sr)";
  }

  if ( !sunDistanceAU(startTime, target, g_solarDist) ) {
@@ -364,6 +346,8 @@ void IsisMain() {
  calibrationLog.addKeyword(PvlKeyword("IOFFactor", toString(g_iof, 16)));
  calibrationLog.addKeyword(PvlKeyword("Units", g_units));

// PSF correction is currently not working and has been removed as an option. 
#if 0 
  // This section will apply the PSF correction
  if ( g_applyPSF ) {
    //PSF correction
@@ -452,6 +436,7 @@ void IsisMain() {
      // Remove the PSF file  
      remove( psfModel.expanded().toLatin1().data() );
  }
#endif 

  // Write Calibration group to output file
  ocube->putGroup(calibrationLog);
@@ -491,6 +476,7 @@ FileName DetermineFlatFieldFile(const QString &filter, const bool nullPolarPix)
}


#if 0
/**
 * @brief This function moves the PSF kernel through each pixel of the input cube and approximates
 * the amount of light diffusion produced by that pixel.
@@ -545,6 +531,7 @@ void psfCorrection(vector<Buffer *> &in, vector<Buffer *> &out) {
  }

}
#endif 


/**
@@ -553,8 +540,7 @@ void psfCorrection(vector<Buffer *> &in, vector<Buffer *> &out) {

QString loadCalibrationVariables(const QString &config)  {

  UserInterface& ui = Application::GetUserInterface();

//  UserInterface& ui = Application::GetUserInterface();

//  FileName calibFile("$hayabusa/calibration/amica/amicaCalibration????.trn");
  FileName calibFile(config);
@@ -563,21 +549,18 @@ QString loadCalibrationVariables(const QString &config) {
  // Pvl configFile;
  g_configFile.read(calibFile.expanded());


  // Load the groups

  PvlGroup &Bias = g_configFile.findGroup("Bias");
  PvlGroup &DarkCurrent = g_configFile.findGroup("DarkCurrent");
  PvlGroup &Smear = g_configFile.findGroup("SmearRemoval");
  PvlGroup &Linearity = g_configFile.findGroup("Linearity");
  PvlGroup &hotPixels = g_configFile.findGroup("HotPixels");
  PvlGroup &psfDiffuse = g_configFile.findGroup("PSFDiffuse");
  PvlGroup &psfFocused = g_configFile.findGroup("PSFFocused");
//  PvlGroup &psfDiffuse = g_configFile.findGroup("PSFDiffuse");
//  PvlGroup &psfFocused = g_configFile.findGroup("PSFFocused");
  PvlGroup &solar = g_configFile.findGroup("SOLARFLUX");
  PvlGroup &iof = g_configFile.findGroup("IOF");
  PvlGroup &iof = g_configFile.findGroup("RAD");

  // Load the hot pixels into a vector

  for (int i = 0; i< hotPixels.keywords(); i++ ){

    int samp(hotPixels[i][0].toInt());
@@ -616,7 +599,6 @@ QString loadCalibrationVariables(const QString &config) {
  //cout << "g_t0"  << g_t0.EtString();

  // Compute BIAS correction factor (it's a constant so do it once!)

  double obsStartTime;
  double tsecs;
  double tdays;
@@ -631,13 +613,12 @@ QString loadCalibrationVariables(const QString &config) {
  //g_bias = 0;
  //cout << "g_bias = "  << g_bias << endl;


  //Load the PSF constants.  These come from
  //Ishiguro, 2014 ('Scattered light correction of Hayabusa/AMICA data and
  //quantitative spectral comparisons of Itokawa')

  QString kernel_sz=ui.GetString("KERNEL_SIZE");
  g_size = kernel_sz.toInt();
//  QString kernel_sz=ui.GetString("KERNEL_SIZE");
//  g_size = kernel_sz.toInt();

  //Commenting out this code and making it a user parameter
  //to make it easier to try out optimum values
@@ -651,14 +632,15 @@ QString loadCalibrationVariables(const QString &config) {

#endif

// PSF correction is not working and is temporarily removed. 
#if 0 
  g_alpha = psfFocused[g_filter.toLower()];

   for (int i =0; i < g_N; i++) {

     g_sigma[i] = psfDiffuse["sigma"][i].toDouble();
     g_A[i] = psfDiffuse[g_filter.toLower()][i].toDouble();

   }
#endif

  // Load the Solar Flux for the specific filter
  g_solarFlux=solar[g_filter.toLower()];
@@ -670,7 +652,6 @@ QString loadCalibrationVariables(const QString &config) {
  g_iofScale   = iof[g_filter];

  return ( calibFile.original() );

}


@@ -697,7 +678,6 @@ void Calibrate(vector<Buffer *>& in, vector<Buffer *>& out) {
      imageOut[i] = Isis::Null;
    }
    return;

  }


@@ -718,13 +698,11 @@ void Calibrate(vector<Buffer *>& in, vector<Buffer *>& out) {
  }


  //iterate over the line space

  // Iterate over the line space
  for (int i = 0; i < imageIn.size(); i++) {

    imageOut[i] = imageIn[i];


    // Check for special pixel in input image and pass through
    if ( IsSpecial(imageOut[i]) ) {
      imageOut[i] = imageIn[i];
@@ -734,7 +712,6 @@ void Calibrate(vector<Buffer *>& in, vector<Buffer *>& out) {
    // Apply compression factor here to raise LOSSY dns to proper response
    imageOut[i] *= g_compfactor;


    // 1) BIAS Removal - Only needed if not on-board corrected
    if ( nsubImages <= 1 ) {

@@ -748,19 +725,14 @@ void Calibrate(vector<Buffer *>& in, vector<Buffer *>& out) {
    }

    // 2) LINEARITY Correction - always done
    
    imageOut[i] = pow(imageOut[i],g_Gamma) + g_L0*imageOut[i]*exp(g_L1*imageOut[i]);


    // 3) DARK Current - Currently negligible and removed

#if 0

      imageOut[i] = imageOut[i]-g_darkCurrent;

#endif


    // 4) HOT Pixel Removal

    bool hot = false;
@@ -768,31 +740,22 @@ void Calibrate(vector<Buffer *>& in, vector<Buffer *>& out) {
    for (int j=0; j < hotPixelVector.size(); j++) {

      if ((hotPixelVector[j].sample() == currentSample) && (hotPixelVector[j].line() == i)) {

        imageOut[i] = Null;
        hot = true;

      }
    }

    if (hot == true)
      continue;


    // 5) READOUT Smear Removal - Not needed if on-board corrected.  Binning is
    //    accounted for in computation of c1 before loop.

    if ( nsubImages <= 1 || g_smear) {

    if (nsubImages <= 1) {
      imageOut[i] = c1*(imageOut[i] - smear);

    }


    // 6) FLATFIELD correction
    //  Check for any special pixels in the flat field (unlikely)


    if ( IsSpecial(flatField[i]) ) {
      imageOut[i] = Isis::Null;
      continue;
@@ -801,13 +764,9 @@ void Calibrate(vector<Buffer *>& in, vector<Buffer *>& out) {
      imageOut[i] /= flatField[i];
    }


    // 7) I/F Conversion

    // 7) I/F or Radiance Conversion (or g_iof might = 1, in which case the output will be in DNs)
    imageOut[i] *= g_iof;

  }

  return;
}
+65 −34
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
    <li><a href="#HotPixel">Step 3: Remove the hot pixels.</a ></li>
    <li><a href="#Smear">Step 4: Readout smear correction.</a ></li>
    <li><a href="#Flatfield">Step 5: Uniformity (flat field) correction.</a ></li>
    <li><a href="#ConvertIOF">Step 6: Conversion to I/F</a ></li>
    <li><a href="#PSFCorrection">Step 7: PSF correction</a ></li>
    <li><a href="#ConvertIOF">Step 6 (Optional): Unit conversion to Radiance or I/F</a ></li>
<!--    <li><a href="#PSFCorrection">Step 7: PSF correction</a ></li> -->
    <li><a href="#Notes">Notes</a></li>
    <li><a href="#References">References</a ></li>
  </ul>
@@ -247,16 +247,7 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
      <td>B</td><td>The binning number.</td>
    </tr>
    </table></center>



    </div>






  </p>
  <p>
    <h1><a id="Flatfield">Step 5: Flat-field correction:</a ></h1>
@@ -271,21 +262,50 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
    flat-field image.
  </p>
  <p>
    <h1><a id="ConvertIOF">Step 6: Convert units to I over F:</a ></h1>
    This converts the raw DN values to I/F (radiance) units.  The formula is as follows:
    <h1><a id="ConvertIOF">Step 6 (Optional): Convert output units to Radiance or I over F:</a ></h1>
    This step is optional, and the formula used depends on the value of the UNITS user parameter. 

    If UNITS=RADIANCE, the following formula will be used to convert the raw DN values to radiance 
    (W/m2/sr/µm):

    <br/><br/>
     <div style="font-size:90%; font-family:monospace; margin:5px; margin-left:30px;">
      <center><strong>IoF = Raw*[pi*(R<sub>s</sub>)<sup>2</sup>]/F</strong></center>
      <center><strong>R = Raw*RadianceStandard*RadianceScaleFactor</strong></center>
      <br/><br/>
      <center><table border="1" cellpadding="5">
      <tr>
          <td>Variable</td><td>Description</td>
     </tr>
     <tr>
          <td>R</td><td>The calibrated radiance (w/m2/sr/µm). </td>
     </tr>
     <tr>
          <td>Raw</td><td>The raw DN value. </td>
     </tr>
     <tr>
          <td>IoF</td><td>The IoF units of the raw DN value.</td>
          <td>RadianceStandard</td><td>The standard conversion factor from DNs to radiance. </td>
     </tr>
     <tr>
          <td>RadianceScaleFactor</td><td>An adjustment factor for each filter.</td>
     </tr>
     </table></center>
     </div>

    If UNITS = IOF, first the above formula will be used to convert from raw DNs to calibrated Radiance, and then
    the following formula will be used to convert the raw DN values to I/F (radiance) units:
    <br/><br/>
     <div style="font-size:90%; font-family:monospace; margin:5px; margin-left:30px;">
      <center><strong>IoF = R*[pi*(R<sub>s</sub>)<sup>2</sup>]/F</strong></center>
      <br/><br/>
      <center><table border="1" cellpadding="5">
      <tr>
          <td>Variable</td><td>Description</td>
     </tr>
     <tr>
          <td>IoF</td><td>The calibrated radiance in units of I over F.</td>
     </tr>
     <tr>
          <td>R</td><td>The calibrated radiance (w/m2/sr/µm). </td>
     </tr>
     <tr>
         <td>R<sub>s</sub></td><td>The distance in Astronomical Units (AU) between the Sun
@@ -293,14 +313,15 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
         </td>
     </tr>
     <tr>
          <td>F</td><td>The solar flux at the target body.</td>
          <td>F</td><td>The solar flux (w/m2/µm) at 1 AU. </td>
     </tr>
     </table></center>
     </div>

    If UNITS=DN, no output conversion will be performed and the output units will be in raw DNs. 
  </p>
  <p>

<!--  <p>
    <h1><a id="PSFCorrection">Step 7: PSF Correction:</a ></h1>
    The point-spread function (PSF) is a model describing the two-dimensional distribution of
    light emitted from an infinitely small point source.  For point light sources, there
@@ -420,7 +441,7 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
    </tr>
    </table></center>
    </div>
  </p>
  </p> --> 
  <p>
  <h1><a id="Notes">Notes</a></h1>
  <ol>
@@ -450,14 +471,14 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
  </p>


  <p>
 <!-- <p>
    <h1>Output units</h1>
    The output units of the DNs will depend on which calibration flags are turned on.
    <ul>
      <li>If IOF=TRUE, output units are measured in I/F</li>
      <li>Otherwise output units are measured in W/(m<sup>2</sup> micrometer sr)</li>
    </ul>
  </p>
  </p> -->

  </description>

@@ -499,6 +520,19 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
        applyPSF boolean parameter into a global variable for consistency with the applySmear
        global variable.
    </change>
    <change name="Kristin Berry" date="2017-02-07">
       Removed the "APPLYSMEAR" option as a user-specifiable parameter. The smear correction
       will still be applied automatically when an image is being processed for which on-board smear 
       correction was not applied (NSUB &lt;= 1). Also updated application code for conformity with ISIS3
       Coding Standards. Backward Compatibility Issue: The APPLYSMEAR parameter was removed. The smear
       correction will automatically be applied to images with 1 sub-image. 
    </change>
    <change name="Kristin Berry" date="2017-02-08">
       Removed the "PSF" correction option, since the PSF correction is not yet working. Related code has been commented-
       out rather than removed entirely so that this work can potentially be resumed at a later date. 
       Backward Compatibility Issue: The PSF parameter was removed, since it is not yet working. 
       amicacal cannot apply a PSF correction anymore.
    </change>
  </history>

  <groups>
@@ -521,11 +555,11 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
        <fileMode>output</fileMode>
        <pixelType>real</pixelType>
        <brief>
          Non-PSF Corrected Output cube
          Corrected Output cube
        </brief>
        <description>
          This is the output file. The output cube will be a calibrated version 
          of the input cube (without PSF correction).
          of the input cube.
        </description>
        <filter>
          *.cub
@@ -551,7 +585,7 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica

    <group name="Options">

      <parameter name = "APPLYPSF">
<!--      <parameter name = "APPLYPSF">
          <type>boolean</type>
          <default><item>False</item></default>
          <brief>
@@ -559,8 +593,8 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
          </brief>
          <description>
          </description>
      </parameter>
      <parameter name = "APPLYSMEAR">
      </parameter> --> 
<!--      <parameter name = "APPLYSMEAR">
          <type>boolean</type>
          <default><item>False</item></default>
          <brief>
@@ -568,7 +602,7 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
          </brief>
          <description>
          </description>
      </parameter>
      </parameter> -->
      <parameter name = "NULLPOLARPIX">
        <type>boolean</type>
        <default><item>True</item></default>
@@ -617,6 +651,7 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
        </list>
      </parameter>

<!--   Part of the PSF correction, so removed until PSF is added back in   
         <parameter name = "KERNEL_SIZE">
        <type>string</type>
        <default><item>23</item></default>
@@ -626,11 +661,7 @@ xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Applica
        <description>

      </description>
      </parameter>

      </parameter>-->
    </group>
    

  </groups>
  
</application>
+8 −4
Original line number Diff line number Diff line
@@ -3,11 +3,15 @@ APPNAME = amicacal
include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) \
	FROM=$(INPUT)/st_2433548889_w.cub \
	TO=$(OUTPUT)/smearCorrected_nsubimages2_st_2433548889_w.cub \
	applysmear=yes nullpolarpix=no >/dev/null;\
	# Test application of smear removal for SubImageCount = 1
	$(APPNAME) \
	FROM=$(INPUT)/st_2539482843_v.cub \
	TO=$(OUTPUT)/smearCorrected_nsubimages1_st_2539482843_v.cub.cub \
	nullpolarpix=no > /dev/null;

	# Test NON-application of smear removal for SubImageCount = 2
	$(APPNAME) \
	FROM=$(INPUT)/st_2433548889_w.cub \
	TO=$(OUTPUT)/notSmearCorrected_nsubimages2_st_2433548889_w.cub \
	nullpolarpix=no >/dev/null;\