Skip to content

Commit

Permalink
Update metadata BRN operator (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninaburg authored Jul 16, 2024
1 parent fa86228 commit 0ad0a3c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/meteodatalab/operators/brn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,47 @@
import xarray as xr

# Local
from .. import metadata
from .. import physical_constants as pc
from .destagger import destagger
from .thetav import fthetav


def fbrn(p, t, qv, u, v, hhl, hsurf):
"""Bulk Richardson Number (BRN)."""
def fbrn(
p: xr.DataArray,
t: xr.DataArray,
qv: xr.DataArray,
u: xr.DataArray,
v: xr.DataArray,
hhl: xr.DataArray,
hsurf: xr.DataArray,
) -> xr.DataArray:
"""Bulk Richardson Number (BRN).
Parameters
----------
p : xarray.DataArray
pressure in Pa
t : xarray.DataArray
air temperature in K
qv : xarray.DataArray
specific humidity (dimensionless)
u : xarray.DataArray
the x component of the wind velocity in m/s
v : xarray.DataArray
the y component of the wind velocity in m/s
hhl : xarray.DataArray
Heights of the interfaces between vertical layers in m amsl
hsurf : xarray.DataArray
earth surface height in m amsl
Returns
-------
xarray.DataArray
Bulk Richardson Number (dimensionless)
"""
nlevels = p.sizes["z"]

thetav = fthetav(p, t, qv)
Expand All @@ -34,4 +68,7 @@ def fbrn(p, t, qv, u, v, hhl, hsurf):
/ (thetav_sum * (u_**2 + v_**2))
)

return brn
return xr.DataArray(
data=brn,
attrs=metadata.override(p.message, shortName="BRN"),
)
8 changes: 8 additions & 0 deletions tests/test_meteodatalab/test_brn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def test_brn(data_dir, fieldextra):
ds["P"], ds["T"], ds["QV"], ds["U"], ds["V"], ds["HHL"], ds["HSURF"]
)

assert brn.parameter == {
"centre": "lssw",
"paramId": 503154,
"shortName": "BRN",
"units": "Numeric",
"name": "Bulk Richardson number",
}

fs_ds = fieldextra("BRN")

assert_allclose(fs_ds["BRN"], brn, rtol=5e-3, atol=5e-2)

0 comments on commit 0ad0a3c

Please sign in to comment.