-
Notifications
You must be signed in to change notification settings - Fork 104
Adding functionality to choose closest matching threshold. #2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -588,28 +588,39 @@ def test_returns_used_cubes(self): | |
| for constraint in unexpected: | ||
| self.assertEqual(len(result.extract(constraint)), 0) | ||
|
|
||
| def test_raises_error_matching_threshold(self): | ||
| """Test prepare_input_cubes method raises error for matching thresholds in a | ||
| diagnostic.""" | ||
| def test_selects_closest_threshold_when_multiple_matches(self): | ||
| """Test prepare_input_cubes method raises a warning for matching thresholds | ||
| in a diagnostic and selects the closest threshold.""" | ||
|
|
||
| # Modify the cube snowfall_rate to add an additional threshold | ||
| threshold_coord = find_threshold_coordinate(self.cubes[0]) | ||
| additional_threshold = threshold_coord.points[0] * ( | ||
| original_threshold = threshold_coord.points[0] | ||
| additional_threshold = original_threshold * ( | ||
| 1 + 0.5 * self.plugin.float_tolerance | ||
| ) | ||
| threshold_coord.points = np.array( | ||
| [ | ||
| threshold_coord.points[0], | ||
| original_threshold, | ||
| additional_threshold, | ||
| threshold_coord.points[2], | ||
| ], | ||
| dtype=np.float32, | ||
| ) | ||
| msg = ( | ||
| r"Multiple \(2\) matching thresholds found for name: " | ||
| "probability_of_lwe_snowfall_rate_above_threshold" | ||
| ) | ||
|
|
||
| with self.assertRaisesRegex(ValueError, msg): | ||
| self.plugin.prepare_input_cubes(self.cubes) | ||
| # Check warning is raised | ||
| msg = r"Multiple \(2\) matching thresholds found.*Using closest match" | ||
| with self.assertWarnsRegex(UserWarning, msg): | ||
| result, _ = self.plugin.prepare_input_cubes(self.cubes) | ||
| # Check thresholds extracted for snowfall_cubes | ||
| # We expect the original_threshold to be selected over the additional_threshold | ||
| expected_thresholds = {original_threshold, threshold_coord.points[2]} | ||
| snowfall_cubes = [cube for cube in result if "lwe_snowfall_rate" in cube.name()] | ||
| self.assertGreater(len(snowfall_cubes), 0) | ||
| for cube in snowfall_cubes: | ||
| cube_thresholds = cube.coord(find_threshold_coordinate(cube).name()).points | ||
| self.assertEqual(len(cube_thresholds), 1) | ||
| cube_threshold_value = cube_thresholds[0] | ||
| self.assertIn(cube_threshold_value, expected_thresholds) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be able to know which threshold we expect to be in the output cube, and to check that the actual returned threshold is the expected one.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, there are multiple cubes in |
||
| self.assertNotEqual(cube_threshold_value, additional_threshold) | ||
|
|
||
| def test_zero_threshold_uses_absolute_tolerance(self): | ||
| """Test prepare_input_cubes method uses absolute tolerance when the threshold | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an inline code comment here to describe how we handle finding multiple thresholds could be useful here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline comment added