Commit 1eb5801a authored by Cole Neubauer's avatar Cole Neubauer
Browse files

Upgrade Cisscal to latest corresponding version Fixes #4708

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@8014 41f8697f-d340-4b68-9986-7bafba869bb8
parent b4b3bad9
Loading
Loading
Loading
Loading
+171 −4
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
 *   http://www.usgs.gov/privacy.html.
 */

#include <QDir>
#include <algorithm>
#include <cmath>  //use ceiling and floor functions
#include <vector>
#include "Application.h"
@@ -58,6 +60,7 @@ namespace Isis {
    p_gainMode = cissLab.GainModeId();
    p_narrow = cissLab.NarrowAngle();
    p_sum = toString(cissLab.SummingMode());
    p_imageTime = cissLab.ImageTime();

    if(cissLab.ReadoutCycleIndex() == "Unknown") {
      p_readoutIndex = -999;
@@ -173,9 +176,18 @@ namespace Isis {
      }
    }
    if(notzero != 0) {
      double DNSatPoint;
      if (p_dataConvType == "8Bit") {
        DNSatPoint = 255.0;
      }
      else {
        DNSatPoint = 4095.0;
      }
      // correct for gain:
      double gain2, gainRatio;
      int ESatPoint;
      if(p_narrow) {
        ESatPoint = 1.237e5;
        gain2 = 30.27;
        switch(p_gainMode) { // GainState()){
          case 215: //gs = 0:
@@ -197,6 +209,7 @@ namespace Isis {
        }
      }
      else {
        ESatPoint = 1.133e5;
        gain2 = 27.68;
        switch(p_gainMode) { // GainState()){
          case 215://0:
@@ -220,6 +233,9 @@ namespace Isis {
      for(unsigned int i = 0; i < dark_e.size(); i++) {
        for(unsigned int j = 0; j < dark_e[0].size(); j++) {
          dark_DN[i][j] = (dark_e[i][j] / (gain2 / gainRatio));
          if (dark_DN[i][j] >= DNSatPoint || dark_e[i][j] >= ESatPoint){
            dark_DN[i][j] = DNSatPoint;
          }
        }
      }
      return dark_DN;
@@ -1044,8 +1060,30 @@ namespace Isis {
    else {
      instModeId += "full";
    }
    p_dparamfile = darkDir + instrumentId + "_median_dark_parameters" + "?????" + "." + instModeId + ".cub";
    p_dparamfile = p_dparamfile.highestVersion();
    p_dparamfile = darkDir + instrumentId + "_dark_parameters" + "." + instModeId + ".cub";

    // needs to check directory for closeest epochs and compare
    double closestEpochFileNum = 0;
    QStringList fileList = QDir(darkDir).entryList();
    QString instrument;
    if (p_narrow) {
      instrument = "NAC";
    }
    else {
      instrument = "WAC";
    }
    double imgTime = p_imageTime.mid(0, 4).toDouble() + (p_imageTime.mid(5, 3).toDouble() / 365);
    for(int i = 0; i < fileList.count(); i++){
      if (FileName(fileList[i]).baseName().mid(0, 3) != instrument){
        continue;
      }
      double currentEpoch = FileName(fileList[i]).baseName().mid(10, 6).toDouble();
      if (abs(currentEpoch - imgTime) < abs(closestEpochFileNum - imgTime)) { // find closest epoch
          closestEpochFileNum = currentEpoch;
          p_hotpixfile = FileName(fileList[i]);
      }
    }
    p_hotpixfile = darkDir + p_hotpixfile.baseName() + ".tab";
    return;
  }//end FindDarkFiles

@@ -1157,6 +1195,105 @@ namespace Isis {
      darkCoefficients->SetBasePosition(1, 1, 1);
      dparamCube.read(*darkCoefficients);
      dparamCube.close();

      CisscalFile *hotPixFile = new CisscalFile(p_hotpixfile.expanded());
      int num_params = 8;
      long numHotPixels = hotPixFile->LineCount();
      vector<double> exptimes;
      vector<double> tgrid(num_params);
      vector <vector <double> > v1(num_params);

      for(int i = 0; i < num_params; i++) {
        v1[i].resize(num_params);
        switch(i) {
          case 0:
            tgrid[i] = 0.0;
            break;
          case 1:
            tgrid[i] = 10.0;
            break;
          case 2:
            tgrid[i] = 32.0;
            break;
          case 3:
            tgrid[i] = 100.0;
            break;
          case 4:
            tgrid[i] = 220.0;
            break;
          case 5:
            tgrid[i] = 320.0;
            break;
          case 6:
            tgrid[i] = 460.0;
            break;
          case 7:
            tgrid[i] = 1200.0;
            break;
          default:
            tgrid[i] = Null;
        }
      }

      QString exposureLine;
      hotPixFile->GetLine(exposureLine);
      exposureLine=exposureLine.simplified().trimmed();
      QStringList exposureLineList = exposureLine.split(' ');
      for (int j = 2; j < exposureLineList.size(); j++ ){
        exptimes.push_back(toDouble(exposureLineList[j]));
      }
      QString junk;
      hotPixFile->GetLine(junk); //this line is gain values which are not used

      int x;
      int y;
      double hotsat;
      vector<double> elec;
      for(long i = 0; i < numHotPixels; i++){
        QString line;
        hotPixFile->GetLine(line);
        if(line == "") {
          break;
        }
        line = line.simplified();
        QStringList lineList = line.split(' ');
        // make hotpix corrections
        x = floor((toDouble(lineList[0]) / 1024) * p_samples);
        y = floor((toDouble(lineList[1]) / 1024) * p_lines);
        elec.resize(lineList.size() - 3);
        for (unsigned int j = 0; j < elec.size(); j ++){
          elec[j] = (toDouble(lineList[j + 2]));
        }
        hotsat = toDouble(lineList.back());

        if (hotsat != 0.0) {
          double maxExp;
          if (hotsat > 0.0) {
            maxExp = exptimes[hotsat - 1];
          }
          else {
            maxExp = *(std::max_element(exptimes.begin(), exptimes.end()));
          }

          IDLLinearInterpolation interpol;
          for (unsigned int j = 0; j < exptimes.size(); j++) {
            if (exptimes[j] <= maxExp) {
              interpol.insert(exptimes[j], elec[j]);
            }
          }
          if (interpol.size() > 1) {
            for (int j = 0; j < 8; j++){
              (*darkCoefficients)[darkCoefficients->Index(x+1, y+1, j+1)] = interpol.evaluate(tgrid[j]);
            }
          }
        }
      }
      for(int x = 0; x < 256 ; x ++) {
        for (int y = 0; y < 256 ; y++) {
          for (int j = 0; j < 8; j++){
          }
        }
      }
      // Assume WAC dark current is 0 for 0.005 ms. This is not the case for
      // the NAC where there are negative values near the left edge of the frame:
      if(!p_narrow) {
@@ -1207,6 +1344,9 @@ namespace Isis {
      }
      // correct for the average bias distortion at the beginning of each line:
      if(p_narrow) {
        // They gave a new bias file to compare against but it currently
        // is not implemented in the IDL code as it is commented out in their code.
/*
        CisscalFile *biasDist = new CisscalFile(p_bdpath.expanded());
        vector<double> samp, bias_distortion;
        for(int i = 0; i < biasDist->LineCount(); i++) {
@@ -1225,6 +1365,7 @@ namespace Isis {
            dark_e[i][j] = dark_e[i][j] - bias_distortion[i];
          }
        }
*/
      }
      return dark_e;
    }
@@ -1259,7 +1400,10 @@ namespace Isis {
    vector <vector <double> > dark(p_samples), v1(num_params);
    vector <double> temp(p_samples), tgrid(num_params);
    vector <double> c(2), timespan(2);

    for(int i = 0; i < 256 ; i ++) {
      for (int line = 0; line < 256 ; line++) {
      }
    }
    for(unsigned int i = 0; i < dark.size(); i++) {
      dark[i].resize(p_lines);
    }
@@ -1336,5 +1480,28 @@ namespace Isis {
    }
    return dark;
  }//end MakeManyLineDark
}//end namespace Isis


  double DarkCurrent::IDLLinearInterpolation::evaluate(const double input) const{
    double lowKey, highKey, slope;
    IDLLinearInterpolation::const_iterator lowIt = lowerBound(input);
    if (lowIt == begin()){
      lowKey = lowIt.key();
      highKey = (++lowIt).key();
    }
    else if (lowIt == end()){
      highKey = (--lowIt).key();
      lowKey = (--lowIt).key();
    }
    else {
      highKey = lowIt.key();
      lowKey = (--lowIt).key();
    }
    if (fabs(highKey - lowKey) < 1.0e-10) {
      QString msg("Cannot Interpolate Repeated X Values");
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    slope = (value(highKey) - value(lowKey)) / (highKey - lowKey);
    return slope * (input - lowKey) + value(lowKey);
  }
}//end namespace Isis
+8 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
 */

#include <QString>
#include <QMap>
#include <vector>
#include "FileName.h"

@@ -50,6 +51,7 @@ namespace Isis {
   *  @history 2010-07-19 Jeannie Walldren - Fixed formatting.
   *  @history 2016-08-28 Kelvin Rodriguez - Removed usused private member variables to
   *           eliminate unused member variables warnings in clang. Part of porting to OS X 10.11.
   *  @history 2917-08-22 Cole Neubauer - Updated DarkCurrent for latest Cisscal upgrade
   */
  class DarkCurrent {
    public:
@@ -66,8 +68,11 @@ namespace Isis {
      FileName DarkParameterFile()  {
        return p_dparamfile;
      };
      class IDLLinearInterpolation : public QMap<double,double> {
        public:
          double evaluate( const double input) const;


      };
    private:
      double ComputeLineTime(int lline);
      void   FindDarkFiles();
@@ -80,6 +85,7 @@ namespace Isis {
      int p_samples;          //!< Number of samples in the image.
      FileName p_bdpath;      //!< Bias distortion table for the image.  Only exists for narrow camera images.
      FileName p_dparamfile;  //!< Dark parameters file for the image.
      FileName p_hotpixfile;  //!< Erroneously bright hotpixels to encorporate into Dark Parameters.

      //LABEL VARIABLES
      int p_btsm;                   //!< Value dependent upon <b>PvlKeyword</b> DelayedReadoutFlag. Valid values are: "No"=0, "Yes"=1, "Unknown"=-1.  Called "botsim" or "btsm" in IDL code.
@@ -94,7 +100,7 @@ namespace Isis {
      int p_readoutOrder;           //!< Value of <b>PvlKeyword</b> ReadoutOrder from the labels of the image. Valid values are: NAC first = 0, WAC first = 1.  Called "roo" in IDL code.
      QString p_sum;                //!< Summing mode, as found in the labels of the image.  This integer is created as an QString so that it may be added to a QString.  Called "sum" in IDL code.
      int p_telemetryRate;          //!< Telemetry rate of the image in packets per second.  This is dependent on the range of the instrument data rate.  Called "cdsr" in IDL code.

      QString p_imageTime;          //!<Actual Time Stamp On Photo.
      std::vector <std::vector <double> > p_startTime;    //!< Array of start times for each pixel of the image.
      std::vector <std::vector <double> > p_endTime;      //!< Array of end times for each pixel of the image.
      std::vector <std::vector <double> > p_duration;     //!< Array of durations for each pixel of the image.
+162 −104

File changed.

Preview size limit exceeded, changes collapsed.

+17 −17
Original line number Diff line number Diff line
@@ -69,18 +69,19 @@
      This step consists of two parts: dust ring removal  and division by flat
      field.  <strong>Dust ring removal</strong>  only applies to images from
      narrow angle cameras.  This process masks a dust ring found on images and,
      if the image has SummingMode equal to 1 (i.e. it is a full, 1024x1024
      image) and is recent (after 286th day of 2003), divides out a mottle map.
      if the image is recent (after 286th day of 2003), divides out a mottle map.
      <strong> Flat field correction </strong> is applied to all images. During
      this process, each pixel is divided by the average of the center of the
      image.  For SummingMode 2 or 4, the results from this method diverge from
      the IDL results due to differences in the bilinear method used to expand
      the flat file image.  Flat field correction requires no user defined
      parameters. If narrow angle, it uses a dust ring file found in the Cassini
      calibration dustring directory.  If narrow and full, it also uses a mottle
      file and an effective wavelength file found in dustring and efficiency
      directories. And, for any image a slope database and a flat file are used,
      found in slope and slope/slope2flat directories.
      calibration dustring directory. The dust ring file is determined by the epoch
      number associated with the file, the program choses the file with the largest
      epoch before the time stamp of the image being calibrated. It also uses a
      mottle file and an effective wavelength file found in dustring and efficiency
      directories. And, for any image a slope database and a flat file are used,found
      in slope and slope/slope2flat directories.
    </p>
    <p>
      <strong>
@@ -112,12 +113,11 @@
        Step 7: Divide by Correction Factor
      </strong>
      This step is implemented in order to force theory and observation to match.
      It consists of 2 processes.  First, if polarized, (i.e. a filter value of
      IRP0, IRP90, P0, P60, or P120) the image is divided by a polarization
      factor.  Next, the image is divided by its correction factor.  This step
      requires no user defined parameters. It uses a polarization factor file
      and a correction factor file found in the Cassini calibration correction
      directory.
      It consists of 2 processes.  First, the image is divided by its correction
      factor. Next, if the target of the image is Jupiter it is divided by another
      correction factor specific to Jupiter images. This step requires no user defined
      parameters. It uses a correction factor file and Jupiter correction factor found
      in the Cassini calibration correction directory.
    </p>
    <p>
    <strong>
@@ -206,9 +206,9 @@
      Cassini ISS Image Calibration: Theoretical Basis, and In-flight Calibration of the Cassini Imaging Science Subsystem Cameras
      to local assests in case the pdf sites are taken down. Fixes #2358.
    </change>
    <change name="Christopher Combs" date="2017-05-19">
      Changed pvl.DIFF of input for all app tests to ignore file names. Allows test to pass when not
      using default data area. Fixes #4738.
    <change name="Cole Neubauer" date="2017-06-08">
      Updated cisscal and documentation to better reflect the steps as of idl cisscal program
      version, 3.8, and added capabilities to use new dustrings files based on epoch.. Fixes #4708
    </change>
  </history>

@@ -264,7 +264,7 @@
        </title>
        <source>
          <filename></filename>
          <path>http://pds-imaging.jpl.nasa.gov/data/cassini/cassini_orbiter/coiss_0011_v2/document/report/</path>
          <path>http://pds-imaging.jpl.nasa.gov/data/cassini/cassini_orbiter/coiss_0011_v3/document/report/</path>
        </source>
        <author>Cassini ISS Development Team</author>
        <publisher>Planetary Data System Rings Node</publisher>
@@ -275,7 +275,7 @@
        </title>
        <source>
          <filename> </filename>
          <path>http://pds-imaging.jpl.nasa.gov/data/cassini/cassini_orbiter/coiss_0011_v2/document/report/iss/7.0/7.0.html</path>
          <path>http://pds-imaging.jpl.nasa.gov/data/cassini/cassini_orbiter/coiss_0011_v3/document/report/iss/7.0/7.0.html</path>
        </source>
        <author>Alfred McEwen and James Winburn</author>
        <publisher>Planetary Data System Rings Node</publisher>
+0 −12
Original line number Diff line number Diff line
APPNAME = cisscal

N1536363784_1.truth.cub.TOLERANCE = 1.0e-5

include $(ISISROOT)/make/isismake.tsts


commands:
	$(APPNAME) from=$(INPUT)/N1597182735_2.cub \
	to=$(OUTPUT)/N1597182735_2.truth.cub \
	> /dev/null;
	catlab from=$(OUTPUT)/N1597182735_2.truth.cub to=$(OUTPUT)/labels.truth.pvl > /dev/null;
Loading