acoular 25.7__py3-none-any.whl → 25.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/tools/helpers.py CHANGED
@@ -17,17 +17,7 @@
17
17
  from pathlib import Path
18
18
  from warnings import warn
19
19
 
20
- from numpy import (
21
- array,
22
- concatenate,
23
- isscalar,
24
- newaxis,
25
- searchsorted,
26
- sum, # noqa A004
27
- where,
28
- zeros_like,
29
- )
30
- from numpy.ma import masked_where
20
+ import numpy as np
31
21
 
32
22
  from acoular.tools.utils import mole_fraction_of_water_vapor
33
23
 
@@ -79,20 +69,20 @@ def synthetic(data, freqs, f, num=3):
79
69
  and used :attr:`FFT block size<acoular.spectra.PowerSpectra.block_size>`.
80
70
 
81
71
  """
82
- if isscalar(f):
72
+ if np.isscalar(f):
83
73
  f = (f,)
84
74
  if num == 0:
85
75
  # single frequency lines
86
76
  res = []
87
77
  for i in f:
88
- ind = searchsorted(freqs, i)
78
+ ind = np.searchsorted(freqs, i)
89
79
  if ind >= len(freqs):
90
80
  warn(
91
81
  f'Queried frequency ({i:g} Hz) not in resolved frequency range. Returning zeros.',
92
82
  Warning,
93
83
  stacklevel=2,
94
84
  )
95
- h = zeros_like(data[0])
85
+ h = np.zeros_like(data[0])
96
86
  else:
97
87
  if freqs[ind] != i:
98
88
  warn(
@@ -110,8 +100,8 @@ def synthetic(data, freqs, f, num=3):
110
100
  for i in f:
111
101
  f1 = i * 2.0 ** (-0.5 / num)
112
102
  f2 = i * 2.0 ** (+0.5 / num)
113
- ind1 = searchsorted(freqs, f1)
114
- ind2 = searchsorted(freqs, f2)
103
+ ind1 = np.searchsorted(freqs, f1)
104
+ ind2 = np.searchsorted(freqs, f2)
115
105
  if ind1 == ind2:
116
106
  warn(
117
107
  f'Queried frequency band ({f1:g} to {f2:g} Hz) does not '
@@ -120,11 +110,11 @@ def synthetic(data, freqs, f, num=3):
120
110
  Warning,
121
111
  stacklevel=2,
122
112
  )
123
- h = zeros_like(data[0])
113
+ h = np.zeros_like(data[0])
124
114
  else:
125
- h = sum(data[ind1:ind2], 0)
115
+ h = np.sum(data[ind1:ind2], 0)
126
116
  res += [h]
127
- return array(res)
117
+ return np.array(res)
128
118
 
129
119
 
130
120
  def return_result(source, nmax=-1, num=128):
@@ -154,8 +144,8 @@ def return_result(source, nmax=-1, num=128):
154
144
 
155
145
  if nmax > 0:
156
146
  nblocks = (nmax - 1) // num + 1
157
- return concatenate([res for _, res in zip(range(nblocks), resulter)])[:nmax]
158
- return concatenate(list(resulter))
147
+ return np.concatenate([res for _, res in zip(range(nblocks), resulter)])[:nmax]
148
+ return np.concatenate(list(resulter))
159
149
 
160
150
 
161
151
  def barspectrum(data, fftfreqs, num=3, bar=True, xoffset=0.0):
@@ -203,9 +193,9 @@ def barspectrum(data, fftfreqs, num=3, bar=True, xoffset=0.0):
203
193
  return (0, 0, 0)
204
194
 
205
195
  # preferred center freqs after din en iso 266 for third-octave bands
206
- fcbase = array([31.5, 40, 50, 63, 80, 100, 125, 160, 200, 250])
196
+ fcbase = np.array([31.5, 40, 50, 63, 80, 100, 125, 160, 200, 250])
207
197
  # DIN band center frequencies from 31.5 Hz to 25 kHz
208
- fc = concatenate((fcbase, fcbase * 10.0, fcbase[:] * 100.0))[:: (3 // num)]
198
+ fc = np.concatenate((fcbase, fcbase * 10.0, fcbase[:] * 100.0))[:: (3 // num)]
209
199
 
210
200
  # exponent for band width calculation
211
201
  ep = 1.0 / (2.0 * num)
@@ -215,16 +205,16 @@ def barspectrum(data, fftfreqs, num=3, bar=True, xoffset=0.0):
215
205
  f_low = fftfreqs[1] * 2**ep
216
206
  f_high = fftfreqs[-1] * 2**-ep
217
207
  # get possible index range
218
- i_low = 0 if fc[0] >= f_low else where(fc < f_low)[0][-1]
208
+ i_low = 0 if fc[0] >= f_low else np.where(fc < f_low)[0][-1]
219
209
 
220
- i_high = fc.shape[0] if fc[-1] <= f_high else where(fc > f_high)[0][0]
210
+ i_high = fc.shape[0] if fc[-1] <= f_high else np.where(fc > f_high)[0][0]
221
211
 
222
212
  # synthesize sound pressure values
223
- p = array([synthetic(data, fftfreqs, list(fc[i_low:i_high]), num)])
213
+ p = np.array([synthetic(data, fftfreqs, list(fc[i_low:i_high]), num)])
224
214
 
225
215
  if bar:
226
216
  # upper and lower band borders
227
- flu = concatenate(
217
+ flu = np.concatenate(
228
218
  (
229
219
  fc[i_low : i_low + 1] * 2**-ep,
230
220
  (fc[i_low : i_high - 1] * 2**ep + fc[i_low + 1 : i_high] * 2**-ep) / 2.0,
@@ -232,9 +222,9 @@ def barspectrum(data, fftfreqs, num=3, bar=True, xoffset=0.0):
232
222
  ),
233
223
  )
234
224
  # band borders as coordinates for bar plotting
235
- flulist = 2 ** (2 * xoffset * ep) * (array([1, 1])[:, newaxis] * flu[newaxis, :]).T.reshape(-1)[1:-1]
225
+ flulist = 2 ** (2 * xoffset * ep) * (np.array([1, 1])[:, np.newaxis] * flu[np.newaxis, :]).T.reshape(-1)[1:-1]
236
226
  # sound pressures as list for bar plotting
237
- plist = (array([1, 1])[:, newaxis] * p[newaxis, :]).T.reshape(-1)
227
+ plist = (np.array([1, 1])[:, np.newaxis] * p[np.newaxis, :]).T.reshape(-1)
238
228
  else:
239
229
  flulist = fc[i_low:i_high]
240
230
  plist = p[0, :]
@@ -280,17 +270,19 @@ def bardata(data, fc, num=3, bar=True, xoffset=0.0, masked=-360):
280
270
 
281
271
  if bar:
282
272
  # upper and lower band borders
283
- flu = concatenate((fc[:1] * 2**-ep, (fc[:-1] * 2**ep + fc[1:] * 2**-ep) / 2.0, fc[-1:] * 2**ep))
273
+ flu = np.concatenate((fc[:1] * 2**-ep, (fc[:-1] * 2**ep + fc[1:] * 2**-ep) / 2.0, fc[-1:] * 2**ep))
284
274
  # band borders as coordinates for bar plotting
285
- flulist = 2 ** (xoffset * 1.0 / num) * (array([1, 1])[:, newaxis] * flu[newaxis, :]).T.reshape(-1)[1:-1]
275
+ flulist = (
276
+ 2 ** (xoffset * 1.0 / num) * (np.array([1, 1])[:, np.newaxis] * flu[np.newaxis, :]).T.reshape(-1)[1:-1]
277
+ )
286
278
  # sound pressures as list for bar plotting
287
- plist = (array([1, 1])[:, newaxis] * data[newaxis, :]).T.reshape(-1)
279
+ plist = (np.array([1, 1])[:, np.newaxis] * data[np.newaxis, :]).T.reshape(-1)
288
280
  else:
289
281
  flulist = fc
290
282
  plist = data
291
283
  # print(flulist.shape, plist.shape)
292
284
  if masked > -360:
293
- plist = masked_where(plist <= masked, plist)
285
+ plist = np.ma.masked_where(plist <= masked, plist)
294
286
  return (flulist, plist)
295
287
 
296
288
 
acoular/tools/metrics.py CHANGED
@@ -11,12 +11,7 @@
11
11
 
12
12
  from copy import copy
13
13
 
14
- from numpy import (
15
- empty,
16
- inf,
17
- minimum,
18
- ones,
19
- )
14
+ import numpy as np
20
15
  from scipy.spatial.distance import cdist
21
16
  from traits.api import Bool, CArray, HasStrictTraits, Instance, Property
22
17
 
@@ -82,13 +77,13 @@ class MetricEvaluator(HasStrictTraits):
82
77
 
83
78
  def _get_sector_radii(self):
84
79
  ns = self.target_data.shape[1]
85
- radii = ones(ns) * self.sector.r
80
+ radii = np.ones(ns) * self.sector.r
86
81
  if self.adaptive_sector_size:
87
82
  locs = self.target_grid.pos.T
88
83
  intersrcdist = cdist(locs, locs)
89
- intersrcdist[intersrcdist == 0] = inf
84
+ intersrcdist[intersrcdist == 0] = np.inf
90
85
  intersrcdist = intersrcdist.min(0) / 2
91
- radii = minimum(radii, intersrcdist)
86
+ radii = np.minimum(radii, intersrcdist)
92
87
  return radii
93
88
 
94
89
  def _get_sectors(self):
@@ -115,7 +110,7 @@ class MetricEvaluator(HasStrictTraits):
115
110
 
116
111
  """
117
112
  sectors = self.sectors
118
- results = empty(shape=self.target_data.shape)
113
+ results = np.empty(shape=self.target_data.shape)
119
114
  for f in range(self.target_data.shape[0]):
120
115
  data = self.data[f]
121
116
  for i in range(self.target_data.shape[1]):