Skip to content

Input units for metpy.calc.density() and mixing_ratio_from_relative_humidity() #2650

Answered by Z-Richard
figaroleo asked this question in Q&A
Discussion options

You must be logged in to vote

There is no "required" input unit in MetPy because the arguments to these functions (pressure, temperature) are Pint.Quantity, which means that they have units attached to the numerical values such that MetPy could process them correctly. An example:

>>> import metpy.calc as mpcalc
>>> from metpy.units import units
>>> p = 1013 * units.millibar
>>> t = 273 * units.K
>>> q = 0.023 * units.dimensionless
>>> mpcalc.density(p, t, q)
<Quantity(1.27525864, 'kilogram / meter ** 3')>

Note that you can use something like t = 20 * units.celsius too.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@figaroleo
Comment options

@dopplershift
Comment options

@figaroleo
Comment options

@dopplershift
Comment options

@figaroleo
Comment options

Answer selected by dopplershift
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