Skip to content

Commit

Permalink
SensorList has a better handling of the channel_map. This is still a …
Browse files Browse the repository at this point in the history
…bit unsatisfying
  • Loading branch information
ghislainp committed Sep 11, 2020
1 parent 5f3e786 commit e02642f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions smrt/core/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,25 +289,33 @@ def __init__(self, sensor_list, axis="channel"):
self.axis = axis

# check uniqueness of axis
a = [getattr(s, axis) for s in self.sensor_list]
if axis == 'channel':
self.channel_list = [ch for s in self.sensor_list for ch in s.channel_map]
a = self.channel_list
self.channel_map = {ch: s.channel_map[ch] for s in self.sensor_list for ch in s.channel_map}
else:
a = [getattr(s, axis) for s in self.sensor_list]
self.channel_map = {ch: dict(**s.channel_map[ch], **{axis: getattr(s, axis)}) for s in sensor_list for ch in s.channel_map}

if None in a:
raise SMRTError("It is required to set '%s' value for each sensor" % axis)
if len(set(a)) != len(a):
raise SMRTError("It is required to set different '%s' values for each sensor" % axis)

self.channel_map = {ch: dict(**s.channel_map[ch], **{axis: getattr(s, axis)}) for s in sensor_list for ch in s.channel_map}

@property
def channel(self):
return [s.channel for s in self.sensor_list]
return [ch for ch in s.channel_map for s in self.sensor_list]

@property
def frequency(self):
return [s.frequency for s in self.sensor_list]

def configurations(self):
yield self.axis, np.array([getattr(s, self.axis) for s in self.sensor_list])
if self.axis == "channel":
yield self.axis, np.array(self.channel_list)
else:
yield self.axis, np.array([getattr(s, self.axis) for s in self.sensor_list])

def iterate(self, axis=None):

Expand Down

0 comments on commit e02642f

Please sign in to comment.