From 924ddeb6e24abd15259d6db0f3865598fcb94f7f Mon Sep 17 00:00:00 2001 From: lewisblake Date: Mon, 9 Dec 2024 08:23:03 +0000 Subject: [PATCH 1/4] infer info from geojson files in contour dir as well --- pyaerocom/aeroval/experiment_output.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pyaerocom/aeroval/experiment_output.py b/pyaerocom/aeroval/experiment_output.py index dadad71af..2e1358a25 100644 --- a/pyaerocom/aeroval/experiment_output.py +++ b/pyaerocom/aeroval/experiment_output.py @@ -365,16 +365,18 @@ def _info_from_contour_dir_file(file: pathlib.PosixPath): """ spl = os.path.basename(file.name).split(file.suffix)[0].split("_") - if len(spl) != 3: - raise ValueError( - f"invalid contour filename: {file}. Must " - f"contain exactly 2 underscores _ to separate " - f"name, vertical, and periods" - ) - name = spl[0] - var_name = spl[1] - per = spl[2] - return (name, var_name, per) + if len(spl) == 3: # png, webp + name = spl[0] + var_name = spl[1] + per = spl[2] + return (name, var_name, per) + elif len(spl) == 2: # geojson + name = spl[0] + var_name = spl[1] + per = None + return (name, var_name, per) + else: + raise ValueError("Could not infer information from contour dir file") def _results_summary(self) -> dict[str, list[str]]: if self.cfg.processing_opts.only_model_maps: From b561616fcdc50e032db103d4510b15a9c9a28653 Mon Sep 17 00:00:00 2001 From: lewisblake Date: Mon, 9 Dec 2024 08:27:46 +0000 Subject: [PATCH 2/4] info order reversed --- pyaerocom/aeroval/experiment_output.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyaerocom/aeroval/experiment_output.py b/pyaerocom/aeroval/experiment_output.py index 2e1358a25..5a1b784e3 100644 --- a/pyaerocom/aeroval/experiment_output.py +++ b/pyaerocom/aeroval/experiment_output.py @@ -371,8 +371,8 @@ def _info_from_contour_dir_file(file: pathlib.PosixPath): per = spl[2] return (name, var_name, per) elif len(spl) == 2: # geojson - name = spl[0] - var_name = spl[1] + name = spl[1] + var_name = spl[0] per = None return (name, var_name, per) else: From 67ae46b524bf2ccf5e041f3c06248c915dca6906 Mon Sep 17 00:00:00 2001 From: lewisblake Date: Mon, 9 Dec 2024 08:32:15 +0000 Subject: [PATCH 3/4] update value error message --- pyaerocom/aeroval/experiment_output.py | 2 +- tests/aeroval/test_experiment_output.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyaerocom/aeroval/experiment_output.py b/pyaerocom/aeroval/experiment_output.py index 5a1b784e3..773065bec 100644 --- a/pyaerocom/aeroval/experiment_output.py +++ b/pyaerocom/aeroval/experiment_output.py @@ -376,7 +376,7 @@ def _info_from_contour_dir_file(file: pathlib.PosixPath): per = None return (name, var_name, per) else: - raise ValueError("Could not infer information from contour dir file") + raise ValueError(f"invalid contour filename: {file}") def _results_summary(self) -> dict[str, list[str]]: if self.cfg.processing_opts.only_model_maps: diff --git a/tests/aeroval/test_experiment_output.py b/tests/aeroval/test_experiment_output.py index 2f3db0a57..8af7a4d66 100644 --- a/tests/aeroval/test_experiment_output.py +++ b/tests/aeroval/test_experiment_output.py @@ -209,7 +209,7 @@ def test_ExperimentOutput__info_from_contour_dir_file_error(): file = pathlib.PosixPath("path/to/obs_vertical_model_period.txt") with pytest.raises(ValueError) as e: ExperimentOutput._info_from_contour_dir_file(file) - assert "invalid contour filename" in str(e.value) + assert "" in str(e.value) def test_ExperimentOutput__results_summary_EMPTY(dummy_expout: ExperimentOutput): From dd555233d833a28864650272230f4795838c42f2 Mon Sep 17 00:00:00 2001 From: lewisblake Date: Mon, 9 Dec 2024 08:33:21 +0000 Subject: [PATCH 4/4] fix test --- tests/aeroval/test_experiment_output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/aeroval/test_experiment_output.py b/tests/aeroval/test_experiment_output.py index 8af7a4d66..2f3db0a57 100644 --- a/tests/aeroval/test_experiment_output.py +++ b/tests/aeroval/test_experiment_output.py @@ -209,7 +209,7 @@ def test_ExperimentOutput__info_from_contour_dir_file_error(): file = pathlib.PosixPath("path/to/obs_vertical_model_period.txt") with pytest.raises(ValueError) as e: ExperimentOutput._info_from_contour_dir_file(file) - assert "" in str(e.value) + assert "invalid contour filename" in str(e.value) def test_ExperimentOutput__results_summary_EMPTY(dummy_expout: ExperimentOutput):