acoular 25.7__py3-none-any.whl → 26.1__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/signals.py CHANGED
@@ -4,6 +4,12 @@
4
4
  """
5
5
  Implements signal generators for the simulation of acoustic sources.
6
6
 
7
+ .. inheritance-diagram::
8
+ acoular.signals
9
+ :top-classes:
10
+ acoular.signals.SignalGenerator
11
+ :parts: 1
12
+
7
13
  .. autosummary::
8
14
  :toctree: generated/
9
15
 
@@ -21,8 +27,7 @@ Implements signal generators for the simulation of acoustic sources.
21
27
  from abc import abstractmethod
22
28
  from warnings import warn
23
29
 
24
- from numpy import arange, array, log, pi, repeat, sin, sqrt, tile, zeros
25
- from numpy.random import RandomState
30
+ import numpy as np
26
31
  from scipy.signal import resample, sosfilt, tf2sos
27
32
  from traits.api import (
28
33
  ABCHasStrictTraits,
@@ -39,11 +44,9 @@ from traits.api import (
39
44
 
40
45
  # acoular imports
41
46
  from .base import SamplesGenerator
42
- from .deprecation import deprecated_alias
43
47
  from .internal import digest
44
48
 
45
49
 
46
- @deprecated_alias({'numsamples': 'num_samples'}, removal_version='25.10')
47
50
  class SignalGenerator(ABCHasStrictTraits):
48
51
  """
49
52
  ABC for a simple one-channel signal generator.
@@ -64,7 +67,7 @@ class SignalGenerator(ABCHasStrictTraits):
64
67
  """
65
68
 
66
69
  #: Sampling frequency of the signal in Hz. Default is ``1.0``.
67
- sample_freq = Float(1.0, desc='sampling frequency')
70
+ sample_freq = Float(1.0)
68
71
 
69
72
  #: The number of samples to generate for the signal.
70
73
  num_samples = CInt
@@ -138,10 +141,10 @@ class PeriodicSignalGenerator(SignalGenerator):
138
141
  """
139
142
 
140
143
  #: The frequency of the signal. Default is ``1000.0``.
141
- freq = Float(1000.0, desc='Frequency')
144
+ freq = Float(1000.0)
142
145
 
143
146
  #: The phase of the signal (in radians). Default is ``0.0``.
144
- phase = Float(0.0, desc='Phase')
147
+ phase = Float(0.0)
145
148
 
146
149
  #: The amplitude of the signal. Default is ``1.0``.
147
150
  amplitude = Float(1.0)
@@ -170,19 +173,19 @@ class NoiseGenerator(SignalGenerator):
170
173
 
171
174
  See Also
172
175
  --------
173
- :class:`acoular.signals.PNoiseGenerator` : For pink noise generation.
174
- :class:`acoular.signals.WNoiseGenerator` : For pink white generation.
175
- :class:`acoular.sources.UncorrelatedNoiseSource` : For per-channel noise generation.
176
+ :class:`~acoular.signals.PNoiseGenerator` : For pink noise generation.
177
+ :class:`~acoular.signals.WNoiseGenerator` : For white noise generation.
178
+ :class:`~acoular.sources.UncorrelatedNoiseSource` : For per-channel noise generation.
176
179
  """
177
180
 
178
181
  #: Root mean square (RMS) amplitude of the signal. For a point source,
179
182
  #: this corresponds to the RMS amplitude at a distance of 1 meter. Default is ``1.0``.
180
- rms = Float(1.0, desc='rms amplitude')
183
+ rms = Float(1.0)
181
184
 
182
185
  #: Seed for random number generator. Default is ``0``.
183
186
  #: This parameter should be set differently for different instances
184
187
  #: to guarantee statistically independent (non-correlated) outputs.
185
- seed = Int(0, desc='random seed value')
188
+ seed = Int(0)
186
189
 
187
190
  #: Internal identifier based on generator properties. (read-only)
188
191
  digest = Property(depends_on=['rms', 'seed', 'sample_freq', 'num_samples'])
@@ -211,8 +214,8 @@ class WNoiseGenerator(NoiseGenerator):
211
214
  --------
212
215
  :obj:`numpy.random.RandomState.standard_normal` :
213
216
  Used here to generate normally distributed noise.
214
- :class:`acoular.signals.PNoiseGenerator` : For pink noise generation.
215
- :class:`acoular.sources.UncorrelatedNoiseSource` : For per-channel noise generation.
217
+ :class:`~acoular.signals.PNoiseGenerator` : For pink noise generation.
218
+ :class:`~acoular.sources.UncorrelatedNoiseSource` : For per-channel noise generation.
216
219
 
217
220
  Examples
218
221
  --------
@@ -240,7 +243,7 @@ class WNoiseGenerator(NoiseGenerator):
240
243
  array([False, False, False])
241
244
  """
