Skip to content

Commit

Permalink
Review changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bayliffe committed Jun 5, 2023
1 parent e590b26 commit 9051f20
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
29 changes: 14 additions & 15 deletions improver/psychrometric_calculations/precip_phase_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,27 @@ def _extract_input_cubes(self, cubes: Union[CubeList, List[Cube]]) -> None:
for diagnostic, definition in definitions.items():
extracted_cube = cubes.extract(f"altitude_of_{diagnostic}_falling_level")
if extracted_cube:
(self.falling_level_cube,) = extracted_cube
self.param = diagnostic
self.comparator = definition["comparator"]
if self.falling_level_cube.coords("percentile"):
constraint = iris.Constraint(percentile=definition["percentile"])
required_percentile = self.falling_level_cube.extract(constraint)
if not required_percentile:
raise ValueError(
f"Cube {self.falling_level_cube.name()} does not "
"contain the required percentile "
f"{definition['percentile']}."
)
self.falling_level_cube = required_percentile
self.falling_level_cube.remove_coord("percentile")
# Once a falling-level cube has been extracted, exit this loop.
break

if not extracted_cube:
raise ValueError(
"Could not extract a rain, rain from hail or snow falling-level "
f"cube from {', '.join([cube.name() for cube in cubes])}"
)
(self.falling_level_cube,) = extracted_cube
self.param = diagnostic
self.comparator = definition["comparator"]
if self.falling_level_cube.coords("percentile"):
constraint = iris.Constraint(percentile=definition["percentile"])
required_percentile = self.falling_level_cube.extract(constraint)
if not required_percentile:
raise ValueError(
f"Cube {self.falling_level_cube.name()} does not "
"contain the required percentile "
f"{definition['percentile']}."
)
self.falling_level_cube = required_percentile
self.falling_level_cube.remove_coord("percentile")

