sharppy / SHARPpy

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

muCAPE returns all NaN #166

Closed am-thyst closed 5 years ago

am-thyst commented 5 years ago

I'm trying to calculate muCAPE using netCDF data. I'm wondering if that is my problem here. The calculation runs fine but produces all nan results. I open the files using xarray, but tried converting them to numpys for the calculation. Same result occurred.

dict = {}
with sharedmem.MapReduce(np=45) as pool:
  for i in range(600, 1000, 50): # This opens the .nc files as xarray 
    dict["p" + str(i)] = np.array(pressure_levels(i))
    dict["t" + str(i)] = np.array(temps(str(i)) - 273) # Kelvin to degC
    dict["dp" + str(i)] = np.array(dewpoints(str(i)) - 273) # Kelvin to degC
    dict["wind_spd" + str(i)] = np.array(np.sqrt(((u_wind(str(i))*0.514)**2)+((v_wind(str(i))*0.514)**2))) # Wind vectors to wind speed
    dict["wind_dr" + str(i)] = np.array((np.arctan2(u_wind(str(i)),v_wind(str(i))) * (180/math.pi)) + 180) # Wind vectors to wind direction
    dict["height" + str(i)] = np.array(geopotential(str(i)) / 9.80665) # Geopotential to geopotential height
  def loop(that):
    for l in range(that, that+1):
      for k in range(241):
        for j in range(4):
          # The following produces the array of variable values at each pressure level 
          pres = [dict["p950"][j,k,l], dict["p900"][j,k,l], dict["p850"][j,k,l], dict["p800"][j,k,l], dict["p750"][j,k,l], dict["p700"][j,k,l], dict["p650"][j,k,l]]
          tmpc = [dict["t950"][j,k,l], dict["t900"][j,k,l], dict["t850"][j,k,l], dict["t800"][j,k,l], dict["t750"][j,k,l], dict["t700"][j,k,l], dict["t650"][j,k,l]]
          dwpc = [dict["dp950"][j,k,l], dict["dp900"][j,k,l], dict["dp850"][j,k,l], dict["dp800"][j,k,l], dict["dp750"][j,k,l], dict["dp700"][j,k,l], dict["dp650"][j,k,l]]
          wspd = [dict["wind_spd950"][j,k,l], dict["wind_spd900"][j,k,l], dict["wind_spd850"][j,k,l], dict["wind_spd800"][j,k,l], dict["wind_spd750"][j,k,l], dict["wind_spd700"][j,k,l], dict["wind_spd650"][j,k,l]]
          wdir = [dict["wind_dr950"][j,k,l], dict["wind_dr900"][j,k,l], dict["wind_dr850"][j,k,l], dict["wind_dr800"][j,k,l], dict["wind_dr750"][j,k,l], dict["wind_dr700"][j,k,l], dict["wind_dr650"][j,k,l]]
          hght = [dict["height950"][j,k,l], dict["height900"][j,k,l], dict["height850"][j,k,l], dict["height800"][j,k,l], dict["height750"][j,k,l], dict["height700"][j,k,l], dict["height650"][j,k,l]]
          # Here you've got the SHARPpy code
          prof = tab.profile.create_profile(profile='default', pres=pres, hght=hght, tmpc=tmpc, \
                                    dwpc=dwpc, wspd=wspd, wdir=wdir, missing=-9999, strictQC=True)
          ag = tab.params.parcelx(prof, flag=3)
          counter[j,k,l] = ag.bplus
  pool.map(loop, range(0, 480))

^ This runs and I put it into a new netCDF file. I then test the results:

muCAPE.max()

/nerc/n02/n02/amethyst/minic/envs/newenv/lib/python3.6/site-packages/xarray/core/nputils.py:220:,
                                   RuntimeWarning: All-NaN slice encountered
  result = getattr(npmodule, name)(values, axis=axis, **kwds)
<xarray.DataArray 'muCAPE' ()>
array(nan)
am-thyst commented 5 years ago

update: if I ensure all arrays are .asfloat before putting them into the sharppy function, I get an entire array of zeros.

update: I think it is bad data, will see if it is solved once the data is fixed