def test_list_of_constraints(self): """Test construct_extract_constraint returns a list of iris.Constraint.""" plugin = WeatherSymbols() diagnostics = [ 'probability_of_rainfall_rate_above_threshold', 'probability_of_lwe_snowfall_rate_above_threshold' ] thresholds = [ AuxCoord(0.03, units='mm hr-1'), AuxCoord(0.03, units='mm hr-1') ] result = plugin.construct_extract_constraint(diagnostics, thresholds, False) expected = ("iris.Constraint(" "name='probability_of_lwe_snowfall_rate_above_threshold', " "lwe_snowfall_rate=lambda cell: 0.03 * {t_min} < cell " "< 0.03 * {t_max})".format( t_min=(1. - WeatherSymbols().float_tolerance), t_max=(1. + WeatherSymbols().float_tolerance))) self.assertIsInstance(result, list) self.assertIsInstance(result[1], str) self.assertEqual(len(result), 2) self.assertEqual(result[1], expected)
def test_zero_threshold(self): """Test construct_extract_constraint when threshold is zero.""" plugin = WeatherSymbols() diagnostic = 'probability_of_rainfall_rate_above_threshold' threshold = AuxCoord(0.0, units='mm hr-1') result = plugin.construct_extract_constraint(diagnostic, threshold, False) expected = ("iris.Constraint(" "name='probability_of_rainfall_rate_above_threshold', " "rainfall_rate=lambda cell: -1e-12 < cell < 1e-12)") self.assertIsInstance(result, str) self.assertEqual(result, expected)
def test_basic(self): """Test construct_extract_constraint returns a iris.Constraint.""" plugin = WeatherSymbols() diagnostic = 'probability_of_rainfall_rate' threshold = AuxCoord(0.03, units='mm hr-1') result = plugin.construct_extract_constraint(diagnostic, threshold) expected = ("iris.Constraint(name='probability_of_rainfall_rate', " "threshold=lambda cell: 0.03 * {t_min} < cell < 0.03 * " "{t_max})".format( t_min=(1. - WeatherSymbols().float_tolerance), t_max=(1. + WeatherSymbols().float_tolerance))) self.assertIsInstance(result, str) self.assertEqual(result, expected)
def test_old_naming_convention(self): """Test construct_extract_constraint can return a constraint with a "threshold" coordinate""" plugin = WeatherSymbols() diagnostic = 'probability_of_rainfall_rate_above_threshold' threshold = AuxCoord(0.03, units='mm hr-1') result = plugin.construct_extract_constraint(diagnostic, threshold, True) expected = ("iris.Constraint(" "name='probability_of_rainfall_rate_above_threshold', " "threshold=lambda cell: 0.03 * {t_min} < cell < 0.03 * " "{t_max})".format( t_min=(1. - WeatherSymbols().float_tolerance), t_max=(1. + WeatherSymbols().float_tolerance))) self.assertIsInstance(result, str) self.assertEqual(result, expected)
def test_basic(self): """Test construct_extract_constraint returns a iris.Constraint.""" plugin = WeatherSymbols() diagnostic = "probability_of_rainfall_rate_above_threshold" threshold = AuxCoord(0.03, units="mm hr-1") result = plugin.construct_extract_constraint(diagnostic, threshold, False) expected = ("iris.Constraint(" "name='probability_of_rainfall_rate_above_threshold', " "rainfall_rate=lambda cell: 0.03 * {t_min} < cell < " "0.03 * {t_max})".format( t_min=(1.0 - WeatherSymbols().float_tolerance), t_max=(1.0 + WeatherSymbols().float_tolerance), )) self.assertIsInstance(result, str) self.assertEqual(result, expected)