def test_time(self):
     """Test output time coordinates are as expected"""
     current_time = self.cubes[1].coord("time").points[0]
     result = generate_advection_velocities_from_winds(
         self.cubes, self.steering_flow, self.orogenh)
     for cube in result:
         self.assertIsInstance(cube, iris.cube.Cube)
         self.assertEqual(cube.coord("time").points[0], current_time)
Exemple #2
0
 def test_basic(self):
     """Test function returns a cubelist with the expected components"""
     result = generate_advection_velocities_from_winds(
         self.cubes, self.steering_flow, self.orogenh
     )
     self.assertIsInstance(result, iris.cube.CubeList)
     self.assertEqual(result[0].name(), "precipitation_advection_x_velocity")
     self.assertEqual(result[1].name(), "precipitation_advection_y_velocity")
 def test_input_sort(self):
     """Test output time coordinates are correct if the inputs are in the wrong
     order"""
     current_time = self.cubes[1].coord("time").points[0]
     reversed_cubelist = iris.cube.CubeList([self.cubes[1], self.cubes[0]])
     result = generate_advection_velocities_from_winds(
         reversed_cubelist, self.steering_flow, self.orogenh)
     for cube in result:
         self.assertIsInstance(cube, iris.cube.Cube)
         self.assertEqual(cube.coord("time").points[0], current_time)
Exemple #4
0
def process(
    steering_flow: inputflow,
    orographic_enhancement: cli.inputcube,
    *cubes: cli.inputcube,
):
    """Calculate optical flow components as perturbations from the model
    steering flow.  Advects the older of the two input radar observations to
    the validity time of the newer observation, then calculates the velocity
    required to adjust this forecast to match the observation.  Sums the
    steering flow and perturbation values to give advection components for
    extrapolation nowcasting.

    Args:
        steering_flow (iris.cube.CubeList):
            Model steering flow as u- and v- wind components.  These must
            have names: "grid_eastward_wind" and "grid_northward_wind".
        orographic_enhancement (iris.cube.Cube):
            Cube containing the orographic enhancement fields.
        cubes (tuple of iris.cube.Cube):
            Two radar precipitation observation cubes.

    Returns:
        iris.cube.CubeList:
            List of u- and v- advection velocities
    """
    from iris.cube import CubeList

    from improver.nowcasting.optical_flow import (
        generate_advection_velocities_from_winds,
    )

    if len(cubes) != 2:
        raise ValueError("Expected 2 radar cubes - got {}".format(len(cubes)))

    advection_velocities = generate_advection_velocities_from_winds(
        CubeList(cubes), steering_flow, orographic_enhancement
    )

    return advection_velocities