MetPy 1.0 API Changes#
This is the overview of the changes to MetPy’s programming interface that are coming with the 1.0 release of MetPy. These include changes made to unify and clarify MetPy’s API to be more consistent throughout. Changes are categorized to help you find breakages and see how your code might need to change in upgrading to MetPy 1.0. You might find some functions in multiple categories. You can search this page for some of your commonly used functions to find any relevant breakages you might encounter.
Xarray support for function input/output#
One of the most important changes you may run into is that many of the functions in
metpy.calc
would have only returned pint.Quantity
even when provided
xarray.DataArray
. Now, MetPy will properly return a DataArray
when
provided one where able, except where otherwise explicitly stated. See the
MetPy xarray tutorial for more information.
Positional argument name changes#
Many of the functions in metpy.calc
have had changes to the names of their positional
arguments to make parameter names consistent among functions and make the documentation of
parameters clearer for users. Functions in your code with only this change will be unaffected
by the upgrade to MetPy 1.0 if the values are only specified positionally. For example,
wind_components(10. * units('m/s'), 225. * units.deg)
will work the same on MetPy before and after the upgrade to 1.0. However, if you specify these arguments by name, e.g.
wind_components(speed=10. * units('m/s'), wdir=225. * units.deg)
then you will see breakage upgrading to MetPy 1.0, where the wdir
argument has been
expanded as wind_direction
. Common arguments changed here include rh
to
relative_humidity
, heights
to height
, and dewpt
to dewpoint
, among others.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Keyword-only argument name changes#
Similar to the positional argument name changes above, some of the functions in
metpy.calc
have had names changed for keyword-only arguments. If you have specified
any of the affected parameters in your code, these functions will break with the upgrade to
MetPy 1.0. For example,
mean_pressure_weighted(pressure, temperature, heights=my_height_values)
will break as the heights
keyword has changed to height
.
|
|
|
|
|
|
|
|
New keyword-only arguments#
The following functions have had some of their positional or optional arguments changed to keyword-only arguments. As such, any use of these positionally, e.g.
vorticity(u, v, my_dx_values, my_dy_values)
will break, and you must specify
vorticity(u, v, dx=my_dx_values, dy=my_dy_values)
going forward.
|
|
|
|
|
|
|
|
Parameter re-ordering#
Some functions in metpy.calc
have had the ordering of their arguments rearranged.
If you are specifying values positionally, e.g.
mixing_ratio_from_relative_humidity(75 * units.percent, 1013.25 * units.hPa,
25 * units.degC)
these will break, as the signature ordering has changed from
(relative_humidity, temperature, pressure)
to
(pressure, temperature, relative_humidity)
. If you have specified these arguments by name,
however, e.g.
mixing_ratio_from_relative_humidity(relative_humidity=75 * units.percent,
pressure=1015 * units.hPa, temperature=25 * units.degC)
then your code will function as before even with the updated signature ordering in MetPy 1.0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Deltas and grid specification#
Many of the functions in metpy.calc
relating to vorticity and advection require
information about the space between your data points. MetPy has generally standardized the
interface for these functions to more explicitly receive dimension information and ordering
with consistent parameter names across the board. Particularly, anywhere you may have been
specifying dim_order
before, you will now need to specify the particular axis number for
the requisite dimensions explicitly. Importantly, MetPy’s new
xarray functionality in 1.0 can handle these grid
specifications for you if you are using it, and these signature updates were made to coincide
with that functionality. Please see the the documentation for the following functions for more
information.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Latitude and f#
In MetPy 1.0, geostrophic_wind()
and ageostrophic_wind()
have been changed to expect latitude
instead of the coriolis parameter f
, where we
will calculate f
using coriolis_parameter()
. These have also been
updated with the same new deltas and grid specification as above. If you are using MetPy’s
new xarray functionality in 1.0, this can be automatically
taken from your latitude coordinate information, if possible.
|
|
|
|
Moved, renamed, miscellaneous#
Functions that have been moved, replaced, or had their function signatures drastically altered.
|
|
|
|
|
|
|
|
|
|
|