コード例 #1
0
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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 iterate_over_threshold(self, cubelist, threshold):
        """
        Iterate over the application of thresholding to multiple cubes.

        Args:
            cubelist : Iris.cube.CubeList
                Cubelist containing cubes to be thresholded.
            threshold : float
                The threshold that will be applied.

        Returns:
            cubes : Iris.cube.CubeList
                Cubelist after thresholding each cube.
        """
        cubes = iris.cube.CubeList([])
        for cube in cubelist:
            threshold_cube = (BasicThreshold(
                threshold,
                fuzzy_factor=self.fuzzy_factor,
                below_thresh_ok=self.below_thresh_ok).process(cube.copy()))
            cubes.append(threshold_cube)
        return cubes
コード例 #10
0
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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)
コード例 #11
0
ファイル: test_BasicThreshold.py プロジェクト: wxtim/improver
 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)