-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathsm.py
39 lines (27 loc) · 1.03 KB
/
sm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Derivation of variable `sm`."""
import cf_units
import numpy as np
from esmvalcore.iris_helpers import var_name_constraint
from ._baseclass import DerivedVariableBase
class DerivedVariable(DerivedVariableBase):
"""Derivation of variable `sm`."""
@staticmethod
def required(project):
"""Declare the variables needed for derivation."""
required = [{'short_name': 'mrsos'}]
return required
@staticmethod
def calculate(cubes):
"""Compute soil moisture.
Note
----
Convert moisture content of soil layer (kg/m2) into volumetric soil
moisture (m3/m3), assuming density of water 998.2 kg/m2 (at temperature
20 deg C).
"""
mrsos_cube = cubes.extract_strict(var_name_constraint('mrsos'))
depth = mrsos_cube.coord('depth').bounds.astype(np.float32)
layer_thickness = depth[..., 1] - depth[..., 0]
sm_cube = mrsos_cube / layer_thickness / 998.2
sm_cube.units = cf_units.Unit('m3 m^-3')
return sm_cube