Coverage for src / CSET / operators / pressure.py: 0%
27 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-02 15:01 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-02 15:01 +0000
1# © Crown copyright, Met Office (2022-2026) and CSET contributors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15"""Operators for pressure conversions."""
17import iris.cube
18import numpy as np
20from CSET._common import iter_maybe
21from CSET.operators.atmospheric_constants import E0
24def vapour_pressure(
25 temperature: iris.cube.Cube | iris.cube.CubeList,
26) -> iris.cube.Cube | iris.cube.CubeList:
27 """Calculate the vapour pressure of the atmosphere."""
28 v_pressure = iris.cube.CubeList([])
29 for T in iter_maybe(temperature):
30 es = T.copy()
31 exponent = 17.27 * (T - 273.16) / (T - 35.86)
32 es.data[:] = E0 * np.exp(exponent.core_data())
33 es.units = "hPa"
34 es.rename("vapour_pressure")
35 v_pressure.append(es)
36 if len(v_pressure) == 1:
37 return v_pressure[0]
38 else:
39 return v_pressure
42def vapour_pressure_from_RH(
43 temperature: iris.cube.Cube | iris.cube.CubeList,
44 relative_humidity: iris.cube.Cube | iris.cube.CubeList,
45) -> iris.cube.Cube | iris.cube.CubeList:
46 """Calculate the vapour pressure using RH."""
47 v_pressure = iris.cube.CubeList([])
48 for T, RH in zip(
49 iter_maybe(temperature), iter_maybe(relative_humidity), strict=True
50 ):
51 if RH.units == "%":
52 RH /= 100.0
53 RH.units = "1"
54 vp = vapour_pressure(T) * RH
55 v_pressure.append(vp)
56 if len(v_pressure) == 1:
57 return v_pressure[0]
58 else:
59 return v_pressure