Loading isis/src/base/objs/ProcessExportPds4/ProcessExportPds4.cpp +250 −63 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ namespace Isis { ProcessExportPds4::ProcessExportPds4() { m_lid = ""; m_imageType = StandardImage; qSetGlobalQHashSeed(1031); // hash seed to force consistent output Loading @@ -68,6 +69,7 @@ namespace Isis { QDomProcessingInstruction header = m_domDoc->createProcessingInstruction("xml-model", xmlModel); m_domDoc->appendChild(header); } Loading @@ -87,24 +89,19 @@ namespace Isis { * @return @b QDomDocument The output PDS4 label. */ QDomDocument &ProcessExportPds4::StandardPds4Label() { if (InputCubes.size() == 0) { QString msg("Must set an input cube before creating a PDS4 label."); throw IException(IException::Programmer, msg, _FILEINFO_); } else { if (m_domDoc->documentElement().isNull()) { QDomElement root = m_domDoc->createElement("Product_Observational"); root.setAttribute("xmlns", "http://pds.nasa.gov/pds4/pds/v1"); root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.setAttribute("xsi:schemaLocation", "http://pds.nasa.gov/pds4/pds/v1 http://pds.nasa.gov/pds4/pds/v1"); m_domDoc->appendChild(root); } CreateImageLabel(); translateUnits(*m_domDoc); return *m_domDoc; } /** * Create a standard PDS4 image label from the input cube. * * @return @b QDomDocument The output PDS4 label. */ void ProcessExportPds4::setImageType(ImageType imageType) { m_imageType = imageType; } Loading @@ -118,6 +115,18 @@ namespace Isis { * Array_3D_Spectrum. */ void ProcessExportPds4::CreateImageLabel() { if (InputCubes.size() == 0) { QString msg("Must set an input cube before creating a PDS4 label."); throw IException(IException::Programmer, msg, _FILEINFO_); } if (m_domDoc->documentElement().isNull()) { QDomElement root = m_domDoc->createElement("Product_Observational"); root.setAttribute("xmlns", "http://pds.nasa.gov/pds4/pds/v1"); root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.setAttribute("xsi:schemaLocation", "http://pds.nasa.gov/pds4/pds/v1 http://pds.nasa.gov/pds4/pds/v1"); m_domDoc->appendChild(root); } try { // <Product_Observational> Loading Loading @@ -397,36 +406,212 @@ namespace Isis { * */ void ProcessExportPds4::standardBandBin() { Pvl *inputLabel = InputCubes[0]->label(); if ( !inputLabel->findObject("IsisCube").hasGroup("BandBin") ) return; // Spectra // Get the input Isis cube label and find the BandBin group if it has one Pvl *inputLabel = InputCubes[0]->label(); QString imageObject = imageObjectType(*inputLabel); QString translationFile = "$base/translations/"; if (m_imageType == StandardImage) { translationFile += "pds4ExportBandBinImage.trn"; } else if (m_imageType == UniformlySampledSpectrum) { translationFile += "pds4ExportBandBinSpectrumUniform.trn"; } else if (m_imageType == BinSetSpectrum) { translationFile += "pds4ExportBandBinSpectrumBinSet.trn"; } FileName translationFileName(translationFile); PvlToXmlTranslationManager xlator(*inputLabel, translationFileName.expanded()); xlator.Auto(*m_domDoc); if (imageObject.compare("Array_3D_Spectrum") == 0) { if (m_imageType == StandardImage) { // Add header info addSchema("PDS4_IMG_1900.sch", "PDS4_IMG_1900.xsd", "xmlns:img", "http://pds.nasa.gov/pds4/img/v1"); } else { // spectral PvlGroup bandBinGroup = inputLabel->findObject("IsisCube").findGroup("BandBin"); // Add header info addSchema("PDS4_SP_1100.sch", "PDS4_SP_1100.xsd", "xmlns:sp", "http://pds.nasa.gov/pds4/sp/v1"); // fix multi-valued bandbin info QStringList xmlPath; xmlPath << "Product_Observational" << "Observation_Area" << "Discipline_Area" << "sp:Spectral_Characteristics"; QDomElement baseElement = m_domDoc->documentElement(); QDomElement spectralCharElement = getElement(xmlPath, baseElement); // Axis_Bin_Set for variable bin widths // required - bin_sequence_number, center_value, bin_width // optional - detector_number, grating_position, original_bin_number, scaling_factor, value_offset, Filter // ... see schema for more... if (m_imageType == BinSetSpectrum) { PvlKeyword center; if (bandBinGroup.hasKeyword("Center")) { center = bandBinGroup["Center"]; } else if (bandBinGroup.hasKeyword("FilterCenter")) { center = bandBinGroup["FilterCenter"]; } else { QString msg = "Unable to translate BandBin info for BinSetSpectrum. " "Translation for PDS4 required value [center_value] not found."; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlKeyword width; if (bandBinGroup.hasKeyword("Width")) { width = bandBinGroup["Width"]; } else if (bandBinGroup.hasKeyword("FilterWidth")) { width = bandBinGroup["FilterWidth"]; } else { QString msg = "Unable to translate BandBin info for BinSetSpectrum. " "Translation for PDS4 required value [bin_width] not found."; throw IException(IException::Programmer, msg, _FILEINFO_); } if ( (imageObject.compare("Array_2D_Image") == 0) || (imageObject.compare("Array_3D_Image") == 0) ) { // Add header info addSchema("PDS4_IMG_1900.sch", "PDS4_IMG_1900.xsd", "xmlns:img", "http://pds.nasa.gov/pds4/img/v1"); QString units = center.unit(); if (!width.unit().isEmpty() ) { if (units.isEmpty()) { units = width.unit(); } if (units.compare(width.unit(), Qt::CaseInsensitive) != 0) { QString msg = "Unable to translate BandBin info for BinSetSpectrum. " "Unknown or unmatching units for [center_value] and [bin_width]."; throw IException(IException::Programmer, msg, _FILEINFO_); } } QString translationFile = "$base/translations/pds4ExportBandBin"; translationFile += imageObject.remove(0,9); // remove first 9 characters: Array_2D_ or Array_3D_ translationFile += ".trn"; FileName translationFileName(translationFile); PvlKeyword originalBand; if (bandBinGroup.hasKeyword("OriginalBand")) { originalBand = bandBinGroup["OriginalBand"]; } PvlKeyword name; if (bandBinGroup.hasKeyword("Name")) { name = bandBinGroup["Name"]; } else if (bandBinGroup.hasKeyword("FilterName")) { name = bandBinGroup["FilterName"]; } else if (bandBinGroup.hasKeyword("FilterId")) { name = bandBinGroup["FilterId"]; } PvlKeyword number; if (bandBinGroup.hasKeyword("Number")) { number = bandBinGroup["Number"]; } else if (bandBinGroup.hasKeyword("FilterNumber")) { number = bandBinGroup["FilterNumber"]; } PvlToXmlTranslationManager xlator(*inputLabel, translationFileName.expanded()); xlator.Auto(*m_domDoc); QDomElement axisBinSetElement = spectralCharElement.firstChildElement("sp:Axis_Bin_Set"); if (axisBinSetElement.isNull()) { axisBinSetElement = m_domDoc->createElement("sp:Axis_Bin_Set"); spectralCharElement.appendChild(axisBinSetElement); } int bands = (int)inputLabel->findObject("IsisCube") .findObject("Core") .findGroup("Dimensions") .findKeyword("Bands"); for (int i = 0; i < bands; i++) { QDomElement bin = m_domDoc->createElement("sp:Bin"); axisBinSetElement.appendChild(bin); QDomElement binSequenceNumber = m_domDoc->createElement("sp:bin_sequence_number"); PvlToXmlTranslationManager::setElementValue(binSequenceNumber, toString(i+1)); bin.appendChild(binSequenceNumber); QDomElement centerValue = m_domDoc->createElement("sp:center_value"); PvlToXmlTranslationManager::setElementValue(centerValue, center[i], units); bin.appendChild(centerValue); QDomElement binWidth = m_domDoc->createElement("sp:bin_width"); if (width.size() == bands) { PvlToXmlTranslationManager::setElementValue(binWidth, width[i] , units); } else { PvlToXmlTranslationManager::setElementValue(binWidth, width[0] , units); } bin.appendChild(binWidth); QDomElement originalBinNumber = m_domDoc->createElement("sp:original_bin_number"); if (originalBand.size() > 0) { PvlToXmlTranslationManager::setElementValue(originalBinNumber, originalBand[i]); bin.appendChild(originalBinNumber); } if (name.size() > 0 || number.size() > 0) { QDomElement filter = m_domDoc->createElement("sp:Filter"); bin.appendChild(filter); if (name.size() > 0) { QDomElement filterName = m_domDoc->createElement("sp:filter_name"); PvlToXmlTranslationManager::setElementValue(filterName, name[i]); filter.appendChild(filterName); } if (number.size() > 0) { QDomElement filterNumber= m_domDoc->createElement("sp:filter_number"); PvlToXmlTranslationManager::setElementValue(filterNumber, number[i]); filter.appendChild(filterNumber); } } } } else if (m_imageType == UniformlySampledSpectrum) { // Axis_Uniformly_Sampled // required - sampling_parameter_type (frequency, wavelength, wavenumber) // sampling_interval (units Hz, Angstrom, cm**-1, respectively) // bin_width (units Hz, Angstrom, cm**-1, respectively) // first_center_value (units Hz, Angstrom, cm**-1, respectively) // last_center_value (units Hz, Angstrom, cm**-1, respectively) // Local_Internal_Reference // Local_Internal_Reference:local_reference_type = spectral_characteristics_to_array_axis // Local_Internal_Reference:local_identifier_reference, // 1. At least one Axis_Array:axis_name must match the // value of the local_identifier_reference in the // Axis_Uniformly_Sampled. // Set Axis_Uniformly_Sampled:local_identifier_reference = Axis_Array:axis_name = Band // 2. At least one Array_3D_Spectrum:local_identifier must match // the value of the local_identifier_reference in the // Spectral_Characteristics. // Set Spectral_Characteristics:local_identifier_reference = Array_3D_Spectrum:local_identifier = Spectral_Array_Object // Local_Internal_Reference:local_reference_type = spectral_characteristics_to_array_axis PvlKeyword center("Center"); if (bandBinGroup.hasKeyword("FilterCenter")) { center = bandBinGroup["FilterCenter"]; } else if (bandBinGroup.hasKeyword("Center")) { center = bandBinGroup["Center"]; } else { QString msg = "Unable to translate BandBin info for UniformlySpacedSpectrum. " "Translation for PDS4 required value [last_center_value] not found."; throw IException(IException::Programmer, msg, _FILEINFO_); } QString lastCenter = center[center.size() - 1]; QDomElement axisBinSetElement = spectralCharElement.firstChildElement("sp:Axis_Uniformly_Sampled"); if (axisBinSetElement.isNull()) { axisBinSetElement = m_domDoc->createElement("sp:Axis_Uniformly_Sampled"); spectralCharElement.appendChild(axisBinSetElement); } QDomElement lastCenterElement = m_domDoc->createElement("sp:last_center_value"); PvlToXmlTranslationManager::setElementValue(lastCenterElement, lastCenter); spectralCharElement.appendChild(lastCenterElement); } } } Loading @@ -437,10 +622,32 @@ namespace Isis { */ void ProcessExportPds4::fileAreaObservational() { Pvl *inputLabel = InputCubes[0]->label(); QString imageObject = imageObjectType(*inputLabel); QString imageObject = ""; QString translationFile = "$base/translations/pds4Export"; if (m_imageType == StandardImage) { int bands = (int)inputLabel->findObject("IsisCube") .findObject("Core") .findGroup("Dimensions") .findKeyword("Bands"); if (bands > 1) { imageObject = "Array_3D_Image"; } else { imageObject = "Array_2D_Image"; } translationFile += QString(imageObject).remove('_'); } else { imageObject = "Array_3D_Spectrum"; translationFile += QString(imageObject).remove('_'); if (m_imageType == UniformlySampledSpectrum) { translationFile += "Uniform"; } else if (m_imageType == BinSetSpectrum) { translationFile += "BinSet"; } } translationFile += ".trn"; FileName translationFileName(translationFile); Loading Loading @@ -513,26 +720,6 @@ namespace Isis { } QString ProcessExportPds4::imageObjectType(Pvl &inputLabel) { // not sure how to easily determine whether an isis3 cube should be // exported as spectral. for now, we will only export image arrays #if 0 if (inputLabel.findObject("IsisCube").hasGroup("BandBin")) { return "Array_3D_Spectrum"; } #endif int bands = (int) inputLabel.findObject("IsisCube") .findObject("Core") .findGroup("Dimensions") .findKeyword("Bands"); if (bands > 1) { return "Array_3D_Image"; } return "Array_2D_Image"; } /** * Adds necessary information to the xml header for a pds4 class. * Loading Loading @@ -651,13 +838,13 @@ namespace Isis { // PvlToXmlTranslationManager::setElementValue(creationElement, ); // fileElement.appendChild(creationElement); ofstream oLabel(labelName.toLatin1().data()); OutputLabel(oLabel); oLabel.close(); ofstream outputLabel(labelName.toLatin1().data()); OutputLabel(outputLabel); outputLabel.close(); ofstream oCube(imageName.toLatin1().data()); StartProcess(oCube); oCube.close(); ofstream outputImageFile(imageName.toLatin1().data()); StartProcess(outputImageFile); outputImageFile.close(); EndProcess(); } Loading isis/src/base/objs/ProcessExportPds4/ProcessExportPds4.h +9 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,14 @@ namespace Isis { ProcessExportPds4(); ~ProcessExportPds4(); enum ImageType { StandardImage, BinSetSpectrum, UniformlySampledSpectrum }; QDomDocument &StandardPds4Label(); QDomDocument &SpectralPds4Label(); void StandardAllMapping(); void CreateImageLabel(); Loading @@ -102,6 +109,7 @@ namespace Isis { void addHistory(QString description, QString date = "tbd", QString version = "1.0"); void setLogicalId(QString lid); void setSchemaLocation(QString schema); void setImageType(ImageType imageType); static void translateUnits(QDomDocument &label, QString transMapFile = "$base/translations/pds4ExportUnits.pvl"); Loading @@ -114,7 +122,6 @@ namespace Isis { void standardBandBin(); void displaySettings(); void fileAreaObservational(); QString imageObjectType(Pvl &inputLabel); QString PDS4PixelType(PixelType pixelType, ByteOrder endianType); static QMap<QString, QString> createUnitMap(Pvl configPvl); static void translateChildUnits(QDomElement parent, QMap<QString, QString> transMap); Loading @@ -122,6 +129,7 @@ namespace Isis { QDomDocument *m_domDoc; //!< XML label. QString m_schemaLocation; //!< QString with all schema locations required. QString m_lid; //!< QString with specified logical identifier. ImageType m_imageType; //!< Type of image data to be written. }; } Loading isis/src/hayabusa/apps/amica2isis/amica2isis.cpp +27 −16 Original line number Diff line number Diff line Loading @@ -103,25 +103,30 @@ void IsisMain () // Create a PVL to store the translated labels in Pvl outLabel; // Translate the BandBin group FileName transFile (transDir + "amicaBandBin.trn"); PvlToPvlTranslationManager bandBinXlater (label, transFile.expanded()); bandBinXlater.Auto(outLabel); // Translate the Instrument group FileName transFile = transDir + "amicaInstrument.trn"; PvlToPvlTranslationManager instrumentXlater (label, transFile.expanded()); instrumentXlater.Auto(outLabel); // Translate the Archive group transFile = transDir + "amicaArchive.trn"; PvlToPvlTranslationManager archiveXlater (label, transFile.expanded()); archiveXlater.Auto(outLabel); // Translate the Instrument group transFile = transDir + "amicaInstrument.trn"; PvlToPvlTranslationManager instrumentXlater (label, transFile.expanded()); instrumentXlater.Auto(outLabel); // Translate the BandBin group transFile = transDir + "amicaBandBin.trn"; PvlToPvlTranslationManager bandBinXlater (label, transFile.expanded()); bandBinXlater.Auto(outLabel); // Translate the Kernels group transFile = transDir + "amicaKernels.trn"; PvlToPvlTranslationManager kernelsXlater (label, transFile.expanded()); kernelsXlater.Auto(outLabel); // Create YearDoy keyword in Archive group iTime stime(outLabel.findGroup("Instrument", Pvl::Traverse)["StartTime"][0]); PvlKeyword yeardoy("YearDoy", toString(stime.Year()*1000 + stime.DayOfYear())); (void) outLabel.findGroup("Archive", Pvl::Traverse).addKeyword(yeardoy); outLabel.findGroup("Archive", Pvl::Traverse).addKeyword(yeardoy); // Update target if user specifies it Loading @@ -130,16 +135,22 @@ void IsisMain () igrp["TargetName"] = target; } QString units = ""; if (outLabel.findGroup("BandBin", Pvl::Traverse).hasKeyword("Unit")) { units = outLabel.findGroup("BandBin", Pvl::Traverse).findKeyword("Unit")[0].toLower(); } else { units = "nanometers"; } outLabel.findGroup("BandBin", Pvl::Traverse).findKeyword("Center").setUnits(units); outLabel.findGroup("BandBin", Pvl::Traverse).findKeyword("Width").setUnits(units); // 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)); // Use the HAYABUSA_AMICA frame code rather than HAYABUSA_AMICA_IDEAL PvlGroup kerns("Kernels"); kerns += PvlKeyword("NaifFrameCode","-130102"); outcube->putGroup(kerns); outcube->putGroup(outLabel.findGroup("Archive",Pvl::Traverse)); outcube->putGroup(outLabel.findGroup("BandBin",Pvl::Traverse)); outcube->putGroup(outLabel.findGroup("Kernels",Pvl::Traverse)); // Now write the FITS augmented label as the original label OriginalLabel oldLabel(label); Loading isis/src/hayabusa/apps/hyb1pds4gen/hyb1pds4gen.cpp +112 −47 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ using namespace std; using namespace Isis; void generateCSVOutput(Pvl &inputCubeLabel); void IsisMain() { UserInterface &ui = Application::GetUserInterface(); Loading @@ -32,20 +34,35 @@ void IsisMain() { ProcessExportPds4 process; Cube *inputCube = process.SetInputCube("FROM"); Pvl *inputLabel = inputCube->label(); generateCSVOutput(*inputLabel); QString logicalId = ui.GetString("PDS4LOGICALIDENTIFIER"); process.setLogicalId(logicalId); QString translationFile = "$hayabusa/translations/"; PvlGroup instGroup = inputLabel->findObject("IsisCube").findGroup("Instrument"); if (instGroup["InstrumentId"][0].compare("NIRS", Qt::CaseInsensitive) == 0) { process.setImageType(ProcessExportPds4::BinSetSpectrum); QDomDocument &pdsLabel = process.StandardPds4Label(); translationFile += "nirsPds4Export.trn"; PvlToXmlTranslationManager xlator(*(inputLabel), translationFile); xlator.Auto(pdsLabel); ProcessExportPds4::translateUnits(pdsLabel); } else { // AMICA QDomDocument &pdsLabel = process.StandardPds4Label(); translationFile += "amicaPds4Export.trn"; PvlToXmlTranslationManager xlator(*(inputLabel), translationFile); xlator.Auto(pdsLabel); /* * Add additional pds label data here */ // QDomDocument &pdsLabel = process.GetLabel(); PvlToXmlTranslationManager xlator(*(inputLabel), "$hayabusa/translations/hyb1Pds4Export.trn"); xlator.Auto(pdsLabel); PvlGroup instGroup = inputLabel->findObject("IsisCube").findGroup("Instrument"); QStringList xmlPath; xmlPath << "Product_Observational" << "Observation_Area" Loading Loading @@ -89,10 +106,58 @@ void IsisMain() { radiometricParametersElement.appendChild(radianceFactorElement); ProcessExportPds4::translateUnits(pdsLabel); } QString outFile = ui.GetFileName("TO"); process.WritePds4(outFile); return; } /** * Write extra values to an output CSV formatted file. */ void generateCSVOutput(Pvl &inputCubeLabel) { if (inputCubeLabel.findObject("IsisCube").hasGroup("Instrument")) { UserInterface &ui = Application::GetUserInterface(); // Create the vars for holding the info QString keys; QString values; const QString delimeter = ","; // Output the result fstream outFile;//QFile??? QString outputImage = ui.GetAsString("TO"); FileName imgOutput(outputImage); FileName csvOutput = imgOutput.removeExtension().setExtension("csv"); PvlGroup instGroup = inputCubeLabel.findObject("IsisCube").findGroup("Instrument"); if (instGroup["InstrumentId"][0].compare("amica", Qt::CaseInsensitive) == 0) { if (inputCubeLabel.findObject("IsisCube").hasGroup("RadiometricCalibration")) { outFile.open(csvOutput.expanded().toLatin1().data(), std::ios::out); PvlGroup radiometricGroup = inputCubeLabel.findObject("IsisCube").findGroup("RadiometricCalibration"); outFile << "RadiometricCalibrationUnits" << delimeter << "RadianceStandard" << delimeter << "RadianceScaleFactor" << endl; outFile << radiometricGroup["Units"][0] << delimeter << radiometricGroup["RadianceStandard"][0] << delimeter << radiometricGroup["RadianceScaleFactor"][0] << endl; outFile.close(); } } else { // NIRS outFile.open(csvOutput.expanded().toLatin1().data(), std::ios::out); outFile << "IntegrationTime" << endl; outFile << instGroup["IntegrationTime"][0] << endl; outFile.close(); } } } isis/src/hayabusa/apps/hyb1pds4gen/tsts/amicaitokawa2diof/Makefile +5 −7 Original line number Diff line number Diff line Loading @@ -5,9 +5,7 @@ include $(ISISROOT)/make/isismake.tsts commands: $(APPNAME) from=$(INPUT)/corrected_iof_st_2459265790_w.cub \ to=$(OUTPUT)/corrected_iof_st_2459265790_w.img \ pds4logical="urn:nasa:pds:mybundle:mycollection:myproduct" \ > /dev/null; pds4logical="urn:nasa:pds:mybundle:mycollection:myproduct" > /dev/null; # Remove parts of output that can occur in any order and convert to txt for comparison $(SED) 's+\Product_Observational.*>+\Product_Observational>+' \ $(OUTPUT)/corrected_iof_st_2459265790_w.xml \ Loading @@ -19,7 +17,7 @@ commands: $(OUTPUT)/tempLabel2.txt \ > $(OUTPUT)/corrected_iof_st_2459265790_w.xmlLabel.txt; $(RM) $(OUTPUT)/corrected_iof_st_2459265790_w.xml > /dev/null; $(RM) $(OUTPUT)/tempLabel1.txt > /dev/null; $(RM) $(OUTPUT)/tempLabel2.txt > /dev/null; $(RM) $(OUTPUT)/corrected_iof_st_2459265790_w.xml;# > /dev/null; $(RM) $(OUTPUT)/tempLabel1.txt;# > /dev/null; $(RM) $(OUTPUT)/tempLabel2.txt;# > /dev/null; Loading
isis/src/base/objs/ProcessExportPds4/ProcessExportPds4.cpp +250 −63 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ namespace Isis { ProcessExportPds4::ProcessExportPds4() { m_lid = ""; m_imageType = StandardImage; qSetGlobalQHashSeed(1031); // hash seed to force consistent output Loading @@ -68,6 +69,7 @@ namespace Isis { QDomProcessingInstruction header = m_domDoc->createProcessingInstruction("xml-model", xmlModel); m_domDoc->appendChild(header); } Loading @@ -87,24 +89,19 @@ namespace Isis { * @return @b QDomDocument The output PDS4 label. */ QDomDocument &ProcessExportPds4::StandardPds4Label() { if (InputCubes.size() == 0) { QString msg("Must set an input cube before creating a PDS4 label."); throw IException(IException::Programmer, msg, _FILEINFO_); } else { if (m_domDoc->documentElement().isNull()) { QDomElement root = m_domDoc->createElement("Product_Observational"); root.setAttribute("xmlns", "http://pds.nasa.gov/pds4/pds/v1"); root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.setAttribute("xsi:schemaLocation", "http://pds.nasa.gov/pds4/pds/v1 http://pds.nasa.gov/pds4/pds/v1"); m_domDoc->appendChild(root); } CreateImageLabel(); translateUnits(*m_domDoc); return *m_domDoc; } /** * Create a standard PDS4 image label from the input cube. * * @return @b QDomDocument The output PDS4 label. */ void ProcessExportPds4::setImageType(ImageType imageType) { m_imageType = imageType; } Loading @@ -118,6 +115,18 @@ namespace Isis { * Array_3D_Spectrum. */ void ProcessExportPds4::CreateImageLabel() { if (InputCubes.size() == 0) { QString msg("Must set an input cube before creating a PDS4 label."); throw IException(IException::Programmer, msg, _FILEINFO_); } if (m_domDoc->documentElement().isNull()) { QDomElement root = m_domDoc->createElement("Product_Observational"); root.setAttribute("xmlns", "http://pds.nasa.gov/pds4/pds/v1"); root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.setAttribute("xsi:schemaLocation", "http://pds.nasa.gov/pds4/pds/v1 http://pds.nasa.gov/pds4/pds/v1"); m_domDoc->appendChild(root); } try { // <Product_Observational> Loading Loading @@ -397,36 +406,212 @@ namespace Isis { * */ void ProcessExportPds4::standardBandBin() { Pvl *inputLabel = InputCubes[0]->label(); if ( !inputLabel->findObject("IsisCube").hasGroup("BandBin") ) return; // Spectra // Get the input Isis cube label and find the BandBin group if it has one Pvl *inputLabel = InputCubes[0]->label(); QString imageObject = imageObjectType(*inputLabel); QString translationFile = "$base/translations/"; if (m_imageType == StandardImage) { translationFile += "pds4ExportBandBinImage.trn"; } else if (m_imageType == UniformlySampledSpectrum) { translationFile += "pds4ExportBandBinSpectrumUniform.trn"; } else if (m_imageType == BinSetSpectrum) { translationFile += "pds4ExportBandBinSpectrumBinSet.trn"; } FileName translationFileName(translationFile); PvlToXmlTranslationManager xlator(*inputLabel, translationFileName.expanded()); xlator.Auto(*m_domDoc); if (imageObject.compare("Array_3D_Spectrum") == 0) { if (m_imageType == StandardImage) { // Add header info addSchema("PDS4_IMG_1900.sch", "PDS4_IMG_1900.xsd", "xmlns:img", "http://pds.nasa.gov/pds4/img/v1"); } else { // spectral PvlGroup bandBinGroup = inputLabel->findObject("IsisCube").findGroup("BandBin"); // Add header info addSchema("PDS4_SP_1100.sch", "PDS4_SP_1100.xsd", "xmlns:sp", "http://pds.nasa.gov/pds4/sp/v1"); // fix multi-valued bandbin info QStringList xmlPath; xmlPath << "Product_Observational" << "Observation_Area" << "Discipline_Area" << "sp:Spectral_Characteristics"; QDomElement baseElement = m_domDoc->documentElement(); QDomElement spectralCharElement = getElement(xmlPath, baseElement); // Axis_Bin_Set for variable bin widths // required - bin_sequence_number, center_value, bin_width // optional - detector_number, grating_position, original_bin_number, scaling_factor, value_offset, Filter // ... see schema for more... if (m_imageType == BinSetSpectrum) { PvlKeyword center; if (bandBinGroup.hasKeyword("Center")) { center = bandBinGroup["Center"]; } else if (bandBinGroup.hasKeyword("FilterCenter")) { center = bandBinGroup["FilterCenter"]; } else { QString msg = "Unable to translate BandBin info for BinSetSpectrum. " "Translation for PDS4 required value [center_value] not found."; throw IException(IException::Programmer, msg, _FILEINFO_); } PvlKeyword width; if (bandBinGroup.hasKeyword("Width")) { width = bandBinGroup["Width"]; } else if (bandBinGroup.hasKeyword("FilterWidth")) { width = bandBinGroup["FilterWidth"]; } else { QString msg = "Unable to translate BandBin info for BinSetSpectrum. " "Translation for PDS4 required value [bin_width] not found."; throw IException(IException::Programmer, msg, _FILEINFO_); } if ( (imageObject.compare("Array_2D_Image") == 0) || (imageObject.compare("Array_3D_Image") == 0) ) { // Add header info addSchema("PDS4_IMG_1900.sch", "PDS4_IMG_1900.xsd", "xmlns:img", "http://pds.nasa.gov/pds4/img/v1"); QString units = center.unit(); if (!width.unit().isEmpty() ) { if (units.isEmpty()) { units = width.unit(); } if (units.compare(width.unit(), Qt::CaseInsensitive) != 0) { QString msg = "Unable to translate BandBin info for BinSetSpectrum. " "Unknown or unmatching units for [center_value] and [bin_width]."; throw IException(IException::Programmer, msg, _FILEINFO_); } } QString translationFile = "$base/translations/pds4ExportBandBin"; translationFile += imageObject.remove(0,9); // remove first 9 characters: Array_2D_ or Array_3D_ translationFile += ".trn"; FileName translationFileName(translationFile); PvlKeyword originalBand; if (bandBinGroup.hasKeyword("OriginalBand")) { originalBand = bandBinGroup["OriginalBand"]; } PvlKeyword name; if (bandBinGroup.hasKeyword("Name")) { name = bandBinGroup["Name"]; } else if (bandBinGroup.hasKeyword("FilterName")) { name = bandBinGroup["FilterName"]; } else if (bandBinGroup.hasKeyword("FilterId")) { name = bandBinGroup["FilterId"]; } PvlKeyword number; if (bandBinGroup.hasKeyword("Number")) { number = bandBinGroup["Number"]; } else if (bandBinGroup.hasKeyword("FilterNumber")) { number = bandBinGroup["FilterNumber"]; } PvlToXmlTranslationManager xlator(*inputLabel, translationFileName.expanded()); xlator.Auto(*m_domDoc); QDomElement axisBinSetElement = spectralCharElement.firstChildElement("sp:Axis_Bin_Set"); if (axisBinSetElement.isNull()) { axisBinSetElement = m_domDoc->createElement("sp:Axis_Bin_Set"); spectralCharElement.appendChild(axisBinSetElement); } int bands = (int)inputLabel->findObject("IsisCube") .findObject("Core") .findGroup("Dimensions") .findKeyword("Bands"); for (int i = 0; i < bands; i++) { QDomElement bin = m_domDoc->createElement("sp:Bin"); axisBinSetElement.appendChild(bin); QDomElement binSequenceNumber = m_domDoc->createElement("sp:bin_sequence_number"); PvlToXmlTranslationManager::setElementValue(binSequenceNumber, toString(i+1)); bin.appendChild(binSequenceNumber); QDomElement centerValue = m_domDoc->createElement("sp:center_value"); PvlToXmlTranslationManager::setElementValue(centerValue, center[i], units); bin.appendChild(centerValue); QDomElement binWidth = m_domDoc->createElement("sp:bin_width"); if (width.size() == bands) { PvlToXmlTranslationManager::setElementValue(binWidth, width[i] , units); } else { PvlToXmlTranslationManager::setElementValue(binWidth, width[0] , units); } bin.appendChild(binWidth); QDomElement originalBinNumber = m_domDoc->createElement("sp:original_bin_number"); if (originalBand.size() > 0) { PvlToXmlTranslationManager::setElementValue(originalBinNumber, originalBand[i]); bin.appendChild(originalBinNumber); } if (name.size() > 0 || number.size() > 0) { QDomElement filter = m_domDoc->createElement("sp:Filter"); bin.appendChild(filter); if (name.size() > 0) { QDomElement filterName = m_domDoc->createElement("sp:filter_name"); PvlToXmlTranslationManager::setElementValue(filterName, name[i]); filter.appendChild(filterName); } if (number.size() > 0) { QDomElement filterNumber= m_domDoc->createElement("sp:filter_number"); PvlToXmlTranslationManager::setElementValue(filterNumber, number[i]); filter.appendChild(filterNumber); } } } } else if (m_imageType == UniformlySampledSpectrum) { // Axis_Uniformly_Sampled // required - sampling_parameter_type (frequency, wavelength, wavenumber) // sampling_interval (units Hz, Angstrom, cm**-1, respectively) // bin_width (units Hz, Angstrom, cm**-1, respectively) // first_center_value (units Hz, Angstrom, cm**-1, respectively) // last_center_value (units Hz, Angstrom, cm**-1, respectively) // Local_Internal_Reference // Local_Internal_Reference:local_reference_type = spectral_characteristics_to_array_axis // Local_Internal_Reference:local_identifier_reference, // 1. At least one Axis_Array:axis_name must match the // value of the local_identifier_reference in the // Axis_Uniformly_Sampled. // Set Axis_Uniformly_Sampled:local_identifier_reference = Axis_Array:axis_name = Band // 2. At least one Array_3D_Spectrum:local_identifier must match // the value of the local_identifier_reference in the // Spectral_Characteristics. // Set Spectral_Characteristics:local_identifier_reference = Array_3D_Spectrum:local_identifier = Spectral_Array_Object // Local_Internal_Reference:local_reference_type = spectral_characteristics_to_array_axis PvlKeyword center("Center"); if (bandBinGroup.hasKeyword("FilterCenter")) { center = bandBinGroup["FilterCenter"]; } else if (bandBinGroup.hasKeyword("Center")) { center = bandBinGroup["Center"]; } else { QString msg = "Unable to translate BandBin info for UniformlySpacedSpectrum. " "Translation for PDS4 required value [last_center_value] not found."; throw IException(IException::Programmer, msg, _FILEINFO_); } QString lastCenter = center[center.size() - 1]; QDomElement axisBinSetElement = spectralCharElement.firstChildElement("sp:Axis_Uniformly_Sampled"); if (axisBinSetElement.isNull()) { axisBinSetElement = m_domDoc->createElement("sp:Axis_Uniformly_Sampled"); spectralCharElement.appendChild(axisBinSetElement); } QDomElement lastCenterElement = m_domDoc->createElement("sp:last_center_value"); PvlToXmlTranslationManager::setElementValue(lastCenterElement, lastCenter); spectralCharElement.appendChild(lastCenterElement); } } } Loading @@ -437,10 +622,32 @@ namespace Isis { */ void ProcessExportPds4::fileAreaObservational() { Pvl *inputLabel = InputCubes[0]->label(); QString imageObject = imageObjectType(*inputLabel); QString imageObject = ""; QString translationFile = "$base/translations/pds4Export"; if (m_imageType == StandardImage) { int bands = (int)inputLabel->findObject("IsisCube") .findObject("Core") .findGroup("Dimensions") .findKeyword("Bands"); if (bands > 1) { imageObject = "Array_3D_Image"; } else { imageObject = "Array_2D_Image"; } translationFile += QString(imageObject).remove('_'); } else { imageObject = "Array_3D_Spectrum"; translationFile += QString(imageObject).remove('_'); if (m_imageType == UniformlySampledSpectrum) { translationFile += "Uniform"; } else if (m_imageType == BinSetSpectrum) { translationFile += "BinSet"; } } translationFile += ".trn"; FileName translationFileName(translationFile); Loading Loading @@ -513,26 +720,6 @@ namespace Isis { } QString ProcessExportPds4::imageObjectType(Pvl &inputLabel) { // not sure how to easily determine whether an isis3 cube should be // exported as spectral. for now, we will only export image arrays #if 0 if (inputLabel.findObject("IsisCube").hasGroup("BandBin")) { return "Array_3D_Spectrum"; } #endif int bands = (int) inputLabel.findObject("IsisCube") .findObject("Core") .findGroup("Dimensions") .findKeyword("Bands"); if (bands > 1) { return "Array_3D_Image"; } return "Array_2D_Image"; } /** * Adds necessary information to the xml header for a pds4 class. * Loading Loading @@ -651,13 +838,13 @@ namespace Isis { // PvlToXmlTranslationManager::setElementValue(creationElement, ); // fileElement.appendChild(creationElement); ofstream oLabel(labelName.toLatin1().data()); OutputLabel(oLabel); oLabel.close(); ofstream outputLabel(labelName.toLatin1().data()); OutputLabel(outputLabel); outputLabel.close(); ofstream oCube(imageName.toLatin1().data()); StartProcess(oCube); oCube.close(); ofstream outputImageFile(imageName.toLatin1().data()); StartProcess(outputImageFile); outputImageFile.close(); EndProcess(); } Loading
isis/src/base/objs/ProcessExportPds4/ProcessExportPds4.h +9 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,14 @@ namespace Isis { ProcessExportPds4(); ~ProcessExportPds4(); enum ImageType { StandardImage, BinSetSpectrum, UniformlySampledSpectrum }; QDomDocument &StandardPds4Label(); QDomDocument &SpectralPds4Label(); void StandardAllMapping(); void CreateImageLabel(); Loading @@ -102,6 +109,7 @@ namespace Isis { void addHistory(QString description, QString date = "tbd", QString version = "1.0"); void setLogicalId(QString lid); void setSchemaLocation(QString schema); void setImageType(ImageType imageType); static void translateUnits(QDomDocument &label, QString transMapFile = "$base/translations/pds4ExportUnits.pvl"); Loading @@ -114,7 +122,6 @@ namespace Isis { void standardBandBin(); void displaySettings(); void fileAreaObservational(); QString imageObjectType(Pvl &inputLabel); QString PDS4PixelType(PixelType pixelType, ByteOrder endianType); static QMap<QString, QString> createUnitMap(Pvl configPvl); static void translateChildUnits(QDomElement parent, QMap<QString, QString> transMap); Loading @@ -122,6 +129,7 @@ namespace Isis { QDomDocument *m_domDoc; //!< XML label. QString m_schemaLocation; //!< QString with all schema locations required. QString m_lid; //!< QString with specified logical identifier. ImageType m_imageType; //!< Type of image data to be written. }; } Loading
isis/src/hayabusa/apps/amica2isis/amica2isis.cpp +27 −16 Original line number Diff line number Diff line Loading @@ -103,25 +103,30 @@ void IsisMain () // Create a PVL to store the translated labels in Pvl outLabel; // Translate the BandBin group FileName transFile (transDir + "amicaBandBin.trn"); PvlToPvlTranslationManager bandBinXlater (label, transFile.expanded()); bandBinXlater.Auto(outLabel); // Translate the Instrument group FileName transFile = transDir + "amicaInstrument.trn"; PvlToPvlTranslationManager instrumentXlater (label, transFile.expanded()); instrumentXlater.Auto(outLabel); // Translate the Archive group transFile = transDir + "amicaArchive.trn"; PvlToPvlTranslationManager archiveXlater (label, transFile.expanded()); archiveXlater.Auto(outLabel); // Translate the Instrument group transFile = transDir + "amicaInstrument.trn"; PvlToPvlTranslationManager instrumentXlater (label, transFile.expanded()); instrumentXlater.Auto(outLabel); // Translate the BandBin group transFile = transDir + "amicaBandBin.trn"; PvlToPvlTranslationManager bandBinXlater (label, transFile.expanded()); bandBinXlater.Auto(outLabel); // Translate the Kernels group transFile = transDir + "amicaKernels.trn"; PvlToPvlTranslationManager kernelsXlater (label, transFile.expanded()); kernelsXlater.Auto(outLabel); // Create YearDoy keyword in Archive group iTime stime(outLabel.findGroup("Instrument", Pvl::Traverse)["StartTime"][0]); PvlKeyword yeardoy("YearDoy", toString(stime.Year()*1000 + stime.DayOfYear())); (void) outLabel.findGroup("Archive", Pvl::Traverse).addKeyword(yeardoy); outLabel.findGroup("Archive", Pvl::Traverse).addKeyword(yeardoy); // Update target if user specifies it Loading @@ -130,16 +135,22 @@ void IsisMain () igrp["TargetName"] = target; } QString units = ""; if (outLabel.findGroup("BandBin", Pvl::Traverse).hasKeyword("Unit")) { units = outLabel.findGroup("BandBin", Pvl::Traverse).findKeyword("Unit")[0].toLower(); } else { units = "nanometers"; } outLabel.findGroup("BandBin", Pvl::Traverse).findKeyword("Center").setUnits(units); outLabel.findGroup("BandBin", Pvl::Traverse).findKeyword("Width").setUnits(units); // 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)); // Use the HAYABUSA_AMICA frame code rather than HAYABUSA_AMICA_IDEAL PvlGroup kerns("Kernels"); kerns += PvlKeyword("NaifFrameCode","-130102"); outcube->putGroup(kerns); outcube->putGroup(outLabel.findGroup("Archive",Pvl::Traverse)); outcube->putGroup(outLabel.findGroup("BandBin",Pvl::Traverse)); outcube->putGroup(outLabel.findGroup("Kernels",Pvl::Traverse)); // Now write the FITS augmented label as the original label OriginalLabel oldLabel(label); Loading
isis/src/hayabusa/apps/hyb1pds4gen/hyb1pds4gen.cpp +112 −47 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ using namespace std; using namespace Isis; void generateCSVOutput(Pvl &inputCubeLabel); void IsisMain() { UserInterface &ui = Application::GetUserInterface(); Loading @@ -32,20 +34,35 @@ void IsisMain() { ProcessExportPds4 process; Cube *inputCube = process.SetInputCube("FROM"); Pvl *inputLabel = inputCube->label(); generateCSVOutput(*inputLabel); QString logicalId = ui.GetString("PDS4LOGICALIDENTIFIER"); process.setLogicalId(logicalId); QString translationFile = "$hayabusa/translations/"; PvlGroup instGroup = inputLabel->findObject("IsisCube").findGroup("Instrument"); if (instGroup["InstrumentId"][0].compare("NIRS", Qt::CaseInsensitive) == 0) { process.setImageType(ProcessExportPds4::BinSetSpectrum); QDomDocument &pdsLabel = process.StandardPds4Label(); translationFile += "nirsPds4Export.trn"; PvlToXmlTranslationManager xlator(*(inputLabel), translationFile); xlator.Auto(pdsLabel); ProcessExportPds4::translateUnits(pdsLabel); } else { // AMICA QDomDocument &pdsLabel = process.StandardPds4Label(); translationFile += "amicaPds4Export.trn"; PvlToXmlTranslationManager xlator(*(inputLabel), translationFile); xlator.Auto(pdsLabel); /* * Add additional pds label data here */ // QDomDocument &pdsLabel = process.GetLabel(); PvlToXmlTranslationManager xlator(*(inputLabel), "$hayabusa/translations/hyb1Pds4Export.trn"); xlator.Auto(pdsLabel); PvlGroup instGroup = inputLabel->findObject("IsisCube").findGroup("Instrument"); QStringList xmlPath; xmlPath << "Product_Observational" << "Observation_Area" Loading Loading @@ -89,10 +106,58 @@ void IsisMain() { radiometricParametersElement.appendChild(radianceFactorElement); ProcessExportPds4::translateUnits(pdsLabel); } QString outFile = ui.GetFileName("TO"); process.WritePds4(outFile); return; } /** * Write extra values to an output CSV formatted file. */ void generateCSVOutput(Pvl &inputCubeLabel) { if (inputCubeLabel.findObject("IsisCube").hasGroup("Instrument")) { UserInterface &ui = Application::GetUserInterface(); // Create the vars for holding the info QString keys; QString values; const QString delimeter = ","; // Output the result fstream outFile;//QFile??? QString outputImage = ui.GetAsString("TO"); FileName imgOutput(outputImage); FileName csvOutput = imgOutput.removeExtension().setExtension("csv"); PvlGroup instGroup = inputCubeLabel.findObject("IsisCube").findGroup("Instrument"); if (instGroup["InstrumentId"][0].compare("amica", Qt::CaseInsensitive) == 0) { if (inputCubeLabel.findObject("IsisCube").hasGroup("RadiometricCalibration")) { outFile.open(csvOutput.expanded().toLatin1().data(), std::ios::out); PvlGroup radiometricGroup = inputCubeLabel.findObject("IsisCube").findGroup("RadiometricCalibration"); outFile << "RadiometricCalibrationUnits" << delimeter << "RadianceStandard" << delimeter << "RadianceScaleFactor" << endl; outFile << radiometricGroup["Units"][0] << delimeter << radiometricGroup["RadianceStandard"][0] << delimeter << radiometricGroup["RadianceScaleFactor"][0] << endl; outFile.close(); } } else { // NIRS outFile.open(csvOutput.expanded().toLatin1().data(), std::ios::out); outFile << "IntegrationTime" << endl; outFile << instGroup["IntegrationTime"][0] << endl; outFile.close(); } } }
isis/src/hayabusa/apps/hyb1pds4gen/tsts/amicaitokawa2diof/Makefile +5 −7 Original line number Diff line number Diff line Loading @@ -5,9 +5,7 @@ include $(ISISROOT)/make/isismake.tsts commands: $(APPNAME) from=$(INPUT)/corrected_iof_st_2459265790_w.cub \ to=$(OUTPUT)/corrected_iof_st_2459265790_w.img \ pds4logical="urn:nasa:pds:mybundle:mycollection:myproduct" \ > /dev/null; pds4logical="urn:nasa:pds:mybundle:mycollection:myproduct" > /dev/null; # Remove parts of output that can occur in any order and convert to txt for comparison $(SED) 's+\Product_Observational.*>+\Product_Observational>+' \ $(OUTPUT)/corrected_iof_st_2459265790_w.xml \ Loading @@ -19,7 +17,7 @@ commands: $(OUTPUT)/tempLabel2.txt \ > $(OUTPUT)/corrected_iof_st_2459265790_w.xmlLabel.txt; $(RM) $(OUTPUT)/corrected_iof_st_2459265790_w.xml > /dev/null; $(RM) $(OUTPUT)/tempLabel1.txt > /dev/null; $(RM) $(OUTPUT)/tempLabel2.txt > /dev/null; $(RM) $(OUTPUT)/corrected_iof_st_2459265790_w.xml;# > /dev/null; $(RM) $(OUTPUT)/tempLabel1.txt;# > /dev/null; $(RM) $(OUTPUT)/tempLabel2.txt;# > /dev/null;