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; }
/** * 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(); }
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; }
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; } }