Acoular 24.07 documentation

MaskedTimeSamples

«  TimeSamples   ::   sources   ::   PointSource  »

MaskedTimeSamples

class acoular.sources.MaskedTimeSamples

Bases: TimeSamples

Container for processing time data in *.h5 or NumPy array format.

This class loads measured data from HDF5 files and provides information about this data. It supports storing information about (in)valid samples and (in)valid channels and allows to specify a start and stop index for the valid samples. It also serves as an interface where the data can be accessed (e.g. for use in a block chain) via the result() generator.

Examples

Data can be loaded from a HDF5 file and invalid channels can be specified as follows:

>>> from acoular import MaskedTimeSamples
>>> name = <some_h5_file.h5>  
>>> ts = MaskedTimeSamples(name=name, invalid_channels=[0, 1])  
>>> print(f'number of valid channels: {ts.numchannels}')  
number of valid channels: 54 

Alternatively, the time data can be specified directly as a numpy array. In this case, the data and sample_freq attributes must be set manually.

>>> from acoular import MaskedTimeSamples
>>> import numpy as np
>>> data = np.random.rand(1000, 4)
>>> ts = MaskedTimeSamples(data=data, sample_freq=51200)

Chunks of the time data can be accessed iteratively via the result() generator:

>>> blocksize = 512
>>> generator = ts.result(num=blocksize)
>>> for block in generator:
...     print(block.shape)
(512, 4)
(488, 4)
start = CLong(0, desc='start of valid samples')

Index of the first sample to be considered valid.

stop = Trait(None, None, CLong, desc='stop of valid samples')

Index of the last sample to be considered valid.

invalid_channels = ListInt(desc='list of invalid channels')

Channels that are to be treated as invalid.

channels = Property(depends_on=['invalid_channels', 'numchannels_total'], desc='channel mask')

Channel mask to serve as an index for all valid channels, is set automatically.

numchannels_total = CLong(0, desc='total number of input channels')

Number of channels (including invalid channels), is set automatically.

numsamples_total = CLong(0, desc='total number of samples per channel')

Number of time data samples (including invalid samples), is set automatically.

numchannels = Property(depends_on=['invalid_channels', 'numchannels_total'], desc='number of valid input channels')

Number of valid channels, is set automatically.

numsamples = Property(depends_on=['start', 'stop', 'numsamples_total'], desc='number of valid samples per channel')

Number of valid time data samples, is set automatically.

result(num=128)

Python generator that yields the output block-wise.

Reads the time data either from a HDF5 file or from a numpy array given by data and iteratively returns a block of size num samples. Calibrated data is returned if a calibration object is given by calib.

Parameters:
numinteger, defaults to 128

This parameter defines the size of the blocks to be yielded (i.e. the number of samples per block).

Yields:
numpy.ndarray

Samples in blocks of shape (num, numchannels). The last block may be shorter than num.

«  TimeSamples   ::   sources   ::   PointSource  »