Skip to content

Commit a390238

Browse files
committed
Update docstrings and add support for returning None from a CLI.
1 parent 784a662 commit a390238

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

improver/calibration/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ def forecast_and_truth_dataframes_to_cubes(
679679
Training length in days as an integer.
680680
percentiles:
681681
The set of percentiles to be used for estimating EMOS coefficients.
682+
These should be a set of equally spaced quantiles.
682683
683684
Returns:
684685
Forecasts and truths for the training period in Cube format.

improver/cli/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ def with_output(
328328
from improver.utilities.save import save_netcdf
329329

330330
result = wrapped(*args, **kwargs)
331-
if output:
331+
332+
if output and result:
332333
save_netcdf(result, output, compression_level, least_significant_digit)
333334
return
334335
return result

improver/cli/estimate_emos_coefficients_from_table.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def process(
130130
coefficients to solve.
131131
percentiles (List[float]):
132132
The set of percentiles to be used for estimating EMOS coefficients.
133+
These should be a set of equally spaced quantiles.
133134
134135
Returns:
135136
iris.cube.CubeList:
@@ -172,6 +173,9 @@ def process(
172173
percentiles=percentiles,
173174
)
174175

176+
if not forecast_cube or not truth_cube:
177+
return
178+
175179
# Extract WMO IDs from the additional predictors.
176180
if additional_predictors:
177181
constr = iris.Constraint(wmo_id=truth_cube.coord("wmo_id").points)

improver_tests/acceptance/test_estimate_emos_coefficients_from_table.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,33 @@ def test_invalid_truth_filter(tmp_path,):
204204
IOError, match="The requested filepath.*temperature_at_screen_level.*"
205205
):
206206
run_cli(args)
207+
208+
209+
@pytest.mark.slow
210+
def test_return_none(tmp_path,):
211+
"""
212+
Test that None is returned if a non-existent forecast period is requested.
213+
"""
214+
kgo_dir = acc.kgo_root() / "estimate-emos-coefficients-from-table/"
215+
history_path = kgo_dir / "forecast_table_quantiles"
216+
truth_path = kgo_dir / "truth_table"
217+
output_path = tmp_path / "output.nc"
218+
args = [
219+
history_path,
220+
truth_path,
221+
"--diagnostic",
222+
"temperature_at_screen_level",
223+
"--cycletime",
224+
"20210805T2100Z",
225+
"--forecast-period",
226+
"1000",
227+
"--training-length",
228+
"5",
229+
"--distribution",
230+
"norm",
231+
"--tolerance",
232+
EST_EMOS_TOL,
233+
"--output",
234+
output_path,
235+
]
236+
assert run_cli(args) is None

0 commit comments

Comments
 (0)