acoular 24.7__py3-none-any.whl → 24.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
acoular/spectra.py CHANGED
@@ -7,7 +7,6 @@
7
7
  :toctree: generated/
8
8
 
9
9
  BaseSpectra
10
- FFTSpectra
11
10
  PowerSpectra
12
11
  synthetic
13
12
  PowerSpectraImport
@@ -33,7 +32,6 @@ from numpy import (
33
32
  ones,
34
33
  real,
35
34
  searchsorted,
36
- sqrt,
37
35
  sum,
38
36
  zeros,
39
37
  zeros_like,
@@ -54,13 +52,13 @@ from traits.api import (
54
52
  property_depends_on,
55
53
  )
56
54
 
55
+ from .base import SamplesGenerator
57
56
  from .calib import Calib
58
57
  from .configuration import config
59
58
  from .fastFuncs import calcCSM
60
59
  from .h5cache import H5cache
61
60
  from .h5files import H5CacheFileBase
62
61
  from .internal import digest
63
- from .tprocess import SamplesGenerator, TimeInOut
64
62
 
65
63
 
66
64
  class BaseSpectra(HasPrivateTraits):
@@ -105,8 +103,8 @@ class BaseSpectra(HasPrivateTraits):
105
103
  desc='number of samples per FFT block',
106
104
  )
107
105
 
108
- #: The floating-number-precision of entries of csm, eigenvalues and
109
- #: eigenvectors, corresponding to numpy dtypes. Default is 64 bit.
106
+ #: The floating-number-precision of the resulting spectra, corresponding to numpy dtypes.
107
+ #: Default is 'complex128'.
110
108
  precision = Trait('complex128', 'complex64', desc='precision of the fft')
111
109
 
112
110
  # internal identifier
@@ -130,7 +128,7 @@ class BaseSpectra(HasPrivateTraits):
130
128
  return None
131
129
 
132
130
  # generator that yields the time data blocks for every channel (with optional overlap)
133
- def get_source_data(self):
131
+ def _get_source_data(self):
134
132
  bs = self.block_size
135
133
  temp = empty((2 * bs, self.numchannels))
136
134
  pos = bs
@@ -146,48 +144,12 @@ class BaseSpectra(HasPrivateTraits):
146
144
  pos -= bs
147
145
 
148
146
 
149
- class FFTSpectra(BaseSpectra, TimeInOut):
150
- """Provides the spectra of multichannel time data.
151
-
152
- Returns Spectra per block over a Generator.
153
- """
154
-
155
- # internal identifier
156
- digest = Property(depends_on=['source.digest', 'precision', 'block_size', 'window', 'overlap'])
157
-
158
- @cached_property
159
- def _get_digest(self):
160
- return digest(self)
161
-
162
- # generator that yields the fft for every channel
163
- def result(self):
164
- """Python generator that yields the output block-wise.
165
-
166
- Parameters
167
- ----------
168
- num : integer
169
- This parameter defines the size of the blocks to be yielded
170
- (i.e. the number of samples per block).
171
-
172
- Returns
173
- -------
174
- Samples in blocks of shape (numfreq, :attr:`numchannels`).
175
- The last block may be shorter than num.
176
-
177
- """
178
- wind = self.window_(self.block_size)
179
- weight = sqrt(2) / self.block_size * sqrt(self.block_size / dot(wind, wind)) * wind[:, newaxis]
180
- for data in self.get_source_data():
181
- ft = fft.rfft(data * weight, None, 0).astype(self.precision)
182
- yield ft
183
-
184
-
185
147
  class PowerSpectra(BaseSpectra):
