Loading isis/src/base/objs/Cube/Cube.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,10 @@ namespace Isis { putGroup(*grpIt); } for (int i = 1; i < label.objects(); i++) { m_label->addObject(label.object(i)); } close(); open(fileName.toString(), access); } Loading isis/src/hayabusa2/apps/hyb2pds4gen/hyb2pds4gen.cpp 0 → 100644 +237 −0 Original line number Diff line number Diff line #include <sstream> #include <QDomDocument> #include <QDomElement> #include <QString> #include "Application.h" #include "Cube.h" #include "ExportDescription.h" #include "FileName.h" #include "Process.h" #include "ProcessExportPds.h" #include "ProcessExportPds4.h" #include "Pvl.h" #include "PvlKeyword.h" #include "PvlToXmlTranslationManager.h" #include "hyb2pds4gen.h" using namespace std; namespace Isis { static QMap<QString, QString> descMap({ {"J2000Q0", "element q0 of quaternion representing a rotation"}, {"J2000Q1", "element q1 of quaternion representing a rotation"}, {"J2000Q2", "element q2 of quaternion representing a rotation"}, {"J2000Q3", "element q3 of quaternion representing a rotation"}, {"AV1", "Angular velocity vector"}, {"AV2", "Angular velocity vector"}, {"AV3", "Angular velocity vector"}, {"ET", "Ephemeris time"}, {"J2000X", "J2000 position x"}, {"J2000Y", "J2000 position y"}, {"J2000Z", "J2000 position z"}, {"J2000XV", "J2000 velocity xv"}, {"J2000YV", "J2000 velocity yv"}, {"J2000ZV", "J2000 velocity zv"} }); Pvl toPvl(PvlObject &container); QDomDocument emptyDoc(); extern void hyb2pds4gen(UserInterface &ui) { Cube icube; icube.open(ui.GetFileName("FROM")); hyb2pds4gen(&icube, ui); } void hyb2pds4gen(Cube *inputCube, UserInterface &ui) { QString translationFile = "$ISISROOT/appdata/translations/Hayabusa2OncPds4Export.trn"; // Setup the process and set the input cube ProcessExportPds4 process; process.SetInputCube(inputCube); Pvl *inputLabel = inputCube->label(); process.setImageType(ProcessExportPds4::BinSetSpectrum); QDomDocument &pdsLabel = process.StandardPds4Label(); ProcessExportPds4::translateUnits(pdsLabel); QString logicalId = ui.GetString("PDS4LOGICALIDENTIFIER"); process.setLogicalId(logicalId); QStringList xmlPath = {"Product_Observational", "File_Area_Observational"}; for (int i = 0; i < inputLabel->objects(); i++) { PvlObject obj = inputLabel->object(i); if (obj.name() == "Table") { QDomDocument doc = emptyDoc(); Pvl pvlObj = toPvl(obj); PvlToXmlTranslationManager tableXlator(pvlObj,"$ISISROOT/appdata/translations/pds4ExportSpiceTable.trn"); tableXlator.Auto(doc); QDomElement recordBinary = doc.createElement("Record_Binary"); QDomElement fields = doc.createElement("fields"); QDomElement groups = doc.createElement("groups"); QDomElement record_len = doc.createElement("record_length"); QDomElement tableBinary = process.getElement({"Product_Observational", "File_Area_Observational", "Table_Binary"}, doc.documentElement()); PvlToXmlTranslationManager::setElementValue(fields, QString::number(obj.groups())); PvlToXmlTranslationManager::setElementValue(groups, QString::number(0)); PvlToXmlTranslationManager::setElementValue(record_len, obj["Bytes"]); record_len.setAttribute("unit", "byte"); tableBinary.appendChild(recordBinary).appendChild(fields); recordBinary.appendChild(groups); recordBinary.appendChild(record_len); // Translate Field Groups for (int j = 0; j < obj.groups(); j++) { PvlGroup grp = obj.group(j); QDomElement field = doc.createElement("Field_Binary"); QDomElement name = doc.createElement("name"); PvlToXmlTranslationManager::setElementValue(name, grp["Name"]); QDomElement fieldNumber = doc.createElement("field_number"); PvlToXmlTranslationManager::setElementValue(fieldNumber, QString::number(j+1)); QDomElement fieldLocation = doc.createElement("field_location"); PvlToXmlTranslationManager::setElementValue(fieldLocation, QString::number((j*8)+1)); fieldLocation.setAttribute("unit", "byte"); QDomElement dataType = doc.createElement("data_type"); PvlToXmlTranslationManager::setElementValue(dataType, "IEEE754MSBDouble"); QDomElement fieldLength = doc.createElement("field_length"); PvlToXmlTranslationManager::setElementValue(fieldLength, QString::number(8)); fieldLength.setAttribute("unit", "byte"); QDomElement description = doc.createElement("description"); PvlToXmlTranslationManager::setElementValue(description, descMap[grp["Name"]]); field.appendChild(name); field.appendChild(fieldNumber); field.appendChild(fieldLocation); field.appendChild(dataType); field.appendChild(fieldLength); field.appendChild(description); recordBinary.appendChild(field); } // translation files do not support adding attrs to siblings so we have to do it manually QDomNodeList fieldList = doc.elementsByTagName("field_length"); for (int j = 0; j < fieldList.size(); j++) { fieldList.at(j).toElement().setAttribute("unit", "byte"); } QDomElement tableElement = process.getElement(xmlPath, doc.documentElement()).firstChildElement("Table_Binary"); QDomElement base = process.getElement(xmlPath, pdsLabel.documentElement()); base.appendChild(tableElement); } } // remove elements not wanted in hyb2 QDomElement del = process.getElement({"Product_Observational", "Observation_Area", "Discipline_Area"}, pdsLabel.documentElement()); del.removeChild(del.firstChildElement("img:Imaging")); del.removeChild(del.firstChildElement("sp:Spectral_Characteristics")); del = process.getElement({"Product_Observational", "File_Area_Observational", "Array_3D_Spectrum"}, pdsLabel.documentElement()); del.removeChild(del.firstChildElement("Special_Constants")); PvlToXmlTranslationManager xlator(*(inputLabel), translationFile); xlator.Auto(pdsLabel); QDomElement base = process.getElement(xmlPath, pdsLabel.documentElement()); QDomDocument tempDoc = emptyDoc(); PvlToXmlTranslationManager originalLabelXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportOriginalLabel.trn"); originalLabelXlator.Auto(tempDoc); QDomElement ogLabelElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); base.appendChild(ogLabelElem); tempDoc = emptyDoc(); PvlToXmlTranslationManager histXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportHistory.trn"); histXlator.Auto(tempDoc); QDomElement histElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); base.appendChild(histElem); tempDoc = emptyDoc(); PvlToXmlTranslationManager labXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportLabelObject.trn"); labXlator.Auto(tempDoc); QDomElement labElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); QDomElement fileElem = process.getElement({"Product_Observational", "File_Area_Observational", "Array_3D_Spectrum"}, pdsLabel.documentElement()); base.insertBefore(labElem, fileElem); PvlGroup instGroup = inputLabel->findObject("IsisCube").findGroup("Instrument"); QStringList subFramePath = {"Product_Observational", "Observation_Area", "Discipline_Area", "img:Imaging", "img:Image_Product_Information", "img:Subframe_Parameters"}; if (instGroup.hasKeyword("FirstLine") && instGroup.hasKeyword("LastLine")) { int lines = (int) instGroup["LastLine"] - (int) instGroup["FirstLine"]; QDomElement baseElement = pdsLabel.documentElement(); QDomElement subframeParametersElement = process.getElement(subFramePath, baseElement); QDomElement linesElement = pdsLabel.createElement("img:lines"); PvlToXmlTranslationManager::setElementValue(linesElement, toString(lines)); subframeParametersElement.appendChild(linesElement); } if (instGroup.hasKeyword("FirstSample") && instGroup.hasKeyword("LastSample")) { int samples = (int) instGroup["LastSample"] - (int) instGroup["FirstSample"]; QDomElement baseElement = pdsLabel.documentElement(); QDomElement subframeParametersElement = process.getElement(subFramePath, baseElement); QDomElement samplesElement = pdsLabel.createElement("img:samples"); PvlToXmlTranslationManager::setElementValue(samplesElement, toString(samples)); subframeParametersElement.appendChild(samplesElement); } QString outFile = ui.GetFileName("TO"); process.WritePds4(outFile); return; } /** * Converts a PvlObject instance to a PVL instance. * * Something about the relationship between the Pvl class and PvlObject class * makes it impossible to simply cast without a segfault, so we have to do a * bit more massaging. * */ Pvl toPvl(PvlObject &container) { Pvl newPvl; std::stringstream buffer; buffer << container << std::endl; buffer >> newPvl; return newPvl; } /** * Returns a minimal QDomDocument for running it through * PvlToXmlTranslationManager */ QDomDocument emptyDoc() { QDomDocument doc; QDomElement root = doc.createElement("Product_Observational"); doc.appendChild(root); return doc; } }; No newline at end of file isis/src/hayabusa2/apps/hyb2pds4gen/hyb2pds4gen.h 0 → 100644 +12 −0 Original line number Diff line number Diff line #ifndef hyb2pds4gen_h #define hyb2pds4gen_h #include "UserInterface.h" #include "Cube.h" namespace Isis { extern void hyb2pds4gen(UserInterface &ui); extern void hyb2pds4gen(Cube *iCube, UserInterface &ui); } #endif isis/src/hayabusa2/apps/hyb2pds4gen/main.cpp +3 −222 Original line number Diff line number Diff line #include "Isis.h" #include <sstream> #include <QDomDocument> #include <QDomElement> #include <QString> #include "hyb2pds4gen.h" #include "Application.h" #include "Cube.h" #include "ExportDescription.h" #include "FileName.h" #include "Process.h" #include "ProcessExportPds.h" #include "ProcessExportPds4.h" #include "Pvl.h" #include "PvlKeyword.h" #include "PvlToXmlTranslationManager.h" using namespace std; using namespace Isis; static QMap<QString, QString> descMap({ {"J2000Q0", "element q0 of quaternion representing a rotation"}, {"J2000Q1", "element q1 of quaternion representing a rotation"}, {"J2000Q2", "element q2 of quaternion representing a rotation"}, {"J2000Q3", "element q3 of quaternion representing a rotation"}, {"AV1", "Angular velocity vector"}, {"AV2", "Angular velocity vector"}, {"AV3", "Angular velocity vector"}, {"ET", "Ephemeris time"}, {"J2000X", "J2000 position x"}, {"J2000Y", "J2000 position y"}, {"J2000Z", "J2000 position z"}, {"J2000XV", "J2000 velocity xv"}, {"J2000YV", "J2000 velocity yv"}, {"J2000ZV", "J2000 velocity zv"} }); Pvl toPvl(PvlObject &container); QDomDocument emptyDoc(); void IsisMain() { UserInterface &ui = Application::GetUserInterface(); QString translationFile = "$ISISROOT/appdata/translations/Hayabusa2OncPds4Export.trn"; // Setup the process and set the input cube ProcessExportPds4 process; Cube *inputCube = process.SetInputCube("FROM"); Pvl *inputLabel = inputCube->label(); process.setImageType(ProcessExportPds4::BinSetSpectrum); QDomDocument &pdsLabel = process.StandardPds4Label(); ProcessExportPds4::translateUnits(pdsLabel); QString logicalId = ui.GetString("PDS4LOGICALIDENTIFIER"); process.setLogicalId(logicalId); QStringList xmlPath = {"Product_Observational", "File_Area_Observational"}; for (int i = 0; i < inputLabel->objects(); i++) { PvlObject obj = inputLabel->object(i); if (obj.name() == "Table") { QDomDocument doc = emptyDoc(); Pvl pvlObj = toPvl(obj); PvlToXmlTranslationManager tableXlator(pvlObj,"$ISISROOT/appdata/translations/pds4ExportSpiceTable.trn"); tableXlator.Auto(doc); QDomElement recordBinary = doc.createElement("Record_Binary"); QDomElement fields = doc.createElement("fields"); QDomElement groups = doc.createElement("groups"); QDomElement record_len = doc.createElement("record_length"); QDomElement tableBinary = process.getElement({"Product_Observational", "File_Area_Observational", "Table_Binary"}, doc.documentElement()); PvlToXmlTranslationManager::setElementValue(fields, QString::number(obj.groups())); PvlToXmlTranslationManager::setElementValue(groups, QString::number(0)); PvlToXmlTranslationManager::setElementValue(record_len, obj["Bytes"]); record_len.setAttribute("unit", "byte"); tableBinary.appendChild(recordBinary).appendChild(fields); recordBinary.appendChild(groups); recordBinary.appendChild(record_len); // Translate Field Groups for (int j = 0; j < obj.groups(); j++) { PvlGroup grp = obj.group(j); QDomElement field = doc.createElement("Field_Binary"); QDomElement name = doc.createElement("name"); PvlToXmlTranslationManager::setElementValue(name, grp["Name"]); QDomElement fieldNumber = doc.createElement("field_number"); PvlToXmlTranslationManager::setElementValue(fieldNumber, QString::number(j+1)); QDomElement fieldLocation = doc.createElement("field_location"); PvlToXmlTranslationManager::setElementValue(fieldLocation, QString::number((j*8)+1)); fieldLocation.setAttribute("unit", "byte"); QDomElement dataType = doc.createElement("data_type"); PvlToXmlTranslationManager::setElementValue(dataType, "IEEE754MSBDouble"); QDomElement fieldLength = doc.createElement("field_length"); PvlToXmlTranslationManager::setElementValue(fieldLength, QString::number(8)); fieldLength.setAttribute("unit", "byte"); QDomElement description = doc.createElement("description"); PvlToXmlTranslationManager::setElementValue(description, descMap[grp["Name"]]); field.appendChild(name); field.appendChild(fieldNumber); field.appendChild(fieldLocation); field.appendChild(dataType); field.appendChild(fieldLength); field.appendChild(description); recordBinary.appendChild(field); } // translation files do not support adding attrs to siblings so we have to do it manually QDomNodeList fieldList = doc.elementsByTagName("field_length"); for (int j = 0; j < fieldList.size(); j++) { fieldList.at(j).toElement().setAttribute("unit", "byte"); } QDomElement tableElement = process.getElement(xmlPath, doc.documentElement()).firstChildElement("Table_Binary"); QDomElement base = process.getElement(xmlPath, pdsLabel.documentElement()); base.appendChild(tableElement); } hyb2pds4gen(ui); } No newline at end of file // remove elements not wanted in hyb2 QDomElement del = process.getElement({"Product_Observational", "Observation_Area", "Discipline_Area"}, pdsLabel.documentElement()); del.removeChild(del.firstChildElement("img:Imaging")); del.removeChild(del.firstChildElement("sp:Spectral_Characteristics")); del = process.getElement({"Product_Observational", "File_Area_Observational", "Array_3D_Spectrum"}, pdsLabel.documentElement()); del.removeChild(del.firstChildElement("Special_Constants")); PvlToXmlTranslationManager xlator(*(inputLabel), translationFile); xlator.Auto(pdsLabel); QDomElement base = process.getElement(xmlPath, pdsLabel.documentElement()); QDomDocument tempDoc = emptyDoc(); PvlToXmlTranslationManager originalLabelXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportOriginalLabel.trn"); originalLabelXlator.Auto(tempDoc); QDomElement ogLabelElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); base.appendChild(ogLabelElem); tempDoc = emptyDoc(); PvlToXmlTranslationManager histXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportHistory.trn"); histXlator.Auto(tempDoc); QDomElement histElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); base.appendChild(histElem); tempDoc = emptyDoc(); PvlToXmlTranslationManager labXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportLabelObject.trn"); labXlator.Auto(tempDoc); QDomElement labElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); QDomElement fileElem = process.getElement({"Product_Observational", "File_Area_Observational", "Array_3D_Spectrum"}, pdsLabel.documentElement()); base.insertBefore(labElem, fileElem); PvlGroup instGroup = inputLabel->findObject("IsisCube").findGroup("Instrument"); QStringList subFramePath = {"Product_Observational", "Observation_Area", "Discipline_Area", "img:Imaging", "img:Image_Product_Information", "img:Subframe_Parameters"}; if (instGroup.hasKeyword("FirstLine") && instGroup.hasKeyword("LastLine")) { int lines = (int) instGroup["LastLine"] - (int) instGroup["FirstLine"]; QDomElement baseElement = pdsLabel.documentElement(); QDomElement subframeParametersElement = process.getElement(subFramePath, baseElement); QDomElement linesElement = pdsLabel.createElement("img:lines"); PvlToXmlTranslationManager::setElementValue(linesElement, toString(lines)); subframeParametersElement.appendChild(linesElement); } if (instGroup.hasKeyword("FirstSample") && instGroup.hasKeyword("LastSample")) { int samples = (int) instGroup["LastSample"] - (int) instGroup["FirstSample"]; QDomElement baseElement = pdsLabel.documentElement(); QDomElement subframeParametersElement = process.getElement(subFramePath, baseElement); QDomElement samplesElement = pdsLabel.createElement("img:samples"); PvlToXmlTranslationManager::setElementValue(samplesElement, toString(samples)); subframeParametersElement.appendChild(samplesElement); } QString outFile = ui.GetFileName("TO"); process.WritePds4(outFile); return; } /** * Converts a PvlObject instance to a PVL instance. * * Something about the relationship between the Pvl class and PvlObject class * makes it impossible to simply cast without a segfault, so we have to do a * bit more massaging. * */ Pvl toPvl(PvlObject &container) { Pvl newPvl; std::stringstream buffer; buffer << container << std::endl; buffer >> newPvl; return newPvl; } /** * Returns a minimal QDomDocument for running it through * PvlToXmlTranslationManager */ QDomDocument emptyDoc() { QDomDocument doc; QDomElement root = doc.createElement("Product_Observational"); doc.appendChild(root); return doc; } isis/tests/Fixtures.cpp +105 −16 Original line number Diff line number Diff line Loading @@ -214,7 +214,6 @@ namespace Isis { void DefaultCube::SetUp() { TempTestingFiles::SetUp(); std::ifstream isdFile("data/defaultImage/defaultCube.isd"); std::ifstream cubeLabel("data/defaultImage/defaultCube.pvl"); std::ifstream projCubeLabel("data/defaultImage/projDefaultCube.pvl"); Loading Loading @@ -1285,4 +1284,94 @@ namespace Isis { testCube.reset(); } void Hayabusa2OncW2Cube::setInstrument(QString ikid, QString instrumentId, QString spacecraftName) { PvlGroup &kernels = testCube->label()->findObject("IsisCube").findGroup("Kernels"); kernels.findKeyword("NaifFrameCode").setValue(ikid); PvlGroup &inst = testCube->label()->findObject("IsisCube").findGroup("Instrument"); std::istringstream iss(R"( Group = Instrument SpacecraftName = HAYABUSA-2 InstrumentId = ONC-W2 InstrumentName = "Optical Navigation Camera" TargetName = Mars StartTime = 2015-12-03T07:29:58.232 StopTime = 2015-12-03T07:29:58.234 ExposureDuration = 0.00272 <seconds> RawSpacecraftClockCount = 0x3C38845A <1/32 sec> Binning = 1 SelectedImageAreaX1 = 1 SelectedImageAreaY1 = 1 SelectedImageAreaX2 = 1024 SelectedImageAreaY2 = 1 SelectedImageAreaX3 = 1 SelectedImageAreaY3 = 1024 SelectedImageAreaX4 = 1024 SelectedImageAreaY4 = 1024 SmearCorrection = NON OffsetCorrection = N/A FlatCorrection = NON RadianceConversion = NON PhotometricCorrection = NON BandRegistration = NON L2BFlatFileName = N/A L2BSystemEfficiencyFileName = N/A L2CShapeModelFileName = N/A L2DPhaseFunctionFileName = N/A L2DShapeModelFileName = N/A SubImageCount = 1 BusLineVoltage = 49.28 <V> ONCCurrent = 0.52 <V> FLACCurrent = 0.00 <V> ONCAETemperature = 1.53 <degC> ONCTOpticsTemperature = 19.17 <degC> ONCTCCDTemperature = -29.62 <degC> ONCTElectricCircuitTemperature = -11.96 <degC> ONCW1OpticsTemperature = 1.42 <degC> ONCW1CCDTemperature = -24.98 <degC> ONCW1ElectricCircuitTemperature = -10.90 <degC> ONCW2OpticsTemperature = 1.28 <degC> ONCW2CCDTemperature = -24.67 <degC> ONCW2ElectricCircuitTemperature = -4.12 <degC> FLACTemperature = -15.27 <degC> End_Group )"); PvlGroup newInstGroup; iss >> newInstGroup; newInstGroup.findKeyword("InstrumentId").setValue(instrumentId); newInstGroup.findKeyword("SpacecraftName").setValue(spacecraftName); inst = newInstGroup; PvlKeyword startcc("SpacecraftClockStartCount", "33322515"); PvlKeyword stopcc("SpaceCraftClockStopCount", "33322516"); inst += startcc; inst += stopcc; PvlObject &naifKeywords = testCube->label()->findObject("NaifKeywords"); json nk; nk["INS"+ikid.toStdString()+"_FOCAL_LENGTH"] = 10.44; nk["INS"+ikid.toStdString()+"_PIXEL_PITCH"] = 0.013; nk["INS"+ikid.toStdString()+"_TRANSX"] = {0.0, 0.013, 0.0}; nk["INS"+ikid.toStdString()+"_TRANSY"] = {0.0, 0.0, 0.013}; nk["INS"+ikid.toStdString()+"_ITRANSS"] = {0.0, 76.923076923077, 0.0}; nk["INS"+ikid.toStdString()+"_ITRANSL"] = {0.0, 0.0, 76.923076923077}; nk["INS"+ikid.toStdString()+"_BORESIGHT_LINE"] = 490.5; nk["INS"+ikid.toStdString()+"_BORESIGHT_SAMPLE"] = 512.5; nk["INS"+ikid.toStdString()+"_OD_K"] = {1.014, 2.933e-07, -1.384e-13}; nk["BODY499_RADII"] = {3396.19, 3396.19, 3376.2}; nk["CLOCK_ET-37_33322515_COMPUTED"] = "8ed6ae8930f3bd41"; nk["BODY_CODE"] = 499; nk["BODY_FRAME_CODE"] = 10014; PvlObject newNaifKeywords("NaifKeywords", nk); naifKeywords = newNaifKeywords; QString fileName = testCube->fileName(); // need to remove old camera pointer delete testCube; // This is now a Hayabusa cube testCube = new Cube(fileName, "rw"); } } Loading
isis/src/base/objs/Cube/Cube.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,10 @@ namespace Isis { putGroup(*grpIt); } for (int i = 1; i < label.objects(); i++) { m_label->addObject(label.object(i)); } close(); open(fileName.toString(), access); } Loading
isis/src/hayabusa2/apps/hyb2pds4gen/hyb2pds4gen.cpp 0 → 100644 +237 −0 Original line number Diff line number Diff line #include <sstream> #include <QDomDocument> #include <QDomElement> #include <QString> #include "Application.h" #include "Cube.h" #include "ExportDescription.h" #include "FileName.h" #include "Process.h" #include "ProcessExportPds.h" #include "ProcessExportPds4.h" #include "Pvl.h" #include "PvlKeyword.h" #include "PvlToXmlTranslationManager.h" #include "hyb2pds4gen.h" using namespace std; namespace Isis { static QMap<QString, QString> descMap({ {"J2000Q0", "element q0 of quaternion representing a rotation"}, {"J2000Q1", "element q1 of quaternion representing a rotation"}, {"J2000Q2", "element q2 of quaternion representing a rotation"}, {"J2000Q3", "element q3 of quaternion representing a rotation"}, {"AV1", "Angular velocity vector"}, {"AV2", "Angular velocity vector"}, {"AV3", "Angular velocity vector"}, {"ET", "Ephemeris time"}, {"J2000X", "J2000 position x"}, {"J2000Y", "J2000 position y"}, {"J2000Z", "J2000 position z"}, {"J2000XV", "J2000 velocity xv"}, {"J2000YV", "J2000 velocity yv"}, {"J2000ZV", "J2000 velocity zv"} }); Pvl toPvl(PvlObject &container); QDomDocument emptyDoc(); extern void hyb2pds4gen(UserInterface &ui) { Cube icube; icube.open(ui.GetFileName("FROM")); hyb2pds4gen(&icube, ui); } void hyb2pds4gen(Cube *inputCube, UserInterface &ui) { QString translationFile = "$ISISROOT/appdata/translations/Hayabusa2OncPds4Export.trn"; // Setup the process and set the input cube ProcessExportPds4 process; process.SetInputCube(inputCube); Pvl *inputLabel = inputCube->label(); process.setImageType(ProcessExportPds4::BinSetSpectrum); QDomDocument &pdsLabel = process.StandardPds4Label(); ProcessExportPds4::translateUnits(pdsLabel); QString logicalId = ui.GetString("PDS4LOGICALIDENTIFIER"); process.setLogicalId(logicalId); QStringList xmlPath = {"Product_Observational", "File_Area_Observational"}; for (int i = 0; i < inputLabel->objects(); i++) { PvlObject obj = inputLabel->object(i); if (obj.name() == "Table") { QDomDocument doc = emptyDoc(); Pvl pvlObj = toPvl(obj); PvlToXmlTranslationManager tableXlator(pvlObj,"$ISISROOT/appdata/translations/pds4ExportSpiceTable.trn"); tableXlator.Auto(doc); QDomElement recordBinary = doc.createElement("Record_Binary"); QDomElement fields = doc.createElement("fields"); QDomElement groups = doc.createElement("groups"); QDomElement record_len = doc.createElement("record_length"); QDomElement tableBinary = process.getElement({"Product_Observational", "File_Area_Observational", "Table_Binary"}, doc.documentElement()); PvlToXmlTranslationManager::setElementValue(fields, QString::number(obj.groups())); PvlToXmlTranslationManager::setElementValue(groups, QString::number(0)); PvlToXmlTranslationManager::setElementValue(record_len, obj["Bytes"]); record_len.setAttribute("unit", "byte"); tableBinary.appendChild(recordBinary).appendChild(fields); recordBinary.appendChild(groups); recordBinary.appendChild(record_len); // Translate Field Groups for (int j = 0; j < obj.groups(); j++) { PvlGroup grp = obj.group(j); QDomElement field = doc.createElement("Field_Binary"); QDomElement name = doc.createElement("name"); PvlToXmlTranslationManager::setElementValue(name, grp["Name"]); QDomElement fieldNumber = doc.createElement("field_number"); PvlToXmlTranslationManager::setElementValue(fieldNumber, QString::number(j+1)); QDomElement fieldLocation = doc.createElement("field_location"); PvlToXmlTranslationManager::setElementValue(fieldLocation, QString::number((j*8)+1)); fieldLocation.setAttribute("unit", "byte"); QDomElement dataType = doc.createElement("data_type"); PvlToXmlTranslationManager::setElementValue(dataType, "IEEE754MSBDouble"); QDomElement fieldLength = doc.createElement("field_length"); PvlToXmlTranslationManager::setElementValue(fieldLength, QString::number(8)); fieldLength.setAttribute("unit", "byte"); QDomElement description = doc.createElement("description"); PvlToXmlTranslationManager::setElementValue(description, descMap[grp["Name"]]); field.appendChild(name); field.appendChild(fieldNumber); field.appendChild(fieldLocation); field.appendChild(dataType); field.appendChild(fieldLength); field.appendChild(description); recordBinary.appendChild(field); } // translation files do not support adding attrs to siblings so we have to do it manually QDomNodeList fieldList = doc.elementsByTagName("field_length"); for (int j = 0; j < fieldList.size(); j++) { fieldList.at(j).toElement().setAttribute("unit", "byte"); } QDomElement tableElement = process.getElement(xmlPath, doc.documentElement()).firstChildElement("Table_Binary"); QDomElement base = process.getElement(xmlPath, pdsLabel.documentElement()); base.appendChild(tableElement); } } // remove elements not wanted in hyb2 QDomElement del = process.getElement({"Product_Observational", "Observation_Area", "Discipline_Area"}, pdsLabel.documentElement()); del.removeChild(del.firstChildElement("img:Imaging")); del.removeChild(del.firstChildElement("sp:Spectral_Characteristics")); del = process.getElement({"Product_Observational", "File_Area_Observational", "Array_3D_Spectrum"}, pdsLabel.documentElement()); del.removeChild(del.firstChildElement("Special_Constants")); PvlToXmlTranslationManager xlator(*(inputLabel), translationFile); xlator.Auto(pdsLabel); QDomElement base = process.getElement(xmlPath, pdsLabel.documentElement()); QDomDocument tempDoc = emptyDoc(); PvlToXmlTranslationManager originalLabelXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportOriginalLabel.trn"); originalLabelXlator.Auto(tempDoc); QDomElement ogLabelElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); base.appendChild(ogLabelElem); tempDoc = emptyDoc(); PvlToXmlTranslationManager histXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportHistory.trn"); histXlator.Auto(tempDoc); QDomElement histElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); base.appendChild(histElem); tempDoc = emptyDoc(); PvlToXmlTranslationManager labXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportLabelObject.trn"); labXlator.Auto(tempDoc); QDomElement labElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); QDomElement fileElem = process.getElement({"Product_Observational", "File_Area_Observational", "Array_3D_Spectrum"}, pdsLabel.documentElement()); base.insertBefore(labElem, fileElem); PvlGroup instGroup = inputLabel->findObject("IsisCube").findGroup("Instrument"); QStringList subFramePath = {"Product_Observational", "Observation_Area", "Discipline_Area", "img:Imaging", "img:Image_Product_Information", "img:Subframe_Parameters"}; if (instGroup.hasKeyword("FirstLine") && instGroup.hasKeyword("LastLine")) { int lines = (int) instGroup["LastLine"] - (int) instGroup["FirstLine"]; QDomElement baseElement = pdsLabel.documentElement(); QDomElement subframeParametersElement = process.getElement(subFramePath, baseElement); QDomElement linesElement = pdsLabel.createElement("img:lines"); PvlToXmlTranslationManager::setElementValue(linesElement, toString(lines)); subframeParametersElement.appendChild(linesElement); } if (instGroup.hasKeyword("FirstSample") && instGroup.hasKeyword("LastSample")) { int samples = (int) instGroup["LastSample"] - (int) instGroup["FirstSample"]; QDomElement baseElement = pdsLabel.documentElement(); QDomElement subframeParametersElement = process.getElement(subFramePath, baseElement); QDomElement samplesElement = pdsLabel.createElement("img:samples"); PvlToXmlTranslationManager::setElementValue(samplesElement, toString(samples)); subframeParametersElement.appendChild(samplesElement); } QString outFile = ui.GetFileName("TO"); process.WritePds4(outFile); return; } /** * Converts a PvlObject instance to a PVL instance. * * Something about the relationship between the Pvl class and PvlObject class * makes it impossible to simply cast without a segfault, so we have to do a * bit more massaging. * */ Pvl toPvl(PvlObject &container) { Pvl newPvl; std::stringstream buffer; buffer << container << std::endl; buffer >> newPvl; return newPvl; } /** * Returns a minimal QDomDocument for running it through * PvlToXmlTranslationManager */ QDomDocument emptyDoc() { QDomDocument doc; QDomElement root = doc.createElement("Product_Observational"); doc.appendChild(root); return doc; } }; No newline at end of file
isis/src/hayabusa2/apps/hyb2pds4gen/hyb2pds4gen.h 0 → 100644 +12 −0 Original line number Diff line number Diff line #ifndef hyb2pds4gen_h #define hyb2pds4gen_h #include "UserInterface.h" #include "Cube.h" namespace Isis { extern void hyb2pds4gen(UserInterface &ui); extern void hyb2pds4gen(Cube *iCube, UserInterface &ui); } #endif
isis/src/hayabusa2/apps/hyb2pds4gen/main.cpp +3 −222 Original line number Diff line number Diff line #include "Isis.h" #include <sstream> #include <QDomDocument> #include <QDomElement> #include <QString> #include "hyb2pds4gen.h" #include "Application.h" #include "Cube.h" #include "ExportDescription.h" #include "FileName.h" #include "Process.h" #include "ProcessExportPds.h" #include "ProcessExportPds4.h" #include "Pvl.h" #include "PvlKeyword.h" #include "PvlToXmlTranslationManager.h" using namespace std; using namespace Isis; static QMap<QString, QString> descMap({ {"J2000Q0", "element q0 of quaternion representing a rotation"}, {"J2000Q1", "element q1 of quaternion representing a rotation"}, {"J2000Q2", "element q2 of quaternion representing a rotation"}, {"J2000Q3", "element q3 of quaternion representing a rotation"}, {"AV1", "Angular velocity vector"}, {"AV2", "Angular velocity vector"}, {"AV3", "Angular velocity vector"}, {"ET", "Ephemeris time"}, {"J2000X", "J2000 position x"}, {"J2000Y", "J2000 position y"}, {"J2000Z", "J2000 position z"}, {"J2000XV", "J2000 velocity xv"}, {"J2000YV", "J2000 velocity yv"}, {"J2000ZV", "J2000 velocity zv"} }); Pvl toPvl(PvlObject &container); QDomDocument emptyDoc(); void IsisMain() { UserInterface &ui = Application::GetUserInterface(); QString translationFile = "$ISISROOT/appdata/translations/Hayabusa2OncPds4Export.trn"; // Setup the process and set the input cube ProcessExportPds4 process; Cube *inputCube = process.SetInputCube("FROM"); Pvl *inputLabel = inputCube->label(); process.setImageType(ProcessExportPds4::BinSetSpectrum); QDomDocument &pdsLabel = process.StandardPds4Label(); ProcessExportPds4::translateUnits(pdsLabel); QString logicalId = ui.GetString("PDS4LOGICALIDENTIFIER"); process.setLogicalId(logicalId); QStringList xmlPath = {"Product_Observational", "File_Area_Observational"}; for (int i = 0; i < inputLabel->objects(); i++) { PvlObject obj = inputLabel->object(i); if (obj.name() == "Table") { QDomDocument doc = emptyDoc(); Pvl pvlObj = toPvl(obj); PvlToXmlTranslationManager tableXlator(pvlObj,"$ISISROOT/appdata/translations/pds4ExportSpiceTable.trn"); tableXlator.Auto(doc); QDomElement recordBinary = doc.createElement("Record_Binary"); QDomElement fields = doc.createElement("fields"); QDomElement groups = doc.createElement("groups"); QDomElement record_len = doc.createElement("record_length"); QDomElement tableBinary = process.getElement({"Product_Observational", "File_Area_Observational", "Table_Binary"}, doc.documentElement()); PvlToXmlTranslationManager::setElementValue(fields, QString::number(obj.groups())); PvlToXmlTranslationManager::setElementValue(groups, QString::number(0)); PvlToXmlTranslationManager::setElementValue(record_len, obj["Bytes"]); record_len.setAttribute("unit", "byte"); tableBinary.appendChild(recordBinary).appendChild(fields); recordBinary.appendChild(groups); recordBinary.appendChild(record_len); // Translate Field Groups for (int j = 0; j < obj.groups(); j++) { PvlGroup grp = obj.group(j); QDomElement field = doc.createElement("Field_Binary"); QDomElement name = doc.createElement("name"); PvlToXmlTranslationManager::setElementValue(name, grp["Name"]); QDomElement fieldNumber = doc.createElement("field_number"); PvlToXmlTranslationManager::setElementValue(fieldNumber, QString::number(j+1)); QDomElement fieldLocation = doc.createElement("field_location"); PvlToXmlTranslationManager::setElementValue(fieldLocation, QString::number((j*8)+1)); fieldLocation.setAttribute("unit", "byte"); QDomElement dataType = doc.createElement("data_type"); PvlToXmlTranslationManager::setElementValue(dataType, "IEEE754MSBDouble"); QDomElement fieldLength = doc.createElement("field_length"); PvlToXmlTranslationManager::setElementValue(fieldLength, QString::number(8)); fieldLength.setAttribute("unit", "byte"); QDomElement description = doc.createElement("description"); PvlToXmlTranslationManager::setElementValue(description, descMap[grp["Name"]]); field.appendChild(name); field.appendChild(fieldNumber); field.appendChild(fieldLocation); field.appendChild(dataType); field.appendChild(fieldLength); field.appendChild(description); recordBinary.appendChild(field); } // translation files do not support adding attrs to siblings so we have to do it manually QDomNodeList fieldList = doc.elementsByTagName("field_length"); for (int j = 0; j < fieldList.size(); j++) { fieldList.at(j).toElement().setAttribute("unit", "byte"); } QDomElement tableElement = process.getElement(xmlPath, doc.documentElement()).firstChildElement("Table_Binary"); QDomElement base = process.getElement(xmlPath, pdsLabel.documentElement()); base.appendChild(tableElement); } hyb2pds4gen(ui); } No newline at end of file // remove elements not wanted in hyb2 QDomElement del = process.getElement({"Product_Observational", "Observation_Area", "Discipline_Area"}, pdsLabel.documentElement()); del.removeChild(del.firstChildElement("img:Imaging")); del.removeChild(del.firstChildElement("sp:Spectral_Characteristics")); del = process.getElement({"Product_Observational", "File_Area_Observational", "Array_3D_Spectrum"}, pdsLabel.documentElement()); del.removeChild(del.firstChildElement("Special_Constants")); PvlToXmlTranslationManager xlator(*(inputLabel), translationFile); xlator.Auto(pdsLabel); QDomElement base = process.getElement(xmlPath, pdsLabel.documentElement()); QDomDocument tempDoc = emptyDoc(); PvlToXmlTranslationManager originalLabelXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportOriginalLabel.trn"); originalLabelXlator.Auto(tempDoc); QDomElement ogLabelElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); base.appendChild(ogLabelElem); tempDoc = emptyDoc(); PvlToXmlTranslationManager histXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportHistory.trn"); histXlator.Auto(tempDoc); QDomElement histElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); base.appendChild(histElem); tempDoc = emptyDoc(); PvlToXmlTranslationManager labXlator(*(inputLabel), "$ISISROOT/appdata/translations/pds4ExportLabelObject.trn"); labXlator.Auto(tempDoc); QDomElement labElem = process.getElement(xmlPath, tempDoc.documentElement()).firstChildElement("Header"); QDomElement fileElem = process.getElement({"Product_Observational", "File_Area_Observational", "Array_3D_Spectrum"}, pdsLabel.documentElement()); base.insertBefore(labElem, fileElem); PvlGroup instGroup = inputLabel->findObject("IsisCube").findGroup("Instrument"); QStringList subFramePath = {"Product_Observational", "Observation_Area", "Discipline_Area", "img:Imaging", "img:Image_Product_Information", "img:Subframe_Parameters"}; if (instGroup.hasKeyword("FirstLine") && instGroup.hasKeyword("LastLine")) { int lines = (int) instGroup["LastLine"] - (int) instGroup["FirstLine"]; QDomElement baseElement = pdsLabel.documentElement(); QDomElement subframeParametersElement = process.getElement(subFramePath, baseElement); QDomElement linesElement = pdsLabel.createElement("img:lines"); PvlToXmlTranslationManager::setElementValue(linesElement, toString(lines)); subframeParametersElement.appendChild(linesElement); } if (instGroup.hasKeyword("FirstSample") && instGroup.hasKeyword("LastSample")) { int samples = (int) instGroup["LastSample"] - (int) instGroup["FirstSample"]; QDomElement baseElement = pdsLabel.documentElement(); QDomElement subframeParametersElement = process.getElement(subFramePath, baseElement); QDomElement samplesElement = pdsLabel.createElement("img:samples"); PvlToXmlTranslationManager::setElementValue(samplesElement, toString(samples)); subframeParametersElement.appendChild(samplesElement); } QString outFile = ui.GetFileName("TO"); process.WritePds4(outFile); return; } /** * Converts a PvlObject instance to a PVL instance. * * Something about the relationship between the Pvl class and PvlObject class * makes it impossible to simply cast without a segfault, so we have to do a * bit more massaging. * */ Pvl toPvl(PvlObject &container) { Pvl newPvl; std::stringstream buffer; buffer << container << std::endl; buffer >> newPvl; return newPvl; } /** * Returns a minimal QDomDocument for running it through * PvlToXmlTranslationManager */ QDomDocument emptyDoc() { QDomDocument doc; QDomElement root = doc.createElement("Product_Observational"); doc.appendChild(root); return doc; }
isis/tests/Fixtures.cpp +105 −16 Original line number Diff line number Diff line Loading @@ -214,7 +214,6 @@ namespace Isis { void DefaultCube::SetUp() { TempTestingFiles::SetUp(); std::ifstream isdFile("data/defaultImage/defaultCube.isd"); std::ifstream cubeLabel("data/defaultImage/defaultCube.pvl"); std::ifstream projCubeLabel("data/defaultImage/projDefaultCube.pvl"); Loading Loading @@ -1285,4 +1284,94 @@ namespace Isis { testCube.reset(); } void Hayabusa2OncW2Cube::setInstrument(QString ikid, QString instrumentId, QString spacecraftName) { PvlGroup &kernels = testCube->label()->findObject("IsisCube").findGroup("Kernels"); kernels.findKeyword("NaifFrameCode").setValue(ikid); PvlGroup &inst = testCube->label()->findObject("IsisCube").findGroup("Instrument"); std::istringstream iss(R"( Group = Instrument SpacecraftName = HAYABUSA-2 InstrumentId = ONC-W2 InstrumentName = "Optical Navigation Camera" TargetName = Mars StartTime = 2015-12-03T07:29:58.232 StopTime = 2015-12-03T07:29:58.234 ExposureDuration = 0.00272 <seconds> RawSpacecraftClockCount = 0x3C38845A <1/32 sec> Binning = 1 SelectedImageAreaX1 = 1 SelectedImageAreaY1 = 1 SelectedImageAreaX2 = 1024 SelectedImageAreaY2 = 1 SelectedImageAreaX3 = 1 SelectedImageAreaY3 = 1024 SelectedImageAreaX4 = 1024 SelectedImageAreaY4 = 1024 SmearCorrection = NON OffsetCorrection = N/A FlatCorrection = NON RadianceConversion = NON PhotometricCorrection = NON BandRegistration = NON L2BFlatFileName = N/A L2BSystemEfficiencyFileName = N/A L2CShapeModelFileName = N/A L2DPhaseFunctionFileName = N/A L2DShapeModelFileName = N/A SubImageCount = 1 BusLineVoltage = 49.28 <V> ONCCurrent = 0.52 <V> FLACCurrent = 0.00 <V> ONCAETemperature = 1.53 <degC> ONCTOpticsTemperature = 19.17 <degC> ONCTCCDTemperature = -29.62 <degC> ONCTElectricCircuitTemperature = -11.96 <degC> ONCW1OpticsTemperature = 1.42 <degC> ONCW1CCDTemperature = -24.98 <degC> ONCW1ElectricCircuitTemperature = -10.90 <degC> ONCW2OpticsTemperature = 1.28 <degC> ONCW2CCDTemperature = -24.67 <degC> ONCW2ElectricCircuitTemperature = -4.12 <degC> FLACTemperature = -15.27 <degC> End_Group )"); PvlGroup newInstGroup; iss >> newInstGroup; newInstGroup.findKeyword("InstrumentId").setValue(instrumentId); newInstGroup.findKeyword("SpacecraftName").setValue(spacecraftName); inst = newInstGroup; PvlKeyword startcc("SpacecraftClockStartCount", "33322515"); PvlKeyword stopcc("SpaceCraftClockStopCount", "33322516"); inst += startcc; inst += stopcc; PvlObject &naifKeywords = testCube->label()->findObject("NaifKeywords"); json nk; nk["INS"+ikid.toStdString()+"_FOCAL_LENGTH"] = 10.44; nk["INS"+ikid.toStdString()+"_PIXEL_PITCH"] = 0.013; nk["INS"+ikid.toStdString()+"_TRANSX"] = {0.0, 0.013, 0.0}; nk["INS"+ikid.toStdString()+"_TRANSY"] = {0.0, 0.0, 0.013}; nk["INS"+ikid.toStdString()+"_ITRANSS"] = {0.0, 76.923076923077, 0.0}; nk["INS"+ikid.toStdString()+"_ITRANSL"] = {0.0, 0.0, 76.923076923077}; nk["INS"+ikid.toStdString()+"_BORESIGHT_LINE"] = 490.5; nk["INS"+ikid.toStdString()+"_BORESIGHT_SAMPLE"] = 512.5; nk["INS"+ikid.toStdString()+"_OD_K"] = {1.014, 2.933e-07, -1.384e-13}; nk["BODY499_RADII"] = {3396.19, 3396.19, 3376.2}; nk["CLOCK_ET-37_33322515_COMPUTED"] = "8ed6ae8930f3bd41"; nk["BODY_CODE"] = 499; nk["BODY_FRAME_CODE"] = 10014; PvlObject newNaifKeywords("NaifKeywords", nk); naifKeywords = newNaifKeywords; QString fileName = testCube->fileName(); // need to remove old camera pointer delete testCube; // This is now a Hayabusa cube testCube = new Cube(fileName, "rw"); } }