Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #24 from cp4cds/skip-wrong-timeperiods
Browse files Browse the repository at this point in the history
skip wrong time periods
  • Loading branch information
cehbrecht authored Jan 11, 2019
2 parents bfaecd7 + f0cc554 commit 6e8ed13
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion c4cds/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def search_pattern(self, domain, experiment, ensemble, model, variable):
def filter_by_year(files, start_year=None, end_year=None):
result = []
for filepath in files:
f_start_year, f_end_year = util.parse_time_period(filepath)
try:
f_start_year, f_end_year = util.parse_time_period(filepath)
except Exception:
LOGGER.warn("could not parse time period: {}".format(filepath))
continue
if end_year is not None and end_year < f_start_year:
continue
elif start_year is not None and start_year > f_end_year:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def test_parse_time_period():
'/path/to/tasmin_AFR-44i_ECMWF-ERAINT_evaluation_r1i1p1_MOHC-HadRM3P_v1_day_19900101-19901231.nc'
) == (1990, 1990)

# false pattern
with pytest.raises(Exception):
util.parse_time_period(
'/path/to/data/cordex/output/EUR-44i/MOHC/ECMWF-ERAINT/evaluation/r1i1p1/MOHC-HadRM3P/v1/mon/tas/files/d20131212' # noqa
)


def test_get_variable_name():
assert util.get_variable_name(CORDEX_NC) == 'tasmin'
Expand Down

0 comments on commit 6e8ed13

Please sign in to comment.