def transform_path(self, path):
            vertices = path.vertices
            # Intelligent interpolation needed
#            ipath = path.interpolated(self._resolution)
            ipath = path
            ipath = path.interpolated(10)
#            ipath = path.interpolated(3050)
            
            verts = self.transform_no_mod(ipath.vertices)
            codes = ipath.codes
#            print verts.shape
#            print 'transforming lon range:', np.min(verts[:, 0]), np.max(verts[:, 0])
#            if np.isnan(np.max(verts[:, 0])):
#                print 'Got nan: ', path, verts
                 
            paths = []
            paths.append(Path(verts, codes))
            
#            # Have any of the points wrapped? If so, pick up the pen, and start from -360
#            if any(ipath.vertices[:, 0] > np.pi):
#                v = ipath.vertices.copy()
#                print 'splitting -:'
#                v[:, 0] -= 2 * np.pi                
#                print v
#                v = self.transform_no_mod(v)
#                paths.append(Path(v))
#                 
#            # Have any of the points wrapped? If so, pick up the pen, and start from +360
#            if any(ipath.vertices[:, 0] < -np.pi):
#                v = ipath.vertices.copy()
#                v[:, 0] += 2 * np.pi
#                print 'splitting +:'
#                v = self.transform_no_mod(v)
#                paths.append(Path(v))
            s_pole = np.deg2rad(np.array([0, -89.9999]))
            if path.contains_point(s_pole):
                print 'POLE ALERT!!!', path 
                path = Path(verts[:-31])
                paths = [path]
            
            if len(paths) == 1:
                path = paths[0]
            else:
                for path in paths:
                    if path.codes is not None:
                        if path.codes[0] == Path.MOVETO and all(path.codes[1:] == Path.LINETO):
                            path.codes = None
                        else:
                            # This is a bit strict... but a condition of make_compound_path
                            raise ValueError('Cannot draw discontiguous polygons.')
#                        print path.codes
                path = Path.make_compound_path(*paths)
                                      
            return path
Example #2
0
 def define_boundary(self, vertices):
     try:
         n = len(vertices) - 2
         p = Path(vertices)
         codes = [p.MOVETO]
         codes += n * [p.LINETO]
         codes += [p.CLOSEPOLY]
         p.codes = codes
         coords = p._vertices
         xmin = min(coords[:, 0])
         xmax = max(coords[:, 0])
         ymin = min(coords[:, 1])
         ymax = max(coords[:, 1])
         self._boundary_path = {
             'path': p,
             'color': 'black',
             'lw': 2.0,
             'limits': ((xmin, ymin), (xmax, ymax))
         }
     except:
         raise ('Invalid data for defining boundary!')