Skip to content

Math between metpy return dataarrays and xarray dataarrays #2987

Answered by dopplershift
Marston asked this question in Q&A
Discussion options

You must be logged in to vote

So I just wanted to follow up and show how I would do this so that you're not fighting the unit framework, but using it to make sure you've got everything right and in proper unit agreement:

from metpy.units import units

# Get pressure and mixing ratio and have as Pint underneath--relies on built-in unit metadata
pa = grb.data_to_da(pkey).metpy.quantify()
mr = grb.data_to_da(mrkey).metpy.quantify()
pw = vapor_pressure(pa, mr)

t = grb.data_to_da(tkey).metpy.quantify()

# Fill in your values here, but notice how I use the units
b1 = 1 * units('K / hPa')
b2 = 2 * units('K / hPa')
b3 = 3 * units('K^2 / hPa')

ref = b1 * ((pa - pw) / t) + b2 * (pw / t) + b3 * (pw / t**2)

By using the built-i…

Replies: 1 comment 13 replies

Comment options

You must be logged in to vote
13 replies
@dopplershift
Comment options

Answer selected by dopplershift
@Marston
Comment options

@Marston
Comment options

@dopplershift
Comment options

@dcamron
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants