-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.py
executable file
·141 lines (103 loc) · 4.08 KB
/
Setup.py
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
'''
Created on Jan 19, 2010
@author: one
'''
def new_setup(platename='',setup_name='',):
#Current setup dict
return {
'plate':platename,
'setup':setup_name,
'unused_holes':[], #bit of a misnomer, mechanical & guide would be more apt
'holes':[],
'assignwithholes':[], #list of holes not in setup but to be assigned
'cassettes':{} #dict of cassettes
}
class Setup(object):
'''
classdocs
'''
def __init__(self, plateName, setupName, channels=[]):
'''
Constructor
'''
self.name=setupName
self.plateName=plateName
self.guideHoles=set()
self.groups=[]
self.dict={}
for c in channels:
self.dict[c]=set()
def __eq__(self, other):
""" Returns true if both have the same channels
and the channels are composed of the same holes."""
def __contains__(self, hole):
""" Returns true if hole is in the setup,
false otherwise."""
for v in self.dict.itervalues():
if hole in v:
return True
return False
def getInfo(self):
return (self.name, self.plateName)
def addHole(self, hole, channel):
""" Adds a hole to specified channel.
A nonexistent channel is an exception.
Attempting to add a hole to a channel when it is
already in the the setup in another channel is an exception."""
if channel not in self.dict:
raise Exception("Channel does not exist")
x=self.dict.keys()
x.remove(channel)
for k in x:
if hole in self.dict[k]:
raise Exception('Hole exists in annother channel')
self.dict[channel].add(hole)
def addGuiderHole(self, hole):
""" Adds a guider hole to the setup """
self.guideHoles.add(hole)
def getGuiderHoles(self):
return self.guideHoles.copy()
def addChannel(self, channel, holes=[]):
""" Adds a channel to the setup, optionally
initializing it with holes given as a sequence object
to holes.
If channel exists no action is taken"""
if channel not in self.dict:
self.dict[channel]=set(holes)
def createGroup(self, fiberBundle, holes, region, side, channel):
if not set(holes).issubset(self.dict[channel]):
raise Exception('Holes must all be in the setup and on the specified channel')
self.groups.append({'fiber_group':fiberBundle, 'holes':holes,
'region':region, 'side':side, 'path':[], 'channel':channel})
def isHoleInChannel(self, hole, channel):
""" Returns true if hole is in channel
channel. False otherwise.
A nonexistent channel is an exception."""
return hole in self.dict[channel]
def delHole(self, hole):
""" Removes a hole from the setup.
If the hole is not part of the setup no action is taken"""
for k in self.dict:
self.dict[k].discard(hole)
def getChannels(self):
""" Returns a list of the channels which are
in use for the setup."""
return [x for x in self.dict.keys() if len(self.dict[x])]
def getHolesInChannel(self, channel):
""" Returns a set of holes in the specified channel,
a nonexistent channel is an exception"""
return self.dict[channel].copy()
def getChannelOfHole(self, hole):
""" Returns the channel of the hole.
If hole is not in setup then an exception is raised."""
for k,v in self.dict.iteritems():
if hole in v:
return k
raise Exception('Hole not in setup')
def isEmpty(self):
""" Returns true if setup has no holes,
false otherwise."""
for k in self.dict.itervalues():
if len(k):
return False
return True