Commit 24b0627e authored by Kristin's avatar Kristin Committed by Jesse Mapel
Browse files

Updates marci2isis to add variable exposure times and associated frame sequences (#3501)

* Update date and other metadata

* ckwriter_test_fix

* Fix unintentional cmakelists change

* Updated voy2isis to add instrument parameter which can be used to specify the instrument name wac or nac if it is not provided in the image label

* Added simple test

* Updates test and documentation for voy2isis adds instrument_name update

* Updated history documentation to add ticket number for voy2isis changes

* Updated to reverse frameseq number appropriately with flip

* Remove commented-out code

* Added documentation for change and test

* Updated no exposure duration in varexp file condition

* Re-remove iTime.h

* Update warning message for assuming a single exposure time
parent 6a9c0f77
Loading
Loading
Loading
Loading
+83 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#include "MultivariateStatistics.h"
#include "OriginalLabel.h"
#include "IException.h"
#include "CSVReader.h"

using namespace std;
using namespace Isis;
@@ -153,6 +154,87 @@ void IsisMain() {
    isisCube.findGroup("Instrument").addKeyword(PvlKeyword("Framelets", framelets[i]));

    outputCubes[i]->write(origLabel);
  }

  QString prodId = outputCubes[0]->label()->findGroup("Archive", Pvl::Traverse)["ProductId"][0]; 
  prodId = prodId.toUpper();
  vector<int> frameseq;
  vector<double> exptime;
  // Populate with first values
  Pvl *isisLabelInitial = outputCubes[0]->label();
  PvlGroup &instInitial = isisLabelInitial->findGroup("Instrument", Pvl::Traverse);
  double exposure = instInitial["ExposureDuration"][0].toDouble() * 1000.0;

  frameseq.push_back(0);
  exptime.push_back(exposure); 

  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.";
          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 (flip && exptime.size() > 0) {
    reverse(frameseq.begin(),frameseq.end());
    reverse(exptime.begin(),exptime.end());
  }

  // If exptime < 2, no additional exposure durations were found in the varexp file, so
  // assume a single exposure duration and warn the user. 
  // Using single exposure duration is correct in many cases, but there is no way to check 
  // using only the information in the label. 
  if (exptime.size() < 2) {
    PvlGroup missing("NoExposureTimeDataFound");
    PvlKeyword message("Message", "No variable exposure information found in the varexp file."
                                  " Assuming exposure time is fixed for [" + inFile.toString() +  "]" );
    missing.addKeyword(message); 
    missing.addKeyword(PvlKeyword("FileNotFoundInVarexpFile", prodId), Pvl::Replace);
    Application::Log(missing);
  }
        
  // Translate labels to every image and close output cubes before calling EndProcess

    // Add these values to the label
    for(unsigned int i = 0; i < outputCubes.size(); i++) {
        Pvl *isisLabel = outputCubes[i]->label();
        PvlGroup &inst = isisLabel->findGroup("Instrument", Pvl::Traverse);

        PvlKeyword varExposure("VariableExposureDuration");
        PvlKeyword frameNumber("FrameNumber");

        for (int i=0; i < exptime.size(); i++) {
          varExposure.addValue( QString::number(exptime[i]), "ms" );
          frameNumber.addValue( QString::number(frameseq[i]) );
        }
      inst.addKeyword(frameNumber);
      inst.addKeyword(varExposure);
      delete outputCubes[i];
    }

+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@
      <change name="Tracie Sucharski" date="2013-06-05">
        Added keywords to the Archive group in labels.
      </change>
      <change name="Kristin Berry" date="2019-11-09">
        Added keywords to the labels for variable exposure duration and the frame sequence. 
	References #2034
      </change>
    </history>

    <category>
+10 −0
Original line number Diff line number Diff line
APPNAME = marci2isis

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) FROM=$(INPUT)/P07_003640_2331_MA_00N288W.IMG TO=$(OUTPUT)/out.cub > /dev/null;
	catlab FROM=$(OUTPUT)/out.even.cub to=$(OUTPUT)/even.pvl > /dev/null;
	catlab FROM=$(OUTPUT)/out.odd.cub to=$(OUTPUT)/odd.pvl > /dev/null;
	$(APPNAME) FROM=$(INPUT)/P07_003640_2331_MA_00N288W.IMG flip=NO TO=$(OUTPUT)/unflipped.cub > /dev/null;
	catlab FROM=$(OUTPUT)/unflipped.even.cub to=$(OUTPUT)/unflipped.pvl > /dev/null;