TimeSamples¶
- class acoular.sources.TimeSamples¶
Bases:
SamplesGenerator
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 also serves as an interface where the data can be accessed (e.g. for use in a block chain) via the
result()
generator.See also
acoular.sources.MaskedTimeSamples
Extends the functionality of class
TimeSamples
by enabling the definition of start and stop samples as well as the specification of invalid channels.
Examples
Data can be loaded from a HDF5 file as follows:
>>> from acoular import TimeSamples >>> name = <some_h5_file.h5> >>> ts = TimeSamples(name=name) >>> print(f'number of channels: {ts.numchannels}') number of channels: 56
Alternatively, the time data can be specified directly as a numpy array. In this case, the
data
andsample_freq
attributes must be set manually.>>> import numpy as np >>> data = np.random.rand(1000, 4) >>> ts = TimeSamples(data=data, sample_freq=51200)
Chunks of the time data can be accessed iteratively via the
result()
generator. The last block will be shorter than the block size if the number of samples is not a multiple of the block size.>>> blocksize = 512 >>> generator = ts.result(num=blocksize) >>> for block in generator: ... print(block.shape) (512, 4) (488, 4)
- name = File(filter=['*.h5'], desc='name of data file')¶
Full name of the .h5 file with data.
- basename = Property( …¶
Basename of the .h5 file with data, is set automatically.
- calib = Trait(Calib, desc='Calibration data')¶
Calibration data, instance of
Calib
class, optional .
- numchannels = CLong(0, desc='number of input channels')¶
Number of channels, is set automatically / read from file.
- numsamples = CLong(0, desc='number of samples')¶
Number of time data samples, is set automatically / read from file.
- data = Any(transient=True, desc='the actual time data array')¶
The time data as array of floats with dimension (numsamples, numchannels).
- h5f = Instance(H5FileBase, transient=True)¶
HDF5 file object
- metadata = Dict(desc='metadata contained in .h5 file')¶
Provides metadata stored in HDF5 file object
- 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 bycalib
.- 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.