Skip to content

Instantly share code, notes, and snippets.

@karmanyaahm
Created August 8, 2025 06:43
Show Gist options
  • Select an option

  • Save karmanyaahm/9d0dfde2a28b1e5a584baaa4a55df06d to your computer and use it in GitHub Desktop.

Select an option

Save karmanyaahm/9d0dfde2a28b1e5a584baaa4a55df06d to your computer and use it in GitHub Desktop.
metpy calculate drybox humidity stuff
from metpy.calc import *
from metpy.constants.nounit import epsilon
from metpy.units import units
print("epsilon", epsilon)
p = 1 * units.atm
T_amb = 20 * units.degC
rh = .90 * units.atm/units.atm
print(f"starting_rel_humid {rh.to('percent'):.1f}")
print(f"ambient_temp {T_amb.to('degC'):.1f}")
T_cool = -20 * units.degC
r = mixing_ratio_from_relative_humidity(p, T_amb, rh)
b = vapor_pressure(p, r)
print(f"ratio_ambient {r.to('g/kg'):.1f}")
print(f"vapor_pressure_ambient {b.to('hPa'):.1f}")
# most of this is just fyi, it doesn't affect the final steady state output
# since the final output is just determined by T_amb and T_cool
print(f"\n\ncoolant_temp {T_cool.to('degC'):.1f}")
d = saturation_vapor_pressure(T_cool, phase='auto')
print(f"sat_vapor_pressure_tube {d.to('hPa'):.1f}")
e = mixing_ratio(d, p)
print(f"post_dewed_air_mixing_ratio {e.to('g/kg'):.1f}")
f = saturation_mixing_ratio(p, T_cool)
print(f"should be the same as {f.to('g/kg'):.1f}")
a = relative_humidity_from_mixing_ratio(p, T_amb, f)
print(f"amb_rel_humid {a.to('percent'):.1f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment