def test_hail_rain_phase_change(self): """Test that process returns a cube with the right name, units and values. In this instance the phase change is from hail to rain. The wet bulb integral is multiplied by 40 so the threshold for the hail to melt is reached before the ground""" self.wet_bulb_integral_cube.data *= 40.0 result = PhaseChangeLevel(phase_change="hail-rain").process( CubeList( [ self.wet_bulb_temperature_cube, self.wet_bulb_integral_cube, self.orog, self.land_sea, ] ) ) expected = np.full_like( self.expected_snow_sleet, fill_value=11.797252, dtype=np.float32 ) expected[:, 1:4, 1:4] = 1.0 expected[:, 2, 2] = 11.797252 self.assertIsInstance(result, iris.cube.Cube) self.assertEqual(result.name(), "altitude_of_rain_from_hail_falling_level") self.assertEqual(result.units, Unit("m")) self.assertArrayAlmostEqual(result.data, expected) if hasattr(result.data, "mask"): self.assertFalse(result.data.mask.any())
def test_sleet_rain_phase_change(self): """Test that process returns a cube with the right name, units and values. In this instance the phase change is from sleet to rain. Note that the wet bulb temperature integral values are doubled such that the rain threshold is reached above the surface. The result has an odd pattern of 49.178673 around the edge and at the centre point with a value of 1 forming a ring around the centre point. This arises because the input data are not entirely realistic in this case. The ring [1::4, 1::4] has a sleet-rain-phase-level below the orography (1 m) but the centre point is an unrealistic point-hill of 100m which is interpolated from the outer ring due to the grid_point_radius default value of 2.""" self.wet_bulb_integral_cube.data *= 2.0 result = PhaseChangeLevel(phase_change="sleet-rain").process( CubeList( [ self.wet_bulb_temperature_cube, self.wet_bulb_integral_cube, self.orog, self.land_sea, ] ) ) expected = np.full_like( self.expected_snow_sleet, fill_value=49.178673, dtype=np.float32 ) expected[:, 1:4, 1:4] = 1.0 expected[:, 2, 2] = 49.178673 self.assertIsInstance(result, iris.cube.Cube) if hasattr(result.data, "mask"): self.assertFalse(result.data.mask.any()) self.assertEqual(result.name(), "altitude_of_rain_falling_level") self.assertEqual(result.units, Unit("m")) self.assertArrayAlmostEqual(result.data, expected)
def test_snow_sleet_phase_change_reorder_cubes(self): """Same test as test_snow_sleet_phase_change but the cubes are in a different order""" self.orog.data[1, 1] = 100.0 result = PhaseChangeLevel(phase_change='snow-sleet').process( CubeList([ self.wet_bulb_integral_cube, self.wet_bulb_temperature_cube, self.orog, self.land_sea ])) self.assertIsInstance(result, iris.cube.Cube) self.assertEqual(result.name(), "altitude_of_snow_falling_level") self.assertEqual(result.units, Unit('m')) self.assertArrayAlmostEqual(result.data, self.expected_snow_sleet)
def test_snow_sleet_phase_change(self): """Test that process returns a cube with the right name, units and values. In this instance the phase change is from snow to sleet. The returned level is consistent across the field, despite a high point that sits above the snow falling level.""" self.orog.data[1, 1] = 100.0 result = PhaseChangeLevel(phase_change='snow-sleet').process( self.wet_bulb_temperature_cube, self.wet_bulb_integral_cube, self.orog, self.land_sea) expected = np.ones((2, 3, 3), dtype=np.float32) * 66.88566 self.assertIsInstance(result, iris.cube.Cube) self.assertEqual(result.name(), "altitude_of_snow_falling_level") self.assertEqual(result.units, Unit('m')) self.assertArrayAlmostEqual(result.data, expected)
def test_sleet_rain_phase_change(self): """Test that process returns a cube with the right name, units and values. In this instance the phase change is from sleet to rain. Note that the wet bulb temperature integral values are doubled such that the rain threshold is reached above the surface. The returned level is consistent across the field, despite a high point that sits above the rain falling level.""" self.orog.data[1, 1] = 100.0 self.wet_bulb_integral_cube = self.wet_bulb_integral_cube * 2. result = PhaseChangeLevel(phase_change='sleet-rain').process( self.wet_bulb_temperature_cube, self.wet_bulb_integral_cube, self.orog, self.land_sea) expected = np.ones((2, 3, 3), dtype=np.float32) * 49.178673 self.assertIsInstance(result, iris.cube.Cube) self.assertEqual(result.name(), "altitude_of_rain_falling_level") self.assertEqual(result.units, Unit('m')) self.assertArrayAlmostEqual(result.data, expected)
def test_snow_sleet_phase_change(self): """Test that process returns a cube with the right name, units and values. In this instance the phase change is from snow to sleet. The returned level has three values, all above orography.""" result = PhaseChangeLevel(phase_change="snow-sleet").process( CubeList([ self.wet_bulb_temperature_cube, self.wet_bulb_integral_cube, self.orog, self.land_sea, ])) self.assertIsInstance(result, iris.cube.Cube) self.assertEqual(result.name(), "altitude_of_snow_falling_level") self.assertEqual(result.units, Unit("m")) self.assertArrayAlmostEqual(result.data, self.expected_snow_sleet) if hasattr(result.data, "mask"): self.assertFalse(result.data.mask.any())