Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
725f272
doc: changed version number
Aug 13, 2026
6ffc25d
feat: initial sensible variable for mass tendency
Aug 13, 2026
a816bc9
fix: corrected mass tendency to be a 2D variable
Aug 13, 2026
5990bea
feat: added UHorizAdvMomentum
Aug 13, 2026
33eaf8c
fix: added function to destagger dimensions
Aug 13, 2026
880befe
fix: changed destaggering to preserve metadata
Aug 13, 2026
9404c88
exp: testing if time value exists in original variable
Aug 13, 2026
1041e13
exp: testing d4var dims
Aug 13, 2026
a83b9bd
fix: readding time var after variable is destagered
Aug 13, 2026
d959757
exp: testing reassignment of Time using ['Time']
Aug 13, 2026
4b8ef03
debug: testing whether setting coords to P field works
Aug 13, 2026
5f73254
fix: corrected syntax for assign_coords
Aug 13, 2026
9e616ee
fix: assigning time explictly too
Aug 13, 2026
cb26383
exp: trying to understand coordinates used by other variables
Aug 14, 2026
4d3f469
exp: trying to set coords via a dict
Aug 14, 2026
bef3986
fix: manually assigning coordinates to dimensions
Aug 14, 2026
aebf7f0
fix: corrected dict syntax
Aug 14, 2026
ce54adf
Merge remote-tracking branch 'origin/dev' into 23-add-plotting-of-mom…
Aug 18, 2026
1251915
fix: got staggering of variables to work with correct metadata
Scottan Aug 19, 2026
9a0381c
Merge remote-tracking branch 'origin/dev' into 23-add-plotting-of-mom…
Aug 21, 2026
77659ce
feat: first stab at calculating projection momentum tendency terms on…
Aug 21, 2026
8342617
feat: added sensible variable for TendHADV
Aug 24, 2026
d1a35fe
fix: corrected logic for extracting tend variable
Aug 24, 2026
787f228
fix: typo
Aug 24, 2026
d541230
fix: started getting TEND_HADV plotting to owkr
Scottan Aug 24, 2026
12ebdcb
fix: changed default scale for tend fields
Aug 24, 2026
6b1b5d2
fix: syntax
Aug 24, 2026
52dbc79
fix: fixing plotting of scale for tend_hadv
Scottan Aug 24, 2026
23c4bb2
fix: tweaked scale for TEND_HADV
Aug 24, 2026
8ec0800
feat: added sensible variables for all tend momentum terms
Aug 24, 2026
9abe45d
fix: tweak to scales
Aug 24, 2026
3a1cd9f
tyle: code tidy
Aug 24, 2026
8098005
Add License and Copyright Headers
invalid-email-address Aug 24, 2026
d9a3f4e
Merge pull request #38 from UoMResearchIT/add-license-headers-to-23-a…
Scottan Aug 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wrf_analysis_toolkit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "wrf_analysis_toolkit"
version = "2.4.2"
version = "2.5.0"
requires-python = ">=3.10"
dependencies = [
"netCDF4>=1.7",
Expand Down
53 changes: 52 additions & 1 deletion wrf_analysis_toolkit/wrf_analysis_toolkit/GetSensVar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@

from wrf import to_np, getvar, g_geoht, interplevel
import numpy as np
from copy import deepcopy

import wrf_analysis_toolkit.SensibleVariables as sv
import wrf_analysis_toolkit.Frontogenesis as Frontogenesis

from wrf_analysis_toolkit.utils import destagger_var, project_vector

MOMENTUM_TEND_DICT = {
"tendhadv": {"var_u": "RU_TEND_HADV", "var_v": "RV_TEND_HADV"},
"tendvadv": {"var_u": "RU_TEND_VADV", "var_v": "RU_TEND_VADV"},
"tendpgf": {"var_u": "RU_TEND_PGF", "var_v": "RU_TEND_PGF"},
"tendcor": {"var_u": "RU_TEND_COR", "var_v": "RU_TEND_COR"},
"tendcurv": {"var_u": "RU_TEND_CURV", "var_v": "RU_TEND_CURV"},
"tendfpbl": {"var_u": "RU_TENDF_PBL", "var_v": "RU_TENDF_PBL"},
"tendfcu": {"var_u": "RU_TENDF_CU", "var_v": "RU_TENDF_CU"},
"tendfdiff": {"var_u": "RU_TENDF_DIFF", "var_v": "RU_TENDF_DIFF"}
}

def GetSensVar(ncfile, svariable, windbarbs=0, time=0, varprevv=None):
u = v = varv = None
Expand All @@ -32,9 +45,10 @@ def GetSensVar(ncfile, svariable, windbarbs=0, time=0, varprevv=None):
# Converts accumulated rain to "hourly" rain (given hourly time indices)
if varprevv is not None:
var.values = var.values - varprevv

# For 3D +value variables, interpolated at interpvalue of interpvar
elif svariable.dim == 4:

interpvar = getvar(ncfile, svariable.interpvar, timeidx=time)
if svariable.wrfname is not None:
d4var = getvar(ncfile, svariable.wrfname, timeidx=time)
Expand All @@ -45,7 +59,42 @@ def GetSensVar(ncfile, svariable, windbarbs=0, time=0, varprevv=None):
F3D = Frontogenesis.frontogenesis3D(ncfile, time)
d4var = getvar(ncfile, svariable.interpvar, timeidx=time)
d4var.values = F3D
elif any([k in svariable.outfile.lower() for k in MOMENTUM_TEND_DICT]):
for k in MOMENTUM_TEND_DICT:
if k in svariable.outfile.lower():
tend_name = k
break
print(f"Extracting variables to calculate {tend_name}")
var_u = getvar(ncfile, MOMENTUM_TEND_DICT[tend_name]["var_u"], timeidx=time)
attrs = var_u.attrs
var_u = destagger_var(var_u, meta=False)
var_v = getvar(ncfile, MOMENTUM_TEND_DICT[tend_name]["var_v"], timeidx=time)
var_v = destagger_var(var_v, meta=False)
ua = getvar(ncfile, "ua", timeidx=time)
va = getvar(ncfile, "va", timeidx=time)
wspd = getvar(ncfile, "wspd", timeidx=time)

# Calculate the variable projected onto the unit vector of
# horizontal winds, to calculate the along-flow values
# This is quickest if calculated using arrays without metadata,
# and the metadata are copied from the interpvar afterwards
d4var = deepcopy(interpvar)
print(f"Projecting {tend_name} onto unit wind vector")
d4var.values = project_vector(var_u, var_v, ua, va, wspd)
d4var.attrs.update(attrs)

else:
if svariable.wrfname is not None:
raise ValueError(f"Failed to extract variable {svariable.wrfname}")
else:
raise ValueError(f"Failed to extract variable for {svariable.outfile}")

# Destagger the variable if it is staggered
d4var = destagger_var(d4var, meta_var=interpvar, meta=True)

# interpolate variable
var = interplevel(d4var, interpvar, svariable.interpvalue)

# Special variable computation
if "AirTempDif6h" in svariable.outfile:
# Temperature difference in 6h
Expand All @@ -59,6 +108,7 @@ def GetSensVar(ncfile, svariable, windbarbs=0, time=0, varprevv=None):
else:
varv = np.append(varprevv[1:], [var.values], axis=0)
var.values = var.values - varprevv[0]

elif "AirTempDif12h" in svariable.outfile:
# Temperature difference in 12h
if varprevv is None:
Expand All @@ -82,6 +132,7 @@ def GetSensVar(ncfile, svariable, windbarbs=0, time=0, varprevv=None):
elif svariable.outfile in ["InstRain"]:
# InstRain (R) from SimRadarReflectivity1km (dBZ) using Marshall-Palmer: Z = 10^(dBZ/10) = 200*R^1.6
var.values = (0.005 * 10 ** (0.1 * var.values)) ** (0.625)

if windbarbs:
# Get wind speed components at interpvalue
ua = getvar(ncfile, "ua", timeidx=time)
Expand Down
Loading