Skip to content

Commit

Permalink
Additional tests for realization collapse and for percentile extracti…
Browse files Browse the repository at this point in the history
…on directly from realization data. Modifies the test in spot_manipulation for selecting the percentile method to check if data is actually masked, rather than just of masked type. This will enable the fast method to be used in more cases.
  • Loading branch information
bayliffe committed May 16, 2024
1 parent 5881475 commit 839a422
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
14 changes: 7 additions & 7 deletions improver/cli/spot_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def process(
And the neighbour cube is a cube of spot-data neighbours and
the spot site information.
apply_lapse_rate_correction (bool):
Use to apply a lapse-rate correction to screen temperature data so
that the data are a better match the altitude of the spot site for
which they have been extracted. This lapse rate will be applied for
a fixed orographic difference between the site and gridpoint
altitude. Differences in orography in excess of this fixed limit
will use the Environmental Lapse Rate (also known as the Standard
Atmosphere Lapse Rate).
Use to apply a lapse-rate correction to screen temperature
forecasts so that they better represent the altitude of the
spot site for which they have been extracted. This lapse rate
will be applied for a fixed orographic difference between the
site and grid point altitude. Differences in orography in
excess of this fixed limit will use the Environmental Lapse
Rate (also known as the Standard Atmosphere Lapse Rate).
fixed_lapse_rate (float):
If provided, use this fixed value as a lapse-rate for adjusting
the forecast values if apply_lapse_rate_correction is True. This
Expand Down
16 changes: 8 additions & 8 deletions improver/spotdata/spot_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def __init__(
Args:
apply_lapse_rate_correction (bool):
Use to apply a lapse-rate correction to screen temperature data so
that the data are a better match the altitude of the spot site for
which they have been extracted. This lapse rate will be applied for
a fixed orographic difference between the site and gridpoint
altitude. Differences in orography in excess of this fixed limit
will use the Environmental Lapse Rate (also known as the Standard
Atmosphere Lapse Rate).
Use to apply a lapse-rate correction to screen temperature
forecasts so that they better represent the altitude of the
spot site for which they have been extracted. This lapse rate
will be applied for a fixed orographic difference between the
site and grid point altitude. Differences in orography in
excess of this fixed limit will use the Environmental Lapse
Rate (also known as the Standard Atmosphere Lapse Rate).
fixed_lapse_rate (float):
If provided, use this fixed value as a lapse-rate for adjusting
the forecast values if apply_lapse_rate_correction is True. This
Expand Down Expand Up @@ -197,7 +197,7 @@ def process(self, cubes: CubeList) -> Cube:
)(result, percentiles=extract_percentiles)
result = iris.util.squeeze(result)
elif result.coords("realization", dim_coords=True):
fast_percentile_method = not np.ma.isMaskedArray(result.data)
fast_percentile_method = not np.ma.is_masked(result.data)
result = PercentileConverter(
"realization",
percentiles=extract_percentiles,
Expand Down
45 changes: 45 additions & 0 deletions improver_tests/spotdata/test_SpotManipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,51 @@ def add_grid_hash(target, source):
{"extract_percentiles": [40, 60]},
np.array([[277, 277], [279, 279]]),
),
# Extraction including realization collapse
(
gridded_variable,
np.arange(273, 291).reshape(2, 3, 3),
np.array([[[1, 2], [0, 0], [5, 10]]]),
{"realization_collapse": True},
np.array([278.5, 279.5]),
),
# Percentile extraction derived from realizations
(
gridded_variable,
np.arange(273, 300).reshape(3, 3, 3),
np.array([[[1, 2], [0, 0], [5, 10]]]),
{"extract_percentiles": [50]},
np.array([283, 284]),
),
# Percentile extraction derived from realizations; masked type, no mask
(
gridded_variable,
np.ma.arange(273, 300).reshape(3, 3, 3),
np.array([[[1, 2], [0, 0], [5, 10]]]),
{"extract_percentiles": [50]},
np.array([283, 284]),
),
# Percentile extraction derived from realizations; masked type, masking
(
gridded_variable,
np.ma.masked_array(
[
np.arange(273, 282).reshape(3, 3),
np.arange(282, 291).reshape(3, 3),
np.arange(291, 300).reshape(3, 3),
np.arange(300, 309).reshape(3, 3),
],
mask=[
np.zeros((3, 3)),
np.zeros((3, 3)),
np.zeros((3, 3)),
np.ones((3, 3)),
],
),
np.array([[[1, 2], [0, 0], [5, 10]]]),
{"extract_percentiles": [50]},
np.array([283, 284]),
),
],
)
def test_extraction(ftype, forecast_data, neighbour_cube, kwargs, expected):
Expand Down

0 comments on commit 839a422

Please sign in to comment.