Skip to content

Commit

Permalink
Merge pull request #1249 from metno/fix1246
Browse files Browse the repository at this point in the history
Fix 1246: var_list not being applied appropriately to obs_vars from networks
  • Loading branch information
heikoklein authored Jul 8, 2024
2 parents d8dcba2 + 77da745 commit 9784dda
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
7 changes: 0 additions & 7 deletions .github/ISSUE_TEMPLATE/general_issue.md

This file was deleted.

14 changes: 12 additions & 2 deletions pyaerocom/aeroval/experiment_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ def _run_single_entry(self, model_name, obs_name, var_list):
engine.run(files_to_convert)

else:
# If a var_list is given, only run on the obs networks which contain that variable
if var_list:
var_list_asked = var_list
obs_vars = ocfg["obs_vars"]
var_list = list(set(obs_vars) & set(var_list))
if not var_list:
logger.warning(
"var_list %s and obs_vars %s mismatch.", var_list_asked, obs_vars
)
return

col = self.get_colocator(model_name, obs_name)
if self.cfg.processing_opts.only_json:
files_to_convert = col.get_available_coldata_files(var_list)
Expand Down Expand Up @@ -100,7 +111,7 @@ def run(self, model_name=None, obs_name=None, var_list=None, update_interface=Tr
var_list : list, optional
list variables supposed to be analysed. If None, then all
variables available are used. Defaults to None. Can also be
`str` type.
`str` type. Must match at least some of the variables provided by a observation network.
update_interface : bool
if true, relevant json files that determine what is displayed
online are updated after the run, including the the menu.json file
Expand Down Expand Up @@ -144,7 +155,6 @@ def run(self, model_name=None, obs_name=None, var_list=None, update_interface=Tr
for obs_name in obs_list:
for model_name in model_list:
self._run_single_entry(model_name, obs_name, var_list)

if update_interface:
self.update_interface()
if use_dummy_model:
Expand Down
2 changes: 1 addition & 1 deletion pyaerocom/colocation/colocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def _print_processing_status(self):
def _filter_var_matches_var_name(self, var_matches, var_name):
filtered = {}
for mvar, ovar in var_matches.items():
if mvar in var_name or ovar in var_name:
if mvar == var_name or ovar == var_name:
filtered[mvar] = ovar
if len(filtered) == 0:
raise DataCoverageError(var_name)
Expand Down
14 changes: 14 additions & 0 deletions tests/aeroval/test_experiment_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ def test_ExperimentProcessor_run_error(processor: ExperimentProcessor, kwargs: d
with pytest.raises(KeyError) as e:
processor.run(**kwargs)
assert str(e.value) == error


@geojson_unavail
@pytest.mark.parametrize(
"cfg,kwargs,error",
[
("cfgexp2", dict(var_list="BLUB"), "var_list %s and obs_vars %s mismatch."),
],
)
def test_ExperimentProcessor_catch_wrong_var_list(
processor: ExperimentProcessor, kwargs: dict, error: str, caplog
):
processor.run(**kwargs)
assert any([error in str(record) for record in caplog.records])

0 comments on commit 9784dda

Please sign in to comment.