242
245
 
243
- # internal identifier
246
+ #: A unique identifier for the generator, based on its properties. (read-only)
244
247
  digest = Property(depends_on=['rms', 'seed', 'sample_freq', 'num_samples'])
245
248
 
246
249
  @cached_property
@@ -260,7 +263,7 @@ class WNoiseGenerator(NoiseGenerator):
260
263
  A 1D array of floats containing the generated white noise signal.
261
264
  The length of the array is equal to :attr:`~SignalGenerator.num_samples`.
262
265
  """
263
- rnd_gen = RandomState(self.seed)
266
+ rnd_gen = np.random.RandomState(self.seed)
264
267
  return self.rms * rnd_gen.standard_normal(self.num_samples)
265
268
 
266
269
 
@@ -278,8 +281,8 @@ class PNoiseGenerator(NoiseGenerator):
278
281
 
279
282
  See Also
280
283
  --------
281
- :class:`acoular.signals.WNoiseGenerator` : For white noise generation.
282
- :class:`acoular.sources.UncorrelatedNoiseSource` : For per-channel noise generation.
284
+ :class:`~acoular.signals.WNoiseGenerator` : For white noise generation.
285
+ :class:`~acoular.sources.UncorrelatedNoiseSource` : For per-channel noise generation.
283
286
 
284
287
  References
285
288
  ----------
@@ -291,7 +294,7 @@ class PNoiseGenerator(NoiseGenerator):
291
294
  #: of the :math:`1/f` spectrum at low frequencies but increase computation time. The maximum
292
295
  #: allowable value depends on the :attr:`number of samples<SignalGenerator.num_samples>`.
293
296
  #: Default is ``16``.
294
- depth = Int(16, desc='octave depth')
297
+ depth = Int(16)
295
298
 
296
299
  #: A unique checksum identifier based on the object properties. (read-only)
297
300
  digest = Property(depends_on=['rms', 'seed', 'sample_freq', 'num_samples', 'depth'])
@@ -320,26 +323,26 @@ class PNoiseGenerator(NoiseGenerator):
320
323
  simulation. If the specified depth exceeds the maximum possible value based on
321
324
  the number of samples, it is automatically adjusted, and a warning is printed.
322
325
  - The output signal is scaled to have the same overall level as white noise by dividing
323
- the result by ``sqrt(depth + 1.5)``.
326
+ the result by ``np.sqrt(depth + 1.5)``.
324
327
  """
325
328
  nums = self.num_samples
326
329
  depth = self.depth
327
330
  # maximum depth depending on number of samples
328
- max_depth = int(log(nums) / log(2))
331
+ max_depth = int(np.log(nums) / np.log(2))
329
332
 
330
333
  if depth > max_depth:
331
334
  depth = max_depth
332
335
  print(f'Pink noise filter depth set to maximum possible value of {max_depth:d}.')
333
336
 
334
- rnd_gen = RandomState(self.seed)
337
+ rnd_gen = np.random.RandomState(self.seed)
335
338
  s = rnd_gen.standard_normal(nums)
336
339
  for _ in range(depth):
337
340
  ind = 2**_ - 1
338
341
  lind = nums - ind
339
342
  dind = 2 ** (_ + 1)
