Beispiel #1
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 #2
0
void IsisMain() {
  // We will be processing by brick
  ProcessByBrick p;
  
  Isis::Cube *amatrixCube=NULL; 
  Isis::Cube *bmatrixCube=NULL; 

  // Setup the user input for the input/output files and the option
  UserInterface &ui = Application::GetUserInterface();

  // Setup the input HiRise cube
  Isis::Cube *icube = p.SetInputCube("FROM");

  if (icube->Bands() != 1) {
    std::string msg = "Only single-band HiRise cubes can be calibrated";
    throw Isis::iException::Message(Isis::iException::Io,msg,_FILEINFO_);
  }

  //Get pertinent label information to determine which band of matrix cube to use
  HiLab hilab(icube);

  int ccd = hilab.getCcd();

  int channel = hilab.getChannel();

  if (channel != 0  && channel != 1) {
    std::string msg = "Only unstitched cubes can be calibrated";
    throw Isis::iException::Message(Isis::iException::Io,msg,_FILEINFO_);
  }
  int band = 1 + ccd*2 + channel;

  string option = ui.GetString("OPTION");

  // Set attributes (input band number) for the matrix cube(s);
  CubeAttributeInput att("+" + iString(band));

  // Determine the file specification to the matrix file(s) if defaulted
  // and open 
  
  if (ui.WasEntered ("MATRIX") ) {
    if (option == "GAIN") {
      string matrixFile = ui.GetFilename("MATRIX");
      amatrixCube = p.SetInputCube(matrixFile, att);
    }
    else if (option == "OFFSET") {
      string matrixFile = ui.GetFilename("MATRIX");
      bmatrixCube = p.SetInputCube(matrixFile, att);
    }
    else { //(option == "BOTH")
      std::string 
        msg = "The BOTH option cannot be used if a MATRIX is entered";
      throw Isis::iException::Message(Isis::iException::Io,msg,_FILEINFO_);
    }
  }
  else {
    int tdi = hilab.getTdi();
    int bin = hilab.getBin();

    if (option == "OFFSET" || option == "BOTH") {
      std::string bmatrixFile = "$mro/calibration";
      bmatrixFile += "/B_matrix_tdi";
      bmatrixFile += iString(tdi) + "_bin" + iString(bin);
      bmatrixCube = p.SetInputCube(bmatrixFile, att);
    }
    if (option == "GAIN" || option == "BOTH") {
       std::string amatrixFile = "$mro/calibration";
       amatrixFile += "/A_matrix_tdi";
       amatrixFile += iString(tdi) + "_bin" + iString(bin);
       amatrixCube = p.SetInputCube(amatrixFile, att);
    }
  }

  // Open the output file and set processing parameters
  Cube *ocube = p.SetOutputCube ("TO");
  p.SetWrap (true);
  p.SetBrickSize ( icube->Samples(), 1, 1);

  // Add the radiometry group if it is not there yet.  Otherwise
  // read the current value of the keyword CalibrationParameters.
  // Then delete the keyword and rewrite it after appending the
  // new value to it.  Do it this way to avoid multiple Calibration
  // Parameter keywords.
  PvlGroup calgrp;
  PvlKeyword calKey;

  if (ocube->HasGroup("Radiometry")) {
    calgrp = ocube->GetGroup ("Radiometry");

    if (calgrp.HasKeyword("CalibrationParameters")) {
      calKey = calgrp.FindKeyword("CalibrationParameters");
      calgrp.DeleteKeyword( "CalibrationParameters" );
    }
    else {
      calKey.SetName ("CalibrationParameters");
    }
  }
  else {
    calgrp.SetName("Radiometry");
    calKey.SetName ("CalibrationParameters");
  }

  string keyValue = option;
  if (option == "GAIN") {
    keyValue += ":" + amatrixCube->Filename();
  }
  else if (option == "OFFSET") {
    keyValue += ":" + bmatrixCube->Filename();
  }
  else { // "BOTH"
    keyValue += ":"+bmatrixCube->Filename()+":"+amatrixCube->Filename();
  }

  calKey += keyValue;
  calgrp += calKey;
  ocube->PutGroup(calgrp);

  // Start the processing based on the option
  if (option == "GAIN") {
    p.StartProcess(mult);
  }
  else if (option == "OFFSET") {
    p.StartProcess(sub);
  }
  else { //(option == "BOTH") 
    p.StartProcess(multSub);
  }

  // Cleanup
  p.EndProcess();
}
Beispiel #3
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);
}