{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "\n",
    "sys.path.append(os.path.abspath('..'))\n",
    "import libpysal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = libpysal.weights.lat2W(5,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.8"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.pct_nonzero"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 1]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.neighbors[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 10, 6]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.neighbors[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['georgia',\n",
       " '__pycache__',\n",
       " 'tests',\n",
       " 'newHaven',\n",
       " 'Polygon_Holes',\n",
       " 'nat',\n",
       " 'Polygon',\n",
       " '10740',\n",
       " 'berlin',\n",
       " 'rio_grande_do_sul',\n",
       " 'sids2',\n",
       " 'sacramento2',\n",
       " 'burkitt',\n",
       " 'arcgis',\n",
       " 'calemp',\n",
       " 'stl',\n",
       " 'virginia',\n",
       " 'geodanet',\n",
       " 'desmith',\n",
       " 'book',\n",
       " 'nyc_bikes',\n",
       " 'Line',\n",
       " 'south',\n",
       " 'snow_maps',\n",
       " 'Point',\n",
       " 'street_net_pts',\n",
       " 'guerry',\n",
       " '__pycache__',\n",
       " 'baltim',\n",
       " 'networks',\n",
       " 'us_income',\n",
       " 'taz',\n",
       " 'columbus',\n",
       " 'tokyo',\n",
       " 'mexico',\n",
       " '__pycache__',\n",
       " 'chicago',\n",
       " 'wmat',\n",
       " 'juvenile',\n",
       " 'clearwater']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "libpysal.examples.available()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'baltim',\n",
       " 'description': 'Baltimore house sales prices and hedonics 1978',\n",
       " 'explanation': ['* baltim.dbf: attribute data. (k=17)',\n",
       "  '* baltim.shp: Point shapefile. (n=211)',\n",
       "  '* baltim.shx: spatial index.',\n",
       "  '* baltim.tri.k12.kwt: kernel weights using a triangular kernel with 12 nearest neighbors in KWT format.',\n",
       "  '* baltim_k4.gwt: nearest neighbor weights (4nn) in GWT format.',\n",
       "  '* baltim_q.gal: queen contiguity weights in GAL format.',\n",
       "  '* baltimore.geojson: spatial weights in geojson format.']}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "libpysal.examples.explain('baltim')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "pth = libpysal.examples.get_path('baltim.shp')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/serge/Dropbox/p/pysal/src/subpackages/libpysal/libpysal/examples/baltim/baltim.shp'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "shp_file = libpysal.io.open(pth)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "shapes = [shp for shp in shp_file]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(907.0, 534.0)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shapes[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = libpysal.io.open(libpysal.examples.get_path('baltim_q.gal')).read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "211"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
