-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIFPath.py
60 lines (46 loc) · 2.02 KB
/
IFPath.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
from Bandpasses import Bandpasses
class IFPath():
"""
This list is responsible for containing and interpreting a single
path through the IF system, stored as a list of IFPathNodes
"""
def __init__(self, ifPathNodes):
# a list of IFPathNodes
self.path = ifPathNodes
def __str__(self):
return "IFPath (%s -> %s)" % (self.path[0], self.path[-1])
def getSummary(self):
return "IFPath (%s -> %s)" % (self.path[0], self.path[-1])
def getNodeNameList(self):
return [p.name for p in self.path]
def getBackendNode(self):
"Assume it's the last one!"
return self.path[-1]
def getUniqueDeviceNode(self, device):
"Retrieves node in path that is like given name, assuming it appears just once or never"
devices = [n for n in self.path if device in n.name]
assert len(devices) < 2
return None if len(devices) == 0 else devices[0]
def getFirstLikeDeviceNode(self, device):
"Retrieves first node in path that is like given device name"
devices = [n for n in self.path if device in n.name]
return None if len(devices) == 0 else devices[0]
def aggregatePathBandpasses(self):
"Put together bandpasses for each node in given path to one collection"
# one motivation is the fact that Bandpasses.show() needs them to all be on
# the same scale to visualize correctly
bps = []
for node in self.path:
if node.ifInfo is not None and node.ifInfo.bandpasses is not None:
bps.extend(node.ifInfo.bandpasses.bandpasses)
bps = Bandpasses(bps)
return bps
def getBandpassUpToNode(self, targetNode):
"Returns the bandpass as it appears before the given node"
bp = None
for node in self.path:
if node == targetNode:
break
if node.ifInfo is not None and node.ifInfo.bandpasses is not None:
bp = node.ifInfo.bandpasses.bandpasses[-1]
return bp