-
Notifications
You must be signed in to change notification settings - Fork 15
Changes made #15
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
Open
tphan5
wants to merge
3
commits into
Geospatial-Python:master
Choose a base branch
from
tphan5:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes made #15
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import math | ||
import random | ||
from .utils import euclidean_distance, random_points | ||
|
||
def mean_center(points): | ||
""" | ||
Given a set of points, compute the mean center | ||
|
||
Parameters | ||
---------- | ||
points : list | ||
A list of points in the form (x,y) | ||
|
||
Returns | ||
------- | ||
x : float | ||
Mean x coordinate | ||
|
||
y : float | ||
Mean y coordinate | ||
""" | ||
#x = None | ||
#y = None | ||
|
||
x = [i[0] for i in points] | ||
y = [i[1] for i in points] | ||
|
||
sumX = (sum(x) / len(points)) | ||
sumY = (sum(y) / len(points)) | ||
|
||
x = sumX | ||
y = sumY | ||
|
||
return x, y | ||
|
||
|
||
def average_nearest_neighbor_distance(points): | ||
""" | ||
Given a set of points, compute the average nearest neighbor. | ||
|
||
Parameters | ||
---------- | ||
points : list | ||
A list of points in the form (x,y) | ||
|
||
Returns | ||
------- | ||
mean_d : float | ||
Average nearest neighbor distance | ||
|
||
References | ||
---------- | ||
Clark and Evan (1954 Distance to Nearest Neighbor as a | ||
Measure of Spatial Relationships in Populations. Ecology. 35(4) | ||
p. 445-453. | ||
""" | ||
mean_d = 0 | ||
|
||
shortDistanceList = [] | ||
|
||
for firstPoint in points: | ||
pointInList = 500 | ||
for secondPoint in points: | ||
if firstPoint is not secondPoint: | ||
distance = euclidean_distance(firstPoint, secondPoint) | ||
if (pointInList > distance): | ||
pointInList = distance | ||
|
||
shortDistanceList.append(pointInList) | ||
|
||
mean_d = sum(shortDistanceList) / len(points) | ||
|
||
return mean_d | ||
|
||
|
||
def minimum_bounding_rectangle(points): | ||
""" | ||
Given a set of points, compute the minimum bounding rectangle. | ||
|
||
Parameters | ||
---------- | ||
points : list | ||
A list of points in the form (x,y) | ||
|
||
Returns | ||
------- | ||
: list | ||
Corners of the MBR in the form [xmin, ymin, xmax, ymax] | ||
""" | ||
|
||
mbr = [0,0,0,0] | ||
|
||
xmin = 0 | ||
ymin = 0 | ||
xmax = 0 | ||
ymax = 0 | ||
|
||
for i in points: | ||
if i[0] < xmin: | ||
xmin = i[0] | ||
if i[1] < ymin: | ||
ymin = i[1] | ||
if i[0] > xmax: | ||
xmax = i[0] | ||
if i[1] > ymax: | ||
ymax = i[1] | ||
|
||
mbr = [xmin,ymin,xmax,ymax] | ||
|
||
|
||
return mbr | ||
|
||
|
||
def mbr_area(mbr): | ||
""" | ||
Compute the area of a minimum bounding rectangle | ||
""" | ||
area = 0 | ||
|
||
length = mbr[3] - mbr[1] | ||
width = mbr[2] - mbr [0] | ||
area = length * width | ||
|
||
return area | ||
|
||
|
||
def expected_distance(area, n): | ||
""" | ||
Compute the expected mean distance given | ||
some study area. | ||
|
||
This makes lots of assumptions and is not | ||
necessarily how you would want to compute | ||
this. This is just an example of the full | ||
analysis pipe, e.g. compute the mean distance | ||
and the expected mean distance. | ||
|
||
Parameters | ||
---------- | ||
area : float | ||
The area of the study area | ||
|
||
n : int | ||
The number of points | ||
""" | ||
|
||
expected = 0 | ||
|
||
expected = (math.sqrt(area/n)) * (0.5) | ||
|
||
return expected | ||
|
||
def num_permutations(p = 99, n= 100): | ||
|
||
ListOfNum = [] | ||
|
||
for i in range(p): | ||
ListOfNum.append(average_nearest_neighbor_distance(random_points(n))) | ||
|
||
return ListOfNum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from . import utils | ||
|
||
class Foo(object): | ||
def __init__(self, x, y, mark={}): | ||
self.x = x | ||
self.y = y | ||
self.mark = mark | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why you have chosen to have mark be a dictionary? Do you image storing multiple key:value pairs? Again, stylistic. |
||
|
||
def coincidentPoint(self, point1): | ||
point2 = (self.x, self.y) | ||
return utils.check_coincident(point1, point2) | ||
|
||
def shiftPoint(self,xShift, yShift): | ||
thePoint = (self.x, self.y) | ||
self.x, self.y = utils.shift_point(thePoint,xShift,yShift) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import unittest | ||
import sys | ||
import random | ||
import os | ||
|
||
from .. import utils | ||
from .. point import Foo | ||
|
||
|
||
|
||
class TestingPointTest(unittest.TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def test_xyCoordinatesCheck(self): | ||
points = Foo(4,8) | ||
self.assertEqual(4,points.x) | ||
self.assertEqual(8,points.y) | ||
|
||
def test_concidentPoint(self): | ||
thePoint = Foo(3,8) | ||
|
||
self.assertTrue(thePoint.coincidentPoint((3,8))) | ||
self.assertFalse(thePoint.coincidentPoint((8,3))) | ||
|
||
def test_shiftPoint(self): | ||
thePoint = Foo(6,2) | ||
shiftX = 1 | ||
shiftY = 1 | ||
thePoint.shiftPoint(shiftX,shiftY) | ||
self.assertEqual((7,3),(thePoint.x, thePoint.y)) | ||
|
||
def test_theMarks(self): | ||
|
||
random.seed(88888888) | ||
marks = ['James', 'Paul', 'Sarah', 'Michael', 'Nancy', 'Henry'] | ||
thePoints = [] | ||
|
||
JamesCounter = 0; | ||
PaulCounter = 0; | ||
SarahCounter = 0; | ||
MichaelCounter = 0; | ||
NancyCounter = 0; | ||
HenryCounter = 0; | ||
|
||
for i in range(20): | ||
addPoints = Foo(random.randint(0,9),random.randint(0,9),random.choice(marks)) | ||
thePoints.append(addPoints) | ||
if thePoints[i].mark == "James": | ||
JamesCounter = JamesCounter + 1 | ||
elif thePoints[i].mark == "Paul": | ||
PaulCounter = PaulCounter + 1 | ||
elif thePoints[i].mark == "Sarah": | ||
SarahCounter = SarahCounter + 1 | ||
elif thePoints[i].mark == "Michael": | ||
MichaelCounter = MichaelCounter + 1 | ||
elif thePoints[i].mark == "Nancy": | ||
NancyCounter = NancyCounter + 1 | ||
elif thePoints[i].mark == "Henry": | ||
HenryCounter = HenryCounter + 1 | ||
|
||
self.assertEqual(JamesCounter, 1) | ||
self.assertEqual(PaulCounter, 5) | ||
self.assertEqual(SarahCounter, 5) | ||
self.assertEqual(MichaelCounter, 4) | ||
self.assertEqual(NancyCounter, 2) | ||
self.assertEqual(HenryCounter, 3) | ||
|
||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe name it
Point
? Easier for the next developer to know thatFoo
is actually a 2D point object. Just a style comment, not a correctness issue.