original_docstring: 
      Creates a list of patches from a shapefile specified by the country code and
      administrative level
      
      Parameters
      ----------
      countrycode : str
          Three letter ISO 3166-1 alpha-3 country code
          
      level : int
          Administrative level 0-5
      
      
docstring: Creates a list of patches from a shapefile specified by the country code and
  administrative level
  
  Parameters
  
  countrycode : str
  Three letter ISO 3166-1 alpha-3 country code
  
  level : int
  Administrative level 0-5
docstring_tokens: Creates a list of patches from a shapefile specified by the country code and administrative level Parameters countrycode : str Three letter ISO 3166 - 1 alpha - 3 country code level : int Administrative level 0 - 5
code: def shapefile_coordinates(countrycode,level=0):
      """
      Creates a list of patches from a shapefile specified by the country code and
      administrative level
      
      Parameters
      ----------
      countrycode : str
          Three letter ISO 3166-1 alpha-3 country code
          
      level : int
          Administrative level 0-5
      
      """
      
      filename = os.path.join(data_path,'shapefiles','{}_adm{}'.format(countrycode,level))
  
      for ext in ['.shp','.shx','.dbf']:
          if not os.path.isfile( filename+ext ):
              raise Exception('Could not find shapefiles, download the first using the download_shapefiles function: download_shapefiles(\'{}\',{})'.format(countrycode,level))
  
      sf = shapefile.Reader(filename)
      shapes  = sf.shapes()
      
      coords = []
   
      
      for shape in shapes:
          parts = shape.parts
          parts.append(len(shape.points)-1)
      
          dxdy_lim = 1
  
          sub_coords = []
  
          for i in range(len(parts)-1):
              xi = [shape.points[j][0] for j in range(parts[i],parts[i+1]) ]
              yi = [shape.points[j][1] for j in range(parts[i],parts[i+1]) ]
  
              # remove very small shapes
              if max(xi)-min(xi) > 1 or max(yi)-min(yi) > dxdy_lim:
              
                  # remove points that are close together
                  si = np.cumsum( [0] + [( (xi[j]-xi[j+1])**2 + (yi[j]-yi[j+1])**2)**0.5  for j in range(len(xi)-1)] )
  
                  if len(si) > 100:
                      xi = np.interp(np.linspace(0,max(si),max(100,int(len(si)/1000))), si,xi)
                      yi = np.interp(np.linspace(0,max(si),max(100,int(len(si)/1000))), si,yi)
                      
                  sub_coords.append((xi,yi))    
                  
          coords.append(sub_coords)    
  
      return coords
code_tokens: def shapefile_coordinates ( countrycode , level = 0 ) : filename = os . path . join ( data_path , 'shapefiles' , '{}_adm{}' . format ( countrycode , level ) ) for ext in [ '.shp' , '.shx' , '.dbf' ] : if not os . path . isfile ( filename + ext ) : raise Exception ( 'Could not find shapefiles, download the first using the download_shapefiles function: download_shapefiles(\'{}\',{})' . format ( countrycode , level ) ) sf = shapefile . Reader ( filename ) shapes = sf . shapes ( ) coords = [ ] for shape in shapes : parts = shape . parts parts . append ( len ( shape . points ) - 1 ) dxdy_lim = 1 sub_coords = [ ] for i in range ( len ( parts ) - 1 ) : xi = [ shape . points [ j ] [ 0 ] for j in range ( parts [ i ] , parts [ i + 1 ] ) ] yi = [ shape . points [ j ] [ 1 ] for j in range ( parts [ i ] , parts [ i + 1 ] ) ] if max ( xi ) - min ( xi ) > 1 or max ( yi ) - min ( yi ) > dxdy_lim : si = np . cumsum ( [ 0 ] + [ ( ( xi [ j ] - xi [ j + 1 ] ) ** 2 + ( yi [ j ] - yi [ j + 1 ] ) ** 2 ) ** 0.5 for j in range ( len ( xi ) - 1 ) ] ) if len ( si ) > 100 : xi = np . interp ( np . linspace ( 0 , max ( si ) , max ( 100 , int ( len ( si ) / 1000 ) ) ) , si , xi ) yi = np . interp ( np . linspace ( 0 , max ( si ) , max ( 100 , int ( len ( si ) / 1000 ) ) ) , si , yi ) sub_coords . append ( ( xi , yi ) ) coords . append ( sub_coords ) return coords
short_docstring: Creates a list of patches from a shapefile specified by the country code and
  administrative level
short_docstring_tokens: Creates a list of patches from a shapefile specified by the country code and administrative level
comment: """
      Creates a list of patches from a shapefile specified by the country code and
      administrative level
      
      Parameters
      ----------
      countrycode : str
          Three letter ISO 3166-1 alpha-3 country code
          
      level : int
          Administrative level 0-5
      
      """$SEP$# remove very small shapes$SEP$# remove points that are close together