Exemple #1
0
void IsisMain (){

  //initialize globals
  summed = false; 
  summedOutput = NULL;
  // Grab the file to import
  ProcessImportPds p;
  UserInterface &ui = Application::GetUserInterface();
  Filename inFile = ui.GetFilename("FROM");
  Filename out = ui.GetFilename("TO");

  // Make sure it is a Galileo SSI image
  Pvl lab(inFile.Expanded());

  //Checks if in file is rdr
  if( lab.HasObject("IMAGE_MAP_PROJECTION") ) {
    string msg = "[" + inFile.Name() + "] appears to be an rdr file.";
    msg += " Use pds2isis.";
    throw iException::Message(iException::Io,msg, _FILEINFO_);
  }

  // data set id value must contain "SSI-2-REDR-V1.0"(valid SSI image) 
  // or "SSI-4-REDR-V1.0"(reconstructed from garbled SSI image)
  string dataSetId;
  dataSetId = (string)lab["DATA_SET_ID"];
  try {
    if (dataSetId.find("SSI-2-REDR-V1.0") == string::npos
        && dataSetId.find("SSI-4-REDR-V1.0") == string::npos) {
      string msg = "Invalid DATA_SET_ID [" + dataSetId + "]";
      throw iException::Message(iException::Pvl,msg,_FILEINFO_);
    }
  }
  catch (iException &e) {
    string msg = "Unable to read [DATA_SET_ID] from input file [" +
                 inFile.Expanded() + "]";
    throw iException::Message(iException::Io,msg,_FILEINFO_);
  }

  // set summing mode 
  if(ui.GetString("FRAMEMODE") == "AUTO") {
    double frameDuration = lab["FRAME_DURATION"];
    // reconstructed images are 800x800 (i.e. not summed)
    // even though they have frame duration of 2.333 
    // (which ordinarily indicates a summed image)
    if (dataSetId.find("SSI-4-REDR-V1.0") != string::npos) {
      summed = false; 
    }
    else if (frameDuration > 2.0 && frameDuration < 3.0) {
      summed = true;
    }
    // seti documentation implies valid frame duration values are 2.333, 8.667, 30.333, 60.667 
    // however some images have value 15.166 (see example 3700R.LBL)
    else if (frameDuration > 15.0 && frameDuration < 16.0) {
      summed = true;
    }
  }
  else if(ui.GetString("FRAMEMODE") == "SUMMED") {
    summed = true;
  }
  else {
    summed = false;
  }

  Progress prog;
  Pvl pdsLabel;
  p.SetPdsFile(inFile.Expanded(),"",pdsLabel);

  //Set up the output file
  Cube *ocube;

  if(!summed) {
    ocube = p.SetOutputCube("TO");
    p.StartProcess();
  }
  else {
    summedOutput = new Cube();
    summedOutput->SetDimensions(p.Samples()/2, p.Lines()/2, p.Bands());
    summedOutput->SetPixelType(p.PixelType());
    summedOutput->Create(ui.GetFilename("TO"));
    p.StartProcess(TranslateData);
    ocube = summedOutput;
  }

  TranslateLabels(pdsLabel, ocube);
  p.EndProcess ();

  if(summed) {
    summedOutput->Close();
    delete summedOutput;
  }

  return;
}
Exemple #2
0
void IsisMain () {
    // Initialize variables
    ResetGlobals();

    //Check that the file comes from the right camera
    UserInterface &ui = Application::GetUserInterface();
    Filename inFile = ui.GetFilename("FROM");
    iString id;
    int sumMode;
    try {
        Pvl lab(inFile.Expanded());

        if (lab.HasKeyword("DATA_SET_ID"))
            id = (string) lab.FindKeyword("DATA_SET_ID");
        else {
            string msg = "Unable to read [DATA_SET_ID] from input file [" + inFile.Expanded() + "]";
            throw iException::Message(iException::Io, msg, _FILEINFO_);
        }

        //Checks if in file is rdr
        bool projected = lab.HasObject("IMAGE_MAP_PROJECTION");
        if (projected) {
            string msg = "[" + inFile.Name() + "] appears to be an rdr file.";
            msg += " Use pds2isis.";
            throw iException::Message(iException::User, msg, _FILEINFO_);
        }

        sumMode = (int) lab.FindKeyword("CROSSTRACK_SUMMING");

        // Store the decompanding information
        PvlKeyword xtermKeyword = lab.FindKeyword("LRO:XTERM"),
                   mtermKeyword = lab.FindKeyword("LRO:MTERM"),
                   btermKeyword = lab.FindKeyword("LRO:BTERM");

        if (mtermKeyword.Size() != xtermKeyword.Size() || btermKeyword.Size() != xtermKeyword.Size()) {
            string msg = "The decompanding terms do not have the same dimensions";
            throw iException::Message(iException::Io, msg, _FILEINFO_);
        }

        for (int i = 0; i < xtermKeyword.Size(); i++) {
            g_xterm.push_back(xtermKeyword[i]);
            g_mterm.push_back(mtermKeyword[i]);
            g_bterm.push_back(btermKeyword[i]);

            if (i == 0)
                g_xterm[i] = g_xterm[i];
            else
                g_xterm[i] = (int) (g_mterm[i - 1] * g_xterm[i] + g_bterm[i - 1] + .5);
        }

        if (lab.FindKeyword("FRAME_ID")[0] == "RIGHT")
            g_flip = true;
        else
            g_flip = false;
    }
    catch (iException &e) {
        string msg = "The PDS header is missing important keyword(s).";
        throw iException::Message(iException::Io, msg, _FILEINFO_);
    }

    id.ConvertWhiteSpace();
    id.Compress();
    id.Trim(" ");
    if (id != "LRO-L-LROC-2-EDR-V1.0") {
        string msg = "Input file [" + inFile.Expanded() + "] does not appear to be "
                + "in LROC-NAC EDR format. DATA_SET_ID is [" + id + "]";
        throw iException::Message(iException::Io, msg, _FILEINFO_);
    }

    //Process the file
    Pvl pdsLab;
    ProcessImportPds p;
    p.SetPdsFile(inFile.Expanded(), "", pdsLab);

    // Set the output bit type to Real
    CubeAttributeOutput &outAtt = ui.GetOutputAttribute("TO");

    g_ocube = new Cube();
    g_ocube->SetByteOrder(outAtt.ByteOrder());
    g_ocube->SetCubeFormat(outAtt.FileFormat());
    g_ocube->SetMinMax((double) VALID_MIN2, (double) VALID_MAX2);
    if (outAtt.DetachedLabel()) g_ocube->SetDetached();
    if (outAtt.AttachedLabel()) g_ocube->SetAttached();
    g_ocube->SetDimensions(p.Samples(), p.Lines(), p.Bands());
    g_ocube->SetPixelType(Isis::SignedWord);
    g_ocube->Create(ui.GetFilename("TO"));

    // Do 8 bit to 12 bit conversion
    // And if NAC-R, flip the frame
    p.StartProcess(Import);

    // Then translate the labels
    TranslateLrocNacLabels(inFile, g_ocube);
    p.EndProcess();

    g_ocube->Close();
    delete g_ocube;
}
Exemple #3
0
/**
 * This program imports Mars Express HRSC files
 *
 *  This works by first determining whether or not the input file
 *    has prefix data.
 *
 *  If there is prefix data, a StartProcess is called with the
 *    IgnoreData() function callback in order to get the import class to
 *    collect prefix data. Once the prefix data is populated, we go ahead
 *    and look for "gaps" - HRSC files can give us a time and exposure duration
 *    for each line, we look for where the time + exposure duration != next line's time.
 *    We populate a table (LineScanTimes) with the prefix data and lineInFile with whether or not
 *    a gap should be inserted.
 *
 *  For all files, we now process the data using the WriteOutput callback. If there were gaps,
 *    WriteOutput will put them in their proper places. Finally, we translate the labels and put
 *    the LineScanTimes (if necessary) in the output cube.
 *
 *   This is a two-pass system for files with prefix data, one-pass for files without.
 *
 *   The Isis2 equivalent to this program is mex2isis.pl. It is worth noting that regardless of the
 *     input file's byte order, the prefix data byte order is always LSB.
 */
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();

  try {
    Pvl temp(ui.GetFileName("FROM"));
    // Check for HRSC file
    if(temp["INSTRUMENT_ID"][0] != "HRSC") throw IException();
  }
  catch(IException &e) {
    IString msg = "File [" + ui.GetFileName("FROM") +
                  "] does not appear to be a Mars Express HRSC image.";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  ProcessImportPds p;
  Pvl label;
  lineInFile.clear();
  numLinesSkipped = 0;

  p.SetPdsFile(ui.GetFileName("FROM"), "", label);

  CubeAttributeOutput outAtt(ui.GetFileName("TO"));
  outCube = new Cube();

  outCube->setByteOrder(outAtt.byteOrder());
  outCube->setFormat(outAtt.fileFormat());
  outCube->setLabelsAttached(outAtt.labelAttachment() == AttachedLabel);

  /**
    * Isis2 mex2isis.pl:
    *   if (index($detector_id,"MEX_HRSC_SRC") < 0 &&
    *   $processing_level_id < 3)
    */
  bool hasPrefix = (label["DETECTOR_ID"][0] != "MEX_HRSC_SRC" && (int)label["PROCESSING_LEVEL_ID"] < 3);

  TableField ephTimeField("EphemerisTime", TableField::Double);
  TableField expTimeField("ExposureTime", TableField::Double);
  TableField lineStartField("LineStart", TableField::Integer);

  TableRecord timesRecord;
  timesRecord += ephTimeField;
  timesRecord += expTimeField;
  timesRecord += lineStartField;

  Table timesTable("LineScanTimes", timesRecord);

  if(hasPrefix) {
    p.SetDataPrefixBytes((int)label.findObject("IMAGE")["LINE_PREFIX_BYTES"]);
    p.SaveDataPrefix();

    p.Progress()->SetText("Reading Prefix Data");
    p.StartProcess(IgnoreData);

    // The prefix data is always in LSB format, regardless of the overall file format
    EndianSwapper swapper("LSB");

    std::vector<double> ephemerisTimes;
    std::vector<double> exposureTimes;
    std::vector< std::vector<char *> > prefix = p.DataPrefix();

    for(int line = 0; line < p.Lines(); line++) {
      double ephTime = swapper.Double((double *)prefix[0][line]);
      double expTime = swapper.Float((float *)(prefix[0][line] + 8)) / 1000.0;

      if(line > 0) {
        /**
         * We know how many skipped lines with this equation. We take the
         *   difference in the current line and the last line's time, which will
         *   ideally be equal to the last line's exposure duration. We divide this by
         *   the last line's exposure duration, and the result is the 1-based count of
         *   how many exposures there were between the last line and the current line.
         *   We subtract one in order to remove the known exposure, and the remaining should
         *   be the 1-based count of how many lines were skipped. Add 0.5 to round up.
         */
        int skippedLines = (int)((ephTime - ephemerisTimes.back()) / exposureTimes.back() - 1.0 + 0.5);

        for(int i = 0; i < skippedLines; i++) {
          ephemerisTimes.push_back(ephemerisTimes.back() + exposureTimes.back());
          exposureTimes.push_back(exposureTimes.back());
          lineInFile.push_back(false);
        }
      }

      ephemerisTimes.push_back(ephTime);
      exposureTimes.push_back(expTime);
      lineInFile.push_back(true);
    }

    double lastExp = 0.0;
    for(unsigned int i = 0; i < ephemerisTimes.size(); i++) {
      if(lastExp != exposureTimes[i]) {
        lastExp = exposureTimes[i];
        timesRecord[0] = ephemerisTimes[i];
        timesRecord[1] = exposureTimes[i];
        timesRecord[2] = (int)i + 1;
        timesTable += timesRecord;
      }
    }

    outCube->setDimensions(p.Samples(), lineInFile.size(), p.Bands());
  }
  else {
    //Checks if in file is rdr
    FileName inFile = ui.GetFileName("FROM");
    QString msg = "[" + inFile.name() + "] appears to be an rdr file.";
    msg += " Use pds2isis.";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  p.Progress()->SetText("Importing");
  outCube->create(ui.GetFileName("TO"));
  p.StartProcess(WriteOutput);

  if(hasPrefix) {
    outCube->write(timesTable);
  }

  // Get as many of the other labels as we can
  Pvl otherLabels;

  //p.TranslatePdsLabels (otherLabels);
  TranslateHrscLabels(label, otherLabels);

  if(otherLabels.hasGroup("Mapping") &&
      (otherLabels.findGroup("Mapping").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("Mapping"));
  }

  if(otherLabels.hasGroup("Instrument") &&
      (otherLabels.findGroup("Instrument").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("Instrument"));
  }

  if(otherLabels.hasGroup("BandBin") &&
      (otherLabels.findGroup("BandBin").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("BandBin"));
  }

  if(otherLabels.hasGroup("Archive") &&
      (otherLabels.findGroup("Archive").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("Archive"));
  }

  if(otherLabels.hasGroup("Kernels") &&
      (otherLabels.findGroup("Kernels").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("Kernels"));
  }

  p.EndProcess();

  outCube->close();
  delete outCube;
  outCube = NULL;
  lineInFile.clear();
}