Skip to content
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
This repository was archived by the owner on Aug 13, 2026. It is now read-only.

Geomtrophic and Ageostrophic Wind problem in the  #132

Open

Description

@takayanamba99

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"

Could you tell me how to solve the problem?

Activity

  1. self-assigned this
    on Feb 22, 2023
  2. dcamron commented on Feb 22, 2023

    @dcamron
    Member

    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:

    >>> import metpy.calc as mpcalc
    >>> help(mpcalc.geostrophic_wind)
    Help on function geostrophic_wind in module metpy.calc:
    
    geostrophic_wind(height, dx=None, dy=None, latitude=None, x_dim=-1, y_dim=-2, *, parallel_scale=None, meridional_scale=None, longitude=None, crs=None)
        Calculate the geostrophic wind given from the height or geopotential.
    ...

    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

    geo_wind_u, geo_wind_v = mpcalc.geostrophic_wind(height * units.m, dx=dx, dy=dy, latitude=lat_2d)

    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 example
    data = ncss.get_data(query)
    
    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'])

    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

    import metpy.calc as mpcalc
    import xarray as xr
    
    ds = xr.open_dataset('my_data.nc')
    
    mpcalc.geostrophic_wind(my_data['my_height_variable'])

    🎉 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!

  3. takayanamba99 commented on Feb 24, 2023

    @takayanamba99
    Author

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions