From 17fd8936b51729b898085b23fee0e1ca84bc5c4a Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 19:20:10 -0700 Subject: [PATCH 01/26] Update point_pattern.py --- point_pattern.py | 57 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 1b0a5cb..14c83fe 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -33,7 +33,9 @@ def read_geojson(input_file): """ # Please use the python json module (imported above) # to solve this one. - gj = None + with open(input_file,'r') as f: + gj = read_geojson(f) + return gj @@ -59,6 +61,11 @@ def find_largest_city(gj): city = None max_population = 0 + for i in gj['features']: + if i['properties']['pop_max'] > max_population: + max_population = i['properties']['pop_max'] + city = i['properties']['name'] + return city, max_population @@ -74,7 +81,15 @@ def write_your_own(gj): Do not forget to write the accompanying test in tests.py! """ - return + min_pop = 9999999 + city = None + + for i in gj['features']: + if i['properties']['pop_min'] < min_pop: + min_pop = i['properties']['pop_min'] + city = i['properties']['name'] + + return city, min_pop def mean_center(points): """ @@ -96,6 +111,12 @@ def mean_center(points): x = None y = None + for i in points: + x += i[0] + y += i[1] + x /= len(points) + y /= len(points) + return x, y @@ -119,7 +140,15 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ - mean_d = 0 + List_distance = [] + mean_d = sum(points)/len(points) + + for x_point,y_point in points: + d = euclidean_distance(x_point,y_point) + if d <= mean_d: + List_distance.append(d) + + mean_d = sum(List_distance)/len(List_distance) return mean_d @@ -140,6 +169,22 @@ def minimum_bounding_rectangle(points): """ mbr = [0,0,0,0] + xmin = None + xmax = None + ymin = None + ymax = None + + for p in points: + if p[0] < xmin: + xmin = p[0] + if p[0] > xmax: + xmax = p[0] + if p[1] < ymin: + ymin = p[1] + if p[1] > ymax: + ymax = p[1] + + mbr = [xmin,xmax,ymin,ymax] return mbr @@ -149,6 +194,9 @@ def mbr_area(mbr): Compute the area of a minimum bounding rectangle """ area = 0 + l = mbr[2] - mbr[0] + w = mbr[3] - mbr[1] + area = l*w return area @@ -173,7 +221,8 @@ def expected_distance(area, n): The number of points """ - expected = 0 + expected = 0.5 * (math.sqrt(area/n)) + return expected From 059a5730e82e5edbabcaba9b01b2f64fc639786b Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 19:22:24 -0700 Subject: [PATCH 02/26] Update tests.py --- tests/tests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index 2518463..4262de1 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -32,8 +32,9 @@ def test_write_your_own(self): Here you will write a test for the code you write in point_pattern.py. """ - some_return = point_pattern.write_your_own(self.gj) - self.assertTrue(False) + city, min_pop = point_pattern.write_your_own(self.gj) + self.assertTrue(city,"Montana" ) + self.assertTrue(min_pop, 10) class TestIterablePointPattern(unittest.TestCase): """ From 0c0df348bcc0c6ea339203a2d7ea59912735e9f8 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 19:34:36 -0700 Subject: [PATCH 03/26] Update tests.py --- tests/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests.py b/tests/tests.py index 4262de1..24d7348 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -32,7 +32,7 @@ def test_write_your_own(self): Here you will write a test for the code you write in point_pattern.py. """ - city, min_pop = point_pattern.write_your_own(self.gj) + self.assertTrue(city,"Montana" ) self.assertTrue(min_pop, 10) From 504670efc8b8522a33fc344462dd63598640de67 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 19:47:16 -0700 Subject: [PATCH 04/26] Update tests.py --- tests/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index 24d7348..ae049bc 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -33,8 +33,8 @@ def test_write_your_own(self): point_pattern.py. """ - self.assertTrue(city,"Montana" ) - self.assertTrue(min_pop, 10) + some_return = point_pattern.write_your_own(self.gj) + self.assertTrue(some_return,"Montana" ) class TestIterablePointPattern(unittest.TestCase): """ From ea045f43d7db715e718dd701031a75af8ef63ebb Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 20:03:57 -0700 Subject: [PATCH 05/26] Update tests.py --- tests/tests.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index ae049bc..4cfd01a 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -33,8 +33,12 @@ def test_write_your_own(self): point_pattern.py. """ - some_return = point_pattern.write_your_own(self.gj) - self.assertTrue(some_return,"Montana" ) + c = "Montana" + mp = 10 + + city, min_pop = point_pattern.write_your_own(self.gj) + self.assertTrue(city, c) + self.assertTrue(min_pop, mp) class TestIterablePointPattern(unittest.TestCase): """ From 4e6d6bc3c1e32ff9feb770d64fa2b95691beac57 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 20:45:04 -0700 Subject: [PATCH 06/26] Update point_pattern.py --- point_pattern.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 14c83fe..f66bf60 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -1,5 +1,6 @@ import math # I am guessing that you will need to use the math module import json # I would like you to use the JSON module for reading geojson (for now) + """ Like last assignment, we are going to be working with point patterns. The readings focused on iteration, sequences, and @@ -33,9 +34,9 @@ def read_geojson(input_file): """ # Please use the python json module (imported above) # to solve this one. - with open(input_file,'r') as f: + with open(input_file, 'r') as f: gj = read_geojson(f) - + return gj @@ -85,12 +86,13 @@ def write_your_own(gj): city = None for i in gj['features']: - if i['properties']['pop_min'] < min_pop: + if i['properties']['pop_min'] < min_pop: min_pop = i['properties']['pop_min'] city = i['properties']['name'] return city, min_pop + def mean_center(points): """ Given a set of points, compute the mean center @@ -141,14 +143,14 @@ def average_nearest_neighbor_distance(points): p. 445-453. """ List_distance = [] - mean_d = sum(points)/len(points) + mean_d = 0 + tot_mean = sum(points) / len(points) - for x_point,y_point in points: - d = euclidean_distance(x_point,y_point) - if d <= mean_d: - List_distance.append(d) - - mean_d = sum(List_distance)/len(List_distance) + for x_point, y_point in points: + d = euclidean_distance(x_point, y_point) + if d <= tot_mean: + List_distance.append(d) + mean_d = sum(List_distance) / len(List_distance) return mean_d @@ -168,11 +170,11 @@ def minimum_bounding_rectangle(points): Corners of the MBR in the form [xmin, ymin, xmax, ymax] """ - mbr = [0,0,0,0] - xmin = None - xmax = None - ymin = None - ymax = None + mbr = [0, 0, 0, 0] + xmin = 0 + xmax = 0 + ymin = 0 + ymax = 0 for p in points: if p[0] < xmin: @@ -184,7 +186,7 @@ def minimum_bounding_rectangle(points): if p[1] > ymax: ymax = p[1] - mbr = [xmin,xmax,ymin,ymax] + mbr = [xmin, xmax, ymin, ymax] return mbr @@ -196,7 +198,7 @@ def mbr_area(mbr): area = 0 l = mbr[2] - mbr[0] w = mbr[3] - mbr[1] - area = l*w + area = l * w return area @@ -221,7 +223,7 @@ def expected_distance(area, n): The number of points """ - expected = 0.5 * (math.sqrt(area/n)) + expected = 0.5 * (math.sqrt(area / n)) return expected @@ -234,6 +236,7 @@ def expected_distance(area, n): the assignment """ + def manhattan_distance(a, b): """ Compute the Manhattan distance between two points @@ -251,7 +254,7 @@ def manhattan_distance(a, b): distance : float The Manhattan distance between the two points """ - distance = abs(a[0] - b[0]) + abs(a[1] - b[1]) + distance = abs(a[0] - b[0]) + abs(a[1] - b[1]) return distance @@ -273,7 +276,7 @@ def euclidean_distance(a, b): distance : float The Euclidean distance between the two points """ - distance = math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2) + distance = math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) return distance From 57b33e5d95f7cec8ef6375e83228c48a37e6c359 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 21:07:57 -0700 Subject: [PATCH 07/26] Update point_pattern.py --- point_pattern.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index f66bf60..03918b9 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -35,7 +35,7 @@ def read_geojson(input_file): # Please use the python json module (imported above) # to solve this one. with open(input_file, 'r') as f: - gj = read_geojson(f) + gj = json.load(f) return gj @@ -110,18 +110,22 @@ def mean_center(points): y : float Mean y coordinate """ - x = None - y = None - + x = 0 + y = 0 + xx = 0 + yy = 0 + for i in points: - x += i[0] - y += i[1] - x /= len(points) - y /= len(points) + xx += i[0] + yy += i[1] + + x = xx / len(points[0]) + y = yy / len(points[1]) return x, y +# noinspection PyTypeChecker def average_nearest_neighbor_distance(points): """ Given a set of points, compute the average nearest neighbor. From a987514c9033c9e757cf043e462968316b450281 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 21:13:55 -0700 Subject: [PATCH 08/26] Update point_pattern.py --- point_pattern.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 03918b9..a65b0a4 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -114,7 +114,7 @@ def mean_center(points): y = 0 xx = 0 yy = 0 - + for i in points: xx += i[0] yy += i[1] @@ -175,22 +175,21 @@ def minimum_bounding_rectangle(points): """ mbr = [0, 0, 0, 0] - xmin = 0 - xmax = 0 - ymin = 0 - ymax = 0 + x_min = 0 + x_max = 0 + y_min = 0 + y_max = 0 for p in points: - if p[0] < xmin: - xmin = p[0] - if p[0] > xmax: - xmax = p[0] - if p[1] < ymin: - ymin = p[1] - if p[1] > ymax: - ymax = p[1] - - mbr = [xmin, xmax, ymin, ymax] + if p[0] < x_min: + x_min = p[0] + if p[0] > x_max: + x_max = p[0] + if p[1] < y_min: + y_min = p[1] + if p[1] > y_max: + y_max = p[1] + mbr = [x_min, x_max, y_min, y_max] return mbr From 362590e875b998cdf4b6fa5fa3123f6cbe688fcf Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 21:17:28 -0700 Subject: [PATCH 09/26] Update point_pattern.py --- point_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index a65b0a4..d0d7092 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -184,9 +184,9 @@ def minimum_bounding_rectangle(points): if p[0] < x_min: x_min = p[0] if p[0] > x_max: - x_max = p[0] + x_max = p[1] if p[1] < y_min: - y_min = p[1] + y_min = p[0] if p[1] > y_max: y_max = p[1] mbr = [x_min, x_max, y_min, y_max] From 1ac3c653dc44a76ea061a5f147356c2c012eb417 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 21:20:57 -0700 Subject: [PATCH 10/26] Update point_pattern.py --- point_pattern.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index d0d7092..1ef0409 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -184,12 +184,12 @@ def minimum_bounding_rectangle(points): if p[0] < x_min: x_min = p[0] if p[0] > x_max: - x_max = p[1] + x_max = p[0] if p[1] < y_min: - y_min = p[0] + y_min = p[1] if p[1] > y_max: y_max = p[1] - mbr = [x_min, x_max, y_min, y_max] + mbr = [x_min, y_min, x_max, y_max] return mbr From 79af3ac19ad06f6819963c2d309699a31ca41e4a Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 21:27:49 -0700 Subject: [PATCH 11/26] Update point_pattern.py --- point_pattern.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 1ef0409..ad33dfa 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -146,15 +146,15 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ - List_distance = [] + list_distance = [] mean_d = 0 tot_mean = sum(points) / len(points) for x_point, y_point in points: d = euclidean_distance(x_point, y_point) if d <= tot_mean: - List_distance.append(d) - mean_d = sum(List_distance) / len(List_distance) + list_distance.append(d) + mean_d = sum(list_distance) / len(list_distance) return mean_d From 9937f6c2c8ed118b03a51f08c9b05633d16d9f1d Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 21:30:49 -0700 Subject: [PATCH 12/26] Update point_pattern.py --- point_pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/point_pattern.py b/point_pattern.py index ad33dfa..9c7698e 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -146,7 +146,7 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ - list_distance = [] + list_distance = [] mean_d = 0 tot_mean = sum(points) / len(points) From ad22d40319aa0b728b36a47453caa30613dc1ef2 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 21:38:57 -0700 Subject: [PATCH 13/26] Update point_pattern.py --- point_pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/point_pattern.py b/point_pattern.py index 9c7698e..38fb78d 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -154,7 +154,7 @@ def average_nearest_neighbor_distance(points): d = euclidean_distance(x_point, y_point) if d <= tot_mean: list_distance.append(d) - mean_d = sum(list_distance) / len(list_distance) + mean_d = sum(list_distance) / len(points) return mean_d From c89bcae736cae774b4a2222ffc7467e5661fe9dc Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 22:01:41 -0700 Subject: [PATCH 14/26] Update point_pattern.py --- point_pattern.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 38fb78d..dd2db19 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -118,9 +118,8 @@ def mean_center(points): for i in points: xx += i[0] yy += i[1] - - x = xx / len(points[0]) - y = yy / len(points[1]) + x = xx / len(points[0]) + y = yy / len(points[1]) return x, y From ccd409c2f4207c7c4c958d65fcd6b2702696bc06 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 22:22:40 -0700 Subject: [PATCH 15/26] Update point_pattern.py --- point_pattern.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index dd2db19..ff2886f 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -149,10 +149,13 @@ def average_nearest_neighbor_distance(points): mean_d = 0 tot_mean = sum(points) / len(points) - for x_point, y_point in points: - d = euclidean_distance(x_point, y_point) - if d <= tot_mean: - list_distance.append(d) + for a in points: + d1 = euclidean_distance(x, y) + for b in points: + if a != b: + d2 = euclidean_distance(x, y) + if d1 <= d2: + list_distance.append(d1) mean_d = sum(list_distance) / len(points) return mean_d From e737e1efd9df15832e78303d00c5dea6389e32b8 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 23 Feb 2016 22:26:45 -0700 Subject: [PATCH 16/26] Update point_pattern.py --- point_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index ff2886f..356ff98 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -155,8 +155,8 @@ def average_nearest_neighbor_distance(points): if a != b: d2 = euclidean_distance(x, y) if d1 <= d2: - list_distance.append(d1) - mean_d = sum(list_distance) / len(points) + list_distance.append(d1) + mean_d = sum(list_distance) / len(points) return mean_d From 9cd98976bf8382da4ad2a2b2c19dfbc5b4c9fb4f Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 1 Mar 2016 18:53:53 -0700 Subject: [PATCH 17/26] Update point_pattern.py --- point_pattern.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 356ff98..52b5f49 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -145,18 +145,18 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ - list_distance = [] + list_distance = [] mean_d = 0 - tot_mean = sum(points) / len(points) - - for a in points: - d1 = euclidean_distance(x, y) - for b in points: - if a != b: - d2 = euclidean_distance(x, y) - if d1 <= d2: - list_distance.append(d1) - mean_d = sum(list_distance) / len(points) + + for x_point, y_point in enumerate(points): + a = euclidean_distance(x_point[0], y_point[0]) + b = euclidean_distance(x_point[1], y_point[1]) + if a != b: + continue + if a < b: + list_distance.append(a) + + mean_d = sum(list_distance) / len(points) return mean_d From 8b36623ce26d682614b22766c3910d8647b3933d Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 1 Mar 2016 19:02:40 -0700 Subject: [PATCH 18/26] Update point_pattern.py --- point_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 52b5f49..9ff3e4a 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -145,7 +145,7 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ - list_distance = [] + list_distance = [] mean_d = 0 for x_point, y_point in enumerate(points): @@ -156,7 +156,7 @@ def average_nearest_neighbor_distance(points): if a < b: list_distance.append(a) - mean_d = sum(list_distance) / len(points) + mean_d = sum(list_distance) / len(points) return mean_d From ff7e8306d1fc032f060d22c380b094c8f4b9c5b4 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 1 Mar 2016 19:21:33 -0700 Subject: [PATCH 19/26] Update point_pattern.py --- point_pattern.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 9ff3e4a..2f809a4 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -145,16 +145,17 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ - list_distance = [] + list_distance = [] mean_d = 0 - - for x_point, y_point in enumerate(points): - a = euclidean_distance(x_point[0], y_point[0]) - b = euclidean_distance(x_point[1], y_point[1]) - if a != b: - continue - if a < b: - list_distance.append(a) + c = 0 + + for a in enumerate(points): + for b in enumerate(points): + if check_coincident(a, b): + c = euclidean_distance(a, b) + + if c < b: + list_distance.append(c) mean_d = sum(list_distance) / len(points) From 408eeaf8854e3beb256457cf73748d1a01f69839 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 1 Mar 2016 19:24:47 -0700 Subject: [PATCH 20/26] Update point_pattern.py --- point_pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/point_pattern.py b/point_pattern.py index 2f809a4..1d2f9c0 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -145,7 +145,7 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ - list_distance = [] + list_distance = [] mean_d = 0 c = 0 From 8c9e7106bb9ad82be6124d12ce4ee232489bc583 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 1 Mar 2016 19:46:41 -0700 Subject: [PATCH 21/26] Update point_pattern.py --- point_pattern.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 1d2f9c0..1042191 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -148,15 +148,17 @@ def average_nearest_neighbor_distance(points): list_distance = [] mean_d = 0 c = 0 + t = 999999 - for a in enumerate(points): - for b in enumerate(points): - if check_coincident(a, b): - c = euclidean_distance(a, b) - - if c < b: - list_distance.append(c) + for p1 in enumerate(points): + for p2 in enumerate(points): + if check_coincident(p1, p2): + continue + c = euclidean_distance(p1, p2) + if c < t: + list_distance.append(c) + mean_d = sum(list_distance) / len(points) return mean_d From 50babea7ce1573add3ec7149be29634a8c2e5f2c Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 8 Mar 2016 17:30:53 -0700 Subject: [PATCH 22/26] Update point_pattern.py --- point_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 1042191..ed41723 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -118,8 +118,8 @@ def mean_center(points): for i in points: xx += i[0] yy += i[1] - x = xx / len(points[0]) - y = yy / len(points[1]) + x = xx / len(points) + y = yy / len(points) return x, y From 4d102451ae179fbc02bcd824922e6ba838d831d0 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 8 Mar 2016 17:53:36 -0700 Subject: [PATCH 23/26] Update point_pattern.py --- point_pattern.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index ed41723..9dd2f55 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -150,20 +150,21 @@ def average_nearest_neighbor_distance(points): c = 0 t = 999999 - for p1 in enumerate(points): - for p2 in enumerate(points): - if check_coincident(p1, p2): + for point1 in enumerate(points): + for point2 in enumerate(points): + if check_coincident(point1, point2): continue - c = euclidean_distance(p1, p2) + c = euclidean_distance(point1, point2) + if c < t: + list_distance.append(c) + c==t - if c < t: - list_distance.append(c) - mean_d = sum(list_distance) / len(points) return mean_d + def minimum_bounding_rectangle(points): """ Given a set of points, compute the minimum bounding rectangle. From f8a0c5c09207604b06572cb41ca4ee0e37ab6080 Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 8 Mar 2016 17:57:52 -0700 Subject: [PATCH 24/26] Update point_pattern.py --- point_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 9dd2f55..6a25640 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -156,9 +156,9 @@ def average_nearest_neighbor_distance(points): continue c = euclidean_distance(point1, point2) if c < t: + c = t list_distance.append(c) - c==t - + mean_d = sum(list_distance) / len(points) return mean_d From 7dbabf69742237b03a6033cf55429c7024a2095d Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 8 Mar 2016 19:22:24 -0700 Subject: [PATCH 25/26] Update point_pattern.py --- point_pattern.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/point_pattern.py b/point_pattern.py index 6a25640..33e1228 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -145,23 +145,23 @@ def average_nearest_neighbor_distance(points): Measure of Spatial Relationships in Populations. Ecology. 35(4) p. 445-453. """ - list_distance = [] mean_d = 0 - c = 0 - t = 999999 + nearest_neighbor = None - for point1 in enumerate(points): - for point2 in enumerate(points): + for point1 in points: + for point2 in points: if check_coincident(point1, point2): continue - c = euclidean_distance(point1, point2) - if c < t: - c = t - list_distance.append(c) - - mean_d = sum(list_distance) / len(points) - - return mean_d + current_distance = euclidean_distance(point1, point2) + if nearest_neighbor is None: + nearest_neighbor = current_distance + elif nearest_neighbor > current_distance: + nearest_neighbor = current_distance + + mean_d += nearest_neighbor + nearest_neighbor = None + + mean_d /= len(points) From e550dd41f538b461d2e80643339233f64cf587cd Mon Sep 17 00:00:00 2001 From: aciepli Date: Tue, 8 Mar 2016 19:31:38 -0700 Subject: [PATCH 26/26] Update point_pattern.py --- point_pattern.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/point_pattern.py b/point_pattern.py index 33e1228..5e01c45 100644 --- a/point_pattern.py +++ b/point_pattern.py @@ -162,6 +162,8 @@ def average_nearest_neighbor_distance(points): nearest_neighbor = None mean_d /= len(points) + + return mean_d