예제 #1
0
 def test_threshold_fuzzy(self):
     """Test when a point is in the fuzzy threshold area."""
     plugin = Threshold(0.6, fuzzy_factor=self.fuzzy_factor)
     result = plugin.process(self.cube)
     expected_result_array = np.zeros_like(self.cube.data)
     expected_result_array[0][2][2] = 1.0 / 3.0
     self.assertArrayAlmostEqual(result.data, expected_result_array)
예제 #2
0
 def test_basic(self):
     """Test that the plugin returns an iris.cube.Cube."""
     fuzzy_factor = 0.95
     threshold = 0.1
     plugin = Threshold(threshold, fuzzy_factor=fuzzy_factor)
     result = plugin.process(self.cube)
     self.assertIsInstance(result, Cube)
예제 #3
0
 def test_threshold_below_fuzzy_miss(self):
     """Test not meeting the threshold in fuzzy below-threshold-mode."""
     plugin = Threshold(2.0,
                        fuzzy_factor=self.fuzzy_factor,
                        below_thresh_ok=True)
     result = plugin.process(self.cube)
     expected_result_array = np.ones_like(self.cube.data)
     self.assertArrayAlmostEqual(result.data, expected_result_array)
예제 #4
0
 def test_threshold_negative(self):
     """Test a point when the threshold is negative."""
     plugin = Threshold(-1.0,
                        fuzzy_factor=self.fuzzy_factor,
                        below_thresh_ok=True)
     result = plugin.process(self.cube)
     expected_result_array = np.ones_like(self.cube.data)
     self.assertArrayAlmostEqual(result.data, expected_result_array)
예제 #5
0
 def test_above_threshold_without_fuzzy_factor(self):
     """Test if the fixed threshold is below the value in the data."""
     # Copy the cube as the cube.data is used as the basis for comparison.
     cube = self.cube.copy()
     plugin = Threshold(0.1)
     result = plugin.process(cube)
     expected_result_array = self.cube.data
     expected_result_array[0][2][2] = 1.0
     self.assertArrayAlmostEqual(result.data, expected_result_array)
예제 #6
0
 def test_threshold_below_fuzzy(self):
     """Test a point in fuzzy threshold in below-threshold-mode."""
     plugin = Threshold(0.6,
                        fuzzy_factor=self.fuzzy_factor,
                        below_thresh_ok=True)
     result = plugin.process(self.cube)
     expected_result_array = np.ones_like(self.cube.data)
     expected_result_array[0][2][2] = 2.0 / 3.0
     self.assertArrayAlmostEqual(result.data, expected_result_array)
예제 #7
0
 def test_threshold(self):
     """Test the basic threshold functionality."""
     # Copy the cube as the cube.data is used as the basis for comparison.
     cube = self.cube.copy()
     fuzzy_factor = 0.95
     plugin = Threshold(0.1, fuzzy_factor=fuzzy_factor)
     result = plugin.process(cube)
     # The single 0.5-valued point => 1.0, so cheat by * 2.0 vs orig data.
     expected_result_array = self.cube.data * 2.0
     self.assertArrayAlmostEqual(result.data, expected_result_array)
예제 #8
0
 def test_threshold_point_nan(self):
     """Test behaviour for a single NaN grid cell."""
     # Need to copy the cube as we're adjusting the data.
     self.cube.data[0][2][2] = np.NAN
     msg = "NaN detected in input cube data"
     plugin = Threshold(2.0,
                        fuzzy_factor=self.fuzzy_factor,
                        below_thresh_ok=True)
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(self.cube)
예제 #9
0
 def test_below_threshold_without_fuzzy_factor(self):
     """Test if the fixed threshold is above the value in the data."""
     plugin = Threshold(0.6)
     result = plugin.process(self.cube)
     expected_result_array = np.zeros_like(self.cube.data)
     self.assertArrayAlmostEqual(result.data, expected_result_array)
예제 #10
0
 def test_threshold_fuzzy_factor_2(self):
     """Test when a fuzzy factor of 2 is given (invalid)."""
     fuzzy_factor = 2.0
     msg = "Invalid fuzzy_factor: must be >0 and <1: 2.0"
     with self.assertRaisesRegexp(ValueError, msg):
         Threshold(0.6, fuzzy_factor=fuzzy_factor)
예제 #11
0
 def test_threshold_zero(self):
     """Test when a threshold of zero is used (invalid)."""
     fuzzy_factor = 0.6
     msg = "Invalid threshold: zero not allowed"
     with self.assertRaisesRegexp(ValueError, msg):
         Threshold(0.0, fuzzy_factor=fuzzy_factor)
예제 #12
0
 def test_threshold_fuzzy_miss_high_threshold(self):
     """Test when a point is not within the fuzzy high threshold area."""
     plugin = Threshold(3.0, fuzzy_factor=self.fuzzy_factor)
     result = plugin.process(self.cube)
     expected_result_array = np.zeros_like(self.cube.data)
     self.assertArrayAlmostEqual(result.data, expected_result_array)