From 5e9cde1a9b0da9fac7a11306fc56b567c00690d0 Mon Sep 17 00:00:00 2001 From: Philippe Mallet-Ladeira Date: Wed, 7 Feb 2024 14:14:49 +0100 Subject: [PATCH] feat: first implementation of margins in Dichotomy This is a dummy implementation of margins into Dichotomy object as it depends on InterpolationFilters that are not yet availables. Refs: #70 --- pandora2d/refinement/dichotomy.py | 6 ++++++ tests/test_dichotomy.py | 13 +++++++++++++ tests/test_pandora2d.py | 25 +++++++++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/pandora2d/refinement/dichotomy.py b/pandora2d/refinement/dichotomy.py index 992c547..3e972f2 100644 --- a/pandora2d/refinement/dichotomy.py +++ b/pandora2d/refinement/dichotomy.py @@ -24,6 +24,8 @@ import xarray as xr from json_checker import And + +from pandora.margins import Margins from . import refinement @@ -60,6 +62,10 @@ def check_conf(cls, cfg: Dict) -> Dict: cfg["iterations"] = cls.NB_MAX_ITER return cfg + @property + def margins(self): + return Margins(2, 2, 2, 2) + def refinement_method(self, cost_volumes: xr.Dataset, pixel_maps: xr.Dataset) -> None: """ Return the subpixel disparity maps diff --git a/tests/test_dichotomy.py b/tests/test_dichotomy.py index cb91a03..ba68da0 100644 --- a/tests/test_dichotomy.py +++ b/tests/test_dichotomy.py @@ -21,6 +21,7 @@ import pytest import json_checker +from pandora.margins import Margins from pytest_mock import MockerFixture from pandora2d import refinement @@ -122,3 +123,15 @@ def test_refinement_method(config, caplog, mocker: MockerFixture): dichotomy_instance.refinement_method(mocker.ANY, mocker.ANY) assert "refinement_method of Dichotomy not yet implemented" in caplog.messages + + +def test_margins(): + """ + Test margins of Dichotomy. + """ + + config = {"refinement_method": "dichotomy", "iterations": 2, "filter": "sinc"} + + dichotomy_instance = refinement.dichotomy.Dichotomy(config) + + assert dichotomy_instance.margins == Margins(2, 2, 2, 2) diff --git a/tests/test_pandora2d.py b/tests/test_pandora2d.py index f218346..d2cdb82 100644 --- a/tests/test_pandora2d.py +++ b/tests/test_pandora2d.py @@ -91,15 +91,32 @@ def test_run_prepare() -> None: pandora2d_machine.disp_max_row, np.full((img_left.sizes["row"], img_left.sizes["col"]), 2) ) - @staticmethod - def test_global_margins() -> None: + @pytest.mark.parametrize( + ["refinement_config", "expected"], + [ + pytest.param({"refinement_method": "interpolation"}, Margins(3, 3, 3, 3), id="interpolation"), + pytest.param( + {"refinement_method": "dichotomy", "iterations": 3, "filter": "sinc"}, + Margins(2, 2, 2, 2), + id="dichotomy with sinc filter", + ), + ], + ) + def test_global_margins(self, refinement_config, expected) -> None: """ Test computed global margins is as expected. """ + pipeline_cfg = { + "pipeline": { + "matching_cost": {"matching_cost_method": "zncc", "window_size": 5}, + "disparity": {"disparity_method": "wta", "invalid_disparity": -99}, + "refinement": refinement_config, + }, + } + pandora2d_machine = state_machine.Pandora2DMachine() - pipeline_cfg = copy.deepcopy(common.correct_pipeline) pandora2d_machine.check_conf(pipeline_cfg) - assert pandora2d_machine.margins.global_margins == Margins(3, 3, 3, 3) + assert pandora2d_machine.margins.global_margins == expected