Beispiel #1
0
void IsisMain() {
  
  UserInterface &ui = Application::GetUserInterface();
  bool append = ui.GetBoolean("APPEND");
  Pvl input (ui.GetFilename("FROM"));
  Pvl output;

  // Check to see if output file exists
  Filename outFile = ui.GetFilename("TO");
  if (outFile.exists()&&!append) {
    string msg = "Output file [" + outFile.Expanded() + "] already exists.";
    msg += " Append option set to False.";
    throw iException::Message(iException::User,msg,_FILEINFO_);
  }

  int numErrors = 0;
  // Search for errors and add to output
  for (int i =0; i < input.Objects(); i++) {
    PvlObject o = input.Object(i);
    if (o.HasGroup("Error")) {
      output.AddObject(o);
      numErrors++;
    }
  }
  PvlKeyword errors("TotalErrors",numErrors);
  output.AddKeyword(errors);
  // write output to file
  if (!append) {
    output.Write(outFile.Expanded());
  } else {
    output.Append(outFile.Expanded());
  }
  cout << errors << endl;
}
Beispiel #2
0
//Function to translate the labels
void TranslateLrocNacLabels ( Filename &labelFile, Cube *ocube ) {

    //Pvl to store the labels
    Pvl outLabel;
    //Set up the directory where the translations are
    PvlGroup dataDir(Preference::Preferences().FindGroup("DataDirectory"));
    iString transDir = (string) dataDir["Lro"] + "/translations/";
    Pvl labelPvl(labelFile.Expanded());

    //Translate the Instrument group
    Filename transFile(transDir + "lronacInstrument.trn");
    PvlTranslationManager instrumentXlator(labelPvl, transFile.Expanded());
    instrumentXlator.Auto(outLabel);

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

    // Set up the BandBin groups
    PvlGroup bbin("BandBin");
    bbin += PvlKeyword("FilterName", "BroadBand");
    bbin += PvlKeyword("Center", 0.650, "micrometers");
    bbin += PvlKeyword("Width", 0.150, "micrometers");

    Pvl lab(labelFile.Expanded());

    //Set up the Kernels group
    PvlGroup kern("Kernels");
    if (lab.FindKeyword("FRAME_ID")[0] == "LEFT")
        kern += PvlKeyword("NaifFrameCode", -85600);
    else
        kern += PvlKeyword("NaifFrameCode", -85610);

    PvlGroup inst = outLabel.FindGroup("Instrument", Pvl::Traverse);
    if (lab.FindKeyword("FRAME_ID")[0] == "LEFT") {
        inst.FindKeyword("InstrumentId") = "NACL";
        inst.FindKeyword("InstrumentName") = "LUNAR RECONNAISSANCE ORBITER NARROW ANGLE CAMERA LEFT";
        g_flip = false;
    }
    else {
        inst.FindKeyword("InstrumentId") = "NACR";
        inst.FindKeyword("InstrumentName") = "LUNAR RECONNAISSANCE ORBITER NARROW ANGLE CAMERA RIGHT";
    }

    inst += PvlKeyword("SpatialSumming", lab.FindKeyword("CROSSTRACK_SUMMING")[0] );
    inst += PvlKeyword("SampleFirstPixel", 0 );

    //Add all groups to the output cube
    ocube->PutGroup(inst);
    ocube->PutGroup(outLabel.FindGroup("Archive", Pvl::Traverse));
    ocube->PutGroup(bbin);
    ocube->PutGroup(kern);
}
Beispiel #3
0
void IsisMain () {
  // Grab the file to import
  UserInterface &ui = Application::GetUserInterface();
  Filename in = ui.GetFilename("FROM");
  Filename out = ui.GetFilename("TO");
 
  // Make sure it is a Clementine EDR
  bool projected;
  try {
    Pvl lab(in.Expanded());
    projected = lab.HasObject("IMAGE_MAP_PROJECTION");
    iString id;
    id = (string)lab["DATA_SET_ID"];
    id.ConvertWhiteSpace();
    id.Compress();
    id.Trim(" ");
    if (id.find("CLEM") == string::npos) {
      string msg = "Invalid DATA_SET_ID [" + id + "]";
      throw iException::Message(iException::Pvl,msg,_FILEINFO_);
    }
  }
  catch (iException &e) {
    string msg = "Input file [" + in.Expanded() + 
                 "] does not appear to be " +
                 "in Clementine EDR format";
    throw iException::Message(iException::Io,msg, _FILEINFO_);
  }

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

  //Decompress the file
  long int lines = 0;
  long int samps = 0;
  iString filename = in.Expanded();
  pdsi = PDSR((char *)filename.c_str(),&lines,&samps);

  ProcessByLine p;
  CubeAttributeOutput cubeAtt("+unsignedByte+1.0:254.0");
  Cube *ocube = p.SetOutputCube(ui.GetFilename("TO"), cubeAtt, pdsi->image_ncols, pdsi->image_nrows);
  p.StartProcess (WriteLine);
  TranslateLabels(in, ocube);
  p.EndProcess ();
}
Beispiel #4
0
void TranslateHiriseEdrLabels (Filename &labelFile, Cube *ocube) {

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

    // Get the directory where the MRO HiRISE translation tables are.
    PvlGroup dataDir (Preference::Preferences().FindGroup("DataDirectory"));
    iString transDir = (string) dataDir["Mro"] + "/translations/";

    // Get a filename for the HiRISE EDR label
    Pvl labelPvl (labelFile.Expanded());

    // Translate the Instrument group
    Filename transFile (transDir + "hiriseInstrument.trn");
    PvlTranslationManager instrumentXlater (labelPvl, transFile.Expanded());
    instrumentXlater.Auto (outLabel);

    // Translate the BandBin group
    transFile  = transDir + "hiriseBandBin.trn";
    PvlTranslationManager bandBinXlater (labelPvl, transFile.Expanded());
    bandBinXlater.Auto (outLabel);

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

    // Create the Instrument group keyword CcdId from the ProductId
    // SCS 28-03-06 Do it in the instrument translation table instead of here
//  PvlGroup &archiveGroup(outLabel.FindGroup("Archive", Pvl::Traverse));
//  iString productId = (string)archiveGroup.FindKeyword("ProductId");
//  productId.Token("_");
//  productId.Token("_");
//  productId = productId.Token("_");
//  outLabel.FindGroup("Instrument", Pvl::Traverse) +=
//      PvlKeyword ("CcdId", productId);

    // Create the Kernel Group
    PvlGroup kerns("Kernels");
    kerns += PvlKeyword("NaifIkCode", "-74699");

    // Write the Instrument, BandBin, Archive, and Kernels groups to the output
    // cube label
    ocube->PutGroup (outLabel.FindGroup("Instrument", Pvl::Traverse));
    ocube->PutGroup (outLabel.FindGroup("BandBin", Pvl::Traverse));
    ocube->PutGroup (outLabel.FindGroup("Archive", Pvl::Traverse));
    ocube->PutGroup (kerns);
}
Beispiel #5
0
void IsisMain() {

  //Get user parameters
  UserInterface &ui = Application::GetUserInterface();
  Filename inFile = ui.GetFilename("FROM");
  int numberOfLines = ui.GetInteger("NL");
  int lineOverlap   = ui.GetInteger("OVERLAP");

  //Throws exception if user is dumb
  if ( lineOverlap >= numberOfLines ) {
    throw iException::Message( iException::User, "The Line Overlap (OVERLAP) must be less than the Number of Lines (LN).", _FILEINFO_ );
  }

  //Opens the cube
  Cube cube;
  cube.Open( inFile.Expanded() );

  //Loops through, cropping as desired
  int cropNum = 1;
  int startLine = 1;
  bool hasReachedEndOfCube = false;
  while ( startLine <= cube.Lines()  &&  not hasReachedEndOfCube ) {
    //! Sets up the proper paramaters for running the crop program
    string parameters = "FROM=" + inFile.Expanded() +
        " TO=" + inFile.Path() + "/" + inFile.Basename() + ".segment" + iString(cropNum) + ".cub"
        + " LINE=" + iString(startLine) + " NLINES=";

    if ( startLine + numberOfLines > cube.Lines() ) {
      parameters += iString( cube.Lines() - ( startLine - 1 ) );
      hasReachedEndOfCube = true;
    }
    else {
      parameters += iString(numberOfLines);
    }
    Isis::iApp ->Exec("crop",parameters);
    //The starting line for next crop
    startLine = 1 + cropNum * ( numberOfLines - lineOverlap );
    cropNum++;
  }
}
Beispiel #6
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();
}
Beispiel #7
0
void TranslateLabels (Filename in, Cube *ocube) {
  // Get the directory where the Clementine translation tables are.
  PvlGroup &dataDir = Preference::Preferences().FindGroup("DataDirectory");

  // Transfer the instrument group to the output cube
  iString transDir = (string) dataDir["clementine1"];
  Filename transFile (transDir + "/translations/clementine.trn");

  Pvl pdsLab(in.Expanded());
  PvlTranslationManager labelXlater (pdsLab, transFile.Expanded());

  // Pvl outputLabels;
  Pvl *outputLabel = ocube->Label();
  labelXlater.Auto(*(outputLabel));

  //Instrument group
  PvlGroup inst = outputLabel->FindGroup ("Instrument",Pvl::Traverse);

  PvlKeyword &startTime = inst.FindKeyword("StartTime");
  startTime.SetValue( startTime[0].substr(0, startTime[0].size()-1));

  // Old PDS labels used keyword INSTRUMENT_COMPRESSION_TYPE & PDS Labels now use ENCODING_TYPE
  if(pdsLab.FindObject("Image").HasKeyword("InstrumentCompressionType")){
    inst += PvlKeyword("EncodingFormat",(string) pdsLab.FindObject("Image")["InstrumentCompressionType"]);
  }
  else {
    inst += PvlKeyword("EncodingFormat",(string) pdsLab.FindObject("Image")["EncodingType"]);
  }

  if (((string)inst["InstrumentId"]) == "HIRES") {
    inst += PvlKeyword("MCPGainModeID", (string)pdsLab["MCP_Gain_Mode_ID"], "");
  }

  ocube->PutGroup(inst);

  PvlGroup bBin = outputLabel->FindGroup ("BandBin", Pvl::Traverse);
  std::string filter = pdsLab["FilterName"];
  if (filter != "F") {
    //Band Bin group
    double center = pdsLab["CenterFilterWavelength"];
    center /= 1000.0;
    bBin.FindKeyword("Center").SetValue(center,"micrometers");
  }
  double width = pdsLab["Bandwidth"];
  width /= 1000.0;
  bBin.FindKeyword("Width").SetValue(width,"micrometers");
  ocube->PutGroup(bBin);

  //Kernel group
  PvlGroup kern("Kernels");
  if (((string)inst["InstrumentId"]) == "HIRES") {
    kern += PvlKeyword("NaifFrameCode","-40001");
  }
  if (((string)inst["InstrumentId"]) == "UVVIS") {
    kern += PvlKeyword("NaifFrameCode","-40002");
  }
  if (((string)inst["InstrumentId"]) == "NIR") {
    kern += PvlKeyword("NaifFrameCode","-40003");
  }
  if (((string)inst["InstrumentId"]) == "LWIR") {
    kern += PvlKeyword("NaifFrameCode","-40004");
  }
  ocube->PutGroup(kern);

  OriginalLabel org(pdsLab);
  ocube->Write(org);
}
Beispiel #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;
}
Beispiel #9
0
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;
}
Beispiel #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;
}
Beispiel #11
0
void TranslateLabels(Pvl &pdsLabel, Cube *ocube) {
  // Get the directory where the MOC translation tables are.
  PvlGroup &dataDir = Preference::Preferences().FindGroup("DataDirectory");

  // Transfer the instrument group to the output cube
  iString transDir = (string) dataDir["Galileo"];
  Filename transFile (transDir + "/translations/galileoSsi.trn");

  // Get the translation manager ready
  PvlTranslationManager labelXlater (pdsLabel, transFile.Expanded());
  // Pvl outputLabels;
  Pvl *outputLabel = ocube->Label();
  labelXlater.Auto(*(outputLabel));

  //Add to the Archive Group
  PvlGroup &arch = outputLabel->FindGroup("Archive",Pvl::Traverse);
  PvlGroup &inst = outputLabel->FindGroup("Instrument",Pvl::Traverse);
  arch.AddKeyword(PvlKeyword("DataType","RADIANCE"));
  string CTC = (string) arch.FindKeyword("ObservationId");
  string CTCout = CTC.substr(0,2);
  arch.AddKeyword(PvlKeyword("CalTargetCode",CTCout));

  // Add to the Instrument Group
  iString itest =(string) inst.FindKeyword("StartTime");
  itest.Remove("Z");
  inst.FindKeyword("StartTime").SetValue(itest);
  //change exposure duration to seconds
  double expDur = inst.FindKeyword("exposureDuration");
  double expDurOut = expDur / 1000.0;
  inst.FindKeyword("exposureDuration").SetValue(expDurOut,"seconds");
  inst.AddKeyword(PvlKeyword("FrameDuration",
                     (string) pdsLabel["frameDuration"],"seconds"));

  //Calculate the Frame_Rate_Id keyword
  string frameModeId = "FULL";
  int summingMode = 1;

  if(summed) {
    frameModeId = "SUMMATION";
    summingMode = 2;
  }

  inst.AddKeyword(PvlKeyword("Summing",summingMode));
  inst.AddKeyword(PvlKeyword("FrameModeId",frameModeId));

  // Create the Band bin Group
  PvlGroup &bandBin = outputLabel->FindGroup("BandBin",Pvl::Traverse);
  string filterName = pdsLabel["FILTER_NAME"];
  string waveLength = "";
  string width = "";
  if (filterName == "CLEAR") {
    waveLength = "0.611";
    width = ".44";
  }
  if (filterName == "VIOLET") {
    waveLength = "0.404";
    width = ".05";
  }
  if (filterName == "GREEN") {
    waveLength = "0.559";
    width = ".06";
  }
  if (filterName == "RED") {
    waveLength = "0.671";
    width = ".06";
  }
  if (filterName == "IR-7270") {
    waveLength = "0.734";
    width = ".01";
  }
  if (filterName == "IR-7560") {
    waveLength = "0.756";
    width = ".018";
  }
  if (filterName == "IR-8890") {
    waveLength = "0.887";
    width = ".116";
  }
  if (filterName == "INFRARED") {
     waveLength = "0.986";
     width = ".04";
  }
  bandBin.AddKeyword(PvlKeyword("Center",waveLength, "micrometers"));
  bandBin.AddKeyword(PvlKeyword("Width",width,"micrometers"));

  //create the kernel group
  PvlGroup kern("Kernels");
  kern += PvlKeyword("NaifFrameCode",-77001);
  ocube->PutGroup(kern);
}