orography_name = "surface_altitude"
extracted_cube = cubes.extract(orography_name)
Expand Down
33 changes: 20 additions & 13 deletions improver_tests/acceptance/SHA256SUMS
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,26 @@ d6f4cc94f3e317b9cad58f5f2a7f4147532b21d9bddd89df79158b44a18ee95e ./phase-mask/r
c707a884f93757cda95533c05e5a1eb7a08ecd18911afb2066f0dd2a097eaba6 ./phase-mask/sleet/kgo.nc
c8ca75da7bd25e37d22989dd6d23bd30b79cabb7689d4f18fae841e335989f08 ./phase-mask/snow/kgo.nc
29f807dbfdc6ffea2125cf57b31fbc417c9f80dfa38dca37349878256b7508db ./phase-mask/snow_fraction.nc
2e905af2bdab2c9bc5b51a11020803fa9caccdee982e1163850886b7a113d2aa ./phase-probability/gridded/altitudes.nc
a2b589593dfdfbd43915f628f1dd769ad8324111f4a0a24243d100717a79a2f3 ./phase-probability/gridded/hail_kgo_deterministic.nc
e6f2609cdeaae9a84867ae8d56aca5738ec7ee30749cb30c4dd9dbb8e6c55a7f ./phase-probability/gridded/hail_kgo_percentiles.nc
f4e72ec7a405e6fc0b1a104d0d2105e661c535972703305715820cebe20db6d0 ./phase-probability/gridded/hail_rain_deterministic.nc
74f65085b6a47cabe2820c919625280d8b581f349e7b136854800d5503a4c2f4 ./phase-probability/gridded/hail_rain_percentiles.nc
7dd37839d0fc3641175d86f8afd307c876f939c44d01c586e8cd13685825e30e ./phase-probability/gridded/rain_kgo_deterministic.nc
ab7438c4023104cb22c6fd93250c2978251e5d8ada04ead6ad7708cf2b815ed2 ./phase-probability/gridded/rain_kgo_percentiles.nc
a241ce4ae3c6ecfc4350acb603672ee8b774ed89abe4ff164c36fd020e808ca2 ./phase-probability/gridded/sleet_rain_deterministic.nc
f792d697a8ff6d40b5fad499ac7482041db0f93aff0379ade128d5831a1a1fe7 ./phase-probability/gridded/sleet_rain_percentiles.nc
ff146b15f995bdef9cbcecf373ef912b71226c80e94a9e4aa6efac064701dbaa ./phase-probability/gridded/snow_kgo_deterministic.nc
e40f6c2e7e99de456100a7dc60bc81ea3c85f46a5efd12346f0f27ed8dc97d78 ./phase-probability/gridded/snow_kgo_percentiles.nc
d7ecac6e2dd7cc589a9875db74f0918b22909ec3cfed0eff2392cde33a08a80e ./phase-probability/gridded/snow_sleet_deterministic.nc
53285eb9ecda350dceddf44c6b2e46a917d495af199a97e0c5db570a92549bbc ./phase-probability/gridded/snow_sleet_percentiles.nc
2e905af2bdab2c9bc5b51a11020803fa9caccdee982e1163850886b7a113d2aa ./phase-probability/equalarea/altitudes.nc
a2b589593dfdfbd43915f628f1dd769ad8324111f4a0a24243d100717a79a2f3 ./phase-probability/equalarea/hail_kgo_deterministic.nc
e6f2609cdeaae9a84867ae8d56aca5738ec7ee30749cb30c4dd9dbb8e6c55a7f ./phase-probability/equalarea/hail_kgo_percentiles.nc
f4e72ec7a405e6fc0b1a104d0d2105e661c535972703305715820cebe20db6d0 ./phase-probability/equalarea/hail_rain_deterministic.nc
74f65085b6a47cabe2820c919625280d8b581f349e7b136854800d5503a4c2f4 ./phase-probability/equalarea/hail_rain_percentiles.nc
7dd37839d0fc3641175d86f8afd307c876f939c44d01c586e8cd13685825e30e ./phase-probability/equalarea/rain_kgo_deterministic.nc
ab7438c4023104cb22c6fd93250c2978251e5d8ada04ead6ad7708cf2b815ed2 ./phase-probability/equalarea/rain_kgo_percentiles.nc
a241ce4ae3c6ecfc4350acb603672ee8b774ed89abe4ff164c36fd020e808ca2 ./phase-probability/equalarea/sleet_rain_deterministic.nc
f792d697a8ff6d40b5fad499ac7482041db0f93aff0379ade128d5831a1a1fe7 ./phase-probability/equalarea/sleet_rain_percentiles.nc
ff146b15f995bdef9cbcecf373ef912b71226c80e94a9e4aa6efac064701dbaa ./phase-probability/equalarea/snow_kgo_deterministic.nc
e40f6c2e7e99de456100a7dc60bc81ea3c85f46a5efd12346f0f27ed8dc97d78 ./phase-probability/equalarea/snow_kgo_percentiles.nc
d7ecac6e2dd7cc589a9875db74f0918b22909ec3cfed0eff2392cde33a08a80e ./phase-probability/equalarea/snow_sleet_deterministic.nc
53285eb9ecda350dceddf44c6b2e46a917d495af199a97e0c5db570a92549bbc ./phase-probability/equalarea/snow_sleet_percentiles.nc
11c26266048c7703c63aff247dce7c5e0b0868e6bec3bdf434d5a4712e9ba220 ./phase-probability/latlon/altitudes.nc
979d3de4fec7286aa89f83a9c078374c4bfecdb4409f2c4850ae4f693ad7171d ./phase-probability/latlon/hail_kgo_deterministic.nc
c542a7c576d9e81be14311caabcdeec0292b127e0c6d8fc8b4801de0be450bbc ./phase-probability/latlon/hail_rain_deterministic.nc
f22c7436f44428c57bf488e3474429c679e9b2f11154ab6cacfe85a6d7158f0e ./phase-probability/latlon/rain_kgo_deterministic.nc
50f1f3dfc43a601c9c9dc685ed7d05cef4a91f78551118e08d2005c9bf7ed57c ./phase-probability/latlon/sleet_rain_deterministic.nc
15e660d70389379947f68c14c5901f8f52fc9cd51697a7689ea8e4e5551ac024 ./phase-probability/latlon/snow_kgo_deterministic.nc
e01e3a2a3ef61acf392f0e0eb4ce69874f593e5ca21f5d387a74af4fa6b7998e ./phase-probability/latlon/snow_sleet_deterministic.nc
ac706582f917c59260b0c381ad49cdc6ca47cd47c01ff83b499b88ca19cc6761 ./phase-probability/spot/altitudes.nc
004b3482b71907d34c0a66df9e64d991f5dad2768ff9d68f713ecc22fd17c32c ./phase-probability/spot/hail_kgo_deterministic.nc
004b3482b71907d34c0a66df9e64d991f5dad2768ff9d68f713ecc22fd17c32c ./phase-probability/spot/hail_kgo_percentiles.nc
Expand Down
7 changes: 6 additions & 1 deletion improver_tests/acceptance/test_phase_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
run_cli = acc.run_cli(CLI)


@pytest.mark.parametrize("gtype", ("gridded", "spot"))
@pytest.mark.parametrize("gtype", ("equalarea", "latlon", "spot"))
@pytest.mark.parametrize("ptype", ("deterministic", "percentiles"))
@pytest.mark.parametrize(
"kgo_name,input_file",
Expand All @@ -55,6 +55,11 @@ def test_phase_probabilities(tmp_path, kgo_name, input_file, ptype, gtype):
"""Test phase probability calculations for snow->sleet, sleet->rain and hail->rain.
Parameterisation covers gridded and spot forecasts, and for both inputs
that include a percentile coordinate and those that do not."""

# Excessive testing, only need to demonstrate latlon grid works.
if ptype == "percentiles" and gtype == "latlon":
pytest.skip("Nope")

kgo_dir = acc.kgo_root() / f"{CLI}/{gtype}"
kgo_path = kgo_dir / f"{kgo_name}_{ptype}.nc"
output_path = tmp_path / "output.nc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def check_metadata(result, phase):
assert result.name() == f"probability_of_{phase}_at_surface"
assert result.units == Unit("1")
assert result.dtype == np.int8
assert result.attributes == LOCAL_MANDATORY_ATTRIBUTES


def spot_coords():
Expand Down

0 comments on commit 9051f20

Please sign in to comment.