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

ValueError with showalter_index on FNL dataset #2210

Closed
IncubatorShokuhou opened this issue Nov 17, 2021 · 2 comments
Closed

ValueError with showalter_index on FNL dataset #2210

IncubatorShokuhou opened this issue Nov 17, 2021 · 2 comments
Labels
Area: Calc Pertains to calculations Status: Duplicate Duplicates an existing issue Status: Not A Bug Describes behavior that is working as expected Type: Bug Something is not working like it should

Comments

@IncubatorShokuhou
Copy link

What went wrong?

Error when try to calculate SI using FNL dataset.

Operating System

Linux

Version

1.1

Python Version

3.7

Code to Reproduce

import xarray as xr
from metpy.units import units
from metpy.calc import showalter_index ,dewpoint_from_relative_humidity

# read fnl dataset
ds = xr.open_dataset("fnl_20210131_18_00.grib2",engine="pynio")

# get t,rh and p
t = ds.TMP_P0_L100_GLL0.loc[rh.lv_ISBL5,...]
rh = ds.RH_P0_L100_GLL0
p = ds.lv_ISBL5.broadcast_like(rh)

# quantify
t = t.metpy.quantify()
rh = rh.metpy.quantify()
p = p.metpy.quantify()

# calculate td. No error here.
td = dewpoint_from_relative_humidity(t,rh)

# calculate SI
si = showalter_index(p,t,td)

Errors, Traceback, and Logs

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-13-e690a27c6cba> in <module>
----> 1 showalter_index(p,t,td)

/opt/conda/lib/python3.7/site-packages/metpy/xarray.py in wrapper(*args, **kwargs)
   1214 
   1215             # Evaluate inner calculation
-> 1216             result = func(*bound_args.args, **bound_args.kwargs)
   1217 
   1218             # Wrap output based on match and match_unit

/opt/conda/lib/python3.7/site-packages/metpy/units.py in wrapper(*args, **kwargs)
    244                                'that the function is being called properly.\n') + msg
    245                 raise ValueError(msg)
--> 246             return func(*args, **kwargs)
    247 
    248         return wrapper

/opt/conda/lib/python3.7/site-packages/metpy/calc/thermo.py in showalter_index(pressure, temperature, dewpoint)
   3382 
   3383     # Lift parcel from 850 to 500, handling any needed dry vs. saturated adiabatic processes
-> 3384     prof = parcel_profile(units.Quantity([850., 500.], 'hPa'), t850, td850)
   3385 
   3386     # Calculate the Showalter index

/opt/conda/lib/python3.7/site-packages/metpy/xarray.py in wrapper(*args, **kwargs)
   1214 
   1215             # Evaluate inner calculation
-> 1216             result = func(*bound_args.args, **bound_args.kwargs)
   1217 
   1218             # Wrap output based on match and match_unit

/opt/conda/lib/python3.7/site-packages/metpy/units.py in wrapper(*args, **kwargs)
    244                                'that the function is being called properly.\n') + msg
    245                 raise ValueError(msg)
--> 246             return func(*args, **kwargs)
    247 
    248         return wrapper

/opt/conda/lib/python3.7/site-packages/metpy/calc/thermo.py in parcel_profile(pressure, temperature, dewpoint)
    742 
    743     """
--> 744     _, _, _, t_l, _, t_u = _parcel_profile_helper(pressure, temperature, dewpoint)
    745     return concatenate((t_l, t_u))
    746 

/opt/conda/lib/python3.7/site-packages/metpy/calc/thermo.py in _parcel_profile_helper(pressure, temperature, dewpoint)
    902 
    903     # Find the LCL
--> 904     press_lcl, temp_lcl = lcl(pressure[0], temperature, dewpoint)
    905     press_lcl = press_lcl.to(pressure.units)
    906 

/opt/conda/lib/python3.7/site-packages/metpy/xarray.py in wrapper(*args, **kwargs)
   1214 
   1215             # Evaluate inner calculation
-> 1216             result = func(*bound_args.args, **bound_args.kwargs)
   1217 
   1218             # Wrap output based on match and match_unit

/opt/conda/lib/python3.7/site-packages/metpy/units.py in wrapper(*args, **kwargs)
    244                                'that the function is being called properly.\n') + msg
    245                 raise ValueError(msg)
--> 246             return func(*args, **kwargs)
    247 
    248         return wrapper

/opt/conda/lib/python3.7/site-packages/metpy/calc/thermo.py in lcl(pressure, temperature, dewpoint, max_iters, eps)
    419     w = mixing_ratio(saturation_vapor_pressure(dewpoint), pressure)
    420     lcl_p = so.fixed_point(_lcl_iter, pressure.m, args=(pressure.m, w, temperature),
--> 421                            xtol=eps, maxiter=max_iters)
    422     lcl_p = np.where(nan_mask, np.nan, lcl_p)
    423 

/opt/conda/lib/python3.7/site-packages/scipy/optimize/minpack.py in fixed_point(func, x0, args, xtol, maxiter, method)
    901     use_accel = {'del2': True, 'iteration': False}[method]
    902     x0 = _asarray_validated(x0, as_inexact=True)
--> 903     return _fixed_point_helper(func, x0, args, xtol, maxiter, use_accel)

/opt/conda/lib/python3.7/site-packages/scipy/optimize/minpack.py in _fixed_point_helper(func, x0, args, xtol, maxiter, use_accel)
    850         else:
    851             p = p1
--> 852         relerr = _lazywhere(p0 != 0, (p, p0), f=_relerr, fillvalue=p)
    853         if np.all(np.abs(relerr) < xtol):
    854             return p

/opt/conda/lib/python3.7/site-packages/scipy/_lib/_util.py in _lazywhere(cond, arrays, f, fillvalue, f2)
     53     tcode = np.mintypecode([a.dtype.char for a in arrays])
     54     out = _valarray(np.shape(arrays[0]), value=fillvalue, typecode=tcode)
---> 55     np.place(out, cond, f(*temp))
     56     if f2 is not None:
     57         temp = tuple(np.extract(~cond, arr) for arr in arrays)

<__array_function__ internals> in place(*args, **kwargs)

/opt/conda/lib/python3.7/site-packages/numpy/lib/function_base.py in place(arr, mask, vals)
   1796                         "not {name}".format(name=type(arr).__name__))
   1797 
-> 1798     return _insert(arr, mask, vals)
   1799 
   1800 

ValueError: place: mask and data must be the same size
@IncubatorShokuhou IncubatorShokuhou added the Type: Bug Something is not working like it should label Nov 17, 2021
@IncubatorShokuhou
Copy link
Author

Seems it is also a LCL error on grid. Should we condiser to fill NaN into the array when similar error occoured in grid?

@dopplershift
Copy link
Member

The problem is that parcel_profile currently only works with 1D profiles, not grids. See #1533 for more discussion. This is definitely a high priority item for us (we have direct funding to support it), but it's not trivial to fix so it won't be fixed in the short term.

The unfortunate workaround is to loop in Python and call showalter_index on each profile. 😞

I'm going to close this as a duplicate of #1533.

@dopplershift dopplershift added Area: Calc Pertains to calculations Status: Duplicate Duplicates an existing issue Status: Not A Bug Describes behavior that is working as expected labels Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations Status: Duplicate Duplicates an existing issue Status: Not A Bug Describes behavior that is working as expected Type: Bug Something is not working like it should
Projects
None yet
Development

No branches or pull requests

2 participants