<commit_before>"""Module containing class `Channel`."""


from vesper.util.named import Named


'''
A `Channel` is intended for use as a standalone object, and so has a
full set of attributes. For example, signal metadata like the time axis,
the sample array shape, and the sample type are available as channel
attributes, even though they are also available as attributes of the
channels' signal.


c.signal

c.number           # channel number, in [0, `c.signal.channel_count`]

c.name

c.time_axis        # `TimeAxis`

len(c)             # sample array count, `c.time_axis.length`

c.array_shape      # sample array shape

c.shape            # `(len(c),) + c.array_shape`

c.sample_type      # NumPy `dtype` of samples

r[...]             # synchronous, reads one channel segment, raises exception
                   # if not all of segment available

r.read(...)        # asynchronous, can read multiple channel segments, yields
                   # intersection of requested segments and available
                   # segments
'''


# TODO: Make channel name mutable?


class Channel(Named):
    
    """
    One channel of a signal.
    
    A channel is a sequence of sample arrays and associated metadata.
    """
    

    def __init__(self, signal, number, name=None):
        
        if name is None:
            name = str(number)
            
        super().__init__(name)
        
        self._signal = signal
        self._number = number

        
    @property
    def signal(self):
        return self._signal
    
    
    @property
    def number(self):
        return self._number
    
    
    @property
    def time_axis(self):
        return self.signal.time_axis
    
    
    def __len__(self):
        return self.time_axis.frame_count
    
    
    @property
    def array_shape(self):
        return self.signal.array_shape
    
    
    @property
    def shape(self):
        return (len(self),) + self.array_shape
    
    
    @property
    def sample_type(self):
        return self.signal.sample_type
    
    
    def __getitem__(self, key):
        
        # Build `Signal.as_channels` key from `Channel` key.
        if isinstance(key, tuple):
            key = (self.number,) + key
        else:
            key = (self.number, key)
            
        return self.signal.as_channels[key]
<commit_msg>Fix bug in signal channel class.<commit_after>"""Module containing class `Channel`."""


from vesper.util.named import Named


'''
A `Channel` is intended for use as a standalone object, and so has a
full set of attributes. For example, signal metadata like the time axis,
the sample array shape, and the sample type are available as channel
attributes, even though they are also available as attributes of the
channels' signal.


c.signal

c.number           # channel number, in [0, `c.signal.channel_count`]

c.name

c.time_axis        # `TimeAxis`

len(c)             # sample array count, `c.time_axis.length`

c.array_shape      # sample array shape

c.shape            # `(len(c),) + c.array_shape`

c.sample_type      # NumPy `dtype` of samples

r[...]             # synchronous, reads one channel segment, raises exception
                   # if not all of segment available

r.read(...)        # asynchronous, can read multiple channel segments, yields
                   # intersection of requested segments and available
                   # segments
'''


# TODO: Make channel name mutable?


class Channel(Named):
    
    """
    One channel of a signal.
    
    A channel is a sequence of sample arrays and associated metadata.
    """
    

    def __init__(self, signal, number, name=None):
        
        if name is None:
            name = str(number)
            
        super().__init__(name)
        
        self._signal = signal
        self._number = number

        
    @property
    def signal(self):
        return self._signal
    
    
    @property
    def number(self):
        return self._number
    
    
    @property
    def time_axis(self):
        return self.signal.time_axis
    
    
    def __len__(self):
        return self.time_axis.length
    
    
    @property
    def array_shape(self):
        return self.signal.array_shape
    
    
    @property
    def shape(self):
        return (len(self),) + self.array_shape
    
    
    @property
    def sample_type(self):
        return self.signal.sample_type
    
    
    def __getitem__(self, key):
        
        # Build `Signal.as_channels` key from `Channel` key.
        if isinstance(key, tuple):
            key = (self.number,) + key
        else:
            key = (self.number, key)
            
        return self.signal.as_channels[key]

{'fraction_non_alphanumeric': 0.08524659863945579, 'fraction_numerical': 0.00042517006802721087, 'mean_word_length': 1.9025293028994448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5362593', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1295, 'n_words': 425}