Unverified Commit 78b1bf9a authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

Automos App and Test Update (#4166)

* App conversion for automos

* Updated tests for automos

* Removed old automos tests

* Tested applog output in default test and removed other applog variables
parent 18004d21
Loading
Loading
Loading
Loading
+108 −0
Original line number Diff line number Diff line
#include "automos.h"
#include "ProcessMapMosaic.h"
#include "FileList.h"
#include "IException.h"
#include "SpecialPixel.h"
#include "TProjection.h"
#include "ProjectionFactory.h"

using namespace std;

namespace Isis {
  void automos(UserInterface &ui, Pvl *log) {
    FileList list;

    // Get the list of cubes to mosaic
    list.read(FileName(ui.GetFileName("FROMLIST")));

    fstream os;
    bool olistFlag = false;
    if (ui.WasEntered("TOLIST")){
      QString olist = ui.GetFileName("TOLIST");
      olistFlag = true;
      os.open(olist.toLatin1().data(), std::ios::out);
    }

    ProcessMapMosaic m;

    // Set the create flag-mosaic is always created in automos
    m.SetCreateFlag(true);

    // Get the Track Flag
    bool bTrack = ui.GetBoolean("TRACK");
    m.SetTrackFlag(bTrack);

    ProcessMosaic::ImageOverlay overlay = ProcessMosaic::StringToOverlay(
        ui.GetString("PRIORITY"));

    if (overlay == ProcessMapMosaic::UseBandPlacementCriteria) {
      if(ui.GetString("TYPE") == "BANDNUMBER") {
        m.SetBandNumber(ui.GetInteger("NUMBER"));
      }
      else {
        // Key name & value
        m.SetBandKeyword(ui.GetString("KEYNAME"), ui.GetString("KEYVALUE"));
      }
      // Band Criteria
      m.SetBandUseMaxValue( (ui.GetString("CRITERIA") == "GREATER") );
    }

    // Priority
    m.SetImageOverlay(overlay);

    CubeAttributeOutput &oAtt = ui.GetOutputAttribute("MOSAIC");
    if(ui.GetString("GRANGE") == "USER") {
      m.SetOutputCube(list,
                      ui.GetDouble("MINLAT"), ui.GetDouble("MAXLAT"),
                      ui.GetDouble("MINLON"), ui.GetDouble("MAXLON"),
                      oAtt, ui.GetFileName("MOSAIC"));
    }
    else {
      m.SetOutputCube(list, oAtt, ui.GetFileName("MOSAIC"));
    }

    m.SetHighSaturationFlag(ui.GetBoolean("HIGHSATURATION"));
    m.SetLowSaturationFlag(ui.GetBoolean("LOWSATURATION"));
    m.SetNullFlag(ui.GetBoolean("NULL"));

    // Loop for each input file and place it in the output mosaic

    m.SetBandBinMatch(ui.GetBoolean("MATCHBANDBIN"));

    // Get the MatchDEM Flag
    m.SetMatchDEM(ui.GetBoolean("MATCHDEM"));

    bool mosaicCreated = false;
    for (int i = 0; i < list.size(); i++) {
      if (!m.StartProcess(list[i].toString())) {
        PvlGroup outsiders("Outside");
        outsiders += PvlKeyword("File", list[i].toString());
        if (log) {
          log->addGroup(outsiders);
        }
      }
      else {
        mosaicCreated = true;
        if(olistFlag) {
          os << list[i].toString() << endl;
        }
      }
      if(mosaicCreated) {
        // Mosaic is already created, use the existing mosaic
        m.SetCreateFlag(false);
      }
    }
    // Logs the input file location in the mosaic
    for (int i = 0; i < m.imagePositions().groups(); i++) {
      if (log) {
        log->addGroup(m.imagePositions().group(i));
      }
    }

    if(olistFlag) {
      os.close();
    }

    m.EndProcess();
  }
}
+11 −0
Original line number Diff line number Diff line
#ifndef automos_h
#define automos_h

#include "UserInterface.h"
#include "Pvl.h"

namespace Isis {
  extern void automos(UserInterface &ui, Pvl *log=nullptr);
}

#endif
+19 −96
Original line number Diff line number Diff line
#define GUIHELPERS

#include "Isis.h"
#include "ProcessMapMosaic.h"

#include "automos.h"

#include "Application.h"
#include "FileList.h"
#include "IException.h"
#include "SpecialPixel.h"
#include "TProjection.h"
#include "ProjectionFactory.h"
#include "Pvl.h"
#include "TProjection.h"
#include "SpecialPixel.h"

using namespace std;
using namespace Isis;

void calcRange(double &minLat, double &maxLat, double &minLon, double &maxLon);
void helperButtonCalcRange();
static void calcRange(double &minLat, double &maxLat, double &minLon, double &maxLon);
static void helperButtonCalcRange();

map <QString, void *> GuiHelpers() {
  map <QString, void *> helper;
@@ -21,106 +23,27 @@ map <QString, void *> GuiHelpers() {
}

void IsisMain() {
  FileList list;
  UserInterface &ui = Application::GetUserInterface();

  // Get the list of cubes to mosaic
  list.read(FileName(ui.GetFileName("FROMLIST")));
  if(list.size() < 1) {
    QString msg = "The list file [" + ui.GetFileName("FROMLIST") +"does not contain any data";
    throw IException(IException::User, msg, _FILEINFO_);
  Pvl appLog;
  try {
    automos(ui, &appLog);
  }

  fstream os;
  bool olistFlag = false;
  if (ui.WasEntered("TOLIST")){
    QString olist = ui.GetFileName("TOLIST");
    olistFlag = true;
    os.open(olist.toLatin1().data(), std::ios::out);
  catch (...) {
    for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
      Application::Log(*grpIt);
    }

  ProcessMapMosaic m;

  // Set the create flag-mosaic is always created in automos
  m.SetCreateFlag(true);

  // Get the Track Flag
  bool bTrack = ui.GetBoolean("TRACK");
  m.SetTrackFlag(bTrack);

  ProcessMosaic::ImageOverlay overlay = ProcessMosaic::StringToOverlay(
      ui.GetString("PRIORITY"));

  if (overlay == ProcessMapMosaic::UseBandPlacementCriteria) {
    if(ui.GetString("TYPE") == "BANDNUMBER") {
      m.SetBandNumber(ui.GetInteger("NUMBER"));
    }
    else {
      // Key name & value
      m.SetBandKeyword(ui.GetString("KEYNAME"), ui.GetString("KEYVALUE"));
    throw;
  }
    // Band Criteria
    m.SetBandUseMaxValue( (ui.GetString("CRITERIA") == "GREATER") );
  }

  // Priority
  m.SetImageOverlay(overlay);

  CubeAttributeOutput &oAtt = ui.GetOutputAttribute("MOSAIC");
  if(ui.GetString("GRANGE") == "USER") {
    m.SetOutputCube(list,
                    ui.GetDouble("MINLAT"), ui.GetDouble("MAXLAT"),
                    ui.GetDouble("MINLON"), ui.GetDouble("MAXLON"),
                    oAtt, ui.GetFileName("MOSAIC"));
  for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
    Application::Log(*grpIt);
  }
  else {
    m.SetOutputCube(list, oAtt, ui.GetFileName("MOSAIC"));
  }

  m.SetHighSaturationFlag(ui.GetBoolean("HIGHSATURATION"));
  m.SetLowSaturationFlag(ui.GetBoolean("LOWSATURATION"));
  m.SetNullFlag(ui.GetBoolean("NULL"));

  // Loop for each input file and place it in the output mosaic

  m.SetBandBinMatch(ui.GetBoolean("MATCHBANDBIN"));

  // Get the MatchDEM Flag
  m.SetMatchDEM(ui.GetBoolean("MATCHDEM"));

  bool mosaicCreated = false;
  for (int i = 0; i < list.size(); i++) {
    if (!m.StartProcess(list[i].toString())) {
      PvlGroup outsiders("Outside");
      outsiders += PvlKeyword("File", list[i].toString());
      Application::Log(outsiders);
    }
    else {
      mosaicCreated = true;
      if(olistFlag) {
        os << list[i].toString() << endl;
      }
    }
    if(mosaicCreated) {
      // Mosaic is already created, use the existing mosaic
      m.SetCreateFlag(false);
    }
  }
  // Logs the input file location in the mosaic
  for (int i = 0; i < m.imagePositions().groups(); i++) {
    Application::Log(m.imagePositions().group(i));
  }

  if(olistFlag) {
    os.close();
  }

  m.EndProcess();
}

// Function to calculate the ground range from multiple inputs (list of images)
void calcRange(double &minLat, double &maxLat, double &minLon, double &maxLon) {
  UserInterface &ui = Application::GetUserInterface();

  FileList list(FileName(ui.GetFileName("FROMLIST")));
  minLat = DBL_MAX;
  maxLat = -DBL_MAX;
+0 −4
Original line number Diff line number Diff line
BLANKS = "%-6s"    
LENGTH = "%-40s"

include $(ISISROOT)/make/isismake.tststree
+0 −38
Original line number Diff line number Diff line
APPNAME = automos

include $(ISISROOT)/make/isismake.tsts

# Run test.
# Find the first instance of ImageLocation and store the line number in FIRST.
# The number of lines to delete from the start of the file is LINECOUNT = FIRST - 1.
# Find the last intance of StartLine and store the line number in LASTLINE.
# Find the last line number of the last line of the file (EOF).
# Delete from LAST = LASTLINE + 1 to EOF.
# Append End_Group and End onto the end of the pvl.
# Generate outputlist and delete unecessary files.

commands:
	ls $(INPUT)/*.cub > $(OUTPUT)/inputlist.txt;                                           \
	$(APPNAME) fromlist=$(OUTPUT)/inputlist.txt                                            \
	  mosaic=$(OUTPUT)/automosTruth.cub                                                    \
	  tolist=$(OUTPUT)/out.txt                                                             \
	  grange=user minlat=45 maxlat=47.5                                                    \
	  minlon=-105 maxlon=265                                                               \
	  -log=$(OUTPUT)/appLogOutput.pvl                                                      \
	  > /dev/null;                                                                         \
	  FIRST=`grep -m 1 -n ImageLocation $(OUTPUT)/appLogOutput.pvl | sed 's/:.*//'`;       \
	  LINECOUNT=`expr "$$FIRST" - 1`;                                                      \
	  `cat $(OUTPUT)/appLogOutput.pvl | sed -e "1,$${LINECOUNT}d" -e '/ ./!d' > $(OUTPUT)/temp.pvl`;                   \
	  `cat $(OUTPUT)/temp.pvl > $(OUTPUT)/appLogOutput.pvl`;\
	  `grep -n StartLine $(OUTPUT)/appLogOutput.pvl | sed 's/:.*//' > $(OUTPUT)/temp.pvl`; \
	  LASTLINE=`sed '$$!d' $(OUTPUT)/temp.pvl`;                                            \
	  LAST=`expr "$$LASTLINE" + 1`;                                                        \
	  EOF=`wc -l $(OUTPUT)/appLogOutput.pvl | sed 's/\(^ *\)\([0-9]*\)\( .*\$\)/\2/'`;      \
	  cat $(OUTPUT)/appLogOutput.pvl | sed -e "$$LAST","$$EOF"d > $(OUTPUT)/temp.pvl;       \
	  `cat $(OUTPUT)/temp.pvl > $(OUTPUT)/appLogOutput.pvl`;\
	  `echo 'End_Group' >> $(OUTPUT)/appLogOutput.pvl`;                                    \
	  `echo 'End' >> $(OUTPUT)/appLogOutput.pvl`;                                          \
	  cat $(OUTPUT)/out.txt | sed "s#.*/##g" > $(OUTPUT)/outputlist.txt;                   \
	  $(RM) $(OUTPUT)/out.txt;                                                             \
	  $(RM) $(OUTPUT)/temp.pvl;                                                            \
	  $(RM) $(OUTPUT)/inputlist.txt;
Loading