Unverified Commit 07b8a95f authored by Kristin's avatar Kristin Committed by GitHub
Browse files

Merge pull request #185 from makaylas/cassis

Added mosaic reingestion to tgocassis2isis and errors test to tgocassisrdrgen
parents ab256937 a66b5c0b
Loading
Loading
Loading
Loading
+128 −20
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ using namespace Isis;

void translateCoreInfo(FileName &inputLabel, ProcessImport &importer);
void translateCoreInfo(XmlToPvlTranslationManager labelXlater, ProcessImport &importer);
bool translateMappingLabel(FileName inputLabel, Cube *outputCube);
bool translateMosaicLabel(FileName inputLabel, Cube *outputCube);
void translateLabels(FileName &inputLabel, Cube *outputCube, QString transFile);

void IsisMain() {
@@ -51,28 +53,23 @@ void IsisMain() {
      translateLabels(xmlFileName, outputCube, transRawFile); 
    } 
    catch (IException &e) {
      if (translateMappingLabel(xmlFileName, outputCube)) {
        if (!translateMosaicLabel(xmlFileName, outputCube)) {
          translateLabels(xmlFileName, outputCube, transExportFile);
      
      // Try to translate a mapping group
      try {
        PvlGroup &dataDir = Preference::Preferences().findGroup("DataDirectory"); 
        QString missionDir = (QString) dataDir["Tgo"];
        FileName mapTransFile(missionDir + "/translations/tgoCassisMapping.trn");

        // Get the translation manager ready for translating the mapping label

        XmlToPvlTranslationManager labelXlater(xmlFileName, mapTransFile.expanded());

        // Pvl output label
        Pvl *outputLabel = outputCube->label();
        labelXlater.Auto(*(outputLabel));
        }
      catch (IException &e) {
        else {
          Pvl *outputLabel = outputCube->label();
        if(outputLabel->hasGroup("Mapping")) {
          outputLabel->deleteGroup("Mapping"); 
          if(outputLabel->hasGroup("Instrument")) {
            outputLabel->deleteGroup("Instrument"); 
          }
          if(outputLabel->hasGroup("Archive")) {
            outputLabel->deleteGroup("Archive"); 
          }
        }
      }
      else {
        translateLabels(xmlFileName, outputCube, transExportFile);
      }
    }

    FileName outputCubeFileName(ui.GetFileName("TO"));
@@ -161,6 +158,117 @@ void translateCoreInfo(XmlToPvlTranslationManager labelXlater, ProcessImport &im
  importer.SetMultiplier(toDouble(str));
}


/**
 * Translate the cartographic info from the xml.
 * 
 * @param xmlFileName The xml label file name for the input image.
 * @param outputCube Pointer to output cube where ISIS3 labels will be added and 
 *                   updated.
 */
bool translateMappingLabel(FileName xmlFileName, Cube *outputCube) {
  //Translate the Mapping Group
  try {
    PvlGroup &dataDir = Preference::Preferences().findGroup("DataDirectory"); 
    QString missionDir = (QString) dataDir["Tgo"];
    FileName mapTransFile(missionDir + "/translations/tgoCassisMapping.trn");

    // Get the translation manager ready for translating the mapping label

    XmlToPvlTranslationManager labelXMappinglater(xmlFileName, mapTransFile.expanded());

    // Pvl output label
    Pvl *outputLabel = outputCube->label();
    labelXMappinglater.Auto(*(outputLabel));
  }
  catch (IException &e) {
    Pvl *outputLabel = outputCube->label();
    if(outputLabel->hasGroup("Mapping")) {
      outputLabel->deleteGroup("Mapping"); 
    }
    return false;
  }
  return true;
}


/**
 * Translate the Mosaic group info from the xml.
 * 
 * @param xmlFileName The xml label file name for the input image.
 * @param outputCube Pointer to output cube where ISIS3 labels will be added and 
 *                   updated.
 */
bool translateMosaicLabel(FileName xmlFileName, Cube *outputCube) {
  //Now retrieve the logical_identifier to see if this is a mosaic
  QDomDocument xmlDoc;
    
  QFile xmlFile(xmlFileName.expanded());
  if ( !xmlFile.open(QIODevice::ReadOnly) ) {
    QString msg = "Could not open label file [" + xmlFileName.expanded() +
                  "].";
    throw IException(IException::Unknown, msg, _FILEINFO_);
  }

  QString errmsg;
  int errline, errcol;
  if ( !xmlDoc.setContent(&xmlFile, false, &errmsg, &errline, &errcol) ) {
    xmlFile.close();
    QString msg = "XML read/parse error in file [" + xmlFileName.expanded()
        + "] at line [" + toString(errline) + "], column [" + toString(errcol)
        + "], message: " + errmsg;
    throw IException(IException::Unknown, msg, _FILEINFO_);
  }

  xmlFile.close();
  
  QDomElement inputParentElement = xmlDoc.documentElement();
  if (!inputParentElement.isNull()) {
    inputParentElement = inputParentElement.firstChildElement("Identification_Area");
    if (!inputParentElement.isNull()) {
      QDomElement logicalId = inputParentElement.firstChildElement("logical_identifier");
      if (!logicalId.isNull()) {
        QString logicalIdText = logicalId.text();
        QStringList logicalIdStringList = logicalIdText.split(":");
        if (logicalIdStringList.contains("data_mos")) {
          try {
            PvlGroup &dataDir = Preference::Preferences().findGroup("DataDirectory"); 
            QString missionDir = (QString) dataDir["Tgo"];
            
            FileName bandBinTransFile(missionDir + "/translations/tgoCassisBandBin.trn");
            // Get the translation manager ready for translating the band bin label
            XmlToPvlTranslationManager labelXBandBinlater(xmlFileName, bandBinTransFile.expanded());

            // Pvl output label
            Pvl *outputLabel = outputCube->label();
            labelXBandBinlater.Auto(*(outputLabel));
            
            FileName mosaicTransFile(missionDir + "/translations/tgoCassisMosaic.trn");

            // Get the translation manager ready for translating the mapping label
            XmlToPvlTranslationManager labelXMosaiclater(xmlFileName, mosaicTransFile.expanded());

            labelXMosaiclater.Auto(*(outputLabel));
            return true;
          }
          catch (IException &e) {
            Pvl *outputLabel = outputCube->label();
            if(outputLabel->hasGroup("Mosaic")) {
              outputLabel->deleteGroup("Mosaic"); 
            }
            if(outputLabel->hasGroup("BandBin")) {
              outputLabel->deleteGroup("BandBin"); 
            }
            return false;
          }
        }
      }
    }
  }
  return false;
}


/**
 * Translate instrument, bandbin, and archive info from xml label into ISIS3 
 * label and add kernels group. 
+2 −0
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@
    <change name="Kristin Berry and Makayla Shepherd" date="2018-05-15">
     Updated to ingest Mapping groups from images have been exported using tgocassisrdrgen. Fixes #5418.
    </change>
    <change name="Kristin Berry and Makayla Shepherd" date="2018-05-22">
     Updated to ingest mosaics exported from tgocassisrdrgen #5418.
    <change name="Summer Stapleton" date="2018-05-22">
      Stripped the "Z" from the StartTime value in the "Instrument" group to handle re-ingestion 
      of PDS4 compliant .xml files.
+29 −0
Original line number Diff line number Diff line
APPNAME = tgocassisrdrgen

include $(ISISROOT)/make/isismake.tsts

commands:
# TEST: Throws an error for a non-cube input
	echo "Test Non-Cube:" > $(OUTPUT)/errors.txt;
	if [ `$(APPNAME) \
	  from=$(INPUT)/NonCube.xml \
	  to=$(OUTPUT)/BROKEN.img \
	  2>> $(OUTPUT)/errors_temp.txt > /dev/null` ]; \
	  then true; \
	  fi; 
# TEST: Throws an error for a bad instrument name
	echo "" >> $(OUTPUT)/errors.txt ;
	echo "Test InstrumentId:" >> $(OUTPUT)/errors.txt ;
	if [ `$(APPNAME) \
	  from=$(INPUT)/InstrumentError.cub \
	  to=$(OUTPUT)/BROKEN.img \
	  2>> $(OUTPUT)/errors_temp.txt > /dev/null` ]; \
	  then true; \
	  fi;
# Remove everything in brackets like filenames/paths from error messages
	$(SED) 's/\[\([^"]*\)\]//g' $(OUTPUT)/errors_temp.txt \
	> $(OUTPUT)/errors.txt; 

# Cleanup
	$(RM) $(OUTPUT)/errors_temp.txt;
	$(RM) $(OUTPUT)/BROKEN.img;