Unverified Commit 72702615 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Revised GUI parameters, added dropdown menus.

parent 4b0ad30f
......@@ -33,16 +33,17 @@ from threading import Thread
from queue import Queue
from subprocess import Popen, PIPE
from qgis.core import \
(QgsProcessingAlgorithm,
QgsProcessingParameterFile,
QgsProcessingParameterNumber,
QgsProcessingParameterFolderDestination,
QgsProcessingParameterBoolean,
QgsProcessingParameterString,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer
)
from qgis.core import (
QgsProcessingAlgorithm,
QgsProcessingParameterFile,
QgsProcessingParameterNumber,
QgsProcessingParameterFolderDestination,
QgsProcessingParameterBoolean,
QgsProcessingParameterString,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterEnum
)
from .version import __version__
......@@ -60,7 +61,9 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm):
P_output_dir = 'output_dir'
P_working_dir = 'working_dir'
P_n_lines_to_append = 'n_lines_to_append'
P_drop_bad_bands = 'drop_bad_bands'
P_disable_progress_bars = 'disable_progress_bars'
P_output_format = 'output_format'
P_path_earthSunDist = 'path_earthSunDist'
P_path_solar_irr = 'path_solar_irr'
P_scale_factor_toa_ref = 'scale_factor_toa_ref'
......@@ -68,9 +71,6 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm):
P_enable_vnir_swir_coreg = 'enable_vnir_swir_coreg'
P_path_reference_image = 'path_reference_image'
P_enable_ac = 'enable_ac'
P_auto_download_ecmwf = 'auto_download_ecmwf'
P_enable_ice_retrieval = 'enable_ice_retrieval'
P_enable_cloud_screening = 'enable_cloud_screening'
P_scale_factor_boa_ref = 'scale_factor_boa_ref'
P_run_smile_P = 'run_smile_P'
P_run_deadpix_P = 'run_deadpix_P'
......@@ -79,6 +79,8 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm):
P_deadpix_P_interp_spatial = 'deadpix_P_interp_spatial'
P_ortho_resampAlg = 'ortho_resampAlg'
P_vswir_overlap_algorithm = 'vswir_overlap_algorithm'
P_target_projection_type = 'target_projection_type'
P_target_epsg = 'target_epsg'
# # Output parameters
P_OUTPUT_RASTER = 'outraster'
......@@ -133,141 +135,152 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm):
super(_EnPTBaseAlgorithm, self).addParameter(param, *args, **kwargs)
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,
self.addParameter(
QgsProcessingParameterFile(
name=self.P_json_config,
description='Configuration JSON template file',
behavior=QgsProcessingParameterFile.File,
extension='json',
defaultValue=None,
optional=True))
self.addParameter(QgsProcessingParameterNumber(
name=self.P_CPUs,
description='Number of CPU cores to be used for processing',
type=QgsProcessingParameterNumber.Integer,
defaultValue=cpu_count(), minValue=0, maxValue=cpu_count(),
optional=True),
self.addParameter(
QgsProcessingParameterNumber(
name=self.P_CPUs,
description='Number of CPU cores to be used for processing',
type=QgsProcessingParameterNumber.Integer,
defaultValue=cpu_count(), minValue=0, maxValue=cpu_count(),
optional=True),
advanced=True)
self.addParameter(QgsProcessingParameterFile(
name=self.P_path_l1b_enmap_image,
description='EnMAP Level-1B image (zip-archive or root directory)'))
self.addParameter(
QgsProcessingParameterFile(
name=self.P_path_l1b_enmap_image,
description='EnMAP Level-1B image (zip-archive or root directory)'))
self.addParameter(QgsProcessingParameterFile(
name=self.P_path_l1b_enmap_image_gapfill,
description='Adjacent EnMAP Level-1B image to be used for gap-filling (zip-archive or root directory)',
optional=True),
self.addParameter(
QgsProcessingParameterFile(
name=self.P_path_l1b_enmap_image_gapfill,
description='Adjacent EnMAP Level-1B image to be used for gap-filling (zip-archive or root directory)',
optional=True),
advanced=True)
self.addParameter(QgsProcessingParameterRasterLayer(
name=self.P_path_dem,
description='Input path of digital elevation model in map or sensor geometry; GDAL compatible file '
'format \n(must cover the EnMAP L1B data completely if given in map geometry or must have the '
'same \npixel dimensions like the EnMAP L1B data if given in sensor geometry)',
optional=True))
self.addParameter(QgsProcessingParameterNumber(
name=self.P_average_elevation,
description='Average elevation in meters above sea level \n'
'(may be provided if no DEM is available and ignored if DEM is given)',
type=QgsProcessingParameterNumber.Integer,
defaultValue=0,
optional=True),
self.addParameter(
QgsProcessingParameterRasterLayer(
name=self.P_path_dem,
description='Input path of digital elevation model in map or sensor geometry; GDAL compatible file '
'format \n(must cover the EnMAP L1B data completely if given in map geometry or must have '
'the same \npixel dimensions like the EnMAP L1B data if given in sensor geometry)',
optional=True))
self.addParameter(
QgsProcessingParameterNumber(
name=self.P_average_elevation,
description='Average elevation in meters above sea level \n'
'(may be provided if no DEM is available and ignored if DEM is given)',
type=QgsProcessingParameterNumber.Integer,
defaultValue=0,
optional=True),
advanced=True)
self.addParameter(QgsProcessingParameterFolderDestination(
name=self.P_output_dir,
description='Output directory where processed data and log files are saved',
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))
self.addParameter(QgsProcessingParameterNumber(
name=self.P_n_lines_to_append,
description='Number of lines to be added to the main image [if not given, use the whole imgap]',
type=QgsProcessingParameterNumber.Integer,
defaultValue=None,
optional=True),
self.addParameter(
QgsProcessingParameterFolderDestination(
name=self.P_output_dir,
description='Output directory where processed data and log files are saved',
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))
self.addParameter(
QgsProcessingParameterNumber(
name=self.P_n_lines_to_append,
description='Number of lines to be added to the main image [if not given, use the whole imgap]',
type=QgsProcessingParameterNumber.Integer,
defaultValue=None,
optional=True),
advanced=True)
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_disable_progress_bars,
description='Disable all progress bars during processing',
defaultValue=True,
optional=True),
self.addParameter(
QgsProcessingParameterBoolean(
name=self.P_drop_bad_bands,
description='Do not include bad bands (water absorption bands 1358-1453 nm / 1814-1961 nm) '
'in the L2A product',
defaultValue=True),
advanced=True)
self.addParameter(QgsProcessingParameterFile(
name=self.P_path_earthSunDist,
description='Input path of the earth sun distance model',
defaultValue=None,
optional=True),
self.addParameter(
QgsProcessingParameterBoolean(
name=self.P_disable_progress_bars,
description='Disable all progress bars during processing',
defaultValue=True),
advanced=True)
self.addParameter(QgsProcessingParameterFile(
name=self.P_path_solar_irr,
description='Input path of the solar irradiance model',
defaultValue=None,
optional=True),
self.addParameter(
QgsProcessingParameterEnum(
name=self.P_output_format,
description="Output format (file format of all raster output files).",
options=['GTiff', 'ENVI'],
defaultValue=0),
advanced=True)
self.addParameter(QgsProcessingParameterNumber(
name=self.P_scale_factor_toa_ref,
description='Scale factor to be applied to TOA reflectance result',
type=QgsProcessingParameterNumber.Integer,
defaultValue=10000,
optional=True),
advanced=True)
# output_interleave?
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_enable_keystone_correction,
description='Keystone correction',
defaultValue=False,
optional=True))
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_enable_vnir_swir_coreg,
description='VNIR/SWIR co-registration',
defaultValue=False,
optional=True))
self.addParameter(QgsProcessingParameterRasterLayer(
name=self.P_path_reference_image,
description='Reference image for co-registration.',
defaultValue=None,
optional=True))
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_enable_ac,
description='Enable atmospheric correction using SICOR algorithm',
defaultValue=True,
optional=True))
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_auto_download_ecmwf,
description='Automatically download ECMWF data for atmospheric correction',
defaultValue=False,
optional=True),
self.addParameter(
QgsProcessingParameterFile(
name=self.P_path_earthSunDist,
description='Input path of the earth sun distance model',
defaultValue=None,
optional=True),
advanced=True)
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_enable_ice_retrieval,
description='Enable ice retrieval (increases accuracy of water vapour retrieval)',
defaultValue=True,
optional=True),
self.addParameter(
QgsProcessingParameterFile(
name=self.P_path_solar_irr,
description='Input path of the solar irradiance model',
defaultValue=None,
optional=True),
advanced=True)
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_enable_cloud_screening,
description='Cloud screening during atmospheric correction',
defaultValue=False,
optional=True),
self.addParameter(
QgsProcessingParameterNumber(
name=self.P_scale_factor_toa_ref,
description='Scale factor to be applied to TOA reflectance result',
type=QgsProcessingParameterNumber.Integer,
defaultValue=10000),
advanced=True)
self.addParameter(
QgsProcessingParameterBoolean(
name=self.P_enable_keystone_correction,
description='Keystone correction',
defaultValue=False))
self.addParameter(
QgsProcessingParameterBoolean(
name=self.P_enable_vnir_swir_coreg,
description='VNIR/SWIR co-registration',
defaultValue=False))
self.addParameter(
QgsProcessingParameterRasterLayer(
name=self.P_path_reference_image,
description='Reference image for co-registration.',
defaultValue=None,
optional=True))
self.addParameter(
QgsProcessingParameterBoolean(
name=self.P_enable_ac,
description='Enable atmospheric correction using SICOR algorithm',
defaultValue=True))
self.addParameter(QgsProcessingParameterNumber(
name=self.P_scale_factor_boa_ref,
description='Scale factor to be applied to BOA reflectance result',
......@@ -276,61 +289,81 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm):
optional=True),
advanced=True)
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_run_smile_P,
description='Smile detection and correction (provider smile coefficients are ignored)',
defaultValue=False,
optional=True))
self.addParameter(
QgsProcessingParameterBoolean(
name=self.P_run_smile_P,
description='Smile detection and correction (provider smile coefficients are ignored)',
defaultValue=False))
self.addParameter(
QgsProcessingParameterBoolean(
name=self.P_run_deadpix_P,
description='Dead pixel correction',
defaultValue=True))
self.addParameter(
QgsProcessingParameterEnum(
name=self.P_deadpix_P_algorithm,
description="Algorithm for dead pixel correction",
options=['spectral', 'spatial'],
defaultValue=0),
advanced=True)
self.addParameter(QgsProcessingParameterBoolean(
name=self.P_run_deadpix_P,
description='Dead pixel correction',
defaultValue=True,
optional=True))
self.addParameter(
QgsProcessingParameterEnum(
name=self.P_deadpix_P_interp_spectral,
description="Spectral interpolation algorithm to be used during dead pixel correction ",
options=['linear', 'bilinear', 'cubic', 'spline'],
defaultValue=0),
advanced=True)
self.addParameter(QgsProcessingParameterString(
name=self.P_deadpix_P_algorithm,
description="Algorithm for dead pixel correction ('spectral' or 'spatial')",
defaultValue='spectral',
multiLine=False,
optional=True),
self.addParameter(
QgsProcessingParameterEnum(
name=self.P_deadpix_P_interp_spatial,
description="Spatial interpolation algorithm to be used during dead pixel correction",
options=['linear', 'bilinear', 'cubic', 'spline'],
defaultValue=0),
advanced=True)
self.addParameter(QgsProcessingParameterString(
name=self.P_deadpix_P_interp_spectral,
description="Spectral interpolation algorithm to be used during dead pixel correction "
"('linear', 'bilinear', 'cubic', 'spline')",
defaultValue='linear',
multiLine=False,
optional=True),
self.addParameter(
QgsProcessingParameterEnum(
name=self.P_ortho_resampAlg,
description="Ortho-rectification resampling algorithm",
options=['nearest', 'bilinear', 'gauss'],
defaultValue=2),
advanced=True)
self.addParameter(QgsProcessingParameterString(
name=self.P_deadpix_P_interp_spatial,
description="Spatial interpolation algorithm to be used during dead pixel correction "
"('linear', 'bilinear', 'cubic', 'spline')",
defaultValue='linear',
multiLine=False,
optional=True),
self.addParameter(
QgsProcessingParameterEnum(
name=self.P_vswir_overlap_algorithm,
description="Algorithm specifying how to deal with the spectral bands "
"in the VNIR/SWIR spectral overlap region",
options=['VNIR and SWIR bands, order by wavelength', 'average VNIR and SWIR bands',
'VNIR bands only', 'SWIR bands only'],
defaultValue=3),
advanced=True)
self.addParameter(QgsProcessingParameterString(
name=self.P_ortho_resampAlg,
description="Ortho-rectification resampling algorithm ('nearest', 'bilinear', 'gauss')",
defaultValue='bilinear',
multiLine=False,
optional=True),
self.addParameter(
QgsProcessingParameterEnum(
self.P_target_projection_type,
description='Projection type of the raster output files',
options=['UTM', 'Geographic'],
defaultValue=0),
advanced=True)
self.addParameter(QgsProcessingParameterString(
name=self.P_vswir_overlap_algorithm,
description="Algorithm specifying how to deal with the spectral bands in the VNIR/SWIR spectral overlap "
"region ('order_by_wvl', 'average', 'vnir_only', 'swir_only')",
defaultValue='swir_only',
multiLine=False,
optional=True),
self.addParameter(
QgsProcessingParameterNumber(
name=self.P_target_epsg,
description='Custom EPSG code of the target projection (overrides target_projection_type)',
type=QgsProcessingParameterNumber.Integer,
defaultValue=None,
optional=True),
advanced=True)
# TODO:
# "target_coord_grid": "None" /*custom target coordinate grid to which the output is resampled
# ([x0, x1, y0, y1], e.g., [0, 30, 0, 30])*/
@staticmethod
def shortHelpString(*args, **kwargs):
"""Example:
......@@ -367,7 +400,6 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm):
:param cmd: a normal shell command including parameters
"""
def reader(pipe, queue):
try:
with pipe:
......
......@@ -27,6 +27,7 @@
import os
from pkgutil import find_loader
from glob import glob
from pprint import pprint
from qgis.core import \
(QgsProcessingContext,
......@@ -75,6 +76,18 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm):
raise ImportError("enpt", "EnPT must be installed into the QGIS Python environment "
"when calling 'EnPTAlgorithm'.")
# replace Enum parameters with corresponding strings
for n, opts in [
('output_format', {0: 'GTiff', 1: 'ENVI'}),
('deadpix_P_algorithm', {0: 'spectral', 1: 'spatial'}),
('deadpix_P_interp_spectral', {0: 'linear', 1: 'bilinear', 2: 'cubic', 3: 'spline'}),
('deadpix_P_interp_spatial', {0: 'linear', 1: 'bilinear', 2: 'cubic', 3: 'spline'}),
('ortho_resampAlg', {0: 'nearest', 1: 'bilinear', 2: 'gauss'}),
('vswir_overlap_algorithm', {0: 'order_by_wvl', 1: 'average', 2: 'vnir_only', 3: 'swir_only'}),
('target_projection_type', {0: 'UTM', 1: 'Geographic'}),
]:
parameters[n] = opts[parameters[n]]
feedback.pushInfo("The log messages of the EnMAP processing tool are written to the *.log file "
"in the specified output folder.")
......@@ -83,13 +96,14 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm):
if k not in ['anaconda_root']
and v not in [None, NULL, 'NULL', '']}
# print parameters and console call to log
# for key in sorted(parameters):
# feedback.pushInfo('{} = {}'.format(key, repr(parameters[key])))
keyval_str = ' '.join(['--{} {}'.format(key, parameters[key])
for key in sorted(parameters)
if parameters[key] not in [None, NULL, 'NULL', '']])
print(parameters)
pprint(parameters)
print(keyval_str + '\n\n')
feedback.pushInfo("\nCalling EnPT with the following command:\n"
"enpt %s\n\n" % keyval_str)
......
......@@ -170,6 +170,18 @@ class ExternalEnPTAlgorithm(_EnPTBaseAlgorithm):
parameters = {k: v for k, v in parameters.items()
if k not in ['anaconda_root']}
# replace Enum parameters with corresponding strings
for n, opts in [
('output_format', {0: 'GTiff', 1: 'ENVI'}),
('deadpix_P_algorithm', {0: 'spectral', 1: 'spatial'}),
('deadpix_P_interp_spectral', {0: 'linear', 1: 'bilinear', 2: 'cubic', 3: 'spline'}),
('deadpix_P_interp_spatial', {0: 'linear', 1: 'bilinear', 2: 'cubic', 3: 'spline'}),
('ortho_resampAlg', {0: 'nearest', 1: 'bilinear', 2: 'gauss'}),
('vswir_overlap_algorithm', {0: 'order_by_wvl', 1: 'average', 2: 'vnir_only', 3: 'swir_only'}),
('target_projection_type', {0: 'UTM', 1: 'Geographic'}),
]:
parameters[n] = opts[parameters[n]]
# print parameters and console call to log
# for key in sorted(parameters):
# feedback.pushInfo('{} = {}'.format(key, repr(parameters[key])))
......
......@@ -54,8 +54,9 @@ enpt_test_parameters = dict(
deadpix_P_algorithm='spectral',
deadpix_P_interp_spectral='linear',
deadpix_P_interp_spatial='linear',
drop_bad_bands=True,
disable_progress_bars=False,
enable_cloud_screening=False,
output_format='GTiff',
enable_keystone_correction=False,
enable_vnir_swir_coreg=False,
json_config=None,
......
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