コード例 #1
0
 def test_multiply_preserves_bounds(self):
     """Test specific case for precipitation type, where multiplying a
     precipitation accumulation by a point-time probability of snow retains
     the bounds on the original accumulation."""
     validity_time = datetime(2015, 11, 19, 0)
     time_bounds = [datetime(2015, 11, 18, 23), datetime(2015, 11, 19, 0)]
     forecast_reference_time = datetime(2015, 11, 18, 22)
     precip_accum = set_up_variable_cube(
         np.full((2, 3, 3), 1.5, dtype=np.float32),
         name="lwe_thickness_of_precipitation_amount",
         units="mm",
         time=validity_time,
         time_bounds=time_bounds,
         frt=forecast_reference_time,
     )
     snow_prob = set_up_variable_cube(
         np.full(precip_accum.shape, 0.2, dtype=np.float32),
         name="probability_of_snow",
         units="1",
         time=validity_time,
         frt=forecast_reference_time,
     )
     result = CubeMultiplier()(
         [precip_accum, snow_prob],
         "lwe_thickness_of_snowfall_amount",
     )
     self.assertArrayAlmostEqual(result.data, np.full((2, 3, 3), 0.3))
     self.assertArrayEqual(result.coord("time"), precip_accum.coord("time"))
コード例 #2
0
ファイル: test_CubeMultiplier.py プロジェクト: tjtg/improver
 def test_vicinity_names(self):
     """Test plugin names the cube and threshold coordinate correctly for a
     vicinity diagnostic"""
     input = "lwe_thickness_of_precipitation_amount_in_vicinity"
     output = "thickness_of_rainfall_amount_in_vicinity"
     self.cube.rename(f"probability_of_{input}_above_threshold")
     cubelist = iris.cube.CubeList([self.cube.copy(), self.multiplier])
     result = CubeMultiplier(broadcast_to_threshold=True)(cubelist, output)
     self.assertEqual(result.name(),
                      f"probability_of_{output}_above_threshold")
     self.assertEqual(
         result.coord(var_name="threshold").name(),
         "thickness_of_rainfall_amount")
コード例 #3
0
 def test_vicinity_names(self):
     """Test plugin names the cube and threshold coordinate correctly for a
     vicinity diagnostic"""
     input = "lwe_thickness_of_precipitation_amount_in_vicinity"
     output = "thickness_of_rainfall_amount_in_vicinity"
     self.cube4.rename(f"probability_of_{input}_above_threshold")
     cube = self.cube4[:, 0, ...].copy()
     cube.data = np.ones_like(cube.data)
     cube.remove_coord("lwe_thickness_of_precipitation_amount")
     cubelist = iris.cube.CubeList([self.cube4.copy(), cube])
     input_copy = deepcopy(cubelist)
     result = CubeMultiplier()(cubelist, output, broadcast_to_threshold=True)
     self.assertEqual(result.name(), f"probability_of_{output}_above_threshold")
     self.assertEqual(
         result.coord(var_name="threshold").name(), "thickness_of_rainfall_amount"
     )
コード例 #4
0
ファイル: test_CubeMultiplier.py プロジェクト: tjtg/improver
 def test_broadcast_coord(self):
     """Test that plugin broadcasts to threshold coord without changing inputs.
     Using the broadcast_to_coords argument including a value of "threshold"
     will result in the returned cube maintaining the probabilistic elements
     of the name of the first input cube."""
     cubelist = iris.cube.CubeList([self.cube.copy(), self.multiplier])
     input_copy = deepcopy(cubelist)
     result = CubeMultiplier(broadcast_to_threshold=True)(cubelist,
                                                          "new_cube_name")
     self.assertIsInstance(result, Cube)
     self.assertEqual(result.name(),
                      "probability_of_new_cube_name_above_threshold")
     self.assertEqual(
         result.coord(var_name="threshold").name(), "new_cube_name")
     self.assertArrayAlmostEqual(result.data, self.cube.data)
     self.assertCubeListEqual(input_copy, cubelist)
コード例 #5
0
 def test_broadcast_coord(self):
     """Test that plugin broadcasts to threshold coord without changing inputs.
     Using the broadcast_to_coords argument including a value of "threshold"
     will result in the returned cube maintaining the probabilistic elements
     of the name of the first input cube."""
     cube = self.cube4[:, 0, ...].copy()
     cube.data = np.ones_like(cube.data)
     cube.remove_coord("lwe_thickness_of_precipitation_amount")
     cubelist = iris.cube.CubeList([self.cube4.copy(), cube])
     input_copy = deepcopy(cubelist)
     result = CubeMultiplier()(
         cubelist, "new_cube_name", broadcast_to_threshold=True
     )
     self.assertIsInstance(result, Cube)
     self.assertEqual(result.name(), "probability_of_new_cube_name_above_threshold")
     self.assertEqual(result.coord(var_name="threshold").name(), "new_cube_name")
     self.assertArrayAlmostEqual(result.data, self.cube4.data)
     self.assertCubeListEqual(input_copy, cubelist)