Commit 4e1631e3 authored by Stuart Sides's avatar Stuart Sides Committed by Lauren Adoram-Kershner
Browse files

Modified to use the frame and exposure keywords added by marci2isis i… (#3505)

* Modified to use the frame and exposure keywords added by marci2isis instead of the varexp.tab file

* Added the issue that caused this to need to be fixed

* Update main.cpp
parent 24b0627e
Loading
Loading
Loading
Loading
+74 −75
Original line number Diff line number Diff line
@@ -364,48 +364,32 @@ void IsisMain() {
  prodId = prodId.toUpper();
  vector<int> frameseq;
  vector<double> exptime;
  QString varExpFile = "$mro/calibration/marci/varexp.tab";
  
  // Load the MARCI exposure duration calibration tables.
  bool header=false;
  int skip=0;
  FileName csvfile(varExpFile);
    
  CSVReader csv(csvfile.expanded(), header, skip);
    // There may be multiple entries in the file for this productID,
    // so we *must* loop through the entire file.
  for(int i = 0 ; i < csv.rows() ; i++) {
      CSVReader::CSVAxis row = csv.getRow(i);
      // The productId in the file is encapsulated by double quotes.
      QString fileProdId = row[0];
      //This is garbage code, but my compiler isn't allowing me to escape the double quotes
      int prodIdLastIndex = fileProdId.size() - 1 ;
      fileProdId.remove(prodIdLastIndex,1);
      fileProdId.remove(0,1);
      // Now, compare product ids from the input image and from the calibration table.
      if(fileProdId == prodId ) {
        if((row.dim1() - 1) != 2) {
          QString msg = "This appears to be a malformed calibration file."; 
                  msg += " There are not enough columns in the CSV";
                  msg += " file to perform the exposure time correction.";

  // Get the exposure duration(s) and coorisponding frame number(s) (zero based) from the label
  PvlGroup inst = icube.group("Instrument");

  if (!inst.hasKeyword("VariableExposureDuration") || !inst.hasKeyword("FrameNumber")) {
    QString msg = "The instrument keywords VariableExposureDuration and FrameNumber"
                  "must exist to calibrate this MARCI file. Prior to isis3.10.0 these" 
                  "keywords were not added by marci2isis; you may need to rerun isis3.10+"
                  "marci2isis on your images.";
    throw IException(IException::User, msg, _FILEINFO_);
  }
        // Build the two vectors, exptime and frame. We'll relate those to each other
        // back in main(). Remember that a productID may have multiple entries in the table.
        frameseq.push_back(toInt(row[1]));
        exptime.push_back(toDouble(row[2]));
      }
  }

  if (flipped && exptime.size() > 0) {
    reverse(frameseq.begin(),frameseq.end());
    reverse(exptime.begin(),exptime.end());
  // The previous version of marcical read the first exposure duration and frame number from
  // the label and the other durations/frames (if any) from the mission's varexp.tab file.
  // In order to minimize the changes to this code while modifying it to use the keywords instead of
  // reading the varexp.tab file directly, the duration/frame where the frame is zero are dropped from 
  // the array when converting them from the keywords. This calibration code should be 
  // able to be simplified significantly by not removing the frameNumber=0 exposure/frame and
  // removing the first frame ifs in the calibration code below.
  PvlKeyword expTimesKey = inst["VariableExposureDuration"];
  PvlKeyword frameNumbersKey = inst["FrameNumber"];
  for (int i=0; i<expTimesKey.size(); i++) {
    if (toInt(frameNumbersKey[i]) != 0) {
      exptime.push_back(toDouble(expTimesKey[i]));
      frameseq.push_back(toInt(frameNumbersKey[i]));
    }

  if (exptime.size() == 0) {
    PvlGroup missing("NoExposureTimeDataFound");
    missing.addKeyword(PvlKeyword("FileNotFoundInVarexpFile", prodId), Pvl::Replace);
    Application::Log(missing);
  }

  bool iof = ui.GetBoolean("IOF");
@@ -439,18 +423,27 @@ void IsisMain() {
    ocube.read(ocubeMgr);

    int fcubeIndex = filter[ocubeMgr.Band()-1] - 1;
    // First time through the loop or the Mgr finished with one band and has incremented to the next
    if (band != ocubeMgr.Band()) {
      band = ocubeMgr.Band();
      line = 0;
      if (!flipped) {
        // Question: for the first time thru the do loop maxOffset is set above to the max of padding, but
        // for the first framelet of the second band maxOffset seems to be left over from the previous itteration
        // Seems like something might be wrong here.
        frame = 0;
        exposure = ((double)icube.label()->findGroup("Instrument", Pvl::Traverse)["ExposureDuration"]) * 1000.0;
      } 
      else {
        maxOffset = padding[band-1];
        frame = (icube.lineCount() - maxOffset) / filterHeight - 1;
        if (exptime.size() > 0) {
          exposure = exptime[0];
        }
        else {
          exposure = ((double)icube.label()->findGroup("Instrument", Pvl::Traverse)["ExposureDuration"]) * 1000.0;
        }
      }
      seqno = 0;
    }

@@ -467,7 +460,13 @@ void IsisMain() {
      if (!flipped) {
        if (seqno < fsize) {
          if (frame >= frameseq[seqno]) {
            if (exptime.size() > 0) {
              exposure = exptime[seqno];
            }
            else {
              exposure = ((double)icube.label()->findGroup("Instrument", Pvl::Traverse)["ExposureDuration"]) * 1000.0;
            }
            // Exposure duration for the UV filters are calculated from the non-UV exposure duration 
            if ((QString)icube.label()->findGroup("BandBin", Pvl::Traverse)["FilterName"][band-1] == "LONG_UV" ||
                 (QString)icube.label()->findGroup("BandBin", Pvl::Traverse)["FilterName"][band-1] == "SHORT_UV") {
              exposure = ifdelay - 57.763 - exposure;
@@ -536,8 +535,8 @@ void IsisMain() {
    }

    prog.CheckStatus();
  }
  while(!ocubeMgr.end());
  } while (!ocubeMgr.end());


  // Propagate labels and objects (in case of spice data)
  PvlObject &inCubeObj = icube.label()->findObject("IsisCube");
+4 −0
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@ K.D. Supulver, and P.C. Thomas
    <change name="Moses Milazzo" date="2014-12-08">
      Fixed a bug in exposure time accounting. Fixes #1860.
    </change>
    <change name="Stuart Sides" date="2019-11-08">
      Modified to use the exposure duration from the new label keywords added by
      marci2isis. Related #2034
    </change>
  </history>

  <groups>
+11 −0
Original line number Diff line number Diff line
APPNAME = marcical

include $(ISISROOT)/make/isismake.tsts
truth_iof.cub.TOLERANCE = 0.0000000000001
truth_not_iof.cub.TOLERANCE = 0.0000000000001

commands:
	$(APPNAME) FROM=$(INPUT)/K14_059003_3475_MA_00N112W.IMG.even.crop.cub \
	  TO=$(OUTPUT)/truth_iof.cub > /dev/null;
	$(APPNAME) FROM=$(INPUT)/K14_059003_3475_MA_00N112W.IMG.even.crop.cub iof=no \
	  TO=$(OUTPUT)/truth_not_iof.cub > /dev/null;