-
Notifications
You must be signed in to change notification settings - Fork 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
.... is this thing even on? #13
Open
corrinerojas
wants to merge
16
commits into
Geospatial-Python:master
Choose a base branch
from
corrinerojas: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 from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a65a78c
Update utils.py
corrinerojas d44af08
Update point.py
corrinerojas 265b8fa
Update analytics.py
corrinerojas 2ad455f
Update functional_test.py
corrinerojas d50b16d
Create point_test
corrinerojas 1e85eea
Update analytics.py
corrinerojas 2ce132f
Update analytics.py
corrinerojas 708e66e
Update analytics.py
corrinerojas 64a0aed
Update analytics.py
corrinerojas 4ad4a26
Update utils.py
corrinerojas 86b772c
Update functional_test.py
corrinerojas a5b27dd
Update functional_test.py
corrinerojas d2f2965
Update analytics.py
corrinerojas cd3f9d4
Update analytics.py
corrinerojas dd82460
Update analytics.py
corrinerojas 40858b2
Update analytics.py
corrinerojas 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 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,146 @@ | ||
import math | ||
from assignment_06 import utils | ||
|
||
def check_significant(lower, upper, observed_avg): | ||
significance = False | ||
if(upper - lower <= observed_avg): | ||
significance = True | ||
return significance | ||
|
||
def compute_critical(listOfAvgNNDistances): | ||
criticalPoints = [] | ||
criticalPoints[0] = min(listOfAvgNNDistances) | ||
criticalPoints[1] = max(listOfAvgNNDistances) | ||
return criticalPoints | ||
|
||
def permutations(p): | ||
listOfAvgNNDistances = [] | ||
|
||
for x in range(p): | ||
tmpList = [] | ||
tmpList.append(create_random_points(100)) | ||
listOfAvgNNDistances.append(average_nearest_neighbor_distance(tmpList)) | ||
|
||
return listOfAvgNNDistances | ||
|
||
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. | ||
""" | ||
listOfDistances = [] | ||
|
||
for n in points: | ||
lowest = 100 | ||
for x in points: | ||
if euclidean_distance(n,x)!= 0 and euclidean_distance(n,x) < lowest: | ||
lowest = euclidean_distance(n,x) | ||
listOfDistances.append(lowest) | ||
|
||
totalOfDistances = 0 | ||
|
||
for z in listOfDistances: | ||
totalOfDistances += z | ||
|
||
mean_d = totalOfDistances/len(points) | ||
|
||
return mean_d | ||
|
||
def euclidean_distance(a, b): | ||
""" | ||
Compute the Euclidean distance between two points | ||
Parameters | ||
---------- | ||
a : tuple | ||
A point in the form (x,y) | ||
b : tuple | ||
A point in the form (x,y) | ||
Returns | ||
------- | ||
distance : float | ||
The Euclidean distance between the two points | ||
""" | ||
distance = math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2) | ||
return distance | ||
|
||
|
||
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] | ||
""" | ||
minX = 100 | ||
minY = 100 | ||
maxX = 0 | ||
maxY = 0 | ||
|
||
for n in points: | ||
if n[0] < minX: | ||
minX = n[0] | ||
if n[0] > maxX: | ||
maxX = n[0] | ||
if n[1] < minY: | ||
minY = n[1] | ||
if n[1] > maxY: | ||
maxY = n[1] | ||
|
||
mbr = [minX,minY,maxX,maxY] | ||
|
||
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 = 0.5 * (math.sqrt(area/n)) | ||
|
||
|
||
return expected | ||
|
||
|
This file contains 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,13 @@ | ||
class Point(object): | ||
def __init__(self,x,y,mark={}): | ||
self.x = x | ||
self.y = y | ||
self.mark = mark | ||
|
||
def check_coincident(self,point2): | ||
check_this_point = (self.x,self.y) | ||
return check_coincident(point1, point2) | ||
|
||
def shift_point(self, x_shift, y_shift): | ||
point = (self.x, self.y) | ||
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. This is a legitimate indentation issue. Be careful as Python is able to avoid |
||
self.x, self.y = shift_point(point, x_shift, y_shift) |
This file contains 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 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,46 @@ | ||
import unittest | ||
import random | ||
|
||
from .. import point | ||
from collections import Counter | ||
|
||
class TestPoint(unittest.TestCase): | ||
|
||
point = Point(2,4) | ||
|
||
def point_Test(self): | ||
self.assertEqual(2, point.x) | ||
self.assertEqual(4, point.y) | ||
|
||
def coincidence_Test(self): | ||
self.assertTrue(point.check_coincidence(2,4)) | ||
self.assertFalse(point.check_coincidence(3,5)) | ||
|
||
def shift_point_Test(self): | ||
new_point = Point(2,1) | ||
self.assertEqual((4,5), (point.x,point.y)) | ||
|
||
|
||
def marks_Test(self): | ||
random.seed(12345) | ||
marks = ['periwinkle', 'eggshell', 'lavender', 'chiffon'] | ||
i = 0 | ||
|
||
points = [] | ||
countArray = [] | ||
|
||
while i < 15: | ||
new_added_point = Point(random.randint(0,9), random.randint(0,9), random.choice(marks)) | ||
points.append(new_point) | ||
|
||
for counter in points: | ||
|
||
Counter(marks) | ||
Counter({'periwinkle': 1, 'eggshell': 2, 'lavender': 3, 'chiffon': 4}) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
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.
TravisCI is complaining about an indentation error here. Indentation looks good though. I see this sometimes if I use a text editor for a bit (with 4 spaces) and then switch to an IDE using tab. Not sure if that is the case, and not a big deal. More just an FYI incase you see that error in the future for your own work.