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

crashing while plotting - basemap/cartopy #129

Open
barronh opened this issue Nov 17, 2021 · 1 comment
Open

crashing while plotting - basemap/cartopy #129

barronh opened this issue Nov 17, 2021 · 1 comment

Comments

@barronh
Copy link
Owner

barronh commented Nov 17, 2021

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.

  • If basemap alone is installed, everything works well. PseudoNetCDF finds basemap and plots accordingly.
  • If cartopy is installed alone, PseudoNetCDF doesn't add maps.
  • If both are installed, the basemap libgeos expected version is not available (replaced by the cartopy version) and the system may crash.

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
Copy link
Owner Author

barronh commented Mar 31, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant