예제 #1
0
    def test_not_in_vicinity(self):
        """Test for no change if the matching point is too far away."""
        # We need larger arrays for this.
        # Define 5 x 5 arrays with output sea point at [1, 1] and input sea
        # point at [4, 4]. The alternative value of 0.5 at [4, 4] should not
        # be selected with a small vicinity_radius.
        self.plugin = AdjustLandSeaPoints(vicinity_radius=2200.0)
        data = np.ones((5, 5), dtype=np.float32)
        data[1, 1] = 0.0
        cube = set_up_variable_cube(
            data,
            "precipitation_amount",
            "kg m^-2",
            "equalarea",
        )
        self.plugin.output_land = cube.copy()
        self.plugin.nearest_cube = cube.copy()
        self.plugin.nearest_cube.data[4, 4] = 0.5
        self.plugin.output_cube = self.plugin.nearest_cube.copy()
        land_data = np.ones((5, 5), dtype=np.float32)
        land_data[4, 4] = 0.0
        self.plugin.input_land = cube.copy(data=land_data)

        output_cube = self.plugin.output_cube.copy()
        self.plugin.correct_where_input_true(0)
        self.assertArrayEqual(output_cube.data, self.plugin.output_cube.data)
예제 #2
0
 def setUp(self):
     """Create a class-object containing the necessary cubes.
     All cubes are on the target grid. Here this is defined as a 3x3 grid.
     The grid contains ones everywhere except the centre point (a zero).
     The output_cube has a value of 0.5 at [0, 1].
     The move_sea_point cube has the zero value at [0, 1] instead of [1, 1],
     this allows it to be used in place of input_land to trigger the
     expected behaviour in the function.
     """
     self.plugin = AdjustLandSeaPoints(vicinity_radius=2200.0)
     data = np.ones((3, 3), dtype=np.float32)
     data[1, 1] = 0.0
     cube = set_up_variable_cube(
         data,
         "precipitation_amount",
         "kg m^-2",
         "equalarea",
     )
     self.plugin.input_land = cube.copy()
     self.plugin.output_land = cube.copy()
     self.plugin.nearest_cube = cube.copy()
     self.plugin.nearest_cube.data[0, 1] = 0.5
     self.plugin.output_cube = self.plugin.nearest_cube.copy()
     data_move_sea = np.ones((3, 3), dtype=np.float32)
     data_move_sea[0, 1] = 0.0
     self.move_sea_point = cube.copy(data=data_move_sea)
예제 #3
0
    def setUp(self):
        """Create a class-object containing the necessary cubes.
        All cubes are on the target grid. Here this is defined as a 5x5 grid.
        The cubes have values of one everywhere except:
        input_land: zeroes (sea points) at [0, 1], [4, 4]
        output_land: zeroes (sea points) at [0, 0], [1, 1]
        input_cube: 0. at [1, 1]; 0.5 at [0, 1]; 0.1 at [4, 4]
        These should trigger all the behavior we expect.
        """
        data_input_land = np.ones((5, 5), dtype=np.float32)
        data_input_land[0, 1] = 0.0
        data_input_land[4, 4] = 0.0

        data_output_land = np.ones((5, 5), dtype=np.float32)
        data_output_land[0, 0] = 0.0
        data_output_land[1, 1] = 0.0

        data_cube = np.ones((5, 5), dtype=np.float32)
        data_cube[1, 1] = 0.0
        data_cube[0, 1] = 0.5
        data_cube[4, 4] = 0.1

        self.plugin = AdjustLandSeaPoints(vicinity_radius=2200.0)

        self.cube = set_up_variable_cube(
            data_cube,
            "precipitation_amount",
            "kg m^-2",
            "equalarea",
            grid_spacing=2000,
            domain_corner=(0, -50000),
        )

        self.output_land = self.cube.copy(data=data_output_land)
        self.input_land = self.cube.copy(data=data_input_land)

        # Lat-lon coords for reprojection
        # These coords result in a 1:1 regridding with the above cubes.
        x_coord = DimCoord(
            np.linspace(-3.281, -3.153, 5),
            standard_name="longitude",
            units="degrees",
            coord_system=ELLIPSOID,
        )
        y_coord = DimCoord(
            np.linspace(54.896, 54.971, 5),
            standard_name="latitude",
            units="degrees",
            coord_system=ELLIPSOID,
        )
        self.input_land_ll = Cube(
            self.input_land.data,
            long_name="land_sea_mask",
            units="1",
            dim_coords_and_dims=[(y_coord, 0), (x_coord, 1)],
        )
예제 #4
0
 def test_basic(self):
     """Test that instantiating the class results in an object with
     expected variables."""
     expected_members = {
         "nearest_cube": None,
         "input_land": None,
         "output_land": None,
         "output_cube": None,
     }
     result = AdjustLandSeaPoints()
     members = {
         attr: getattr(result, attr)
         for attr in dir(result)
         if not attr.startswith("_")
     }
     non_methods = {key: val for key, val in members.items() if not callable(val)}
     regridder = non_methods.pop("regridder")
     vicinity = members.pop("vicinity")
     self.assertDictEqual(non_methods, expected_members)
     self.assertTrue(isinstance(regridder, iris.analysis.Nearest))
     self.assertTrue(isinstance(vicinity, OccurrenceWithinVicinity))
예제 #5
0
 def test_vicinity_arg(self):
     """Test with vicinity_radius argument."""
     result = AdjustLandSeaPoints(vicinity_radius=30000.0)
     vicinity = getattr(result, "vicinity")
     self.assertTrue(isinstance(vicinity, OccurrenceWithinVicinity))
     self.assertEqual(vicinity.distance, 30000.0)
예제 #6
0
 def test_extrap_arg_error(self):
     """Test with invalid extrapolation_mode argument."""
     msg = "Extrapolation mode 'not_valid' not supported"
     with self.assertRaisesRegex(ValueError, msg):
         AdjustLandSeaPoints(extrapolation_mode="not_valid")
예제 #7
0
 def test_extrap_arg(self):
     """Test with extrapolation_mode argument."""
     result = AdjustLandSeaPoints(extrapolation_mode="mask")
     regridder = getattr(result, "regridder")
     self.assertTrue(isinstance(regridder, iris.analysis.Nearest))