From 8c66bbe6e7cd2dfe246e6678f14f9a436dc9daaf Mon Sep 17 00:00:00 2001 From: msorvoja Date: Mon, 18 Nov 2024 11:52:27 +0200 Subject: [PATCH] refactor(coda): Add columns selection parameter --- .../transformations_coda/alr_transform.py | 20 ++++++++++++---- .../transformations_coda/clr_transform.py | 15 ++++++++++-- .../inverse_alr_transform.py | 23 ++++++++++++++----- .../inverse_clr_transform.py | 17 +++++++++++--- .../transformations_coda/plr_transform.py | 15 ++++++++++-- .../single_plr_transform.py | 14 +++++++++-- 6 files changed, 85 insertions(+), 19 deletions(-) diff --git a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/alr_transform.py b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/alr_transform.py index 42babb7e..fe8ba94c 100644 --- a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/alr_transform.py +++ b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/alr_transform.py @@ -19,7 +19,9 @@ def __init__(self) -> None: self._short_help_string = "Perform an additive logratio transformation on the data." def initAlgorithm(self, config=None): - self.alg_parameters = ["input_vector", "column", "keep_denominator_column", "output_vector"] + self.alg_parameters = [ + "input_vector", "columns", "denominator_column", "keep_denominator_column", "output_vector" + ] input_vector_param = QgsProcessingParameterFeatureSource( name=self.alg_parameters[0], description="Input vector" @@ -27,8 +29,18 @@ def initAlgorithm(self, config=None): input_vector_param.setHelp("Input vector with compositional data.") self.addParameter(input_vector_param) - denominator_column_param = QgsProcessingParameterField( + columns_param = QgsProcessingParameterField( name=self.alg_parameters[1], + description="Columns", + parentLayerParameterName=self.alg_parameters[0], + optional=True, + allowMultiple=True, + ) + columns_param.setHelp("Columns to be transformed.") + self.addParameter(columns_param) + + denominator_column_param = QgsProcessingParameterField( + name=self.alg_parameters[2], description="Denominator column", parentLayerParameterName=self.alg_parameters[0], optional=True, @@ -37,7 +49,7 @@ def initAlgorithm(self, config=None): self.addParameter(denominator_column_param) keep_denominator_column_param = QgsProcessingParameterBoolean( - name=self.alg_parameters[2], + name=self.alg_parameters[3], description="Keep denominator column", defaultValue=False ) @@ -47,7 +59,7 @@ def initAlgorithm(self, config=None): self.addParameter(keep_denominator_column_param) output_vector_param = QgsProcessingParameterVectorDestination( - name=self.alg_parameters[3], + name=self.alg_parameters[4], description="Output vector", ) output_vector_param.setHelp("Output vector with the ALR transformed data.") diff --git a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/clr_transform.py b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/clr_transform.py index 0c2a0758..b22c76cf 100644 --- a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/clr_transform.py +++ b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/clr_transform.py @@ -1,5 +1,6 @@ from qgis.core import ( QgsProcessingParameterFeatureSource, + QgsProcessingParameterField, QgsProcessingParameterVectorDestination, ) @@ -17,7 +18,7 @@ def __init__(self) -> None: self._short_help_string = "Perform a centered logratio transformation on the data." def initAlgorithm(self, config=None): - self.alg_parameters = ["input_vector", "output_vector"] + self.alg_parameters = ["input_vector", "columns", "output_vector"] input_vector_param = QgsProcessingParameterFeatureSource( name=self.alg_parameters[0], description="Input vector" @@ -25,8 +26,18 @@ def initAlgorithm(self, config=None): input_vector_param.setHelp("Input vector with compositional data.") self.addParameter(input_vector_param) - output_vector_param = QgsProcessingParameterVectorDestination( + columns_param = QgsProcessingParameterField( name=self.alg_parameters[1], + description="Columns", + parentLayerParameterName=self.alg_parameters[0], + optional=True, + allowMultiple=True + ) + columns_param.setHelp("The names of the columns to be transformed.") + self.addParameter(columns_param) + + output_vector_param = QgsProcessingParameterVectorDestination( + name=self.alg_parameters[2], description="Output vector", ) output_vector_param.setHelp("Output vector with the CLR transformed data.") diff --git a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/inverse_alr_transform.py b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/inverse_alr_transform.py index 052c3e55..c0fbe3ce 100644 --- a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/inverse_alr_transform.py +++ b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/inverse_alr_transform.py @@ -1,7 +1,7 @@ from qgis.core import ( QgsProcessingParameterFeatureSource, + QgsProcessingParameterField, QgsProcessingParameterNumber, - QgsProcessingParameterString, QgsProcessingParameterVectorDestination, ) @@ -19,7 +19,7 @@ def __init__(self) -> None: self._short_help_string = "Perform the inverse transformation for a set of ALR transformed data." def initAlgorithm(self, config=None): - self.alg_parameters = ["input_vector", "denominator_column", "scale", "output_vector"] + self.alg_parameters = ["input_vector", "denominator_column", "columns", "scale", "output_vector"] input_vector_param = QgsProcessingParameterFeatureSource( name=self.alg_parameters[0], description="Input vector" @@ -27,15 +27,26 @@ def initAlgorithm(self, config=None): input_vector_param.setHelp("Input vector with ALR transformed compositional data.") self.addParameter(input_vector_param) - denominator_column_name_param = QgsProcessingParameterString( + denominator_column_name_param = QgsProcessingParameterField( name=self.alg_parameters[1], - description="Denominator column name", + description="Denominator column", + parentLayerParameterName=self.alg_parameters[0], ) denominator_column_name_param.setHelp("The name of the denominator column.") self.addParameter(denominator_column_name_param) - scale_param = QgsProcessingParameterNumber( + columns_param = QgsProcessingParameterField( name=self.alg_parameters[2], + description="Columns", + parentLayerParameterName=self.alg_parameters[0], + optional=True, + allowMultiple=True, + ) + columns_param.setHelp("The names of the columns to be transformed.") + self.addParameter(columns_param) + + scale_param = QgsProcessingParameterNumber( + name=self.alg_parameters[3], description="Scale", defaultValue=1.0, type=QgsProcessingParameterNumber.Double @@ -47,7 +58,7 @@ def initAlgorithm(self, config=None): self.addParameter(scale_param) output_vector_param = QgsProcessingParameterVectorDestination( - name=self.alg_parameters[3], + name=self.alg_parameters[4], description="Output vector", ) output_vector_param.setHelp("Output vector with inverse transformed data.") diff --git a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/inverse_clr_transform.py b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/inverse_clr_transform.py index ab07f1a3..a5e27d08 100644 --- a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/inverse_clr_transform.py +++ b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/inverse_clr_transform.py @@ -1,5 +1,6 @@ from qgis.core import ( QgsProcessingParameterFeatureSource, + QgsProcessingParameterField, QgsProcessingParameterNumber, QgsProcessingParameterVectorDestination, ) @@ -18,7 +19,7 @@ def __init__(self) -> None: self._short_help_string = "Perform the inverse transformation for a set of CLR transformed data." def initAlgorithm(self, config=None): - self.alg_parameters = ["input_vector", "scale", "output_vector"] # NOTE: Colnames param omitted + self.alg_parameters = ["input_vector", "columns", "scale", "output_vector"] # NOTE: Colnames param omitted input_vector_param = QgsProcessingParameterFeatureSource( name=self.alg_parameters[0], description="Input vector" @@ -26,8 +27,18 @@ def initAlgorithm(self, config=None): input_vector_param.setHelp("Input vector with CLR transformed compositional data.") self.addParameter(input_vector_param) - scale_param = QgsProcessingParameterNumber( + columns_param = QgsProcessingParameterField( name=self.alg_parameters[1], + description="Columns", + parentLayerParameterName=self.alg_parameters[0], + optional=True, + allowMultiple=True, + ) + columns_param.setHelp("The names of the columns to be transformed.") + self.addParameter(columns_param) + + scale_param = QgsProcessingParameterNumber( + name=self.alg_parameters[2], description="Scale", defaultValue=1.0, type=QgsProcessingParameterNumber.Double @@ -39,7 +50,7 @@ def initAlgorithm(self, config=None): self.addParameter(scale_param) output_vector_param = QgsProcessingParameterVectorDestination( - name=self.alg_parameters[2], + name=self.alg_parameters[3], description="Output vector", ) output_vector_param.setHelp("Output vector with inverse transformed data.") diff --git a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/plr_transform.py b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/plr_transform.py index 0620b6c7..e4a45012 100644 --- a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/plr_transform.py +++ b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/plr_transform.py @@ -1,5 +1,6 @@ from qgis.core import ( QgsProcessingParameterFeatureSource, + QgsProcessingParameterField, QgsProcessingParameterVectorDestination, ) @@ -15,11 +16,11 @@ def __init__(self) -> None: self._group = "Transformations — CoDA" self._group_id = "transformations_coda" self._short_help_string = """ - Perform a pivot logratio transformation on the dataframe, returning the full set of transforms. + Perform a pivot logratio transformation on the selected columns. """ def initAlgorithm(self, config=None): - self.alg_parameters = ["input_vector", "output_vector"] + self.alg_parameters = ["input_vector", "columns", "output_vector"] input_vector_param = QgsProcessingParameterFeatureSource( name=self.alg_parameters[0], description="Input vector" @@ -27,6 +28,16 @@ def initAlgorithm(self, config=None): input_vector_param.setHelp("Input vector with compositional data.") self.addParameter(input_vector_param) + columns_param = QgsProcessingParameterField( + name=self.alg_parameters[1], + description="Columns", + parentLayerParameterName=self.alg_parameters[0], + optional=True, + allowMultiple=True, + ) + columns_param.setHelp("The names of the columns to be transformed.") + self.addParameter(columns_param) + output_vector_param = QgsProcessingParameterVectorDestination( name=self.alg_parameters[1], description="Output vector", diff --git a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/single_plr_transform.py b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/single_plr_transform.py index 4c58e2f4..8d1ce28a 100644 --- a/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/single_plr_transform.py +++ b/eis_qgis_plugin/eis_processing/algorithms/transformations_coda/single_plr_transform.py @@ -25,7 +25,7 @@ def __init__(self) -> None: """ def initAlgorithm(self, config=None): - self.alg_parameters = ["input_vector", "column", "output_vector"] + self.alg_parameters = ["input_vector", "numerator", "denominator", "output_vector"] input_vector_param = QgsProcessingParameterFeatureSource( name=self.alg_parameters[0], description="Input vector" @@ -41,8 +41,18 @@ def initAlgorithm(self, config=None): numerator_column.setHelp("The name of the numerator column to use for the transformation.") self.addParameter(numerator_column) - output_vector_param = QgsProcessingParameterVectorDestination( + denominator_columns = QgsProcessingParameterField( name=self.alg_parameters[2], + description="Denominator columns", + parentLayerParameterName=self.alg_parameters[0], + optional=True, + allowMultiple=True, + ) + denominator_columns.setHelp("The name(s) of the denominator column(s) to use for transformation.") + self.addParameter(denominator_columns) + + output_vector_param = QgsProcessingParameterVectorDestination( + name=self.alg_parameters[3], description="Output vector", ) output_vector_param.setHelp("Output vector with the transformed data.")