Unverified Commit 2c81e673 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added default output directory, listing of output directory after successful...


Added default output directory, listing of output directory after successful run and return values. Updated version.
Signed-off-by: Daniel Scheffler's avatardanschef <daniel.scheffler@gfz-potsdam.de>
parent 77804fc5
......@@ -25,15 +25,18 @@
"""This module provides a QGIS EnMAPBox GUI for the EnMAP processing tools (EnPT)."""
import os
from os.path import expanduser
from datetime import date
from subprocess import Popen, PIPE, check_output
from multiprocessing import cpu_count
from glob import glob
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QMenu, QAction, QDialog, QHBoxLayout, QLabel, QPushButton
from enmapbox.gui.applications import EnMAPBoxApplication
from qgis.core import *
VERSION = '0.1.4'
VERSION = '0.1.5'
LICENSE = 'GNU GPL-3'
APP_DIR = os.path.dirname(__file__)
......@@ -169,10 +172,10 @@ class EnPTAlgorithm(QgsProcessingAlgorithm):
P_ortho_resampAlg = 'ortho_resampAlg'
# # Output parameters
# P_OUTPUT_RASTER = 'outraster'
P_OUTPUT_RASTER = 'outraster'
# P_OUTPUT_VECTOR = 'outvector'
# P_OUTPUT_FILE = 'outfile'
# P_OUTPUT_FOLDER = 'outfolder'
P_OUTPUT_FOLDER = 'outfolder'
def group(self):
return 'Pre-Processing'
......@@ -196,17 +199,35 @@ class EnPTAlgorithm(QgsProcessingAlgorithm):
else:
return '' # FIXME is there a default location in Linux/OSX?
@staticmethod
def _get_default_output_dir():
userhomedir = expanduser('~')
default_enpt_dir = \
os.path.join(userhomedir, 'Documents', 'EnPT', 'Output') if os.name == 'nt' else\
os.path.join(userhomedir, 'EnPT', 'Output')
outdir_nocounter = os.path.join(default_enpt_dir, date.today().strftime('%Y%m%d'))
counter = 1
while os.path.isdir('%s__%s' % (outdir_nocounter, counter)):
counter += 1
return '%s__%s' % (outdir_nocounter, counter)
def initAlgorithm(self, configuration=None):
self.addParameter(QgsProcessingParameterFile(
name=self.P_json_config, description='Configuration JSON template file',
behavior=QgsProcessingParameterFile.File, extension='json',
defaultValue=None, optional=True))
defaultValue=None,
optional=True))
self.addParameter(QgsProcessingParameterFile(
name=self.P_anaconda_root,
description='Anaconda root directory (which contains the EnPT Python environment in a subdirectory)',
behavior=QgsProcessingParameterFile.Folder,
defaultValue=self._get_default_anaconda_root(), optional=True))
defaultValue=self._get_default_anaconda_root(),
optional=True))
self.addParameter(QgsProcessingParameterNumber(
name=self.P_CPUs,
......@@ -242,13 +263,15 @@ class EnPTAlgorithm(QgsProcessingAlgorithm):
self.addParameter(QgsProcessingParameterFolderDestination(
name=self.P_output_dir,
description='Output directory where processed data and log files are saved',
defaultValue=None, optional=True))
defaultValue=self._get_default_output_dir(),
optional=True))
self.addParameter(QgsProcessingParameterFile(
name=self.P_working_dir,
description='Directory to be used for temporary files',
behavior=QgsProcessingParameterFile.Folder,
defaultValue=None, optional=True))
defaultValue=None,
optional=True))
self.addParameter(QgsProcessingParameterNumber(
name=self.P_n_lines_to_append,
......@@ -470,11 +493,26 @@ class EnPTAlgorithm(QgsProcessingAlgorithm):
else:
print('success')
# # return outputs
# return {self.P_OUTPUT_RASTER: parameters[self.P_OUTPUT_RASTER],
# self.P_OUTPUT_VECTOR: parameters[self.P_OUTPUT_RASTER],
# self.P_OUTPUT_FILE: parameters[self.P_OUTPUT_RASTER],
# self.P_OUTPUT_FOLDER: parameters[self.P_OUTPUT_RASTER]}
# list output dir
outdir = parameters['output_dir']
outraster_matches = glob(os.path.join(outdir, '*', '*SPECTRAL_IMAGE.GEOTIFF'))
outraster = outraster_matches[0] if len(outraster_matches) > 0 else None
feedback.pushInfo("The output folder '%s' contains:\n" % outdir)
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(outdir)]) + '\n')
if outraster:
subdir = os.path.dirname(outraster_matches[0])
feedback.pushInfo("...where the folder '%s' contains:\n" % os.path.dirname(subdir))
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(subdir)]) + '\n')
# return outputs
return {
self.P_OUTPUT_RASTER: outraster,
# self.P_OUTPUT_VECTOR: parameters[self.P_OUTPUT_RASTER],
# self.P_OUTPUT_FILE: parameters[self.P_OUTPUT_RASTER],
self.P_OUTPUT_FOLDER: outdir
}
@staticmethod
def shortHelpString(*args, **kwargs):
......
......@@ -71,6 +71,6 @@ setup(
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/danschef/enpt_enmapboxapp',
version='0.1.4',
version='0.1.5',
zip_safe=False,
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment