import sys
import os

sys.path.append(os.path.abspath('..'))
import libpysal

w = libpysal.weights.lat2W(5,5)

w.n

25
w.pct_nonzero

12.8
w.neighbors[0]

[5, 1]
w.neighbors[5]

[0, 10, 6]
libpysal.examples.available()

['georgia',
 '__pycache__',
 'tests',
 'newHaven',
 'Polygon_Holes',
 'nat',
 'Polygon',
 '10740',
 'berlin',
 'rio_grande_do_sul',
 'sids2',
 'sacramento2',
 'burkitt',
 'arcgis',
 'calemp',
 'stl',
 'virginia',
 'geodanet',
 'desmith',
 'book',
 'nyc_bikes',
 'Line',
 'south',
 'snow_maps',
 'Point',
 'street_net_pts',
 'guerry',
 '__pycache__',
 'baltim',
 'networks',
 'us_income',
 'taz',
 'columbus',
 'tokyo',
 'mexico',
 '__pycache__',
 'chicago',
 'wmat',
 'juvenile',
 'clearwater']
libpysal.examples.explain('baltim')

{'name': 'baltim',
 'description': 'Baltimore house sales prices and hedonics 1978',
 'explanation': ['* baltim.dbf: attribute data. (k=17)',
  '* baltim.shp: Point shapefile. (n=211)',
  '* baltim.shx: spatial index.',
  '* baltim.tri.k12.kwt: kernel weights using a triangular kernel with 12 nearest neighbors in KWT format.',
  '* baltim_k4.gwt: nearest neighbor weights (4nn) in GWT format.',
  '* baltim_q.gal: queen contiguity weights in GAL format.',
  '* baltimore.geojson: spatial weights in geojson format.']}
pth = libpysal.examples.get_path('baltim.shp')

pth

'/home/serge/Dropbox/p/pysal/src/subpackages/libpysal/libpysal/examples/baltim/baltim.shp'
shp_file = libpysal.io.open(pth)

shapes = [shp for shp in shp_file]

shapes[0]

(907.0, 534.0)
w = libpysal.io.open(libpysal.examples.get_path('baltim_q.gal')).read()

w.n

211