340
- s[ind:] += repeat(rnd_gen.standard_normal(nums // dind + 1), dind)[:lind]
341
- # divide by sqrt(depth+1.5) to get same overall level as white noise
342
- return self.rms / sqrt(depth + 1.5) * s
343
+ s[ind:] += np.repeat(rnd_gen.standard_normal(nums // dind + 1), dind)[:lind]
344
+ # divide by np.sqrt(depth+1.5) to get same overall level as white noise
345
+ return self.rms / np.sqrt(depth + 1.5) * s
343
346
 
344
347
 
345
348
  class FiltWNoiseGenerator(WNoiseGenerator):
@@ -399,11 +402,11 @@ class FiltWNoiseGenerator(WNoiseGenerator):
399
402
 
400
403
  #: A :class:`numpy.ndarray` of autoregressive coefficients (denominator). Default is ``[]``,
401
404
  #: which results in no AR filtering (i.e., all-pole filter is ``[1.0]``).
402
- ar = CArray(value=array([]), dtype=float, desc='autoregressive coefficients (coefficients of the denominator)')
405
+ ar = CArray(value=np.array([]), dtype=float)
403
406
 
404
407
  #: A :class:`numpy.ndarray` of moving-average coefficients (numerator). Default is ``[]``,
405
408
  #: which results in no MA filtering (i.e., all-zero filter is ``[1.0]``).
406
- ma = CArray(value=array([]), dtype=float, desc='moving-average coefficients (coefficients of the numerator)')
409
+ ma = CArray(value=np.array([]), dtype=float)
407
410
 
408
411
  #: A unique checksum identifier based on the object properties. (read-only)
409
412
  digest = Property(depends_on=['rms', 'seed', 'sample_freq', 'num_samples', 'ar', 'ma'])
@@ -432,7 +435,7 @@ class FiltWNoiseGenerator(WNoiseGenerator):
432
435
  if the input array is empty.
433
436
  """
434
437
  if coefficients.size == 0:
435
- return array([1.0])
438
+ return np.array([1.0])
436
439
  return coefficients
437
440
 
438
441
  def signal(self):
@@ -450,7 +453,7 @@ class FiltWNoiseGenerator(WNoiseGenerator):
450
453
  An array representing the filtered white noise signal. The length of the returned array
451
454
  is equal to :attr:`the number of samples<SignalGenerator.num_samples>`.
452
455
  """
453
- rnd_gen = RandomState(self.seed)
456
+ rnd_gen = np.random.RandomState(self.seed)
454
457
  ma = self.handle_empty_coefficients(self.ma)
455
458
  ar = self.handle_empty_coefficients(self.ar)
456
459
  sos = tf2sos(ma, ar)
@@ -552,11 +555,10 @@ class SineGenerator(PeriodicSignalGenerator):
552
555
  The generator supports high-frequency and high-resolution signals,
553
556
  limited by the Nyquist criterion.
554
557
  """
555
- t = arange(self.num_samples, dtype=float) / self.sample_freq
556
- return self.amplitude * sin(2 * pi * self.freq * t + self.phase)
558
+ t = np.arange(self.num_samples, dtype=float) / self.sample_freq
559
+ return self.amplitude * np.sin(2 * np.pi * self.freq * t + self.phase)
557
560
 
558
561
 
559
- @deprecated_alias({'rms': 'amplitude'}, removal_version='25.10')
560
562
  class GenericSignalGenerator(SignalGenerator):
561
563
  """
562
564
  Generate signals from a :class:`~acoular.base.SamplesGenerator` or derived object.
@@ -648,7 +650,7 @@ class GenericSignalGenerator(SignalGenerator):
648
650
  stacklevel=2,
649
651
  )
650
652
  nums = self.num_samples
651
- track = zeros(nums)
653
+ track = np.zeros(nums)
652
654
 
653
655
  # iterate through source generator to fill signal track
654
656
  for i, temp in enumerate(self.source.result(block)):
@@ -665,7 +667,7 @@ class GenericSignalGenerator(SignalGenerator):
665
667
  # fill up empty track with as many full source signals as possible
666
668
  nloops = nums // stop
667
669
  if nloops > 1:
668
- track[stop : stop * nloops] = tile(track[:stop], nloops - 1)
670
+ track[stop : stop * nloops] = np.tile(track[:stop], nloops - 1)
669
671
  # fill up remaining empty track
670
672
  res = nums % stop # last part of unfinished loop
671
673
  if res > 0: