diff --git a/PointPattern.py b/PointPattern.py new file mode 100644 index 0000000..6e7b71d --- /dev/null +++ b/PointPattern.py @@ -0,0 +1,88 @@ +from .point import Point +from . import analytics +import random +import numpy as np + +def PointPattern(object): + def __init__(self): + self.points = [] + + def average_nearest_neighbor_distance(self, mark=None): + return analytics.average_nearest_neighbor_distance(self.points, mark) + + def add_point(self, point): + self.points.append(point) + + def remove_point(self, index): + del(self.points[index]) + + def count_coincident_points(self): + count = 0 + coincidnet_list = [] + + for i, point in enumerate(self.points): + for j, point2 in enumerate(self.points): + if i is j: + continue + if j in coincident_list: + continue + #Should use the magic method in point class + if point == point2: + count += 1 + coincident_list.append(j) + return count + + def list_marks(self): + marks = [] + + for point in self.points: + if point.mark is not None and point.mark not in marks: + marks.append(point.mark) + + def return_subset(self, mark): + #creates a list of points that have the same mark as passed + return [i for i in self.points if i == mark] + + def create_random_points(self, n=None): + rand_points = [] + rand = random.Random() + marks = ['North', 'East', 'South', 'West'] + + if n is None: + n = len(self.points) + + for i in range(n): + rand_points.append(point.Point(rand.randint(1,100), rand.randint(1,100), mark=rand.choice(marks))) + + return rand_points + + def create_realizations(self, k): + return analytics.permutations(k) + + def critical_points(self): + return analytics.find_criticals(self.create_realizations(99)) + + def compute_g(self, nsteps): + ds = np.linspace(0, 100, nsteps) + g_sum = 0 + + for step in range(nsteps): + o_i = ds[step] + min_dis = None + for i, j in enumerate(ds): + + temp = abs(j - o_i) + + if i is step: + continue + if min_dis is None: + min_dis = temp + elif min_dis > temp: + min_dis = temp + else: + continue + g_sum += min_dis + return g_sum / nsteps + + + diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/analytics.py b/analytics.py new file mode 100644 index 0000000..283a8f0 --- /dev/null +++ b/analytics.py @@ -0,0 +1,274 @@ +#analytics +import math +import json +import sys +import os + +sys.path.insert(0, os.path.abspath('..')) + +from . import utils +from . import point + +def find_largest_city(gj): + """ + Iterate through a geojson feature collection and + find the largest city. Assume that the key + to access the maximum population is 'pop_max'. + + Parameters + ---------- + gj : dict + A GeoJSON file read in as a Python dictionary + + Returns + ------- + city : str + The largest city + + population : int + The population of the largest city + """ + temp = gj['features'] + city = "" + max_population = 0 + + for i in temp: + if (i['properties']['pop_max'] > max_population): + max_population = i['properties']['pop_max'] + city = i['properties']['name'] + + return city, max_population + +def write_your_own(gj): + """ + Here you will write your own code to find + some attribute in the supplied geojson file. + + Take a look at the attributes available and pick + something interesting that you might like to find + or summarize. This is totally up to you. + + Do not forget to write the accompanying test in + tests.py! + """ + #Finds how many megacities there are in the geoJSON + temp = gj['features'] + megacities = 0 + + for i in temp: + if(i['properties']['megacity'] == 1): + megacities += 1 + + + return megacities + +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 = 0 + y = 0 + + for point in points: + x += point[0] + y += point[1] + + x = x / len(points) + y = y / len(points) + + return x, y + +def average_nearest_neighbor_distance(points, mark=None): + """ + 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. + """ + + temp_points = [] + + if mark is not None: + for point in points: + if point.mark is mark: + temp_points.append(point) + else: + temp_points = points + + nearest = [] + + for i, point in enumerate(temp_points): + nearest.append(None) + for j, point2 in enumerate(temp_points): + if i is not j: + dist = euclidean_distance((point.x, point.y), (point2.x, point2.y)) + if nearest[i] == None: + nearest[i] = dist + elif nearest[i] > dist: + nearest[i] = dist + + mean_d = sum(nearest) / 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] + """ + + first = True + mbr = [0,0,0,0] + + for point in points: + if first: + first = False + mbr[0] = point[0] + mbr[1] = point[1] + mbr[2] = point[0] + mbr[3] = point[1] + + if point[0] < mbr[0]: + mbr[0] = point[0] + if point[1] < mbr[1]: + mbr[1] = point[1] + if point[0] > mbr[2]: + mbr[2] = point[0] + if point[1] > mbr[3]: + mbr[3] = point[1] + + return mbr + +def mbr_area(mbr): + """ + Compute the area of a minimum bounding rectangle + """ + area = (mbr[1] - mbr[3]) * (mbr[0] - mbr[2]) + 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.5 * (area / n) ** 0.5 + return expected + +def manhattan_distance(a, b): + """ + Compute the Manhattan 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 Manhattan distance between the two points + """ + distance = abs(a[0] - b[0]) + abs(a[1] - b[1]) + return distance + +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 permutations(p=99, n=100, marks=None): + perms = [] + + if marks is None: + for i in range(p): + perms.append(average_nearest_neighbor_distance(utils.create_random_marked_points(n, marks=None))) + + else: + for i in range(p): + perms.append(average_nearest_neighbor_distance(utils.create_random_marked_points(n, marks))) + + return perms + +def find_criticals(perms): + lower = min(perms) + upper = max(perms) + return lower, upper + +def check_significance(lower, upper, observed): + if observed > upper: + return True + elif observed < lower: + return True + else: + return False diff --git a/io_geojson.py b/io_geojson.py new file mode 100644 index 0000000..c41c48f --- /dev/null +++ b/io_geojson.py @@ -0,0 +1,22 @@ +#io_geojson +import json + +def read_geojson(input_file): + """ + Read a geojson file + + Parameters + ---------- + input_file : str + The PATH to the data to be read + + Returns + ------- + gj : dict + An in memory version of the geojson + """ + # Please use the python json module (imported above) + # to solve this one. + with open(input_file, 'r') as f: + gj = json.load(f) + return gj \ No newline at end of file diff --git a/point.py b/point.py new file mode 100644 index 0000000..37bafdf --- /dev/null +++ b/point.py @@ -0,0 +1,36 @@ +#Point class +import sys +import os + +sys.path.insert(0, os.path.abspath('..')) + +from . import utils + + +class Point(object): + + def __init__(self, x, y, mark=None): + self.x = x + self.y = y + self.mark = mark + + #Magic methods + def __str__(self): + return ("({0}, {1}").format(self.x, self.y) + + def __eq__(self, other): + return self.x == other.x and self.y == other.y + + def __add__(self, other): + return Point(self.x + other.x, self.y + other.y) + + def __ne__(self, other): + return self.x != other.x or self.y != other.y + + #Class methods + def check_coincident(self, test): + return utils.check_coincident((self.x, self.y), test) + + def shift_point(self, x_shift, y_shift): + point = (self.x, self.y) + self.x, self.y = utils.shift_point(point, x_shift, y_shift) diff --git a/tests/PointPattern.py b/tests/PointPattern.py new file mode 100644 index 0000000..a5dfa7f --- /dev/null +++ b/tests/PointPattern.py @@ -0,0 +1,88 @@ +from .point import point +from . import analytics +import random +import numpy as np + +def PointPattern(object): + def __init__(self): + self.points = [] + + def average_nearest_neighbor_distance(self, mark=None): + return analytics.average_nearest_neighbor_distance(self.points, mark) + + def add_point(self, point): + self.points.append(point) + + def remove_point(self, index): + del(self.points[index]) + + def count_coincident_points(self): + count = 0 + coincidnet_list = [] + + for i, point in enumerate(self.points): + for j, point2 in enumerate(self.points): + if i is j: + continue + if j in coincident_list: + continue + #Should use the magic method in point class + if point == point2: + count += 1 + coincident_list.append(j) + return count + + def list_marks(self): + marks = [] + + for point in self.points: + if point.mark is not None and point.mark not in marks: + marks.append(point.mark) + + def return_subset(self, mark): + #creates a list of points that have the same mark as passed + return [i for i in self.points if i == mark] + + def create_random_points(self, n=None): + rand_points = [] + rand = random.Random() + marks = ['North', 'East', 'South', 'West'] + + if n is None: + n = len(self.points) + + for i in range(n): + rand_points.append(point.Point(rand.randint(1,100), rand.randint(1,100), mark=rand.choice(marks))) + + return rand_points + + def create_realizations(self, k): + return analytics.permutations(k) + + def critical_points(self): + return analytics.find_criticals(self.create_realizations(99)) + + def compute_g(self, nsteps): + ds = np.linspace(0, 100, nsteps) + g_sum = 0 + + for step in range(nsteps): + o_i = ds[step] + min_dis = None + for i, j in enumerate(ds): + + temp = abs(j - o_i) + + if i is step: + continue + if min_dis is None: + min_dis = temp + elif min_dis > temp: + min_dis = temp + else: + continue + g_sum += min_dis + return g_sum / nsteps + + + diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional_test.py b/tests/functional_test.py new file mode 100644 index 0000000..118ad4d --- /dev/null +++ b/tests/functional_test.py @@ -0,0 +1,77 @@ +import random +import unittest + +from .. import analytics +from .. import io_geojson +from .. import utils +from .. import point + + +class TestFunctionalPointPattern(unittest.TestCase): + + def setUp(self): + random.seed(12345) + i = 0 + self.points = [] + marks = ["North", "East", "South", "West"] + while i < 100: + seed = (round(random.random(),2), round(random.random(),2)) + self.points.append(point.Point(seed[0], seed[1], mark=random.choice(marks))) + n_additional = random.randint(5,10) + i += 1 + c = random.choice([0,1]) + if c: + for j in range(n_additional): + x_offset = random.randint(0,10) / 100 + y_offset = random.randint(0,10) / 100 + pt = (round(seed[0] + x_offset, 2), round(seed[1] + y_offset,2)) + self.points.append(point.Point(pt[0], pt[1], mark=random.choice(marks))) + i += 1 + if i == 100: + break + if i == 100: + break + + def test_point_pattern(self): + """ + This test checks that the code can compute an observed mean + nearest neighbor distance and then use Monte Carlo simulation to + generate some number of permutations. A permutation is the mean + nearest neighbor distance computed using a random realization of + the point process. + """ + random.seed() # Reset the random number generator using system time + # I do not know where you have moved avarege_nearest_neighbor_distance, so update the point_pattern module + observed_avg = analytics.average_nearest_neighbor_distance(self.points) + self.assertAlmostEqual(0.037, observed_avg, 3) + + # Again, update the point_pattern module name for where you have placed the point_pattern module + # Also update the create_random function name for whatever you named the function to generate + # random points + rand_points = utils.create_random_points(100) + self.assertEqual(100, len(rand_points)) + + # As above, update the module and function name. + marks = ["North", "East", "South", "West"] + permutations = analytics.permutations(99, marks=marks) + self.assertEqual(len(permutations), 99) + self.assertNotEqual(permutations[0], permutations[1]) + + # As above, update the module and function name. + lower, upper = analytics.find_criticals(permutations) + self.assertTrue(lower > 1) + self.assertTrue(upper < 101) + self.assertTrue(observed_avg < lower or observed_avg > upper) + + # As above, update the module and function name. + significant = analytics.check_significance(lower, upper, observed_avg) + self.assertTrue(significant) + + self.assertTrue(True) + + # Tests for step 8 + expected = {"North": 0.016635, "East": 0.01878, "South": 0.01533, "West": 0.018719} + + for mark in marks: + avg = analytics.average_nearest_neighbor_distance(self.points, mark) + self.assertAlmostEqual(expected[mark], avg, 3) \ No newline at end of file diff --git a/tests/point_tests.py b/tests/point_tests.py new file mode 100644 index 0000000..bcb96b2 --- /dev/null +++ b/tests/point_tests.py @@ -0,0 +1,58 @@ +import unittest +import random + +from .. import point + +class TestPoint(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.test = point.Point(2,3) + cls.test2 = point.Point(1,1) + + def test_setup(self): + self.assertEqual(self.test.x, 2) + self.assertEqual(self.test.y, 3) + + def test_coincident(self): + coincident = self.test.check_coincident((2,3)) + self.assertTrue(coincident) + coincident = self.test.check_coincident((4,2)) + self.assertFalse(coincident) + + def test_shift(self): + new_point = ((self.test.x + 2), (self.test.y + 4)) + self.test.shift_point(2, 4) + self.assertEqual((self.test.x, self.test.y), new_point) + + #I did this part wrong, not 100% sure what is required for this test + def test_marked(self): + random.seed(12345) + marks = ['North', 'East', 'South', 'West'] + temp = [] + dic = {} + i = 0 + + while i < 15: + temp.append(random.choice(marks)) + i += 1 + + for mark in marks: + if mark not in dic: + dic[mark] = 1 + else: + dic[mark] += 1 + + test1 = point.Point(0,0, dic) + self.assertTrue(test1.mark['North'] == dic['North']) + + + def test_magic_methods(self): + #Checks the __ne__ magic method + self.assertTrue(self.test != self.test2) + + #Checks the __eq__ magic method + self.assertFalse(self.test == self.test2) + + #Checks the __add__ magic method + self.assertEqual(self.test + self.test2, point.Point(3,4)) \ No newline at end of file diff --git a/tests/pointpattern_test.py b/tests/pointpattern_test.py new file mode 100644 index 0000000..562f6a9 --- /dev/null +++ b/tests/pointpattern_test.py @@ -0,0 +1,33 @@ +import unittest + +from .. import PointPattern +from .. import point + +class TestPointPattern(unittest.TestCase): + def setUp(self): + self.test = PointPattern() + self.test.add_point(point.Point(2, 5, mark='North')) + self.test.add_point(point.Point(4, 1, mark='North')) + self.test.add_point(point.Point(2, 5, mark='South')) + self.test.add_point(point.Point(1, 1)) + + def check_coincident(self): + self.assertEqual(self.test.count_coincident_points(), 2) + + def check_list_marks(self): + self.assertEqual(self.test.list_marks(), ['North', 'South']) + + def check_return_subset(self): + self.assertEqual(len(self.test.return_subset('South')), 2) + + def check_generate_points(self): + self.assertEqual(len(self.test.create_random_points(20)), 20) + + def check_realizations(self): + self.assertEqual(len(self.test.create_realizations(20)), 20) + + def check_critical_points(self): + self.assertEqual(self.test.critical_points(), (1, 100)) + + def check_g_function(self): + self.assertAlmostEqual(self.test.compute_g(100), 1, places=4) \ No newline at end of file diff --git a/tests/test_analytics.py b/tests/test_analytics.py new file mode 100644 index 0000000..0b55f2c --- /dev/null +++ b/tests/test_analytics.py @@ -0,0 +1,116 @@ +import os +import sys +import unittest +import random +sys.path.insert(0, os.path.abspath('..')) + +from .. import analytics as point_pattern +from .. import point + +class TestAnalytics(unittest.TestCase): + + def setUp(self): + # Seed a random number generator so we get the same random values every time + random.seed(12345) + # A list comprehension to create 50 random points + self.points = [(random.randint(0,100), random.randint(0,100)) for i in range(50)] + self.gj = [] + + def test_average_nearest_neighbor_distance(self): + temp_points = [point.Point(random.randint(0,100), random.randint(0,100)) for i in range(20)] + mean_d = point_pattern.average_nearest_neighbor_distance(temp_points) + self.assertAlmostEqual(mean_d, 11.8949885, 5) + + def test_mean_center(self): + """ + Something to think about - What values would you + expect to see here and why? Why are the values + not what you might expect? + """ + x, y = point_pattern.mean_center(self.points) + self.assertEqual(x, 47.52) + self.assertEqual(y, 45.14) + + def test_minimum_bounding_rectangle(self): + mbr = point_pattern.minimum_bounding_rectangle(self.points) + self.assertEqual(mbr, [0,0,94,98]) + + def test_mbr_area(self): + mbr = [0,0,94,98] + area = point_pattern.mbr_area(mbr) + self.assertEqual(area, 9212) + + def test_expected_distance(self): + area = 9212 + npoints = 50 + expected = point_pattern.expected_distance(area, npoints) + self.assertAlmostEqual(expected, 6.7867518, 5) + + def test_euclidean_distance(self): + """ + A test to ensure that the distance between points + is being properly computed. + + You do not need to make any changes to this test, + instead, in point_pattern.py, you must complete the + `eucliden_distance` function so that the correct + values are returned. + + Something to think about: Why might you want to test + different cases, e.g. all positive integers, positive + and negative floats, coincident points? + """ + point_a = (3, 7) + point_b = (1, 9) + distance = point_pattern.euclidean_distance(point_a, point_b) + self.assertAlmostEqual(2.8284271, distance, 4) + + point_a = (-1.25, 2.35) + point_b = (4.2, -3.1) + distance = point_pattern.euclidean_distance(point_a, point_b) + self.assertAlmostEqual(7.7074639, distance, 4) + + point_a = (0, 0) + point_b = (0, 0) + distance = point_pattern.euclidean_distance(point_b, point_a) + self.assertAlmostEqual(0.0, distance, 4) + + def test_manhattan_distance(self): + """ + A test to ensure that the distance between points + is being properly computed. + + You do not need to make any changes to this test, + instead, in point_pattern.py, you must complete the + `eucliden_distance` function so that the correct + values are returned. + + Something to think about: Why might you want to test + different cases, e.g. all positive integers, positive + and negative floats, coincident points? + """ + point_a = (3, 7) + point_b = (1, 9) + distance = point_pattern.manhattan_distance(point_a, point_b) + self.assertEqual(4.0, distance) + + point_a = (-1.25, 2.35) + point_b = (4.2, -3.1) + distance = point_pattern.manhattan_distance(point_a, point_b) + self.assertEqual(10.9, distance) + + point_a = (0, 0) + point_b = (0, 0) + distance = point_pattern.manhattan_distance(point_b, point_a) + self.assertAlmostEqual(0.0, distance, 4) + + def test_permutations(self): + self.assertEqual(len(point_pattern.permutations(100)), 100) + + def test_find_criticals(self): + crit_values = point_pattern.find_criticals([1, 2, 3, 4, 5, 6, 7]) + self.assertTrue(crit_values[0] == 1 and crit_values[1] == 7) + + def test_check_significance(self): + self.assertTrue(point_pattern.check_significance(22, 4, 40)) + \ No newline at end of file diff --git a/tests/test_io_geojson.py b/tests/test_io_geojson.py new file mode 100644 index 0000000..ab1375a --- /dev/null +++ b/tests/test_io_geojson.py @@ -0,0 +1,18 @@ +import os +import sys +import unittest +sys.path.insert(0, os.path.abspath('..')) + +from .. import io_geojson as point_pattern + +class TestIoGeoJson(unittest.TestCase): + + def setUp(self): + pass + +''' + def test_read_geojson(self): + self.assertIsInstance(self.gj, dict) +''' + + \ No newline at end of file diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..f755578 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,86 @@ +import os +import sys +import unittest +sys.path.insert(0, os.path.abspath('..')) + +from .. import utils as point_pattern + +class TestUtils(unittest.TestCase): + + def setUp(self): + pass + + def test_getx(self): + """ + A simple test to ensure that you understand how to access + the x coordinate in a tuple of coordinates. + + You do not need to make any changes to this test, + instead, in point_pattern.py, you must complete the + `getx` function so that the correct + values are returned. + """ + point = (1,2) + x = point_pattern.getx(point) + self.assertEqual(1, x) + + def test_gety(self): + """ + As above, except get the y coordinate. + + You do not need to make any changes to this test, + instead, in point_pattern.py, you must complete the + `gety` function so that the correct + values are returned. + """ + point = (3,2.5) + y = point_pattern.gety(point) + self.assertEqual(2.5, y) + + def test_shift_point(self): + """ + Test that a point is being properly shifted + when calling point_pattern.shift_point + """ + point = (0,0) + new_point = point_pattern.shift_point(point, 3, 4) + self.assertEqual((3,4), new_point) + + point = (-2.34, 1.19) + new_point = point_pattern.shift_point(point, 2.34, -1.19) + self.assertEqual((0,0), new_point) + + def test_check_coincident(self): + """ + As above, update the function in point_pattern.py + + """ + point_a = (3, 7) + point_b = (3, 7) + coincident = point_pattern.check_coincident(point_a, point_b) + self.assertEqual(coincident, True) + + point_b = (-3, -7) + coincident = point_pattern.check_coincident(point_a, point_b) + self.assertEqual(coincident, False) + + point_a = (0, 0) + point_b = (0.0, 0.0) + coincident = point_pattern.check_coincident(point_b, point_a) + self.assertEqual(coincident, True) + + def test_check_in(self): + """ + As above, update the function in point_pattern.py + """ + point_list = [(0,0), (1,0.1), (-2.1, 1), + (2,4), (1,1), (3.5, 2)] + + inlist = point_pattern.check_in((0,0), point_list) + self.assertTrue(inlist) + + inlist = point_pattern.check_in((6,4), point_list) + self.assertFalse(inlist) + + def test_create_random_points(self): + self.assertEqual(len(point_pattern.create_random_points(100)), 100) \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..70ce6d2 --- /dev/null +++ b/utils.py @@ -0,0 +1,129 @@ +#utils +import random +from . import point + +def create_random_marked_points(n, marks=[]): + rand = random.Random() + rand_points = [] + + if marks is None: + for i in range(n): + rand_points.append(point.Point(rand.randint(0, 100), rand.randint(0,100))) + else: + for i in range(n): + rand_points.append(point.Point(rand.randint(0, 100), rand.randint(0,100), rand.choice(marks))) + + return rand_points + +def create_random_points(n): + rand = random.Random() + random_points = [(rand.randint(0,100), rand.randint(0,100)) for i in range(n)] + return random_points + +def shift_point(point, x_shift, y_shift): + """ + Shift a point by some amount in the x and y directions + + Parameters + ---------- + point : tuple + in the form (x,y) + + x_shift : int or float + distance to shift in the x direction + + y_shift : int or float + distance to shift in the y direction + + Returns + ------- + new_x : int or float + shited x coordinate + + new_y : int or float + shifted y coordinate + + Note that the new_x new_y elements are returned as a tuple + + Example + ------- + >>> point = (0,0) + >>> shift_point(point, 1, 2) + (1,2) + """ + x = getx(point) + y = gety(point) + + x += x_shift + y += y_shift + + return x, y + +def check_coincident(a, b): + """ + Check whether two points are coincident + Parameters + ---------- + a : tuple + A point in the form (x,y) + + b : tuple + A point in the form (x,y) + + Returns + ------- + equal : bool + Whether the points are equal + """ + return a == b + +def check_in(point, point_list): + """ + Check whether point is in the point list + + Parameters + ---------- + point : tuple + In the form (x,y) + + point_list : list + in the form [point, point_1, point_2, ..., point_n] + """ + return point in point_list + +def getx(point): + """ + A simple method to return the x coordinate of + an tuple in the form(x,y). We will look at + sequences in a coming lesson. + + Parameters + ---------- + point : tuple + in the form (x,y) + + Returns + ------- + : int or float + x coordinate + """ + return point[0] + + +def gety(point): + """ + A simple method to return the x coordinate of + an tuple in the form(x,y). We will look at + sequences in a coming lesson. + + Parameters + ---------- + point : tuple + in the form (x,y) + + Returns + ------- + : int or float + y coordinate + """ + return point[1] \ No newline at end of file