barronh / pseudonetcdf

PseudoNetCDF like NetCDF except for many scientific format backends
GNU Lesser General Public License v3.0
76 stars 35 forks source link

crashing while plotting - basemap/cartopy #129

Open barronh opened 2 years ago

barronh commented 2 years ago

Some users are experiencing crashing while plotting spatial maps. This is not a problem with PseudoNetCDF. This is often due to conflicting libraries associated with basemap and cartopy in anaconda.

Basically, it is possible to create an environment where basemap is available but will fail. Because this is a deep library issue, it does not just error and return control to python. Instead, the system crashes. This is an environment problem, not a PseudoNetCDF problem.

There are two easy work arounds. The plot command accepts map_kw=False to disable mapping. This will work, but you get no map.

A work around that includes a map uses pycno. pycno is easily installable with pip and only requires pyproj for projected maps. pyproj is also easily installable with pip. See the pycno documentation for lat/long and projected plots. For projection plots and IOAPI files, you can define the projection using the PseudoNetCDF.getproj method with the withgrid=True option.


import PseudoNetCDF as pnc
import matplotlib.pyplot as plt
import pycno

cmaqpath= '...'
cmaqf = pnc.pncopen(cmaqpath, format='ioapi')
proj = cmaqf.getproj(withgrid=True)
cno = pycno.cno(proj=proj)

fig, ax = plt.subplots()
qkey = 'O3'
qvar = cmaqf.variables[qkey]
p = ax.pcolormesh(qvar[0, 0])
cno.draw(ax=ax)
fig.colorbar(p, label=qvar.units.strip())
fig.savefig(f'{qkey}.png')```
barronh commented 1 year ago

p.s., I think this is related to incompatible GEOS libraries, which should only matter when shapely optimizations are on... maybe. Maybe try import shapely; shapely.speedups.disable() before running with cartopy and see if that helps