Exemple #1
0
 def test_fuzziness_block_zero_weight_points(self):
     """Test fuzzy weights with a block of zero weight points"""
     # Set 4 grid points to zero in a square.
     self.cube.data[2:4, 3:5] = 0.0
     plugin = SpatiallyVaryingWeightsFromMask(fuzzy_length=2)
     expected = np.array(
         [[1., 1., 1., 1., 1., 1., 1.],
          [1., 1., 0.70710678, 0.5, 0.5, 0.70710678, 1.],
          [1., 1., 0.5, 0., 0., 0.5, 1.], [1., 1., 0.5, 0., 0., 0.5, 1.],
          [1., 1., 0.70710678, 0.5, 0.5, 0.70710678, 1.],
          [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.]],
         dtype=np.float32)
     result = plugin.smooth_initial_weights(self.cube)
     self.assertArrayAlmostEqual(result.data, expected)
Exemple #2
0
 def test_non_integer_fuzziness(self):
     """Test fuzzy weights over 2.5 grid squares"""
     self.cube.data[3, 3] = 0.0
     plugin = SpatiallyVaryingWeightsFromMask(fuzzy_length=2.5)
     expected = np.array(
         [[1., 1., 1., 1., 1., 1., 1.],
          [1., 1., 0.89442719, 0.8, 0.89442719, 1., 1.],
          [1., 0.89442719, 0.56568542, 0.4, 0.56568542, 0.89442719, 1.],
          [1., 0.8, 0.4, 0., 0.4, 0.8, 1.],
          [1., 0.89442719, 0.56568542, 0.4, 0.56568542, 0.89442719, 1.],
          [1., 1., 0.89442719, 0.8, 0.89442719, 1., 1.],
          [1., 1., 1., 1., 1., 1., 1.]],
         dtype=np.float32)
     result = plugin.smooth_initial_weights(self.cube)
     self.assertArrayAlmostEqual(result.data, expected)
Exemple #3
0
 def test_basic_fuzziness(self):
     """Test fuzzy weights over 3 grid squares"""
     self.cube.data[3, 3] = 0.0
     plugin = SpatiallyVaryingWeightsFromMask(fuzzy_length=3)
     expected = np.array(
         [[1., 1., 1., 1., 1., 1., 1.],
          [1., 0.942809, 0.745356, 0.666667, 0.745356, 0.942809, 1.],
          [1., 0.745356, 0.471405, 0.333333, 0.471405, 0.745356, 1.],
          [1., 0.666667, 0.333333, 0., 0.333333, 0.666667, 1.],
          [1., 0.745356, 0.471405, 0.333333, 0.471405, 0.745356, 1.],
          [1., 0.942809, 0.745356, 0.666667, 0.745356, 0.942809, 1.],
          [1., 1., 1., 1., 1., 1., 1.]],
         dtype=np.float32)
     result = plugin.smooth_initial_weights(self.cube)
     self.assertArrayAlmostEqual(result.data, expected)
Exemple #4
0
 def test_fuzziness_more_zero_weight_points(self):
     """Test fuzzy weights with multiple zero weight points"""
     # Set 4 grid points to zero in a square.
     self.cube.data[2, 2] = 0.0
     self.cube.data[4, 4] = 0.0
     plugin = SpatiallyVaryingWeightsFromMask(fuzzy_length=2)
     expected = np.array(
         [
             [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 0.70710678, 0.5, 0.70710678, 1.0, 1.0, 1.0],
             [1.0, 0.5, 0.0, 0.5, 1.0, 1.0, 1.0],
             [1.0, 0.70710678, 0.5, 0.70710678, 0.5, 0.70710678, 1.0],
             [1.0, 1.0, 1.0, 0.5, 0.0, 0.5, 1.0],
             [1.0, 1.0, 1.0, 0.70710678, 0.5, 0.70710678, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
         ],
         dtype=np.float32,
     )
     result = plugin.smooth_initial_weights(self.cube)
     self.assertArrayAlmostEqual(result.data, expected)
Exemple #5
0
 def test_basic_fuzziness_3D_input_cube(self):
     """Test fuzzy weights over 3 grid squares with 3D input cube."""
     thresholds = [10, 20, 30]
     data = np.ones((3, 7, 7), dtype=np.float32)
     cube = set_up_probability_cube(
         data,
         thresholds,
         spatial_grid="equalarea",
         time=datetime(2017, 11, 10, 4, 0),
         frt=datetime(2017, 11, 10, 0, 0),
     )
     cube.data[0, 3, 3] = 0.0
     cube.data[1, 0, 0] = 0.0
     cube.data[2, 6, 6] = 0.0
     plugin = SpatiallyVaryingWeightsFromMask(fuzzy_length=3)
     expected = np.array(
         [[[1., 1., 1., 1., 1., 1., 1.],
           [1., 0.942809, 0.745356, 0.666667, 0.745356, 0.942809, 1.],
           [1., 0.745356, 0.471405, 0.333333, 0.471405, 0.745356, 1.],
           [1., 0.666667, 0.333333, 0., 0.333333, 0.666667, 1.],
           [1., 0.745356, 0.471405, 0.333333, 0.471405, 0.745356, 1.],
           [1., 0.942809, 0.745356, 0.666667, 0.745356, 0.942809, 1.],
           [1., 1., 1., 1., 1., 1., 1.]],
          [[0., 0.33333334, 0.6666667, 1., 1., 1., 1.],
           [0.33333334, 0.47140452, 0.74535596, 1., 1., 1., 1.],
           [0.6666667, 0.74535596, 0.94280905, 1., 1., 1., 1.],
           [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.],
           [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.]],
          [[1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.],
           [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.],
           [1., 1., 1., 1., 0.94280905, 0.74535596, 0.6666667],
           [1., 1., 1., 1., 0.74535596, 0.47140452, 0.33333334],
           [1., 1., 1., 1., 0.6666667, 0.33333334, 0.]]],
         dtype=np.float32)
     result = plugin.smooth_initial_weights(cube)
     self.assertArrayAlmostEqual(result.data, expected)
Exemple #6
0
 def test_initial_weights_all_1(self):
     """Test the input cube all containing weights of one."""
     plugin = SpatiallyVaryingWeightsFromMask(fuzzy_length=4)
     result = plugin.smooth_initial_weights(self.cube)
     self.assertArrayEqual(self.cube.data, result.data)
Exemple #7
0
 def test_no_fuzziness(self):
     """Test fuzziness over only 1 grid square, i.e. no fuzziness"""
     self.cube.data[3, 3] = 0.0
     plugin = SpatiallyVaryingWeightsFromMask(fuzzy_length=1)
     result = plugin.smooth_initial_weights(self.cube)
     self.assertArrayEqual(self.cube.data, result.data)