aboutsummaryrefslogtreecommitdiff
path: root/py/data2.py
blob: a073f4b5bc2265aee0a7bf11546763d6363994ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Data
from scipy.spatial import Voronoi, voronoi_plot_2d, KDTree, distance
from enum import Enum
import matplotlib.pyplot as plt
from matplotlib.path import Path

fancy = {'pits':'Artificial Pits', 'obstacles':'Artificial Obstacles',
'trails':'Trail Erasure'}

class Pit:
  def __init__(self, loc, depth, diam):
    self.loc = loc
    self.depth = depth
    self.diam = diam

  def __repr__(self):
    return '%s @ %.1fcm deep, %.1fcm wide' % (str(self.loc), self.depth, self.diam)

  def disp(self):
    return '%.1fcm dp\n %.1fcm wd' % (self.depth, self.diam)

  def __getitem__(self,ind):
    return self.loc[ind]

class Trial:
  def __init__(self, method, recl, dead, size, pits, fake=None):
    self.method = method
    # intro = 15
    self.recl = recl
    self.dead = dead
    self.size = size
    self.pits = pits
    self.pitlocs = [pit.loc for pit in self.pits]
    self.fake = fake

  def __repr__(self):
    return f'{fancy[self.method]} {self.size[0]}'

  def plot(self, save=False):
    vor = Voronoi([pit.loc for pit in self.pits])
    voronoi_plot_2d(vor)
    if self.method == 'obstacles':
        for obstacle in self.fake:
            plt.fill(*obstacle.unzip())
    plt.xlabel('%s (dimension %dx%dcm)' % (fancy[self.method], self.size[0], self.size[1]))
    if save:
      plt.savefig('%s-%dx%d.png'%(self.method,self.size[0],self.size[1]),
      bbox_inches='tight')
    else:
      plt.show()

  def nearest_neighbor(self):
    tree = KDTree(self.pitlocs)
    sumnn = 0
    return [dists[1] for dists in tree.query(self.pitlocs,2)[0]]

class Obstacle:
    def __init__(self, coords):
        self.coords = coords
        self.path = Path(coords)

    def contains(self, point):
        return self.path.contains_point(point)

    def multicontains(self, points):
        return self.path.contains_points(points)

    def unzip(self):
        return ([x[0] for x in self.coords],[x[1] for x in self.coords])

trials = [
  Trial('trails', 1, 2, [24,24], [
    Pit((24,1),1,2),
    Pit((21,6),1,1),
    Pit((18,18),2,3),
    Pit((18,24),1,1),
    Pit((23,23),5,3),
    Pit((23,13),2,1),
    Pit((20,6),1,1),
    Pit((4,4),2,3),
    Pit((14,5),4,5),
    Pit((16,9),1,1),
    Pit((9,10),3,4),
    Pit((13,12),1,1),
  ]),
  Trial('trails', 2, 3, [12,12], [
    Pit((12,12),1,2),
    Pit((12,0),1,1),
    Pit((11,8),1,1),
    Pit((11,5),4,7),
    Pit((9,7),2,2),
    Pit((9,9),3,4),
    Pit((5,11),1,3),
    Pit((5,9),1,3),
    Pit((1,11),1,1),
    Pit((3,4),1,3),
  ]),
  Trial('pits', 1, 7, [24,24], [
    Pit((1,23),1,1),
    Pit((3,12),3,5),
    Pit((17,5),2,5),
    Pit((10,17),2,4),
    Pit((23,0),1,1),
    Pit((23,9),5,8),
    Pit((24,24),1,1)
  ], fake=[
    Pit((5,4),5,8),
    Pit((7,2),5,8),
    Pit((20,2),5,8),
    Pit((23,4),5,8),
    Pit((12,7),5,8),
    Pit((7,18),5,8),
    Pit((20,18),5,8),
    Pit((5,17),5,8),
    Pit((12,23),5,8),
    Pit((14,23),5,8),
    Pit((18,23),5,8),
    Pit((14,18),5,8),
  ]),
  Trial('pits', 4, 4, [12,12], [
    Pit((2,12),1,2),
    Pit((6,4),2,3),
    Pit((6,7),5,8),
    Pit((8,12),2,3),
    Pit((12,5),1,1),
    Pit((11,9),1,1),
    Pit((2,9),1,1),
  ], fake=[
    Pit((2,3),5,8),
    Pit((2,12),5,8),
    Pit((6,3),5,8),
    Pit((6,7),5,8),
    Pit((11,3),5,8),
    Pit((11,11),5,8),
  ]),
  Trial('obstacles', 0, 4, [24,24], [
    Pit((1,20),1,1),
    Pit((2,12),1,2),
    Pit((12,0),1,1),
    Pit((12,12),1,2),
    Pit((20,15),5,5),
    Pit((20,24),2,3),
    Pit((11,22),3,5),
    Pit((20,5),3,5),
    Pit((21,8),2,6),
    Pit((20,5),3,5),
    Pit((21,8),2,6),
    Pit((22,14),1,1),
    Pit((22,16),2,4),
  ], fake=[
    Obstacle([(8,3),(1,7),(7,16)]),
    Obstacle([(18,1),(16,7),(21,7),(21,4)]),
    Obstacle([(17,15),(18,20),(21,20),(23,19)])
  ]),
  Trial('obstacles', 3, 0, [12,12], [
    Pit((2,11),2,3),
    Pit((2,1),1,1),
    Pit((5,3),1,3),
    Pit((6,10),1,1),
    Pit((12,4),3,6),
    Pit((11,6),1,3),
    Pit((11,9),1,2),
    Pit((10,11),2,4),
    Pit((6,3),3,5),
    Pit((12,9),1,2),
  ], fake=[ Obstacle([(10,2),(11,9),(3,8),(3,5)]) ]),
]