Skip to content

Commit d053bcf

Browse files
committed
rebasing
2 parents 357534d + b4436b3 commit d053bcf

22 files changed

+951
-453
lines changed

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,24 @@ repos:
134134
- "--max-line-length=88"
135135
- "--ignore=E203,W503,F811,I002"
136136
- "--max-complexity=12"
137+
- repo: local
138+
hooks:
139+
- id: mypy
140+
name: mypy
141+
description: Type-check Python code, only for functions with type annotations
142+
language: system
143+
entry: mypy
144+
pass_filenames: false
145+
args:
146+
- "-p"
147+
- "engine"
148+
- "-p"
149+
- "tests"
150+
- "-p"
151+
- "util"
152+
- "-p"
153+
- "visualize"
154+
- "--ignore-missing-imports"
155+
- "--allow-untyped-defs"
156+
- "--follow-imports=silent"
157+
- "--strict-optional"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ python ../externals/probtest/probtest.py check --reference-files stats_ref.csv,
273273

274274
This check can be also visualized by:
275275
```console
276-
python ../externals/probtest/probtest.py check-plot --input-file-ref stats_ref.csv --input-file-cur stats_exp_name.csv --tolerance-file-name exp_name_tolerance.csv --factor 5 --savedir ./plot_dir
276+
python ../externals/probtest/probtest.py check-plot --reference-files stats_ref.csv --current-files stats_exp_name.csv --tolerance-files exp_name_tolerance.csv --factor 5 --savedir ./plot_dir
277277
```
278278

279279
Note that the reference `--reference-files` and test stats files

engine/cdo_table.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,18 @@ def cdo_table(
170170
varnames = [
171171
v
172172
for v in list(ref_data.keys())
173-
if "time" in ref_data.variables.get(v).dims
173+
if (var := ref_data.variables.get(v)) is not None
174+
and "time" in var.dims
174175
]
175176

176177
for v in varnames:
177-
diff_data.variables.get(v).values = compute_rel_diff(
178-
ref_data.variables.get(v).values,
179-
perturb_data.variables.get(v).values,
180-
)
178+
if (ref_var := ref_data.variables.get(v)) is not None and (
179+
pert_var := perturb_data.variables.get(v)
180+
) is not None:
181+
diff_data.variables[v].values = compute_rel_diff(
182+
ref_var.values,
183+
pert_var.values,
184+
)
181185

182186
diff_data.to_netcdf(f"{tmpdir}/{rf}")
183187
ref_data.close()

engine/select_members.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import click
1616

1717
from engine.tolerance import tolerance
18-
from util.click_util import cli_help
18+
from util.click_util import CommaSeparatedStrings, cli_help
1919
from util.dataframe_ops import check_file_with_tolerances
2020
from util.log_handler import logger
21-
from util.utils import FileInfo
21+
from util.utils import FileInfo, validate_single_stats_file
2222

2323

2424
def find_members_and_factor_validating_for_all_stats_files(
@@ -198,16 +198,22 @@ def check_selection_by_ids(
198198
help=cli_help["enable_check_only"],
199199
)
200200
@click.option(
201-
"--stats-file-name",
202-
help=cli_help["stats_file_name"],
201+
"--ensemble-files",
202+
type=CommaSeparatedStrings(),
203+
default=[],
204+
help=cli_help["ensemble_files"]
205+
+ "\nNote: this option accepts exactly one stats file.",
203206
)
204207
@click.option(
205208
"--selected-members-file-name",
206209
help=cli_help["selected_members_file_name"],
207210
)
208211
@click.option(
209-
"--tolerance-file-name",
210-
help=cli_help["tolerance_file_name"],
212+
"--tolerance-files",
213+
type=CommaSeparatedStrings(),
214+
default=[],
215+
help=cli_help["tolerance_files_output"]
216+
+ "\nNote: this option accepts exactly one stats file.",
211217
)
212218
@click.option(
213219
"--member-type",
@@ -248,9 +254,9 @@ def check_selection_by_ids(
248254
def select_members(
249255
experiment_name,
250256
enable_check_only,
251-
stats_file_name,
257+
ensemble_files,
252258
selected_members_file_name,
253-
tolerance_file_name,
259+
tolerance_files,
254260
member_type,
255261
max_member_count,
256262
total_member_count,
@@ -261,9 +267,24 @@ def select_members(
261267
"""
262268
Selects members and writes them to a file together with the tolerance factor
263269
"""
270+
271+
# check for valid input parameters
272+
errors = []
273+
274+
stats_file_name = validate_single_stats_file(ensemble_files, "ensemble", errors)
275+
tolerance_file_name = validate_single_stats_file(
276+
tolerance_files, "tolerance", errors
277+
)
278+
264279
if max_member_count >= total_member_count:
265-
logger.error("ERROR: max_member_count must be smaller than total_member_count")
280+
errors.append("max_member_count must be smaller than total_member_count")
281+
282+
if errors:
283+
for msg in errors:
284+
logger.error("ERROR: %s", msg)
266285
sys.exit(1)
286+
287+
# start with selecting members
267288
if enable_check_only:
268289
check_selection_by_ids(
269290
stats_file_name=stats_file_name,

engine/tolerance.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def tolerance(
7676
ensemble_files = expand_members(
7777
mem, member_ids=member_ids, member_type=member_type
7878
)
79-
8079
dfs = [
8180
file_name_parser[info.file_type](info.path)
8281
for file in ensemble_files

0 commit comments

Comments
 (0)