186
148
  """Provides the cross spectral matrix of multichannel time data
187
149
  and its eigen-decomposition.
188
150
 
189
151
  This class includes the efficient calculation of the full cross spectral
190
- matrix using the Welch method with windows and overlap. It also contains
152
+ matrix using the Welch method with windows and overlap (:cite:`Welch1967`). It also contains
191
153
  the CSM's eigenvalues and eigenvectors and additional properties.
192
154
 
193
155
  The result is computed only when needed, that is when the :attr:`csm`,
@@ -206,7 +168,7 @@ class PowerSpectra(BaseSpectra):
206
168
  #: Data source; :class:`~acoular.sources.SamplesGenerator` or derived object.
207
169
  source = Property(_source, desc='time data object')
208
170
 
209
- #: The :class:`~acoular.tprocess.SamplesGenerator` object that provides the data.
171
+ #: The :class:`~acoular.base.SamplesGenerator` object that provides the data.
210
172
  time_data = Property(
211
173
  _source,
212
174
  desc='deprecated attribute holding the time data object. Use PowerSpectra.source instead!',
@@ -215,9 +177,11 @@ class PowerSpectra(BaseSpectra):
215
177
  #: The :class:`~acoular.calib.Calib` object that provides the calibration data,
216
178
  #: defaults to no calibration, i.e. the raw time data is used.
217
179
  #:
218
- #: **deprecated**: use :attr:`~acoular.sources.TimeSamples.calib` property of
180
+ #: **deprecated, will be removed in version 25.01**: use :attr:`~acoular.sources.TimeSamples.calib` property of
219
181
  #: :class:`~acoular.sources.TimeSamples` objects
220
- calib = Instance(Calib)
182
+ calib = Property(desc='calibration object (deprecated, will be removed in version 25.01)')
183
+
184
+ _calib = Instance(Calib)
221
185
 
222
186
  # Shadow trait, should not be set directly, for internal use.
223
187
  _ind_low = Int(1, desc='index of lowest frequency line')
@@ -292,6 +256,18 @@ class PowerSpectra(BaseSpectra):
292
256
  # hdf5 cache file
293
257
  h5f = Instance(H5CacheFileBase, transient=True)
294
258
 
259
+ def _get_calib(self):
260
+ return self._calib
261
+
262
+ def _set_calib(self, calib):
263
+ msg = (
264
+ "Using 'calib' attribute is deprecated and will be removed in version 25.01. "
265
+ 'use :attr:`~acoular.sources.TimeSamples.calib` property of '
266
+ ':class:`~acoular.sources.TimeSamples` object instead.'
267
+ )
268
+ warn(msg, DeprecationWarning, stacklevel=2)
269
+ self._calib = calib
270
+
295
271
  @property_depends_on('_source.numsamples, block_size, overlap')
296
272
  def _get_num_blocks(self):
297
273
  return self.overlap_ * self._source.numsamples / self.block_size - self.overlap_ + 1
@@ -341,6 +317,11 @@ class PowerSpectra(BaseSpectra):
341
317
  self._ind_low = ind_low
342
318
 
343
319
  def _set_time_data(self, time_data):
320
+ msg = (
321
+ "Using 'time_data' attribute is deprecated and will be removed in version 25.01. "
322
+ "Use 'source' attribute instead."
323
+ )
324
+ warn(msg, DeprecationWarning, stacklevel=2)
344
325
  self._source = time_data
345
326
 
346
327
  def _set_source(self, source):
@@ -392,7 +373,7 @@ class PowerSpectra(BaseSpectra):
392
373
  else:
393
374
  raise ValueError('Calibration data not compatible: %i, %i' % (self.calib.num_mics, t.numchannels))
394
375
  # get time data blockwise
395
- for data in self.get_source_data():
376
+ for data in self._get_source_data():
396
377
  ft = fft.rfft(data * wind, None, 0).astype(self.precision)
397
378
  calcCSM(csm_upper, ft) # only upper triangular part of matrix is calculated (for speed reasons)
398
379
  # create the full csm matrix via transposing and complex conj.
@@ -594,7 +575,7 @@ def synthetic(data, freqs, f, num=3):
594
575
  each grid point (the sum of all values that are contained in the band).
595
576
  Note that the frequency resolution and therefore the bandwidth
596
577
  represented by a single frequency line depends on
597
- the :attr:`sampling frequency<acoular.tprocess.SamplesGenerator.sample_freq>`
578
+ the :attr:`sampling frequency<acoular.base.SamplesGenerator.sample_freq>`
598
579
  and used :attr:`FFT block size<acoular.spectra.PowerSpectra.block_size>`.
599
580
 
600
581
  """