Esempio n. 1
0
    def test_not_equal_areas(self):
        """
        Check it raises an error when the input is not an equal areas grid.
        """

        self.cube.remove_coord("projection_x_coordinate")
        self.cube.add_dim_coord(
            DimCoord(np.linspace(200.0, 600.0, 3),
                     'projection_x_coordinate',
                     units='m'), 0)
        with self.assertRaisesRegex(
                ValueError, "The size of the intervals along the x and y axis"
                " should be equal."):
            convert_number_of_grid_cells_into_distance(self.cube, 2)
Esempio n. 2
0
 def test_check_different_input_radius(self):
     """Check it works for different input values."""
     result_radius = convert_number_of_grid_cells_into_distance(
         self.cube, 5)
     expected_result = 10000.0
     self.assertAlmostEqual(result_radius, expected_result)
     self.assertIs(type(expected_result), float)
Esempio n. 3
0
 def test_basic(self):
     """Test the function does what it's meant to in a simple case."""
     result_radius = convert_number_of_grid_cells_into_distance(
         self.cube, 2)
     expected_result = 4000.0
     self.assertAlmostEqual(result_radius, expected_result)
     self.assertIs(type(expected_result), float)
Esempio n. 4
0
    def _generate_mask(self):
        """
        Generates a boolean mask of areas NOT to calculate orographic
        enhancement.  Criteria for calculating orographic enhancement are that
        all of the following are true:

            - 3x3 mean topography height >= threshold (20 m)
            - Relative humidity (fraction) >= threshold (0.8)
            - v dot grad z (wind x topography gradient) >= threshold (0.0005)

        The mask is therefore "True" if any of these conditions are false.

        Returns:
            mask (numpy.ndarray):
                Boolean mask - where True, set orographic enhancement to a
                default zero value
        """
        # calculate mean 3x3 (square nbhood) orography heights
        radius = convert_number_of_grid_cells_into_distance(self.topography, 1)
        topo_nbhood = NeighbourhoodProcessing('square',
                                              radius).process(self.topography)
        topo_nbhood.convert_units('m')

        # create mask
        mask = np.full(topo_nbhood.shape, False, dtype=bool)
        mask = np.where(topo_nbhood.data < self.orog_thresh_m, True, mask)
        mask = np.where(self.humidity.data < self.rh_thresh_ratio, True, mask)
        mask = np.where(abs(self.vgradz) < self.vgradz_thresh_ms, True, mask)
        return mask
Esempio n. 5
0
 def test_check_input_in_km(self):
     """
     Test that the output is still in metres when the input coordinates
     are in a different unit.
     """
     result_radius = convert_number_of_grid_cells_into_distance(
         self.cube, 2)
     for coord in self.cube.coords():
         coord.convert_units("km")
     expected_result = 4000.0
     self.assertAlmostEqual(result_radius, expected_result)
     self.assertIs(type(expected_result), float)
Esempio n. 6
0
    def find_max_in_nbhood_orography(self, orography_cube):
        """
        Find the maximum value of the orography in the region around each grid
        point in your orography field by finding the maximum in a neighbourhood
        around that point.

        Args:
            orography_cube (iris.cube.Cube):
                The cube containing a single 2 dimensional array of orography
                data
        Returns:
            iris.cube.Cube:
                The cube containing the maximum in a neighbourhood of the
                orography data.
        """
        radius_in_metres = convert_number_of_grid_cells_into_distance(
            orography_cube, self.grid_point_radius)
        max_in_nbhood_orog = OccurrenceWithinVicinity(
            radius_in_metres).process(orography_cube)
        return max_in_nbhood_orog