def test_repeated_scalar_to_list(self): repeated_composite = self.simple_mic_packet.metadata as_list = reader_utils.repeated_to_list(repeated_composite) self.assertEqual(type(as_list), list) self.assertEqual(len(repeated_composite), len(as_list)) for i in range(len(repeated_composite)): self.assertEqual(repeated_composite[i], as_list[i])
def test_repeated_composite_to_list(self): repeated_composite = self.simple_mic_packet.evenly_sampled_channels as_list = reader_utils.repeated_to_list(repeated_composite) self.assertEqual(type(as_list), list) self.assertEqual(len(repeated_composite), len(as_list)) for i in range(len(repeated_composite)): self.assertEqual(repeated_composite[i], as_list[i])
def set_metadata(self, data: typing.List[str]): """ sets the metadata :param data: metadata as list of strings """ del self.protobuf_channel.metadata[:] for meta in data: self.protobuf_channel.metadata.append(meta) self.metadata = reader_utils.repeated_to_list( self.protobuf_channel.metadata)
def set_channel(self, channel: typing.Union[api900_pb2.EvenlySampledChannel, api900_pb2.UnevenlySampledChannel]): """ Sets the protobuf channel :param channel: protobuf channel """ self.protobuf_channel = channel self.sensor_name = channel.sensor_name self.channel_types = reader_utils.repeated_to_list( channel.channel_types) self.payload = reader_utils.extract_payload(channel) self.metadata = reader_utils.repeated_to_list(channel.metadata) self.value_means = reader_utils.repeated_to_array(channel.value_means) self.value_stds = reader_utils.repeated_to_array(channel.value_stds) self.value_medians = reader_utils.repeated_to_array( channel.value_medians) self.channel_type_index = { self.channel_types[i]: i for i in range(len(self.channel_types)) }
def set_channel_types( self, types: typing.List[typing.Union[api900_pb2.EvenlySampledChannel, api900_pb2.UnevenlySampledChannel]]): """ sets the channel_types to the list given :param types: a list of channel types """ del self.protobuf_channel.channel_types[:] for ctype in types: self.protobuf_channel.channel_types.append(ctype) self.channel_types = reader_utils.repeated_to_list( self.protobuf_channel.channel_types) self.channel_type_index = { self.channel_types[i]: i for i in range(len(self.channel_types)) }
def __init__(self, channel: typing.Optional[ typing.Union[api900_pb2.EvenlySampledChannel, api900_pb2.UnevenlySampledChannel]] = None): """ Initializes this interleaved channel object. :param channel: Either a protobuf evenly or unevenly sampled channel. note: value_means, value_medians, value_stds, and channel_type_index are only set during initialization or when payload is altered payload should only be altered by set_payload or set_deinterleaved_payload due to the extra data values that are required to correctly set the protobuf_channel """ if channel is None: self.protobuf_channel = None self.sensor_name = None self.channel_types = [0] self.payload = [0] self.metadata = [] self.value_means = [] self.value_stds = [] self.value_medians = [] self.channel_type_index = [] else: self.protobuf_channel: typing.Union[ api900_pb2.EvenlySampledChannel, api900_pb2.UnevenlySampledChannel] = channel """Reference to the original protobuf channel""" self.sensor_name: str = channel.sensor_name """Provided sensor name""" self.channel_types: typing.List[typing.Union[ api900_pb2.EvenlySampledChannel, api900_pb2. UnevenlySampledChannel]] = reader_utils.repeated_to_list( channel.channel_types) """List of channel type constant enumerations""" self.payload: numpy.ndarray = reader_utils.extract_payload(channel) """This channels payload as a numpy array of either floats or ints""" self.metadata: typing.List[str] = reader_utils.repeated_to_list( channel.metadata) """This channels list of metadata""" self.value_means: numpy.ndarray = reader_utils.repeated_to_array( channel.value_means) """Interleaved array of mean values""" self.value_stds: numpy.ndarray = reader_utils.repeated_to_array( channel.value_stds) """Interleaved array of standard deviations of values""" self.value_medians: numpy.ndarray = reader_utils.repeated_to_array( channel.value_medians) """Interleaves array of median values""" self.channel_type_index: typing.Dict[ api900_pb2.ChannelType, int] = { self.channel_types[i]: i for i in range(len(self.channel_types)) } """Contains a mapping of channel type to index in channel_types array"""
def test_repeated_scalar_to_list_empty(self): repeated_scalar = self.simple_unevenly_sampled_packet.metadata as_list = reader_utils.repeated_to_list(repeated_scalar) self.assertEqual(type(as_list), list) self.assertEqual(len(repeated_scalar), 2) self.assertEqual(len(as_list), 2)
def test_repeated_composite_to_list_empty(self): repeated_composite = self.simple_mic_packet.unevenly_sampled_channels as_list = reader_utils.repeated_to_list(repeated_composite) self.assertEqual(type(as_list), list) self.assertEqual(len(repeated_composite), 0) self.assertEqual(len(as_list), 0)