You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
Geomtrophic and Ageostrophic Wind problem in the #132
On the line of Geomtrophic and Ageostrophic Wind,
geo_wind_u, geo_wind_v = mpcalc.geostrophic_wind(height * units.m, f, dx, dy)
the error happened like
ValueError: This function changed in 1.0--double check that the function is being called properly. geostrophic_wind given arguments with incorrect units: dx requires "[length]" but given "1 / second", latitude requires "[dimensionless]" but given "meter"
That example is very out of date, as are many others on this repository at this moment. Please explore examples in the MetPy docs example gallery instead until we close this issue.
I can still help from here. That function signature has been updated a few times since, check out the documentation or in your particular python install (here, the latest version of MetPy, 1.4) with:
where we can see that the inputs I'm providing my function don't match up. So, on MetPy 1.4, that particular line could be re-written (without any other changes) as
Since MetPy 1.4, there are few ways you can do this without calculating dx, dy by hand, and if you're using xarray you can simplify this much further!
... #continued from the original exampledata=ncss.get_data(query)
importxarrayasxrds=xr.open_dataset(xr.backends.NetCDF4DataStore(data))
geo_wind_u, geo_wind_v=mpcalc.geostrophic_wind(ds['Geopotential_height_isobaric'])
Note, if you use xarray with your own netcdf files, or most remote data not accessed using NCSS + netcdf4-python (as in this example), you won't need the xr.backends.NetCDF4DataStore bit, and your script might just look like
Thank you for the suggestion.
It seems to work on the part below you suggested
After the part, on # Create new figure
the error took place and didn't make the same figures (without geostrophic and ageostrophic winds)
/opt/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in quiver(self, x, y, u, v, *args, **kwargs)
2092 x, y = np.meshgrid(x, y)
2093 u, v = self.projection.transform_vectors(t, x, y, u, v)
-> 2094 return super().quiver(x, y, u, v, *args, **kwargs)
2095
2096 @_add_transform
/opt/miniconda3/lib/python3.9/site-packages/matplotlib/init.py in inner(ax, data, *args, **kwargs)
1445 def inner(ax, *args, data=None, **kwargs):
1446 if data is None:
-> 1447 return func(ax, *map(sanitize_sequence, args), **kwargs)
1448
1449 bound = new_sig.bind(ax, *args, **kwargs)
/opt/miniconda3/lib/python3.9/site-packages/matplotlib/quiver.py in init(self, ax, scale, headwidth, headlength, headaxislength, minshaft, minlength, units, scale_units, angles, width, color, pivot, *args, **kw)
472 """
473 self._axes = ax # The attr actually set by the Artist.axes property.
--> 474 X, Y, U, V, C = _parse_args(*args, caller_name='quiver()')
475 self.X = X
476 self.Y = Y
/opt/miniconda3/lib/python3.9/site-packages/matplotlib/quiver.py in _parse_args(caller_name, *args)
417 f'{len_args} were given')
418
--> 419 nr, nc = (1, U.shape[0]) if U.ndim == 1 else U.shape
420
421 if X is not None:
ValueError: too many values to unpack (expected 2)
Activity
dcamron commentedon Feb 22, 2023
That example is very out of date, as are many others on this repository at this moment. Please explore examples in the MetPy docs example gallery instead until we close this issue.
I can still help from here. That function signature has been updated a few times since, check out the documentation or in your particular python install (here, the latest version of MetPy, 1.4) with:
where we can see that the inputs I'm providing my function don't match up. So, on MetPy 1.4, that particular line could be re-written (without any other changes) as
Since MetPy 1.4, there are few ways you can do this without calculating
dx, dyby hand, and if you're using xarray you can simplify this much further!Note, if you use xarray with your own netcdf files, or most remote data not accessed using NCSS + netcdf4-python (as in this example), you won't need the
xr.backends.NetCDF4DataStorebit, and your script might just look like🎉 Hope this helps. Please start a new discussion here if you have further issues or visit the other MetPy support venues if needed. Be sure to update your install of MetPy!
takayanamba99 commentedon Feb 24, 2023
Thank you for the suggestion.
It seems to work on the part below you suggested
After the part, on # Create new figure
the error took place and didn't make the same figures (without geostrophic and ageostrophic winds)
The part you suggested seems to work
import xarray as xr
ds = xr.open_dataset(xr.backends.NetCDF4DataStore(data))
geo_wind_u, geo_wind_v = mpcalc.geostrophic_wind(ds['Geopotential_height_isobaric'])
geo_wind_u = geo_wind_u
geo_wind_v = geo_wind_v
Calculate ageostrophic wind components
ageo_wind_u = u_wind - geo_wind_u
ageo_wind_v = v_wind - geo_wind_v
================== # Create new figure
An error took place as
ValueError Traceback (most recent call last)
in
32 u_wind[quiver_slices], v_wind[quiver_slices],
33 color='blue', **quiver_kwargs)
---> 34 geo = ax.quiver(lon_2d[quiver_slices], lat_2d[quiver_slices],
35 geo_wind_u[quiver_slices], geo_wind_v[quiver_slices],
36 color='darkorchid', **quiver_kwargs)
/opt/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in wrapper(self, *args, **kwargs)
316
317 kwargs['transform'] = transform
--> 318 return func(self, *args, **kwargs)
319 return wrapper
320
/opt/miniconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py in quiver(self, x, y, u, v, *args, **kwargs)
2092 x, y = np.meshgrid(x, y)
2093 u, v = self.projection.transform_vectors(t, x, y, u, v)
-> 2094 return super().quiver(x, y, u, v, *args, **kwargs)
2095
2096 @_add_transform
/opt/miniconda3/lib/python3.9/site-packages/matplotlib/init.py in inner(ax, data, *args, **kwargs)
1445 def inner(ax, *args, data=None, **kwargs):
1446 if data is None:
-> 1447 return func(ax, *map(sanitize_sequence, args), **kwargs)
1448
1449 bound = new_sig.bind(ax, *args, **kwargs)
/opt/miniconda3/lib/python3.9/site-packages/matplotlib/axes/_axes.py in quiver(self, *args, **kw)
5019 args = self._quiver_units(args, kw)
5020
-> 5021 q = mquiver.Quiver(self, *args, **kw)
5022
5023 self.add_collection(q, autolim=True)
/opt/miniconda3/lib/python3.9/site-packages/matplotlib/quiver.py in init(self, ax, scale, headwidth, headlength, headaxislength, minshaft, minlength, units, scale_units, angles, width, color, pivot, *args, **kw)
472 """
473 self._axes = ax # The attr actually set by the Artist.axes property.
--> 474 X, Y, U, V, C = _parse_args(*args, caller_name='quiver()')
475 self.X = X
476 self.Y = Y
/opt/miniconda3/lib/python3.9/site-packages/matplotlib/quiver.py in _parse_args(caller_name, *args)
417 f'{len_args} were given')
418
--> 419 nr, nc = (1, U.shape[0]) if U.ndim == 1 else U.shape
420
421 if X is not None:
ValueError: too many values to unpack (expected 2)
Could you give me any suggestions for this issue?