Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divergence and Vorticity Dx/Dy creates TypeError: too many positional arguments #2101

Closed
chasecalkins opened this issue Sep 13, 2021 · 2 comments
Labels
Area: Calc Pertains to calculations Type: Question Issues does not require work, but answers a user question

Comments

@chasecalkins
Copy link

chasecalkins commented Sep 13, 2021

Linux
Python 3.8.10

import metpy; print(metpy.__version__)
1.1.0
lat = (np.arange(0,121)*.25)+20
lat = lat[::-1]
lon = (np.arange(0,261)*.25)+230
...
dx,dy = mpcalc.lat_lon_grid_deltas(lon,lat)
GRN = mpcalc.gradient_richardson_number( GPM * units('meter'), thta, u_wind*units('m/s'), v_wind*units('m/s') )
fronto = mpcalc.frontogenesis(thta, u_wind*units('m/s'), v_wind*units('m/s'), dx, dy)
divergence  =  mpcalc.divergence(u_wind, v_wind)  # (or setting dx/dy = None)
    divergence  =  mpcalc.divergence(u_wind, v_wind)
  File "/home/ccalkins/.local/lib/python3.8/site-packages/metpy/xarray.py", line 1506, in wrapper
    raise ValueError('Must provide dx/dy arguments or input DataArray with '
ValueError: Must provide dx/dy arguments or input DataArray with latitude/longitude coordinates.

As it is should, however... adding in the dx/dy

divergence  =  mpcalc.divergence(u_wind, v_wind, dx, dy)
    divergence  =  mpcalc.divergence(u_wind, v_wind, dx, dy)
  File "/home/ccalkins/.local/lib/python3.8/site-packages/metpy/xarray.py", line 1435, in wrapper
    bound_args = signature(func).bind(*args, **kwargs)
  File "/usr/lib/python3.8/inspect.py", line 3037, in bind
    return self._bind(args, kwargs)
  File "/usr/lib/python3.8/inspect.py", line 2963, in _bind
    raise TypeError(
TypeError: too many positional arguments

Is there a issue in how I'm inputting the parameters? In the https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.divergence.html#divergence, theres a * for a parameter, so I'm not sure what this * is referring to, if anything? This also seems to be an issue on vorticity as well.

On https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.html#module-metpy.calc it list divergence and vorticity as

divergence(u, v, *[, dx, dy, x_dim, y_dim]) Calculate the horizontal divergence of a vector.
vorticity(u, v, *[, dx, dy, x_dim, y_dim]) Calculate the vertical vorticity of the horizontal wind.

But on others,

total_deformation(u, v[, dx, dy, x_dim, y_dim]) Calculate the horizontal total deformation of the horizontal wind.
shearing_deformation(u, v[, dx, dy, x_dim, …]) Calculate the shearing deformation of the horizontal wind.
stretching_deformation(u, v[, dx, dy, …]) Calculate the stretching deformation of the horizontal wind.

I've tried these other 3 and they all work as they should so I'm just curious what the issue is on the divergence and vorticity?

-Chase

@chasecalkins chasecalkins added the Type: Bug Something is not working like it should label Sep 13, 2021
@jthielen
Copy link
Collaborator

jthielen commented Sep 13, 2021

divergence, vorticity, and advection have their "grid parameters" specified as keyword-only arguments to be able to most flexibly handle varying dimensions (see #1519 for reasoning). This is what that * in the signature means...everything after that * is a keyword-only argument. In your code, this will look like

divergence = mpcalc.divergence(u_wind, v_wind, dx=dx, dy=dy)

@jthielen jthielen added Area: Calc Pertains to calculations Type: Question Issues does not require work, but answers a user question and removed Type: Bug Something is not working like it should labels Sep 13, 2021
@KCorb11
Copy link

KCorb11 commented Sep 21, 2021

This thread is helpful, but vorticity and advection are behaving in different ways for me. absolute vorticity is fine with the following:

avor_500 = mpcalc.absolute_vorticity(ug_500, vg_500, dx, dy, lat2d_for_coriolis)

but advection will not work the same way. I need to have dx=dx and dy=dy.

adv_500 = mpcalc.advection(avor_500, ug_500, vg_500, dx=dx, dy=dy) * 1e9

I'm trying to understand why for an assignment for my class.

Thanks!

Update: Now I see that vorticity and absolute vorticity are not the same in terms of positional versus keywords; i.e., the *. I think they really should be!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations Type: Question Issues does not require work, but answers a user question
Projects
None yet
Development

No branches or pull requests

3 participants