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: numpy.ndarray: Boolean mask - where True, set orographic enhancement to a default zero value """ # calculate mean 3x3 (square nbhood) orography heights radius = number_of_grid_cells_to_distance(self.topography, 1) topo_nbhood = NeighbourhoodProcessing( 'square', radius)(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
def find_max_in_nbhood_orography(self, orography_cube): """ Find the maximum value of the orography in the neighbourhood around each grid point. If self.grid_point_radius is zero, the orography is used without neighbourhooding. 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 the grid_point_radius neighbourhood of the orography data or the orography data itself if the radius is zero """ if self.grid_point_radius >= 1: radius_in_metres = number_of_grid_cells_to_distance( orography_cube, self.grid_point_radius ) max_in_nbhood_orog = OccurrenceWithinVicinity(radius_in_metres)( orography_cube ) return max_in_nbhood_orog else: return orography_cube.copy()
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 = number_of_grid_cells_to_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)
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 = number_of_grid_cells_to_distance( orography_cube, self.grid_point_radius) max_in_nbhood_orog = OccurrenceWithinVicinity(radius_in_metres)( orography_cube) return max_in_nbhood_orog
def test_check_different_input_radius(self): """Check it works for different input values.""" result_radius = number_of_grid_cells_to_distance(self.cube, 5) expected_result = 10000.0 self.assertAlmostEqual(result_radius, expected_result) self.assertIs(type(expected_result), float)
def test_basic(self): """Test the function does what it's meant to in a simple case.""" result_radius = number_of_grid_cells_to_distance(self.cube, 2) expected_result = 4000.0 self.assertAlmostEqual(result_radius, expected_result) self.assertIs(type(expected_result), float)