Acoular 24.10 documentation

Cache

«  Average   ::   process   ::   SampleSplitter  »

Cache

class acoular.process.Cache

Bases: InOut

Caches source output in cache file.

This class is used to cache the output of a acoular.base.Generator derived source object in a cache file to circumvent time-consuming re-calculation. The cache file is created in the Acoular cache directory.

Examples

>>> import acoular as ac
>>> import numpy as np
>>>
>>> ac.config.h5library = 'tables'
>>> data = np.random.rand(1024, 1)
>>> ts = ac.TimeSamples(data=data, sample_freq=51200)
>>> fft = ac.RFFT(source=ts, block_size=1024)
>>> cache = ac.Cache(source=fft)  # cache the output of the FFT in cache file
>>> for block in cache.result(num=1):  # read the cached data block-wise
...     print(block.shape)
[('_cache.h5', 1)]
(1, 513)

The caching behaviour can be controlled by the Config instance via the global_caching attribute. To turn off caching, set global_caching to ‘none’ before running the code. The cache file directory can be obtained (and set) via the cache_dir

>>> ac.config.global_caching = 'none'
result(num)

Python generator that yields the output from cache block-wise.

Parameters:
numinteger

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

Returns:
Samples in blocks of shape (num, numchannels).

The last block may be shorter than num. Echos the source output, but reads it from cache when available and prevents unnecassary recalculation.

«  Average   ::   process   ::   SampleSplitter  »