jgliss / geonum

Python toolbox for 3D geo-numerical calculations
GNU General Public License v3.0
6 stars 3 forks source link

drawcoastlines() in GeoSetup.plot2d() fails, possibly due to no coastlines being in the plotted area #5

Open twVolc opened 4 years ago

twVolc commented 4 years ago

I have encountered this error after running ex02_meas_geometry.py in pyplis, but I think it's a geonum issue.

Traceback (most recent call last):
  File "C:/Users/tw9616/Documents/PostDoc/Permanent Camera/pyplis/scripts/ex02_meas_geometry.py", line 130, in <module>
    geom_corr, map_ = find_viewing_direction(ds.meas_geometry)
  File "C:/Users/tw9616/Documents/PostDoc/Permanent Camera/pyplis/scripts/ex02_meas_geometry.py", line 85, in find_viewing_direction
    meas_geometry.find_viewing_direction(pix_x=se_crater_img_pos[0],
  File "C:\Users\tw9616\Documents\PostDoc\Permanent Camera\pyplis\pyplis\geometry.py", line 1256, in find_viewing_direction
    map = self.draw_map_2d(draw_fov=False)
  File "C:\Users\tw9616\Documents\PostDoc\Permanent Camera\pyplis\pyplis\geometry.py", line 1410, in draw_map_2d
    m = s.plot_2d(0, 0, draw_topo, draw_coastline, draw_mapscale,
  File "C:\Users\tw9616\Anaconda3\envs\py38\lib\site-packages\geonum\geosetup.py", line 522, in plot_2d
    m.drawcoastlines()
  File "C:\Users\tw9616\Anaconda3\envs\py38\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 1851, in drawcoastlines
    coastlines = LineCollection(self.coastsegs,antialiaseds=(antialiased,))
  File "C:\Users\tw9616\Anaconda3\envs\py38\lib\site-packages\matplotlib\collections.py", line 1333, in __init__
    self.set_segments(segments)
  File "C:\Users\tw9616\Anaconda3\envs\py38\lib\site-packages\matplotlib\collections.py", line 1348, in set_segments
    self._paths = [mpath.Path(_seg) for _seg in _segments]
  File "C:\Users\tw9616\Anaconda3\envs\py38\lib\site-packages\matplotlib\collections.py", line 1348, in <listcomp>
    self._paths = [mpath.Path(_seg) for _seg in _segments]
  File "C:\Users\tw9616\Anaconda3\envs\py38\lib\site-packages\matplotlib\path.py", line 129, in __init__
    raise ValueError(
ValueError: 'vertices' must be a 2D list or array with shape Nx2

Having had a quick look into the issue online it looks like this ValueError can be encountered when trying to plot coastlines in a figure where there are none. I'm not certain if this is the issue in this case or not, but I have found that a rather crude solution of adding a try/except clause (to catch the ValueError and simply pass) for m.drawcoastlines() at line 522 of geosetup.py seemed to do the trick. The pyplis example script executed to the end following this update, with the two figures it produces being saved, and looking how I would anticipate. There's no coastline in this Etna figure, so perhaps this was the issue.

jgliss commented 3 years ago

@twVolc thanks for this, I will see if I can fix this for the upcoming release of v1.5.0. However, note also #4, which I have no idea when I will get to that.