Beispiel #1
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 #2
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 ();
}
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);
}
Beispiel #4
0
void IsisMain() {
  // Open the input cube
  Process p;
  UserInterface &ui = Application::GetUserInterface();
  CubeAttributeInput cai;
  Cube *icube = p.SetInputCube(ui.GetFilename("FROM"), cai, ReadWrite);

  // Make sure at least one CK & SPK quality was selected
  if (!ui.GetBoolean("CKPREDICTED") && !ui.GetBoolean("CKRECON") && !ui.GetBoolean("CKSMITHED") && !ui.GetBoolean("CKNADIR")) {
    string msg = "At least one CK quality must be selected";
    throw iException::Message(iException::User,msg,_FILEINFO_);
  }
  if (!ui.GetBoolean("SPKPREDICTED") && !ui.GetBoolean("SPKRECON") && !ui.GetBoolean("SPKSMITHED")) {
    string msg = "At least one SPK quality must be selected";
    throw iException::Message(iException::User,msg,_FILEINFO_);
  }

  // Make sure it is not projected
  Projection *proj = NULL;
  try {
    proj = icube->Projection();
  } catch (iException &e) {
    proj = NULL;
    e.Clear();
  }

  if (proj != NULL) {
    string msg = "Can not initialize SPICE for a map projected cube";
    throw iException::Message(iException::User,msg,_FILEINFO_);
  }

  Pvl lab = *icube->Label();

  // if cube has existing polygon delete it
  if (icube->Label()->HasObject("Polygon")) {
    icube->Label()->DeleteObject("Polygon");
  }

  // Set up for getting the mission name
  // Get the directory where the system missions translation table is.
  string transFile = p.MissionData("base", "translations/MissionName2DataDir.trn");

  // Get the mission translation manager ready
  PvlTranslationManager missionXlater (lab, transFile);

  // Get the mission name so we can search the correct DB's for kernels
  string mission = missionXlater.Translate ("MissionName");

  // Get system base kernels
  unsigned int allowed = 0;
  unsigned int allowedCK = 0;
  unsigned int allowedSPK = 0;
  if (ui.GetBoolean("CKPREDICTED"))  allowedCK |= spiceInit::kernelTypeEnum("PREDICTED");
  if (ui.GetBoolean("CKRECON"))      allowedCK |= spiceInit::kernelTypeEnum("RECONSTRUCTED");
  if (ui.GetBoolean("CKSMITHED"))    allowedCK |= spiceInit::kernelTypeEnum("SMITHED");
  if (ui.GetBoolean("CKNADIR"))      allowedCK |= spiceInit::kernelTypeEnum("NADIR");
  if (ui.GetBoolean("SPKPREDICTED")) allowedSPK |= spiceInit::kernelTypeEnum("PREDICTED");
  if (ui.GetBoolean("SPKRECON"))     allowedSPK |= spiceInit::kernelTypeEnum("RECONSTRUCTED");
  if (ui.GetBoolean("SPKSMITHED"))   allowedSPK |= spiceInit::kernelTypeEnum("SMITHED");
  KernelDb baseKernels (allowed);
  KernelDb ckKernels (allowedCK);
  KernelDb spkKernels (allowedSPK);

  baseKernels.LoadSystemDb(mission);
  ckKernels.LoadSystemDb(mission);
  spkKernels.LoadSystemDb(mission);

  Kernel lk, pck, targetSpk, fk, ik, sclk, spk, iak, dem, exk;
  std::priority_queue< Kernel > ck;
  lk        = baseKernels.LeapSecond(lab);
  pck       = baseKernels.TargetAttitudeShape(lab);
  targetSpk = baseKernels.TargetPosition(lab);
  ik        = baseKernels.Instrument(lab);
  sclk      = baseKernels.SpacecraftClock(lab);
  iak       = baseKernels.InstrumentAddendum(lab);
  fk        = ckKernels.Frame(lab);
  ck        = ckKernels.SpacecraftPointing(lab);
  spk       = spkKernels.SpacecraftPosition(lab);

  if (ui.GetBoolean("CKNADIR")) {
    // Only add nadir if no spacecraft pointing found
    std::vector<std::string> kernels;
    kernels.push_back("Nadir");
    ck.push(Kernel((spiceInit::kernelTypes)0, kernels));
  }

  // Get user defined kernels and override ones already found
  GetUserEnteredKernel("LS", lk);
  GetUserEnteredKernel("PCK", pck);
  GetUserEnteredKernel("TSPK", targetSpk);
  GetUserEnteredKernel("FK", fk);
  GetUserEnteredKernel("IK", ik);
  GetUserEnteredKernel("SCLK", sclk);
  GetUserEnteredKernel("SPK", spk);
  GetUserEnteredKernel("IAK", iak);
  GetUserEnteredKernel("EXTRA", exk);

  // Get shape kernel
  if (ui.GetString ("SHAPE") == "USER") {
    GetUserEnteredKernel("MODEL", dem);
  } else if (ui.GetString("SHAPE") == "SYSTEM") {
    dem = baseKernels.Dem(lab);
  }

  bool kernelSuccess = false;

  if (ck.size() == 0 && !ui.WasEntered("CK")) {
    throw iException::Message(iException::Camera, 
                              "No Camera Kernel found for the image ["+ui.GetFilename("FROM")
                              +"]", 
                              _FILEINFO_);
  }
  else if(ui.WasEntered("CK")) {
    // ck needs to be array size 1 and empty kernel objects
    while(ck.size()) ck.pop();
    ck.push(Kernel());
  }

  while(ck.size() != 0 && !kernelSuccess) {
    Kernel realCkKernel = ck.top();
    ck.pop();

    if (ui.WasEntered("CK")) {
      ui.GetAsString("CK", realCkKernel.kernels);
    }

    // Merge SpacecraftPointing and Frame into ck
    for (int i = 0; i < fk.size(); i++) {
      realCkKernel.push_back(fk[i]);
    }

    kernelSuccess = TryKernels(icube, p, lk, pck, targetSpk,
                   realCkKernel, fk, ik, sclk, spk, iak, dem, exk);
  }

  if(!kernelSuccess) {
    throw iException::Message(iException::Camera, 
                              "Unable to initialize camera model", 
                              _FILEINFO_);
  }

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