예제 #1
0
// Main program
void IsisMain() {
  ProcessImportPds p;
  Pvl pdsLabel;
  UserInterface &ui = Application::GetUserInterface();
  FileName inFile = ui.GetFileName("FROM");

  p.SetPdsFile(inFile.expanded(), "", pdsLabel);

  QString filename = FileName(ui.GetFileName("FROM")).baseName();
  FileName toFile = ui.GetFileName("TO");
  
  apollo = new Apollo(filename);

  utcTime = (QString)pdsLabel["START_TIME"];  
  
  // Setup the output cube attributes for a 16-bit unsigned tiff
  Isis::CubeAttributeOutput cao;
  cao.setPixelType(Isis::Real);
  p.SetOutputCube(toFile.expanded(), cao);

  // Import image
  p.StartProcess();
  p.EndProcess();

  cube.open(toFile.expanded(), "rw");
  
  // Once the image is imported, we need to find and decrypt the code
  if (apollo->IsMetric() && FindCode())
    TranslateCode();
    
  CalculateTransform();
  // Once we have decrypted the code, we need to populate the image labels
  TranslateApolloLabels(filename, &cube);
  cube.close();
}
예제 #2
0
파일: mar102isis.cpp 프로젝트: corburn/ISIS
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();

  // Determine whether input is a raw Mariner 10 image or an Isis 2 cube
  bool isRaw = false;
  FileName inputFile = ui.GetFileName("FROM");
  Pvl label(inputFile.expanded());

  // If the PVL created from the input labels is empty, then input is raw
  if(label.groups() + label.objects() + label.keywords() == 0) {
    isRaw = true;
  }

  // Import for RAW files
  if(isRaw) {
    ProcessImport p;

    // All mariner images from both cameras share this size
    p.SetDimensions(832, 700, 1);
    p.SetFileHeaderBytes(968);
    p.SaveFileHeader();
    p.SetPixelType(UnsignedByte);
    p.SetByteOrder(Lsb);
    p.SetDataSuffixBytes(136);

    p.SetInputFile(ui.GetFileName("FROM"));
    Cube *oCube = p.SetOutputCube("TO");

    p.StartProcess();
    unsigned char *header = (unsigned char *) p.FileHeader();
    QString labels = EbcdicToAscii(header);
    UpdateLabels(oCube, labels);
    p.EndProcess();
  }
  // Import for Isis 2 cubes
  else {
    ProcessImportPds p;

    // All mariner images from both cameras share this size
    p.SetDimensions(832, 700, 1);
    p.SetPixelType(UnsignedByte);
    p.SetByteOrder(Lsb);
    p.SetDataSuffixBytes(136);

    p.SetPdsFile(inputFile.expanded(), "", label);
    Cube *oCube = p.SetOutputCube("TO");

    TranslateIsis2Labels(inputFile, oCube);
    p.StartProcess();
    p.EndProcess();
  }
}
예제 #3
0
void IsisMain() {
  ProcessImportPds p;
  Pvl label;
  UserInterface &ui = Application::GetUserInterface();

  QString labelFile = ui.GetFileName("FROM");
  FileName inFile = ui.GetFileName("FROM");
  QString id;
  Pvl lab(inFile.expanded());

  try {
    id = (QString) lab.findKeyword("DATA_SET_ID");
  }
  catch(IException &e) {
    QString msg = "Unable to read [DATA_SET_ID] from input file [" +
                 inFile.expanded() + "]";
    throw IException(e, IException::Unknown, msg, _FILEINFO_);
  }

  id = id.simplified().trimmed();
  if(id != "TC_MAP" && id != "TCO_MAP") {
    QString msg = "Input file [" + inFile.expanded() + "] does not appear to be " +
                  "in Kaguya Terrain Camera level 2 format. " +
                  "DATA_SET_ID is [" + id + "]";
    throw IException(IException::Unknown, msg, _FILEINFO_);
  }

  p.SetPdsFile(labelFile, "", label);
  Cube *outcube = p.SetOutputCube("TO");

  p.SetOrganization(Isis::ProcessImport::BSQ);

  p.StartProcess();

  // Get the mapping labels
  Pvl otherLabels;
  p.TranslatePdsProjection(otherLabels);

  // Get the directory where the generic pds2isis level 2 translation tables are.
  PvlGroup dataDir(Preference::Preferences().findGroup("DataDirectory"));
  QString transDir = (QString) dataDir["base"] + "/translations/";

  // Translate the Archive group
  FileName transFile(transDir + "pdsImageArchive.trn");
  PvlTranslationManager archiveXlater(label, transFile.expanded());
  archiveXlater.Auto(otherLabels);

  // Write the Archive and Mapping groups to the output cube label
  outcube->putGroup(otherLabels.findGroup("Mapping"));
  outcube->putGroup(otherLabels.findGroup("Archive"));

  // Add the BandBin group
  PvlGroup bbin("BandBin");
  bbin += PvlKeyword("FilterName", "BroadBand");
  bbin += PvlKeyword("Center", "640nm");
  bbin += PvlKeyword("Width", "420nm");
  outcube->putGroup(bbin);

  p.EndProcess();
}
예제 #4
0
void IsisMain () {
    flipDataBrick1 = NULL;
    flipDataBrick2 = NULL;
    ProcessImportPds p;

    // Input data for MARCI is unsigned byte
    p.SetPixelType(Isis::UnsignedByte);

    UserInterface &ui = Application::GetUserInterface();
    Filename inFile = ui.GetFilename("FROM");

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

    Pvl pdsLab;
    p.SetPdsFile(inFile.Expanded(), "", pdsLab);

    if((int)pdsLab["SAMPLING_FACTOR"] == 12) {
        throw iException::Message(iException::User, "Summing mode of 12 not supported", _FILEINFO_);
    }

    // We need to know how many filters and their height to import the data properly
    numFilters = pdsLab["FILTER_NAME"].Size();
    currentLine.resize(numFilters);
    filterHeight = 16 / (int)pdsLab["SAMPLING_FACTOR"];

    // For simplicity, we'll keep track of line #'s on each band that we've written so far.
    for(int band = 0; band < numFilters; band ++) {
        currentLine[band] = 1;
    }

    int maxPadding = 0;

    padding.resize(numFilters);
    for(int filter = 0; filter < numFilters; filter++) {
        if(ui.GetBoolean("COLOROFFSET") == true) {
            colorOffset = ui.GetInteger("COLOROFFSET_SIZE");

            // find the filter num
            int filtNum = 0;
            int numKnownFilters = sizeof(knownFilters) / sizeof(std::string);

            while(filtNum < numKnownFilters &&
                    (std::string)pdsLab["FILTER_NAME"][filter] != knownFilters[filtNum]) {
                filtNum ++;
            }

            if(filtNum >= numKnownFilters) {
                throw iException::Message(iException::Pvl,
                                          "Nothing is known about the [" + pdsLab["FILTER_NAME"][filter] + "] filter. COLOROFFSET not possible.",
                                          _FILEINFO_);
            }
            else {
                padding[filter] = (colorOffset * filterHeight) * filtNum;
                maxPadding = max(maxPadding, padding[filter]);
            }
        }
        else {
            colorOffset = 0;
            padding[filter] = 0;
        }
    }

    // Output lines/samps.

    int numLines = (int)p.Lines() / numFilters + maxPadding;
    int numSamples = pdsLab.FindKeyword("LINE_SAMPLES", Pvl::Traverse);
    cubeHeight = numLines;

    outputCubes.push_back(new Isis::Cube());
    outputCubes.push_back(new Isis::Cube());

    outputCubes[0]->SetDimensions(numSamples, numLines, numFilters);
    outputCubes[1]->SetDimensions(numSamples, numLines, numFilters);

    Filename outputFile(ui.GetFilename("TO"));
    iString evenFile = outputFile.Path() + "/" + outputFile.Basename() + ".even.cub";
    iString oddFile = outputFile.Path() + "/" + outputFile.Basename() + ".odd.cub";

    outputCubes[0]->Create(evenFile);
    outputCubes[1]->Create(oddFile);

    if(ui.GetString("FLIP") == "AUTO") {
        flip = -1; // Flip is unknown, this let's us know we need to figure it out later
        flipDataBrick1 = new Isis::Brick(numSamples, filterHeight, numFilters, Isis::UnsignedByte);
        flipDataBrick2 = new Isis::Brick(numSamples, filterHeight, numFilters, Isis::UnsignedByte);
    }
    else if(ui.GetString("FLIP") == "YES") {
        flip = 1;
    }
    else {
        flip = 0;
    }

    writeOutputPadding();
    p.StartProcess(writeCubeOutput);

    // Add original labels
    OriginalLabel origLabel(pdsLab);

    std::vector<iString> framelets;

    framelets.push_back("Even");
    framelets.push_back("Odd");

    // Translate labels to every image and close output cubes before calling EndProcess
    for(unsigned int i = 0; i < outputCubes.size(); i++) {
        translateMarciLabels(pdsLab, *outputCubes[i]->Label());

        PvlObject &isisCube = outputCubes[i]->Label()->FindObject("IsisCube");
        isisCube.FindGroup("Instrument").AddKeyword(PvlKeyword("Framelets", framelets[i]));

        outputCubes[i]->Write(origLabel);
        delete outputCubes[i];
    }

    outputCubes.clear();

    if(flipDataBrick1 != NULL) {
        delete flipDataBrick1;
        delete flipDataBrick2;
        flipDataBrick1 = NULL;
        flipDataBrick2 = NULL;
    }

    p.EndProcess();
}
예제 #5
0
// Construct a BLOb to contain the Hirise main line suffix and prefix data
void SaveHiriseAncillaryData (ProcessImportPds &process, Cube *ocube) {

  vector<int> ConvertCalibrationPixels (int samples,
                                        Isis::PixelType pixelType,
                                        unsigned char *data);


  // Setup a Table to hold the main image prefix/suffix data
  TableField gap("GapFlag", TableField::Integer);
  TableField line("LineNumber", TableField::Integer);
  TableField buffer("BufferPixels", TableField::Integer, 12);
  TableField dark("DarkPixels", TableField::Integer, 16);

  TableRecord rec;
  rec += gap;
  rec += line;
  rec += buffer;
  rec += dark;

  Table table("HiRISE Ancillary", rec);
  table.SetAssociation (Table::Lines);

  // Loop through all the prefix and suffix data and construct the table records
  // In the case of HiRISE there is only one band so the outside vector
  // only contains one entry. The inside vector contains nl entries.
  vector<vector<char *> > pre = process.DataPrefix();
  vector<vector<char *> > suf = process.DataSuffix();
  vector<char *> prefix = pre.at(0);
  vector<char *> suffix = suf.at(0);

  Progress progress;
  progress.SetText("Saving ancillary data");
  progress.SetMaximumSteps(prefix.size());
  progress.CheckStatus();

  for (unsigned int l=0; l<prefix.size(); l++) {

    unsigned char *linePrefix = (unsigned char *)(prefix[l]);

    // Pull out the gap byte (in byte 0)
    rec[0] = (int)(linePrefix[0]);

    // Pull out the line number (bytes 3-5 3=MSB, 5=LSB)
    int lineCounter = 0;
    lineCounter += ((int)(linePrefix[3])) << 16;
    lineCounter += ((int)(linePrefix[4])) << 8;
    lineCounter += ((int)(linePrefix[5]));
    rec[1] = lineCounter;

    // Pull the 12 buffer pixels (same type as image data)
    // from the image prefix area
    linePrefix += 6;
    section = 3;
    rec[2] = ConvertCalibrationPixels (12, process.PixelType(),linePrefix);
    linePrefix += 12 * SizeOf(process.PixelType());

    // Pull the 16 dark pixels (same type as image data)
    // from the image suffix area
    unsigned char *lineSuffix = (unsigned char *)(suffix[l]);
    section = 5;
    rec[3] = ConvertCalibrationPixels (16, process.PixelType(),lineSuffix);
    lineSuffix += 16 * SizeOf(process.PixelType());

    // Add this record to the table
    table += rec;

    // Report the progress
    progress.CheckStatus();
  }

  // Add the table to the output cube
  ocube->Write(table);
}
예제 #6
0
void IsisMain ()
{
  ProcessImportPds p;
  Pvl pdsLabel;
  UserInterface &ui = Application::GetUserInterface();

  FileName inFile = ui.GetFileName("FROM");
  QString imageFile("");
  if (ui.WasEntered("IMAGE")) {
    imageFile = ui.GetFileName("IMAGE");
  }


  // Generate the housekeeping filenames
  QString hkLabel("");
  QString hkData("");
  if (ui.WasEntered("HKFROM") ) {
    hkLabel = ui.GetFileName("HKFROM");
  }
  else {
    hkLabel = inFile.originalPath() + "/" + inFile.baseName() + "_HK.LBL";
    // Determine the housekeeping file
    FileName hkFile(hkLabel);
    if (!hkFile.fileExists()) {
      hkFile = hkLabel.replace("_1B_", "_1A_");
      if (hkFile.fileExists()) hkLabel = hkFile.expanded();
    }
  }

  if (ui.WasEntered("HKTABLE")) {
    hkData = ui.GetFileName("HKTABLE");
  }

  QString instid;
  QString missid;

  try {
    Pvl lab(inFile.expanded());
    instid = (QString) lab.findKeyword ("CHANNEL_ID");
    missid = (QString) lab.findKeyword ("INSTRUMENT_HOST_ID");
  }
  catch (IException &e) {
    QString msg = "Unable to read [INSTRUMENT_ID] or [MISSION_ID] from input file [" +
                 inFile.expanded() + "]";
    throw IException(e, IException::Io,msg, _FILEINFO_);
  }

  instid = instid.simplified().trimmed();
  missid = missid.simplified().trimmed();
  if (missid != "DAWN" && instid != "VIS" && instid != "IR") {
    QString msg = "Input file [" + inFile.expanded() + "] does not appear to be a " +
                 "DAWN Visual and InfraRed Mapping Spectrometer (VIR) EDR or RDR file.";
    throw IException(IException::Unknown, msg, _FILEINFO_);
  }

  QString target;
  if (ui.WasEntered("TARGET")) {
    target = ui.GetString("TARGET");
  }

//  p.SetPdsFile (inFile.expanded(),imageFile,pdsLabel);
//  QString labelFile = ui.GetFileName("FROM");
  p.SetPdsFile (inFile.expanded(),imageFile,pdsLabel);
  p.SetOrganization(Isis::ProcessImport::BIP);
  Cube *outcube = p.SetOutputCube ("TO");
//  p.SaveFileHeader();

  Pvl labelPvl (inFile.expanded());

  p.StartProcess ();

  // Get the directory where the DAWN translation tables are.
  PvlGroup dataDir (Preference::Preferences().findGroup("DataDirectory"));
  QString transDir = (QString) dataDir["Dawn"] + "/translations/";

  // Create a PVL to store the translated labels in
  Pvl outLabel;

  // Translate the BandBin group
  FileName transFile (transDir + "dawnvirBandBin.trn");
  PvlTranslationManager bandBinXlater (labelPvl, transFile.expanded());
  bandBinXlater.Auto(outLabel);

  // Translate the Archive group
  transFile = transDir + "dawnvirArchive.trn";
  PvlTranslationManager archiveXlater (labelPvl, transFile.expanded());
  archiveXlater.Auto(outLabel);

  // Translate the Instrument group
  transFile = transDir + "dawnvirInstrument.trn";
  PvlTranslationManager instrumentXlater (labelPvl, transFile.expanded());
  instrumentXlater.Auto(outLabel);

  //  Update target if user specifies it
  if (!target.isEmpty()) {
    PvlGroup &igrp = outLabel.findGroup("Instrument",Pvl::Traverse);
    igrp["TargetName"] = target;
  }

  // Write the BandBin, Archive, and Instrument groups
  // to the output cube label
  outcube->putGroup(outLabel.findGroup("BandBin",Pvl::Traverse));
  outcube->putGroup(outLabel.findGroup("Archive",Pvl::Traverse));
  outcube->putGroup(outLabel.findGroup("Instrument",Pvl::Traverse));

  PvlGroup kerns("Kernels");
  if (instid == "VIS") {
    kerns += PvlKeyword("NaifFrameCode","-203211");
  } else if (instid == "IR") {
    kerns += PvlKeyword("NaifFrameCode","-203213");
  } else {
    QString msg = "Input file [" + inFile.expanded() + "] has an invalid " +
                 "InstrumentId.";
    throw IException(IException::Unknown, msg, _FILEINFO_);
  }
  outcube->putGroup(kerns);

  // Now handle generation of housekeeping data
 try {
   ImportPdsTable hktable(hkLabel, hkData);
   hktable.setType("ScetTimeClock", "CHARACTER");
   hktable.setType("ShutterStatus", "CHARACTER");
   hktable.setType("MirrorSin", "DOUBLE");
   hktable.setType("MirrorCos", "DOUBLE");
   Table hktab = hktable.importTable("ScetTimeClock,ShutterStatus,MirrorSin,MirrorCos",
                                      "VIRHouseKeeping");
   hktab.Label().addKeyword(PvlKeyword("SourceFile", hkLabel));
   outcube->write(hktab);
 }
 catch (IException &e) {
   QString mess = "Cannot read/open housekeeping data";
   throw IException(e, IException::User, mess, _FILEINFO_);
 }

  p.EndProcess ();
}
예제 #7
0
void IsisMain() {
  ProcessImportPds p;
  Pvl pdsLabel;
  UserInterface &ui = Application::GetUserInterface();

  FileName inFile = ui.GetFileName("FROM");
  QString instid;
  QString missid;

  try {
    Pvl lab(inFile.expanded());
    instid = (QString) lab.findKeyword("INSTRUMENT_ID");
    missid = (QString) lab.findKeyword("MISSION_ID");
  }
  catch(IException &e) {
    QString msg = "Unable to read [INSTRUMENT_ID] or [MISSION_ID] from input file [" +
                 inFile.expanded() + "]";
    throw IException(IException::Io, msg, _FILEINFO_);
  }

  instid = instid.simplified().trimmed();
  missid = missid.simplified().trimmed();
  if(missid != "DAWN" && instid != "FC1" && instid != "FC2") {
    QString msg = "Input file [" + inFile.expanded() + "] does not appear to be " +
                 "a DAWN Framing Camera (FC) EDR or RDR file.";
    throw IException(IException::Io, msg, _FILEINFO_);
  }

  QString target;
  if(ui.WasEntered("TARGET")) {
    target = ui.GetString("TARGET");
  }


  p.SetPdsFile(inFile.expanded(), "", pdsLabel);
  p.SetOrganization(Isis::ProcessImport::BSQ);
  QString tmpName = "$TEMPORARY/" + inFile.baseName() + ".tmp.cub";
  FileName tmpFile(tmpName);
  CubeAttributeOutput outatt = CubeAttributeOutput("+Real");
  p.SetOutputCube(tmpFile.expanded(), outatt);
  p.SaveFileHeader();

  Pvl labelPvl(inFile.expanded());

  p.StartProcess();
  p.EndProcess();

  ProcessBySample p2;
  CubeAttributeInput inatt;
  p2.SetInputCube(tmpFile.expanded(), inatt);
  Cube *outcube = p2.SetOutputCube("TO");

  // Get the directory where the DAWN translation tables are.
  PvlGroup dataDir(Preference::Preferences().findGroup("DataDirectory"));
  QString transDir = (QString) dataDir["Dawn"] + "/translations/";

  // Create a PVL to store the translated labels in
  Pvl outLabel;

  // Translate the BandBin group
  FileName transFile(transDir + "dawnfcBandBin.trn");
  PvlTranslationManager bandBinXlater(labelPvl, transFile.expanded());
  bandBinXlater.Auto(outLabel);

  // Translate the Archive group
  transFile = transDir + "dawnfcArchive.trn";
  PvlTranslationManager archiveXlater(labelPvl, transFile.expanded());
  archiveXlater.Auto(outLabel);

  // Translate the Instrument group
  transFile = transDir + "dawnfcInstrument.trn";
  PvlTranslationManager instrumentXlater(labelPvl, transFile.expanded());
  instrumentXlater.Auto(outLabel);

  //  Update target if user specifies it
  if (!target.isEmpty()) {
    PvlGroup &igrp = outLabel.findGroup("Instrument",Pvl::Traverse);
    igrp["TargetName"] = target;
  }

  // Write the BandBin, Archive, and Instrument groups
  // to the output cube label
  outcube->putGroup(outLabel.findGroup("BandBin", Pvl::Traverse));
  outcube->putGroup(outLabel.findGroup("Archive", Pvl::Traverse));
  outcube->putGroup(outLabel.findGroup("Instrument", Pvl::Traverse));

  // Set the BandBin filter name, center, and width values based on the
  // FilterNumber.
  PvlGroup &bbGrp(outLabel.findGroup("BandBin", Pvl::Traverse));
  int filtno = bbGrp["FilterNumber"];
  int center;
  int width;
  QString filtname;
  if(filtno == 1) {
    center = 700;
    width = 700;
    filtname = "Clear_F1";
  }
  else if(filtno == 2) {
    center = 555;
    width = 43;
    filtname = "Green_F2";
  }
  else if(filtno == 3) {
    center = 749;
    width = 44;
    filtname = "Red_F3";
  }
  else if(filtno == 4) {
    center = 917;
    width = 45;
    filtname = "NIR_F4";
  }
  else if(filtno == 5) {
    center = 965;
    width = 85;
    filtname = "NIR_F5";
  }
  else if(filtno == 6) {
    center = 829;
    width = 33;
    filtname = "NIR_F6";
  }
  else if(filtno == 7) {
    center = 653;
    width = 42;
    filtname = "Red_F7";
  }
  else if(filtno == 8) {
    center = 438;
    width = 40;
    filtname = "Blue_F8";
  }
  else {
    QString msg = "Input file [" + inFile.expanded() + "] has an invalid " +
                 "FilterNumber. The FilterNumber must fall in the range 1 to 8.";
    throw IException(IException::Io, msg, _FILEINFO_);
  }
  bbGrp.addKeyword(PvlKeyword("Center", toString(center)));
  bbGrp.addKeyword(PvlKeyword("Width", toString(width)));
  bbGrp.addKeyword(PvlKeyword("FilterName", filtname));
  outcube->putGroup(bbGrp);

  PvlGroup kerns("Kernels");
  if(instid == "FC1") {
    kerns += PvlKeyword("NaifFrameCode", toString(-203110-filtno));
  }
  else if(instid == "FC2") {
    kerns += PvlKeyword("NaifFrameCode", toString(-203120-filtno));
  }
  else {
    QString msg = "Input file [" + inFile.expanded() + "] has an invalid " +
                 "InstrumentId.";
    throw IException(IException::Unknown, msg, _FILEINFO_);
  }
  outcube->putGroup(kerns);

  p2.StartProcess(flipbyline);
  p2.EndProcess();

  QString tmp(tmpFile.expanded());
  QFile::remove(tmp);
}
예제 #8
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;
}
예제 #9
0
파일: hi2isis.cpp 프로젝트: novas0x2a/isis3
void IsisMain ()
{
    stretch.ClearPairs();

    for (int i=0; i<6; i++) {
        gapCount[i] = 0;
        suspectGapCount[i] = 0;
        invalidCount[i] = 0;
        lisCount[i] = 0;
        hisCount[i] = 0;
        validCount[i] = 0;
    }

    void TranslateHiriseEdrLabels (Filename &labelFile, Cube *);
    void SaveHiriseCalibrationData (ProcessImportPds &process, Cube *,
                                    Pvl &pdsLabel);
    void SaveHiriseAncillaryData (ProcessImportPds &process, Cube *);
    void FixDns8 (Buffer &buf);
    void FixDns16 (Buffer &buf);

    ProcessImportPds p;
    Pvl pdsLabel;
    UserInterface &ui = Application::GetUserInterface();

    // Get the input filename and make sure it is a HiRISE EDR
    Filename inFile = ui.GetFilename("FROM");
    iString id;
    bool projected;
    try {
        Pvl lab(inFile.Expanded());
        id = (string) lab.FindKeyword ("DATA_SET_ID");
        projected = lab.HasObject("IMAGE_MAP_PROJECTION");
    }
    catch (iException &e) {
        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
    if( projected ) {
        string msg = "[" + inFile.Name() + "] appears to be an rdr file.";
        msg += " Use pds2isis.";
        throw iException::Message(iException::User,msg, _FILEINFO_);
    }

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

    p.SetPdsFile (inFile.Expanded(), "", pdsLabel);

    // Make sure the data we need for the BLOBs is saved by the Process
    p.SaveFileHeader();
    p.SaveDataPrefix();
    p.SaveDataSuffix();

    // Let the Process create the output file but override any commandline
    // output bit type and min/max. It has to be 16bit for the rest of hi2isis
    // to run.
    // Setting the min/max to the 16 bit min/max keeps all the dns (including
    // the 8 bit special pixels from changing their value when they are mapped
    // to the 16 bit output.
    CubeAttributeOutput &outAtt = ui.GetOutputAttribute("TO");
    outAtt.PixelType (Isis::SignedWord);
    outAtt.Minimum((double)VALID_MIN2);
    outAtt.Maximum((double)VALID_MAX2);
    Cube *ocube = p.SetOutputCube(ui.GetFilename("TO"), outAtt);
    p.StartProcess ();
    TranslateHiriseEdrLabels (inFile, ocube);

    // Pull out the lookup table so we can apply it in the second pass
    // and remove it from the labels.
    // Add the UNLUTTED keyword to the instrument group so we know
    // if the lut has been used to convert back to 14 bit data
    PvlGroup &instgrp = ocube->GetGroup("Instrument");
    PvlKeyword lutKey = instgrp["LookupTable"];
    PvlSequence lutSeq;
    lutSeq = lutKey;

    // Set up the Stretch object with the info from the lookup table
    // If the first entry is (0,0) then no lut was applied.
    if ((lutKey.IsNull()) ||
            (lutSeq.Size()==1 && lutSeq[0][0]=="0" && lutSeq[0][1]=="0")) {
        stretch.AddPair(0.0, 0.0);
        stretch.AddPair(65536.0, 65536.0);
        instgrp.AddKeyword(PvlKeyword("Unlutted","TRUE"));
        instgrp.DeleteKeyword ("LookupTable");
    }
    // The user wants it unlutted
    else if (ui.GetBoolean("UNLUT")) {
        for (int i=0; i<lutSeq.Size(); i++) {
            stretch.AddPair(i, (((double)lutSeq[i][0] + (double)lutSeq[i][1]) / 2.0));
        }
        instgrp.AddKeyword(PvlKeyword("Unlutted","TRUE"));
        instgrp.DeleteKeyword ("LookupTable");
    }
    // The user does not want the data unlutted
    else {
        stretch.AddPair(0.0, 0.0);
        stretch.AddPair(65536.0, 65536.0);
        instgrp.AddKeyword(PvlKeyword("Unlutted","FALSE"));
    }
    ocube->PutGroup(instgrp);

    // Save the calibration and ancillary data as BLOBs. Both get run thru the
    // lookup table just like the image data.
    SaveHiriseCalibrationData (p, ocube, pdsLabel);
    SaveHiriseAncillaryData (p, ocube);

    // Save off the input bit type so we know how to process it on the
    // second pass below.
    Isis::PixelType inType = p.PixelType();

    // All finished with the ImportPds object
    p.EndProcess ();


    // Make another pass thru the data using the output file in read/write mode
    // This allows us to correct gaps, remap special pixels and accumulate some
    // counts
    lsbGap = ui.GetBoolean("LSBGAP");
    ProcessByLine p2;
    string ioFile = ui.GetFilename("TO");
    CubeAttributeInput att;
    p2.SetInputCube(ioFile, att, ReadWrite);
    p2.Progress()->SetText("Converting special pixels");
    section = 4;
    p2.StartProcess((inType == Isis::UnsignedByte) ? FixDns8 : FixDns16);
    p2.EndProcess();


    // Log the results of the image conversion
    PvlGroup results("Results");
    results += PvlKeyword ("From", inFile.Expanded());

    results += PvlKeyword ("CalibrationBufferGaps", gapCount[0]);
    results += PvlKeyword ("CalibrationBufferLIS", lisCount[0]);
    results += PvlKeyword ("CalibrationBufferHIS", hisCount[0]);
    results += PvlKeyword ("CalibrationBufferPossibleGaps", suspectGapCount[0]);
    results += PvlKeyword ("CalibrationBufferInvalid", invalidCount[0]);
    results += PvlKeyword ("CalibrationBufferValid", validCount[0]);

    results += PvlKeyword ("CalibrationImageGaps", gapCount[1]);
    results += PvlKeyword ("CalibrationImageLIS", lisCount[1]);
    results += PvlKeyword ("CalibrationImageHIS", hisCount[1]);
    results += PvlKeyword ("CalibrationImagePossibleGaps", suspectGapCount[1]);
    results += PvlKeyword ("CalibrationImageInvalid", invalidCount[1]);
    results += PvlKeyword ("CalibrationImageValid", validCount[1]);

    results += PvlKeyword ("CalibrationDarkGaps", gapCount[2]);
    results += PvlKeyword ("CalibrationDarkLIS", lisCount[2]);
    results += PvlKeyword ("CalibrationDarkHIS", hisCount[2]);
    results += PvlKeyword ("CalibrationDarkPossibleGaps", suspectGapCount[2]);
    results += PvlKeyword ("CalibrationDarkInvalid", invalidCount[2]);
    results += PvlKeyword ("CalibrationDarkValid", validCount[2]);

    results += PvlKeyword ("ObservationBufferGaps", gapCount[3]);
    results += PvlKeyword ("ObservationBufferLIS", lisCount[3]);
    results += PvlKeyword ("ObservationBufferHIS", hisCount[3]);
    results += PvlKeyword ("ObservationBufferPossibleGaps", suspectGapCount[3]);
    results += PvlKeyword ("ObservationBufferInvalid", invalidCount[3]);
    results += PvlKeyword ("ObservationBufferValid", validCount[3]);

    results += PvlKeyword ("ObservationImageGaps", gapCount[4]);
    results += PvlKeyword ("ObservationImageLIS", lisCount[4]);
    results += PvlKeyword ("ObservationImageHIS", hisCount[4]);
    results += PvlKeyword ("ObservationImagePossibleGaps", suspectGapCount[4]);
    results += PvlKeyword ("ObservationImageInvalid", invalidCount[4]);
    results += PvlKeyword ("ObservationImageValid", validCount[4]);

    results += PvlKeyword ("ObservationDarkGaps", gapCount[5]);
    results += PvlKeyword ("ObservationDarkLIS", lisCount[5]);
    results += PvlKeyword ("ObservationDarkHIS", hisCount[5]);
    results += PvlKeyword ("ObservationDarkPossibleGaps", suspectGapCount[5]);
    results += PvlKeyword ("ObservationDarkInvalid", invalidCount[5]);
    results += PvlKeyword ("ObservationDarkValid", validCount[5]);

    // Write the results to the log
    Application::Log(results);

    return;
}
예제 #10
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;
}
예제 #11
0
파일: hrsc2isis.cpp 프로젝트: corburn/ISIS
/**
 * 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();
}
예제 #12
0
void IsisMain() {
  colorOffset = 0;
  frameletLines.clear();
  outputCubes.clear();

  uveven = NULL;
  uvodd = NULL;
  viseven = NULL;
  visodd = NULL;

  ProcessImportPds p;
  Pvl pdsLab;

  UserInterface &ui = Application::GetUserInterface();
  QString fromFile = ui.GetFileName("FROM");

  flip = false;//ui.GetBoolean("FLIP");

  p.SetPdsFile(fromFile, "", pdsLab);
  ValidateInputLabels(pdsLab);
  inputCubeLines = p.Lines();

  lookupTable = Stretch();

  // read the lut if the option is on
  if(ui.GetBoolean("UNLUT") && pdsLab["LRO:LOOKUP_TABLE_TYPE"][0] == "STORED") {
    PvlKeyword lutKeyword = pdsLab["LRO:LOOKUP_CONVERSION_TABLE"];

    for(int i = 0; i < lutKeyword.size(); i ++) {
      IString lutPair = lutKeyword[i];
      lutPair.ConvertWhiteSpace();
      lutPair.Remove("() ");
      QString outValueMin = lutPair.Token(" ,").ToQt();
      QString outValueMax = lutPair.Token(" ,").ToQt();
      lookupTable.AddPair(i, (toDouble(outValueMin) + toDouble(outValueMax)) / 2.0);
    }
  }

  QString instModeId = pdsLab["INSTRUMENT_MODE_ID"];

  // this will be used to convert num input lines to num output lines,
  //   only changed for when both uv and vis exist (varying summing)
  double visOutputLineRatio = 1.0;
  double uvOutputLineRatio = 1.0;

  int numFilters = 0;
  if(ui.GetBoolean("COLOROFFSET")) {
    colorOffset = ui.GetInteger("COLOROFFSETSIZE");
  }

  // Determine our band information based on
  // INSTRUMENT_MODE_ID - FILTER_NUMBER is
  // only going to be used for BW images
  if(instModeId == "COLOR") {
    numFilters = 7;
    frameletLines.push_back(4);
    frameletLines.push_back(4);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);

    uveven  = new Cube();
    uvodd   = new Cube();
    viseven = new Cube();
    visodd  = new Cube();

    // 14 output lines (1 framelet) from 5vis/2uv lines
    visOutputLineRatio = 14.0 / (14.0 * 5.0 + 4.0 * 2.0);

    // 4 output lines (1 framelet) from 5vis/2uv lines
    uvOutputLineRatio = 4.0 / (14.0 * 5.0 + 4.0 * 2.0);
  }
  else if(instModeId == "VIS") {
    numFilters = 5;

    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);

    viseven = new Cube();
    visodd  = new Cube();

    // 14 output lines (1 framelet) from 5vis/2uv lines
    visOutputLineRatio = 14.0 / (14.0 * 5.0);
  }
  else if(instModeId == "UV") {
    numFilters = 2;

    frameletLines.push_back(4);
    frameletLines.push_back(4);

    uveven = new Cube();
    uvodd  = new Cube();

    // 4 output lines (1 framelet) from 2uv lines
    uvOutputLineRatio = 4.0 / (4.0 * 2.0);
  }
  else if(instModeId == "BW") {
    numFilters = 1;

    frameletLines.push_back(14);

    viseven = new Cube();
    visodd  = new Cube();
  }

  padding.resize(numFilters);


  for(int filter = 0; filter < numFilters; filter++) {
    padding[filter] = (colorOffset * frameletLines[filter]) * filter;

    // dont count UV for VIS offsetting
    if(instModeId == "COLOR" && filter > 1) {
      padding[filter] -= 2 * colorOffset * frameletLines[filter];
    }
  }

  FileName baseFileName(ui.GetFileName("TO"));

  if(uveven && uvodd) {
    // padding[1] is max padding for UV
    int numSamples = ((viseven) ? p.Samples() / 4 : p.Samples());
    numSamples     = 128; // UV is alway sum 4 so it is 128 samples
    int numLines   = (int)(uvOutputLineRatio * inputCubeLines + 0.5) + padding[1];
    int numBands   = 2;

    uveven->setDimensions(numSamples, numLines, numBands);
    uveven->setPixelType(Isis::Real);

    QString filename = baseFileName.path() + "/" + baseFileName.baseName() + ".uv.even.cub";
    uveven->create(filename);

    uvodd->setDimensions(numSamples, numLines, numBands);
    uvodd->setPixelType(Isis::Real);

    filename = baseFileName.path() + "/" + baseFileName.baseName() + ".uv.odd.cub";
    uvodd->create(filename);
  }

  if(viseven && visodd) {
    // padding[size-1] is max padding for vis (padding[0] or padding[4] or padding[6])
    int numSamples = p.Samples();
    int numLines   = (int)(visOutputLineRatio * inputCubeLines + 0.5) + padding[padding.size()-1];
    int numBands   = ((uveven) ? padding.size() - 2 : padding.size());

    viseven->setDimensions(numSamples, numLines, numBands);
    viseven->setPixelType(Isis::Real);

    QString filename = baseFileName.path() + "/" + baseFileName.baseName() + ".vis.even.cub";
    viseven->create(filename);

    visodd->setDimensions(numSamples, numLines, numBands);
    visodd->setPixelType(Isis::Real);

    filename = baseFileName.path() + "/" + baseFileName.baseName() + ".vis.odd.cub";
    visodd->create(filename);
  }

  Pvl isis3VisEvenLab, isis3VisOddLab, isis3UvEvenLab, isis3UvOddLab;
  TranslateLabels(pdsLab, isis3VisEvenLab, isis3VisOddLab, isis3UvEvenLab, isis3UvOddLab);

  writeNullsToFile();
  p.StartProcess(separateFramelets);
  p.EndProcess();

  // Add original labels
  OriginalLabel origLabel(pdsLab);

  int numFramelets = padding.size();
  PvlKeyword numFrameletsKeyword("NumFramelets", toString(numFramelets));

  if(uveven) {
    for(int grp = 0; grp < isis3UvEvenLab.groups(); grp++) {
      uveven->putGroup(isis3UvEvenLab.group(grp));
    }

    History history("IsisCube");
    history.AddEntry();
    uveven->write(history);
    uveven->write(origLabel);

    uveven->close();
    delete uveven;
    uveven = NULL;
  }

  if(uvodd) {
    for(int grp = 0; grp < isis3UvOddLab.groups(); grp++) {
      uvodd->putGroup(isis3UvOddLab.group(grp));
    }

    History history("IsisCube");
    history.AddEntry();
    uvodd->write(history);
    uvodd->write(origLabel);

    uvodd->close();
    delete uvodd;
    uvodd = NULL;
  }

  if(viseven) {
    for(int grp = 0; grp < isis3VisEvenLab.groups(); grp++) {
      viseven->putGroup(isis3VisEvenLab.group(grp));
    }

    History history("IsisCube");
    history.AddEntry();
    viseven->write(history);
    viseven->write(origLabel);

    viseven->close();
    delete viseven;
    viseven = NULL;
  }

  if(visodd) {
    for(int grp = 0; grp < isis3VisOddLab.groups(); grp++) {
      visodd->putGroup(isis3VisOddLab.group(grp));
    }

    History history("IsisCube");
    history.AddEntry();
    visodd->write(history);
    visodd->write(origLabel);

    visodd->close();
    delete visodd;
    visodd = NULL;
  }
}
예제 #13
0
파일: vims2isis.cpp 프로젝트: corburn/ISIS
//***********************************************************************
//   IsisMain()
//***********************************************************************
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();
  FileName in = ui.GetFileName("FROM");
  FileName outIr = ui.GetFileName("IR");
  FileName outVis = ui.GetFileName("VIS");
  Pvl lab(in.expanded());

  //Checks if in file is rdr
  if(lab.hasObject("IMAGE_MAP_PROJECTION")) {
    QString msg = "[" + in.name() + "] appears to be an rdr file.";
    msg += " Use pds2isis.";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  //Make sure it is a vims cube
  try {
    PvlObject qube(lab.findObject("QUBE"));
    QString id;
    id = (QString)qube["INSTRUMENT_ID"];
    id = id.simplified().trimmed();
    if(id != "VIMS") {
      QString msg = "Invalid INSTRUMENT_ID [" + id + "]";
      throw IException(IException::Unknown, msg, _FILEINFO_);
    }
  }
  catch(IException &e) {
    QString msg = "Input file [" + in.expanded() +
                 "] does not appear to be " +
                 "in VIMS EDR/RDR format";
    throw IException(IException::Io, msg, _FILEINFO_);
  }

  FileName tempname(in.baseName() + ".bsq.cub");
  Pvl pdsLab(in.expanded());

  // It's VIMS, let's figure out if it has the suffix data or not
  if(toInt(lab.findObject("QUBE")["SUFFIX_ITEMS"][0]) == 0) {
    // No suffix data, we can use processimportpds
    ProcessImportPds p;

    p.SetPdsFile(in.expanded(), "", pdsLab);
    // Set up the temporary output cube
    //The temporary cube is set to Real pixeltype, regardless of input pixel type
    Isis::CubeAttributeOutput outatt = CubeAttributeOutput("+Real");
    p.SetOutputCube(tempname.name(), outatt);
    p.StartProcess();
    p.EndProcess();
  }
  else {
    // We do it the hard way
    ReadVimsBIL(in.expanded(), lab.findObject("QUBE")["SUFFIX_ITEMS"], tempname.name());
  }

  // Create holder for original labels
  OriginalLabel origLabel(pdsLab);

  //Now separate the cubes
  ProcessByLine l;

  PvlGroup status("Results");

  //VIS cube
  const PvlObject &qube = lab.findObject("Qube");
  if(qube["SAMPLING_MODE_ID"][1] != "N/A") {
    CubeAttributeInput inattvis = CubeAttributeInput("+1-96");
    l.SetInputCube(tempname.name(), inattvis);
    Cube *oviscube = l.SetOutputCube("VIS");
    oviscube->write(origLabel);
    l.StartProcess(ProcessCube);
    TranslateVimsLabels(pdsLab, oviscube, VIS);
    l.EndProcess();

    status += PvlKeyword("VisCreated", "true");
  }
  else {
    status += PvlKeyword("VisCreated", "false");
  }

  //IR cube
  if(qube["SAMPLING_MODE_ID"][0] != "N/A") {
    CubeAttributeInput inattir = CubeAttributeInput("+97-352");
    l.SetInputCube(tempname.name(), inattir);
    Cube *oircube = l.SetOutputCube("IR");
    oircube->write(origLabel);
    l.StartProcess(ProcessCube);
    TranslateVimsLabels(pdsLab, oircube, IR);
    l.EndProcess();

    status += PvlKeyword("IrCreated", "true");
  }
  else {
    status += PvlKeyword("IrCreated", "false");
  }

  Application::Log(status);

  //Clean up
  QString tmp(tempname.expanded());
  QFile::remove(tmp);
}