From ebf7646f4d8d143459c2ab2980676acac4c03857 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 29 Jun 2023 23:27:13 +0200 Subject: [PATCH 1/4] ADD: test for bug #106 --- tests/test_core.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_core.py b/tests/test_core.py index 5207b80..5f65ca0 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -203,6 +203,10 @@ def test_frozen_output_write(): assert app["out"].write("/tmp/test_frozen_app_write.tif") app["out"].filepath.unlink() +def test_parameters(): + app = pyotb.OrthoRectification(FILEPATH) + assert isinstance(app.parameters["map"], str) + assert app.parameters["map"] == "utm" def test_output_in_arg(): info = pyotb.ReadImageInfo(INPUT["out"]) -- GitLab From ef04e7415115aa32960c454fb335938c5399a57c Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@inrae.fr> Date: Thu, 29 Jun 2023 23:31:31 +0200 Subject: [PATCH 2/4] FIX: try to fix #106 --- pyotb/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyotb/core.py b/pyotb/core.py index 1582079..08877d4 100644 --- a/pyotb/core.py +++ b/pyotb/core.py @@ -558,7 +558,7 @@ class App(OTBObject): @property def parameters(self): """Return used OTB application parameters.""" - return {**self._auto_parameters, **self.app.GetParameters(), **self._settings} + return {**self.app.GetParameters(), **self._auto_parameters, **self._settings} @property def exports_dic(self) -> dict[str, dict]: -- GitLab From 645556c76f95a272c287dfb5007e78cbb96305d1 Mon Sep 17 00:00:00 2001 From: Vincent Delbar <vincent.delbar@latelescop.fr> Date: Fri, 30 Jun 2023 10:29:05 +0200 Subject: [PATCH 3/4] ENH: remove key from App._auto_parameters when set by user --- pyotb/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyotb/core.py b/pyotb/core.py index 08877d4..ff0905b 100644 --- a/pyotb/core.py +++ b/pyotb/core.py @@ -691,6 +691,8 @@ class App(OTBObject): self._settings[key] = obj if key in self.outputs: self.outputs[key].filepath = obj + if key in self._auto_parameters: + del self._auto_parameters[key] def propagate_dtype(self, target_key: str = None, dtype: int = None): """Propagate a pixel type from main input to every outputs, or to a target output key only. -- GitLab From 3ea66cf97cb1b764b2fc2b479dafa1478492eb41 Mon Sep 17 00:00:00 2001 From: Vincent Delbar <vincent.delbar@latelescop.fr> Date: Fri, 30 Jun 2023 10:52:02 +0200 Subject: [PATCH 4/4] FIX: duplicated test_parameters function + try update param --- tests/test_core.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 5f65ca0..0c511e7 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -8,6 +8,19 @@ def test_parameters(): assert INPUT.parameters assert INPUT.parameters["in"] == FILEPATH assert (INPUT.parameters["sizex"], INPUT.parameters["sizey"]) == (251, 304) + app = pyotb.OrthoRectification(INPUT) + assert isinstance(app.parameters["map"], str) + assert app.parameters["map"] == "utm" + assert "map" in app._auto_parameters + app.set_parameters({"map": "epsg", "map.epsg.code": 2154}) + assert app.parameters["map"] == "epsg" + assert "map" in app._settings and "map" not in app._auto_parameters + assert app.parameters["map.epsg.code"] == app.app.GetParameters()["map.epsg.code"] + + +def test_param_with_underscore(): + app = pyotb.OrthoRectification(io_in=INPUT, map_epsg_code=2154) + assert app.parameters["map.epsg.code"] == 2154 def test_input_vsi(): @@ -36,11 +49,6 @@ def test_input_vsi_from_user(): pyotb.Input("/vsicurl/" + FILEPATH) -def test_param_with_underscore(): - app = pyotb.OrthoRectification(io_in=INPUT, map_epsg_code=2154) - assert app.parameters["map.epsg.code"] == 2154 - - def test_wrong_key(): with pytest.raises(KeyError): pyotb.BandMath(INPUT, expression="im1b1") @@ -203,10 +211,6 @@ def test_frozen_output_write(): assert app["out"].write("/tmp/test_frozen_app_write.tif") app["out"].filepath.unlink() -def test_parameters(): - app = pyotb.OrthoRectification(FILEPATH) - assert isinstance(app.parameters["map"], str) - assert app.parameters["map"] == "utm" def test_output_in_arg(): info = pyotb.ReadImageInfo(INPUT["out"]) -- GitLab