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

RuntimeError: Unidentified problem with geometry, linestring being re-added. #655

Closed
DamienIrving opened this issue Aug 4, 2015 · 5 comments

Comments

@DamienIrving
Copy link

I've documented a case at this IPython notebook where I get a RuntimeError: Unidentified problem with geometry, linestring being re-added error when using the contourf function.

In the notebook you'll see that I'm transforming data from a ccrs.RotatedPole(260, 20) grid to a
ccrs.RotatedPole(260, 20, central_rotated_longitude=180) grid. This error doesn't happen every time I attempt this transform with the contourf function, so I'm at a loss as to why this specific data file throws an error.

(it looks like this Unidentified problem with geometry error is something others have found in the past - e.g. #311 - but perhaps it hasn't been fully resolved?)

@pelson
Copy link
Member

pelson commented Aug 4, 2015

Thanks @DamienIrving - looks like it is a geometry transformation bug that needs addressing. It can get tricky to track this down, but I've got a few notes on how I've done some of the tracking down in the past: https://github.com/SciTools/cartopy/wiki/DEVEL:-Isolating-misbehaving-polygons-in-cartopy's-matplotlib-interface

Essentially, we want to reduce the scope of the problem to as few coordinates as possible.
The first step is to be able to identify the particular contour which is causing the problem - I typically create a list of the contour levels, and then go through each one individually to identify which one is having the problem.

After that, I try to get hold of the matplotlib.path.Path for that particular contour, and see if I can reproduce the problem without any data file (or Iris). As soon as you are at that point, it is then that the path gets whittled down to as few geometries as possible (for which I have an as yet unpublished path dissection mpl GUI).

If that sounds a little too involved, if you could get to the point of getting hold of your x, y, data arrays, and the exact coordinate systems you are using (thereby removing Iris as a dependency), and I'll try to help (though I'm going to be away from civilisation for a few weeks in a few days).

Cheers,

@coolum001
Copy link

coolum001 commented Feb 12, 2017

I also get this message with the following code

fig = plt.figure(figsize=(10,10))
ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine(central_longitude=100))
#ax.set_extent((110, 155, -45, -5))
ax.coastlines(resolution='10m')
ax.gridlines(draw_labels=False)

ax.add_feature(cartopy.feature.LAND)
ax.add_feature(cartopy.feature.OCEAN)
ax.add_feature(cartopy.feature.COASTLINE)

shp = shapereader.Reader(add_shp)
add_s = shp.records()
ADD_alpha = 0.5

for add in add_s:

    if( add.geometry == None):
        pass
    else:
        ax.add_geometries([add.geometry], ccrs.PlateCarree(),\
                          edgecolor='red',  facecolor='white', alpha = ADD_alpha)
    #end if

#end for

plt.show()

where the shape file being added is from https://github.com/fraxen/tectonicplates

add_shp = '../data/PB2002_plates'

the error message is

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
D:\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    305                 pass
    306             else:
--> 307                 return printer(obj)
    308             # Finally look for special method names
    309             method = get_real_method(obj, self.print_method)

D:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
    225 
    226     if 'png' in formats:
--> 227         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    228     if 'retina' in formats or 'png2x' in formats:
    229         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

D:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    117 
    118     bytes_io = BytesIO()
--> 119     fig.canvas.print_figure(bytes_io, **kw)
    120     data = bytes_io.getvalue()
    121     if fmt == 'svg':

D:\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2178                     orientation=orientation,
   2179                     dryrun=True,
-> 2180                     **kwargs)
   2181                 renderer = self.figure._cachedRenderer
   2182                 bbox_inches = self.figure.get_tightbbox(renderer)

D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    525 
    526     def print_png(self, filename_or_obj, *args, **kwargs):
--> 527         FigureCanvasAgg.draw(self)
    528         renderer = self.get_renderer()
    529         original_dpi = renderer.dpi

D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
    472 
    473         try:
--> 474             self.figure.draw(self.renderer)
    475         finally:
    476             RendererAgg.lock.release()

D:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     60     def draw_wrapper(artist, renderer, *args, **kwargs):
     61         before(artist, renderer)
---> 62         draw(artist, renderer, *args, **kwargs)
     63         after(artist, renderer)
     64 

D:\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
   1157         dsu.sort(key=itemgetter(0))
   1158         for zorder, a, func, args in dsu:
-> 1159             func(*args)
   1160 
   1161         renderer.close_group('figure')

D:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     60     def draw_wrapper(artist, renderer, *args, **kwargs):
     61         before(artist, renderer)
---> 62         draw(artist, renderer, *args, **kwargs)
     63         after(artist, renderer)
     64 

D:\Anaconda3\lib\site-packages\cartopy\mpl\geoaxes.py in draw(self, renderer, inframe)
    370 
    371         return matplotlib.axes.Axes.draw(self, renderer=renderer,
--> 372                                          inframe=inframe)
    373 
    374     def __str__(self):

D:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     60     def draw_wrapper(artist, renderer, *args, **kwargs):
     61         before(artist, renderer)
---> 62         draw(artist, renderer, *args, **kwargs)
     63         after(artist, renderer)
     64 

D:\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
   2317 
   2318         for zorder, a in dsu:
-> 2319             a.draw(renderer)
   2320 
   2321         renderer.close_group('axes')

D:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     60     def draw_wrapper(artist, renderer, *args, **kwargs):
     61         before(artist, renderer)
---> 62         draw(artist, renderer, *args, **kwargs)
     63         after(artist, renderer)
     64 

D:\Anaconda3\lib\site-packages\cartopy\mpl\feature_artist.py in draw(self, renderer, *args, **kwargs)
    158                 if ax.projection != feature_crs:
    159                     projected_geom = ax.projection.project_geometry(
--> 160                         geom, feature_crs)
    161                 else:
    162                     projected_geom = geom

D:\Anaconda3\lib\site-packages\cartopy\crs.py in project_geometry(self, geometry, src_crs)
    173             raise ValueError('Unsupported geometry '
    174                              'type {!r}'.format(geom_type))
--> 175         return getattr(self, method_name)(geometry, src_crs)
    176 
    177     def _project_point(self, point, src_crs):

D:\Anaconda3\lib\site-packages\cartopy\crs.py in _project_multipolygon(self, geometry, src_crs)
    289         geoms = []
    290         for geom in geometry.geoms:
--> 291             r = self._project_polygon(geom, src_crs)
    292             if r:
    293                 geoms.extend(r.geoms)

D:\Anaconda3\lib\site-packages\cartopy\crs.py in _project_polygon(self, polygon, src_crs)
    324         # Convert any lines to rings by attaching them to the boundary.
    325         if multi_lines:
--> 326             rings.extend(self._attach_lines_to_boundary(multi_lines, is_ccw))
    327 
    328         # Resolve all the inside vs. outside rings, and convert to the

D:\Anaconda3\lib\site-packages\cartopy\crs.py in _attach_lines_to_boundary(self, multi_line_strings, is_ccw)
    506                         if debug_plot_edges:
    507                             plt.show()
--> 508                         raise RuntimeError('Unidentified problem with '
    509                                            'geometry, linestring being '
    510                                            're-added. Please raise an issue.')

RuntimeError: Unidentified problem with geometry, linestring being re-added. Please raise an issue.

environment is:

python version : 3.5.2 |Anaconda custom (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
python environment : root
pandas version : 0.18.1
current wkg dir: C:\Users\donrc\Documents\JupyterNotebooks\CartopyNotebookProject\develop
Notebook run at: 2017-02-12 16:45:08.010413 local time
Notebook run at: 2017-02-12 06:45:08.010413 UTC
Notebook run on: Windows-10-10.0.14393-SP0
Cartopy Version: 0.15.0

@lcgthree
Copy link

This is also a problem that I frequently face when attempting to plot 2m-temperature error in an AlbersEqualArea projection using contourf. Here's a basic code example to demonstrate my use case:

ax = plt.axes(projection=ccrs.AlbersEqualArea(central_longitude=-95, central_latitude-37.5))
ax.set_extent([-130, -60, 20, 60])`
ax.coastlines('50m', zorder=10)`

x, y = np.meshgrid(range(0, 361), range(-90, 91))
cf = ax.contourf(x, y, temp_error, levels=range(-10, 11), cmap=plt.cm.RdBu_r,
                 transform=ccrs.PlateCarree(), zorder=0)

The contour levels I supply are range(-10, 11), and I've determined that the problematic level for this particular case is range(5, 7). This is as far as I've gone in trying to track down the issue.

Since the temperature data are supplied in real-time, I've made a local copy of today's file in order to spend some time diagnosing the issue. I'll also be happy to share the file with someone else who would like to reproduce it.

@QuLogic QuLogic added this to the 0.16 milestone Jan 3, 2018
@QuLogic
Copy link
Member

QuLogic commented Jan 3, 2018

Both examples are fixed by #974.

@QuLogic QuLogic closed this as completed Jan 3, 2018
@purpleskyfall
Copy link

I got the same problem when run:

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

plt.figure(figsize=(12, 8))
ax = plt.axes(projection=ccrs.EuroPP())
land = cfeature.NaturalEarthFeature(category='physical', name='land', scale='50m',
                                    facecolor=cfeature.COLORS['land'])
ocean = cfeature.NaturalEarthFeature(category='physical', name='ocean', scale='50m',
                                     facecolor=cfeature.COLORS['water'])
ax.add_feature(ocean)
ax.add_feature(land)
ax.gridlines(linestyle=':')

plt.show()

By the way, I'm using Cartopy 0.15.0, Python 3.5.4 on Windows 10.

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

6 participants