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

storm_relative_helicity,The example code for this function cannot run #3594

Open
pll001 opened this issue Aug 10, 2024 · 5 comments
Open
Labels
Type: Bug Something is not working like it should

Comments

@pll001
Copy link

pll001 commented Aug 10, 2024

What went wrong?

I copied the example code of this function, but when it runs, an error occurs. What is the problem
1723278732507

Operating System

Windows

Version

1.6.2

Python Version

3.9

Code to Reproduce

from metpy.calc import storm_relative_helicity, wind_components
from metpy.units import units
# set needed values of pressure, height, wind direction/speed
p = [1000, 925, 850, 700, 500, 400] * units.hPa
h = [250, 700, 1500, 3100, 5720, 7120] * units.meters
wdir = [165, 180, 190, 210, 220, 250] * units.degree
sped = [5, 15, 20, 30, 50, 60] * units.knots
# compute wind components
u, v = wind_components(sped, wdir)
# compute SRH with a storm vector
storm_relative_helicity(h, u, v, depth=1 * units.km,
                        storm_u=7 * units('m/s'), storm_v=7 * units('m/s'))

Errors, Traceback, and Logs

Traceback (most recent call last):
  File "D:\python\3.10 fog\5.py", line 11, in <module>
    storm_relative_helicity(h, u, v, depth=1 * units.km,
  File "E:\anaconda\envs\python\lib\site-packages\metpy\xarray.py", line 1330, in wrapper
    result = func(*bound_args.args, **bound_args.kwargs)
  File "E:\anaconda\envs\python\lib\site-packages\metpy\units.py", line 333, in wrapper
    return func(*args, **kwargs)
  File "E:\anaconda\envs\python\lib\site-packages\metpy\calc\kinematics.py", line 848, in storm_relative_helicity
    _, u, v = get_layer_heights(height, depth, u, v, with_agl=True, bottom=bottom)
  File "E:\anaconda\envs\python\lib\site-packages\metpy\xarray.py", line 1330, in wrapper
    result = func(*bound_args.args, **bound_args.kwargs)
  File "E:\anaconda\envs\python\lib\site-packages\metpy\units.py", line 333, in wrapper
    return func(*args, **kwargs)
  File "E:\anaconda\envs\python\lib\site-packages\metpy\calc\tools.py", line 476, in get_layer_heights
    sfc_height = np.min(height)
TypeError: no implementation found for 'numpy.min' on types that implement __array_function__: [<class 'pint.util.Quantity'>]
@pll001 pll001 added the Type: Bug Something is not working like it should label Aug 10, 2024
@DWesl
Copy link
Contributor

DWesl commented Aug 13, 2024

It looks like the code here implements min properly, what versions of NumPy and Pint are you using?

@pll001
Copy link
Author

pll001 commented Aug 14, 2024

看起来这里的代码实现min正确,您使用的是哪个版本的 NumPy 和 Pint?

Numpy 1.21.2 Pint 0.20.1

@DWesl
Copy link
Contributor

DWesl commented Aug 14, 2024

Interesting. Works fine for me on Python 3.9.16 with NumPy 1.26.4 and pint 0.23

>>> np.min(pint.Quantity(np.array([250, 700, 1500, 3100, 5720, 7120]), "meter"))
<Quantity(250, 'meter')>

Is there something keeping you from upgrading NumPy or Pint?

@dopplershift
Copy link
Member

I'm unable to reproduce this on my macOS machine with Python 3.9 + Pint 0.20.1 and Numpy 1.21.2 with current MetPy main. I don't think we've changed anything relevant since 1.6.2, so I'm guessing this is an issue with your environment.

I would double check what versions of pint and numpy are being picked up with python -c 'import pint; print(pint.__version__); import numpy; print(numpy.__version__)', and consider rebuilding your environment.

@DWesl
Copy link
Contributor

DWesl commented Aug 23, 2024

Does conda env create -n metpy_test metpy numpy pint && conda activate metpy_test && python "D:\python\3.10 fog\5.py" run into the same problem?
conda env create -n metpy_test2 metpy==1.6.2 numpy==1.21.2 pint==0.20.1 python==3.9 && conda activate metpy_test2 && python "D:\python\3.10 fog\5.py"?

If those fail with conda: No program or batch file with that name or similar errors ("Program not found" is also likely), replacing conda env create -n with pip install --force-reinstall and skipping the conda activate part should work.

I think getting rid of those would be conda env remove -n metpy_test && conda env remove -n metpy_test2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something is not working like it should
Projects
None yet
Development

No branches or pull requests

3 participants