Exemple #1
0
 def test_cube_metadata(self):
     """Check metadata of returned cube."""
     result = WetBulbTemperature().create_wet_bulb_temperature_cube(
         self.temperature, self.relative_humidity, self.pressure
     )
     self.assertIsInstance(result, Cube)
     self.assertEqual(result.units, Unit("K"))
     self.assertEqual(result.name(), "wet_bulb_temperature")
Exemple #2
0
 def test_cube_multi_level(self):
     """Check the cube is returned with expected coordinate order after the
     data has been sliced and reconstructed."""
     temperature = self._make_multi_level(self.temperature, time_promote=True)
     relative_humidity = self._make_multi_level(
         self.relative_humidity, time_promote=True
     )
     pressure = self._make_multi_level(self.pressure, time_promote=True)
     result = WetBulbTemperature().process(
         CubeList([temperature, relative_humidity, pressure])
     )
     self.assertEqual(result.coord_dims("time")[0], 0)
     self.assertEqual(result.coord_dims("height")[0], 1)
Exemple #3
0
 def test_values_multi_level(self):
     """Basic wet bulb temperature calculation using multi-level
     data."""
     temperature = self._make_multi_level(self.temperature)
     relative_humidity = self._make_multi_level(self.relative_humidity)
     pressure = self._make_multi_level(self.pressure)
     result = WetBulbTemperature().process(
         CubeList([temperature, relative_humidity, pressure])
     )
     self.assertArrayAlmostEqual(result.data[0], self.expected_wbt_data, decimal=3)
     self.assertArrayAlmostEqual(result.data[1], self.expected_wbt_data, decimal=3)
     self.assertEqual(result.units, Unit("K"))
     self.assertArrayEqual(result.coord("height").points, [10, 20])
Exemple #4
0
def process(*cubes: cli.inputcube, convergence_condition=0.05):
    """Module to generate wet-bulb temperatures.

    Call the calculate_wet_bulb_temperature function to calculate wet-bulb
    temperatures. This process function splits input cubes over vertical levels
    to mitigate memory issues when trying to operate on multi-level data.

    Args:
        cubes (iris.cube.CubeList or list or iris.cube.Cube):
            containing:
                temperature (iris.cube.Cube):
                    Cube of air temperatures, where these may be on multiple
                    height levels.
                relative_humidity (iris.cube.Cube):
                    Cube of relative humidities, where these may be on multiple
                    height levels.
                pressure (iris.cube.Cube):
                    Cube of air pressure, where these may be on multiple height
                    levels.
        convergence_condition (float):
            The precision in Kelvin to which the Newton iterator must converge
            before returning wet-bulb temperatures.

    Returns:
        iris.cube.Cube:
            Cube of wet-bulb temperature (K).

    """
    from improver.psychrometric_calculations.wet_bulb_temperature import (
        WetBulbTemperature,
    )

    return WetBulbTemperature(precision=convergence_condition)(cubes)
Exemple #5
0
 def test_calculate_enthalpy_gradient(self):
     """Test calculation of enthalpy gradient with temperature. Comparison
     adjusted for 32-bit precision."""
     expected = [41662.730, 41300.594, 36356.254]
     result = WetBulbTemperature()._calculate_enthalpy_gradient(
         self.mixing_ratio, self.specific_heat, self.latent_heat, self.temperature
     )
     self.assertArrayAlmostEqual(result.data, expected, decimal=3)
Exemple #6
0
 def test_calculate_enthalpy(self):
     """Basic calculation of some enthalpies. Comparison adjusted for
     32-bit precision."""
     expected = [454734.6, 807677.3, 1171053.1]
     result = WetBulbTemperature()._calculate_enthalpy(
         self.mixing_ratio, self.specific_heat, self.latent_heat, self.temperature
     )
     self.assertArrayAlmostEqual(result, expected, decimal=1)
Exemple #7
0
 def test_too_many_cubes(self):
     """Tests that an error is raised if there are too many cubes."""
     temp = self.temperature
     humid = self.relative_humidity
     pressure = self.pressure
     msg = "Expected 3"
     with self.assertRaisesRegex(ValueError, msg):
         WetBulbTemperature().process(CubeList([temp, humid, pressure, temp]))
Exemple #8
0
 def test_values_single_level_reorder_cubes(self):
     """Same test as test_values_single_level but the cubes are in a
     different order."""
     result = WetBulbTemperature().process(
         CubeList([self.relative_humidity, self.temperature, self.pressure])
     )
     self.assertArrayAlmostEqual(result.data, self.expected_wbt_data, decimal=3)
     self.assertEqual(result.units, Unit("K"))
Exemple #9
0
 def test_values_single_level(self):
     """Basic wet bulb temperature calculation as if calling the
     create_wet_bulb_temperature_cube function directly with single
     level data."""
     result = WetBulbTemperature().process(
         CubeList([self.temperature, self.relative_humidity, self.pressure])
     )
     self.assertArrayAlmostEqual(result.data, self.expected_wbt_data, decimal=3)
     self.assertEqual(result.units, Unit("K"))
Exemple #10
0
 def test_different_units(self):
     """Wet bulb temperature calculation with unit conversion."""
     self.temperature.convert_units("celsius")
     self.relative_humidity.convert_units("1")
     self.pressure.convert_units("kPa")
     result = WetBulbTemperature().create_wet_bulb_temperature_cube(
         self.temperature, self.relative_humidity, self.pressure
     )
     self.assertArrayAlmostEqual(result.data, self.expected_wbt_data, decimal=3)
     self.assertEqual(result.units, Unit("K"))
Exemple #11
0
 def test_different_level_types(self):
     """Check an exception is raised if trying to work with data on a mix of
     height and pressure levels."""
     temperature = self._make_multi_level(self.temperature)
     relative_humidity = self._make_multi_level(self.relative_humidity)
     pressure = self._make_multi_level(self.pressure)
     temperature.coord("height").rename("pressure")
     msg = "WetBulbTemperature: Cubes have differing"
     with self.assertRaisesRegex(ValueError, msg):
         WetBulbTemperature().process(
             CubeList([temperature, relative_humidity, pressure])
         )
Exemple #12
0
 def test_calculate_specific_heat(self):
     """Test specific heat calculation"""
     expected = np.array([1089.5, 1174.0, 1258.5], dtype=np.float32)
     result = WetBulbTemperature()._calculate_specific_heat(self.mixing_ratio)
     self.assertArrayAlmostEqual(result, expected, decimal=2)
Exemple #13
0
 def test_empty_cube_list(self):
     """Tests that an error is raised if there is an empty list."""
     msg = "Expected 3"
     with self.assertRaisesRegex(ValueError, msg):
         WetBulbTemperature().process(CubeList([]))
Exemple #14
0
 def test_values(self):
     """Basic wet bulb temperature calculation."""
     result = WetBulbTemperature().create_wet_bulb_temperature_cube(
         self.temperature, self.relative_humidity, self.pressure
     )
     self.assertArrayAlmostEqual(result.data, self.expected_wbt_data, decimal=3)