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

Fixed test cases and added methods to PointPattern #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,420 changes: 3,420 additions & 0 deletions .ipynb_checkpoints/Assignment_08-checkpoint.ipynb

Large diffs are not rendered by default.

128 changes: 128 additions & 0 deletions Assignment_08.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-72.976512, 41.337662, all-cases-dead-on-arrival\n",
"-72.960621, 41.326316, animal-bites\n",
"-72.896278, 41.324366, animal-bites\n",
"-72.952039, 41.325584, animal-bites\n"
]
}
],
"source": [
"from pointpattern import PointPattern\n",
"from point import Point\n",
"import pysal as ps\n",
"\n",
"shapefile = ps.open(ps.examples.get_path('new_haven_merged.shp'))\n",
"dbf = ps.open(ps.examples.get_path('new_haven_merged.dbf'))\n",
"\n",
"points = []\n",
"\n",
"for geometry, attributes in zip(shapefile, dbf):\n",
" points.append(Point(geometry[0], geometry[1], mark=attributes[1]))\n",
"\n",
"i = 0\n",
"\n",
"\n",
"for point in points:\n",
" i += 1\n",
" #Print the first five of the points\n",
" if i < 5:\n",
" print(\"{0}, {1}, {2}\".format(point.x, point.y, point.mark))\n",
" else:\n",
" break\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The overall nearest neighbor distance of the data set is: 0.000120180676464\n"
]
},
{
"ename": "AttributeError",
"evalue": "'list' object has no attribute 'mark'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-37-2af7d0f17676>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"The overall nearest neighbor distance of the data set is: \"\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[0mnn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpattern\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maverage_nearest_neighbor_distance_kdtree\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmark\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"all-cases-dead-on-arrival\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"The nearest neighbor distance of the mark 'all-cases-dead-on-arrival' is \"\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m/home/schuyler/Desktop/GIS321/assignment_08/pointpattern.py\u001b[0m in \u001b[0;36maverage_nearest_neighbor_distance_kdtree\u001b[1;34m(self, mark)\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[0mdistances\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 22\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mmark_name\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 23\u001b[0m \u001b[0mtemp_points\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpoints\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m/home/schuyler/Desktop/GIS321/assignment_08/pointpattern.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[0mdistances\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 22\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mmark_name\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 23\u001b[0m \u001b[0mtemp_points\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpoints\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mAttributeError\u001b[0m: 'list' object has no attribute 'mark'"
]
}
],
"source": [
"pattern = PointPattern()\n",
"\n",
"for point in points:\n",
" pattern.add_point(point)\n",
"\n",
"#It prints the mark attribute... not sure why recieving error below\n",
"#for point in pattern.points:\n",
" #print(point.mark)\n",
"\n",
"nn = pattern.average_nearest_neighbor_distance_kdtree()\n",
"print(\"The overall nearest neighbor distance of the data set is: \" + str(nn))\n",
"\n",
"nn = pattern.average_nearest_neighbor_distance_kdtree(mark=\"all-cases-dead-on-arrival\")\n",
"print(\"The nearest neighbor distance of the mark 'all-cases-dead-on-arrival' is \" + str(nn))\n",
"\n",
"nn = pattern.average_nearest_neighbor_distance_kdtree(mark=\"animal-bites\")\n",
"print(\"The nearest neighbor distance of the mark 'animal-bites' is \" + str(nn))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Empty file added __init__.py
Empty file.
Binary file added __pycache__/PointPattern.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/analytics.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/point.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/pointpattern.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/utils.cpython-35.pyc
Binary file not shown.
Loading