sharppy / SHARPpy

Sounding/Hodograph Analysis and Research Program in Python
https://sharppy.github.io/SHARPpy/index.html
Other
216 stars 112 forks source link

calculations when no wind data is present #139

Closed swnesbitt closed 5 years ago

swnesbitt commented 6 years ago

I am running SHARPpy on some archived sounding data (pre-GPS sonde era) and finding that it crashes when all of the wind data are missing. I am just wanting to calculate thermodynamic parameters so I would think that SHARPpy should be able to handle this issues.

<ipython-input-10-558e80a009ca> in calc_cape(data, flag)
      9                               wdir=np.ma.masked_invalid(data['direction'].values),
     10                               missing=np.nan, strictQC=False)
---> 11     sfcpcl = params.parcelx( prof, flag=flag )
     12     return sfcpcl.bplus

~/anaconda/lib/python3.6/site-packages/SHARPpy-1.4.0-py3.6.egg/sharppy/sharptab/params.py in parcelx(prof, pbot, ptop, dp, **kwargs)
   1967 
   1968     # Calculate BRN if available
-> 1969     bulk_rich(prof, pcl)
   1970 
   1971     # Save params

~/anaconda/lib/python3.6/site-packages/SHARPpy-1.4.0-py3.6.egg/sharppy/sharptab/params.py in bulk_rich(prof, pcl)
   2026     # Calculate the lowest 500m mean wind
   2027     p = interp.pres(prof, interp.hght(prof, pbot)+500.)
-> 2028     mnlu, mnlv = winds.mean_wind(prof, pbot, p)
   2029 
   2030     # Calculate the 6000m mean wind

~/anaconda/lib/python3.6/site-packages/SHARPpy-1.4.0-py3.6.egg/sharppy/sharptab/winds.py in mean_wind(prof, pbot, ptop, dp, stu, stv)
     44     if dp > 0: dp = -dp
     45     ps = np.arange(pbot, ptop+dp, dp)
---> 46     u, v = interp.components(prof, ps)
     47     # u -= stu; v -= stv
     48     return ma.average(u, weights=ps)-stu, ma.average(v, weights=ps)-stv

~/anaconda/lib/python3.6/site-packages/SHARPpy-1.4.0-py3.6.egg/sharppy/sharptab/interp.py in components(prof, p)
    251     # vertical, we must reverse the order of the two arrays to satisfy
    252     # this requirement.
--> 253     U = generic_interp_pres(np.log10(p), prof.logp[::-1], prof.u[::-1])
    254     V = generic_interp_pres(np.log10(p), prof.logp[::-1], prof.v[::-1])
    255     return U, V

~/anaconda/lib/python3.6/site-packages/SHARPpy-1.4.0-py3.6.egg/sharppy/sharptab/interp.py in generic_interp_pres(p, pres, field)
    402 
    403     field_intrp = np.interp(p, pres[not_masked], field[not_masked], left=ma.masked,
--> 404                  right=ma.masked)
    405 
    406     if hasattr(p, 'shape') and p.shape == tuple():

~/anaconda/lib/python3.6/site-packages/numpy/lib/function_base.py in interp(x, xp, fp, left, right, period)
   1879             return interp_func([x], xp, fp, left, right).item()
   1880         else:
-> 1881             return interp_func(x, xp, fp, left, right)
   1882     else:
   1883         if period == 0:

ValueError: array of sample points is empty
wblumberg commented 6 years ago

Hi @swnesbitt ...so I run into this problem often because I work with thermodynamic profilers. What I do is I just make up random data for the wind speed and direction arrays when I initialize the profile object. When lifting parcels, the only place wind data gets used in calculating the bulk Richardson number, so it's mainly a workaround for this issue.

I should implement a simple fix to the code though.

swnesbitt commented 6 years ago

Ahh, good call @wblumberg. I can do that temporary fix for now.

wblumberg commented 5 years ago

This issue has been addressed in the upcoming release of SHARPpy. Data files with missing wind data can still be plotted.