acoular 24.3__py3-none-any.whl → 24.7__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.
Files changed (139) hide show
  1. acoular/__init__.py +119 -54
  2. acoular/calib.py +29 -38
  3. acoular/configuration.py +132 -82
  4. acoular/demo/__init__.py +10 -4
  5. acoular/demo/acoular_demo.py +73 -55
  6. acoular/environments.py +270 -264
  7. acoular/fastFuncs.py +366 -196
  8. acoular/fbeamform.py +1797 -1934
  9. acoular/grids.py +504 -548
  10. acoular/h5cache.py +74 -83
  11. acoular/h5files.py +159 -142
  12. acoular/internal.py +13 -14
  13. acoular/microphones.py +57 -53
  14. acoular/sdinput.py +57 -53
  15. acoular/signals.py +180 -178
  16. acoular/sources.py +920 -724
  17. acoular/spectra.py +353 -363
  18. acoular/tbeamform.py +416 -416
  19. acoular/tfastfuncs.py +180 -104
  20. acoular/tools/__init__.py +25 -0
  21. acoular/tools/aiaa.py +185 -0
  22. acoular/tools/helpers.py +189 -0
  23. acoular/tools/metrics.py +165 -0
  24. acoular/tprocess.py +1240 -1182
  25. acoular/traitsviews.py +513 -501
  26. acoular/trajectory.py +50 -52
  27. acoular/version.py +5 -6
  28. acoular/xml/minidsp_uma-16.xml +20 -0
  29. acoular/xml/{minidsp_uma16.xml → minidsp_uma-16_mirrored.xml} +3 -0
  30. {acoular-24.3.dist-info → acoular-24.7.dist-info}/METADATA +58 -39
  31. acoular-24.7.dist-info/RECORD +50 -0
  32. {acoular-24.3.dist-info → acoular-24.7.dist-info}/WHEEL +1 -1
  33. acoular-24.7.dist-info/licenses/LICENSE +28 -0
  34. acoular/fileimport.py +0 -380
  35. acoular/nidaqimport.py +0 -273
  36. acoular/tests/reference_data/BeamformerBase.npy +0 -0
  37. acoular/tests/reference_data/BeamformerBaseFalse1.npy +0 -0
  38. acoular/tests/reference_data/BeamformerBaseFalse2.npy +0 -0
  39. acoular/tests/reference_data/BeamformerBaseFalse3.npy +0 -0
  40. acoular/tests/reference_data/BeamformerBaseFalse4.npy +0 -0
  41. acoular/tests/reference_data/BeamformerBaseTrue1.npy +0 -0
  42. acoular/tests/reference_data/BeamformerBaseTrue2.npy +0 -0
  43. acoular/tests/reference_data/BeamformerBaseTrue3.npy +0 -0
  44. acoular/tests/reference_data/BeamformerBaseTrue4.npy +0 -0
  45. acoular/tests/reference_data/BeamformerCMFLassoLarsBIC.npy +0 -0
  46. acoular/tests/reference_data/BeamformerCMFNNLS.npy +0 -0
  47. acoular/tests/reference_data/BeamformerCapon.npy +0 -0
  48. acoular/tests/reference_data/BeamformerClean.npy +0 -0
  49. acoular/tests/reference_data/BeamformerCleansc.npy +0 -0
  50. acoular/tests/reference_data/BeamformerCleant.npy +0 -0
  51. acoular/tests/reference_data/BeamformerCleantSq.npy +0 -0
  52. acoular/tests/reference_data/BeamformerCleantSqTraj.npy +0 -0
  53. acoular/tests/reference_data/BeamformerCleantTraj.npy +0 -0
  54. acoular/tests/reference_data/BeamformerDamas.npy +0 -0
  55. acoular/tests/reference_data/BeamformerDamasPlus.npy +0 -0
  56. acoular/tests/reference_data/BeamformerEig.npy +0 -0
  57. acoular/tests/reference_data/BeamformerEigFalse1.npy +0 -0
  58. acoular/tests/reference_data/BeamformerEigFalse2.npy +0 -0
  59. acoular/tests/reference_data/BeamformerEigFalse3.npy +0 -0
  60. acoular/tests/reference_data/BeamformerEigFalse4.npy +0 -0
  61. acoular/tests/reference_data/BeamformerEigTrue1.npy +0 -0
  62. acoular/tests/reference_data/BeamformerEigTrue2.npy +0 -0
  63. acoular/tests/reference_data/BeamformerEigTrue3.npy +0 -0
  64. acoular/tests/reference_data/BeamformerEigTrue4.npy +0 -0
  65. acoular/tests/reference_data/BeamformerFunctional.npy +0 -0
  66. acoular/tests/reference_data/BeamformerGIB.npy +0 -0
  67. acoular/tests/reference_data/BeamformerGridlessOrth.npy +0 -0
  68. acoular/tests/reference_data/BeamformerMusic.npy +0 -0
  69. acoular/tests/reference_data/BeamformerOrth.npy +0 -0
  70. acoular/tests/reference_data/BeamformerSODIX.npy +0 -0
  71. acoular/tests/reference_data/BeamformerTime.npy +0 -0
  72. acoular/tests/reference_data/BeamformerTimeSq.npy +0 -0
  73. acoular/tests/reference_data/BeamformerTimeSqTraj.npy +0 -0
  74. acoular/tests/reference_data/BeamformerTimeTraj.npy +0 -0
  75. acoular/tests/reference_data/Environment.npy +0 -0
  76. acoular/tests/reference_data/Example1_numerical_values_testsum.h5 +0 -0
  77. acoular/tests/reference_data/FiltFiltOctave__.npy +0 -0
  78. acoular/tests/reference_data/FiltFiltOctave_band_100_0_fraction_Thirdoctave_.npy +0 -0
  79. acoular/tests/reference_data/FiltFreqWeight_weight_A_.npy +0 -0
  80. acoular/tests/reference_data/FiltFreqWeight_weight_C_.npy +0 -0
  81. acoular/tests/reference_data/FiltFreqWeight_weight_Z_.npy +0 -0
  82. acoular/tests/reference_data/FiltOctave__.npy +0 -0
  83. acoular/tests/reference_data/FiltOctave_band_100_0_fraction_Thirdoctave_.npy +0 -0
  84. acoular/tests/reference_data/Filter__.npy +0 -0
  85. acoular/tests/reference_data/GeneralFlowEnvironment.npy +0 -0
  86. acoular/tests/reference_data/OctaveFilterBank__.npy +0 -0
  87. acoular/tests/reference_data/OpenJet.npy +0 -0
  88. acoular/tests/reference_data/PointSource.npy +0 -0
  89. acoular/tests/reference_data/PowerSpectra_csm.npy +0 -0
  90. acoular/tests/reference_data/PowerSpectra_ev.npy +0 -0
  91. acoular/tests/reference_data/RotatingFlow.npy +0 -0
  92. acoular/tests/reference_data/SlotJet.npy +0 -0
  93. acoular/tests/reference_data/TimeAverage__.npy +0 -0
  94. acoular/tests/reference_data/TimeCumAverage__.npy +0 -0
  95. acoular/tests/reference_data/TimeExpAverage_weight_F_.npy +0 -0
  96. acoular/tests/reference_data/TimeExpAverage_weight_I_.npy +0 -0
  97. acoular/tests/reference_data/TimeExpAverage_weight_S_.npy +0 -0
  98. acoular/tests/reference_data/TimeInOut__.npy +0 -0
  99. acoular/tests/reference_data/TimePower__.npy +0 -0
  100. acoular/tests/reference_data/TimeReverse__.npy +0 -0
  101. acoular/tests/reference_data/UniformFlowEnvironment.npy +0 -0
  102. acoular/tests/reference_data/beamformer_traj_time_data.h5 +0 -0
  103. acoular/tests/run_tests.sh +0 -18
  104. acoular/tests/run_tests_osx.sh +0 -16
  105. acoular/tests/test.npy +0 -0
  106. acoular/tests/test_beamformer_results.py +0 -213
  107. acoular/tests/test_classes.py +0 -60
  108. acoular/tests/test_digest.py +0 -125
  109. acoular/tests/test_environments.py +0 -73
  110. acoular/tests/test_example1.py +0 -124
  111. acoular/tests/test_grid.py +0 -92
  112. acoular/tests/test_integrate.py +0 -102
  113. acoular/tests/test_signals.py +0 -60
  114. acoular/tests/test_sources.py +0 -65
  115. acoular/tests/test_spectra.py +0 -38
  116. acoular/tests/test_timecache.py +0 -35
  117. acoular/tests/test_tprocess.py +0 -90
  118. acoular/tests/test_traj_beamformer_results.py +0 -164
  119. acoular/tests/unsupported/SpeedComparison/OvernightTestcasesBeamformer_nMics32_nGridPoints100_nFreqs4_nTrials10.png +0 -0
  120. acoular/tests/unsupported/SpeedComparison/cythonBeamformer.pyx +0 -237
  121. acoular/tests/unsupported/SpeedComparison/mainForCython.py +0 -103
  122. acoular/tests/unsupported/SpeedComparison/mainForParallelJit.py +0 -143
  123. acoular/tests/unsupported/SpeedComparison/setupCythonOpenMP.py +0 -63
  124. acoular/tests/unsupported/SpeedComparison/sharedFunctions.py +0 -153
  125. acoular/tests/unsupported/SpeedComparison/timeOverNMics_AllImportantMethods.png +0 -0
  126. acoular/tests/unsupported/SpeedComparison/timeOverNMics_faverage.png +0 -0
  127. acoular/tests/unsupported/SpeedComparison/vglOptimierungFAverage.py +0 -204
  128. acoular/tests/unsupported/SpeedComparison/vglOptimierungGaussSeidel.py +0 -182
  129. acoular/tests/unsupported/SpeedComparison/vglOptimierungR_BEAMFULL_INVERSE.py +0 -764
  130. acoular/tests/unsupported/SpeedComparison/vglOptimierungR_BEAM_OS.py +0 -231
  131. acoular/tests/unsupported/SpeedComparison/whatsFastestWayFor_absASquared.py +0 -48
  132. acoular/tests/unsupported/functionalBeamformer.py +0 -123
  133. acoular/tests/unsupported/precisionTest.py +0 -153
  134. acoular/tests/unsupported/validationOfBeamformerFuncsPOSTAcoularIntegration.py +0 -254
  135. acoular/tests/unsupported/validationOfBeamformerFuncsPREeAcoularIntegration.py +0 -531
  136. acoular/tools.py +0 -422
  137. acoular-24.3.dist-info/RECORD +0 -148
  138. acoular-24.3.dist-info/licenses/LICENSE +0 -29
  139. {acoular-24.3.dist-info → acoular-24.7.dist-info}/licenses/AUTHORS.rst +0 -0
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Created on Thu Jan 24 09:58:04 2019
5
-
6
- @author: newuser
7
- """
8
- #standard testing suite from python
9
- import unittest
10
-
11
- #acoular imports
12
- import acoular
13
-
14
- from acoular import L_p, Calib, MicGeom, PowerSpectra, Environment, \
15
- RectGrid, BeamformerBase, BeamformerEig, BeamformerOrth, BeamformerCleansc, \
16
- MaskedTimeSamples, FiltFiltOctave, BeamformerTimeSq, TimeAverage, \
17
- TimeCache, BeamformerTime, TimePower, BeamformerCMF, \
18
- BeamformerCapon, BeamformerMusic, BeamformerDamas, BeamformerClean, \
19
- BeamformerFunctional, BeamformerDamasPlus, BeamformerGIB, SteeringVector
20
-
21
- from numpy import zeros, empty
22
- from os import path
23
- import tables
24
-
25
- #load numerical values from Examples
26
- h5file_num = tables.open_file('reference_data/Example1_numerical_values_testsum.h5', 'r')
27
-
28
- mpos_num = h5file_num.get_node('/mpos_values').read()
29
- grid_pos_num = h5file_num.get_node('/grid_pos_values').read()
30
- transfer_num = h5file_num.get_node('/transfer_values').read()
31
- csm_num = h5file_num.get_node('/csm_values').read()
32
- eve_num = h5file_num.get_node('/eva_values').read()
33
- eva_num = h5file_num.get_node('/eve_values').read()
34
-
35
- d={}
36
- for b in ('bb', 'bc', 'be', 'bm', 'bl', 'bo', 'bs', 'bd', 'bcmf', 'bf', 'bdp', 'bgib'):
37
- d[b+'num'] = h5file_num.get_node('/'+str(b)+'_values').read()
38
-
39
-
40
- #load exampledata
41
- datafile = '../../examples/example_data.h5'
42
- calibfile = '../../examples/example_calib.xml'
43
- micgeofile = path.join( path.split(acoular.__file__)[0],'xml','array_56.xml')
44
-
45
- #calc all values from example 1
46
- cfreq = 4000
47
- t1 = MaskedTimeSamples(name= datafile)
48
- t1.start = 0 # first sample, default
49
- t1.stop = 16000 # last valid sample = 15999
50
- invalid = [1,7] # list of invalid channels (unwanted microphones etc.)
51
- t1.invalid_channels = invalid
52
- t1.calib = Calib(from_file=calibfile)
53
- m = MicGeom(from_file=micgeofile)
54
- m.invalid_channels = invalid
55
-
56
- g = RectGrid(x_min=-0.6, x_max=-0.0, y_min=-0.3, y_max=0.3, z=0.68,
57
- increment=0.05 )
58
-
59
- env=Environment(c=346.04)
60
-
61
- st = SteeringVector(grid=g, mics=m, env=env)
62
-
63
- f = PowerSpectra(time_data=t1,
64
- window='Hanning', overlap='50%', block_size=128, #FFT-parameters
65
- cached = False ) #cached = False
66
-
67
-
68
- bb = BeamformerBase(freq_data=f, steer=st, r_diag=True, cached = False)
69
- bc = BeamformerCapon(freq_data=f, steer=st, cached=False)
70
- be = BeamformerEig(freq_data=f, steer=st, r_diag=True, n=54, cached = False)
71
- bm = BeamformerMusic(freq_data=f, steer=st, n=6, cached = False)
72
- bd = BeamformerDamas(beamformer=bb, n_iter=100, cached = False)
73
- bdp = BeamformerDamasPlus(beamformer=bb, n_iter=100, cached = False)
74
- bo = BeamformerOrth(beamformer=be, eva_list=list(range(38,54)), cached = False)
75
- bs = BeamformerCleansc(freq_data=f, steer=st, r_diag=True, cached = False)
76
- bcmf = BeamformerCMF(freq_data=f, steer=st, method='LassoLarsBIC', cached = False)
77
- bl = BeamformerClean(beamformer=bb, n_iter=100, cached = False)
78
- bf = BeamformerFunctional(freq_data=f, steer=st, r_diag=False, gamma=4, cached = False)
79
- bgib = BeamformerGIB(freq_data=f, steer=st, method= 'LassoLars', n=10, cached = False)
80
-
81
- class acoular_test(unittest.TestCase):
82
-
83
- #test if microfon positions are correct
84
- def test_mic_positions(self):
85
- self.assertAlmostEqual(m.mpos.sum()/mpos_num.sum(),1,3)
86
-
87
- #test if grid points are correct
88
- def test_grid_positions(self):
89
- self.assertAlmostEqual(g.gpos.sum()/grid_pos_num.sum(),1,3)
90
-
91
- #test steering vector calculation
92
- def test_steering(self):
93
- ind=0
94
- checktrans=0
95
- for freq in f.fftfreq()[1:-1]:
96
- checktrans=checktrans+st.transfer(freq)
97
- ind+=1
98
- self.assertAlmostEqual(checktrans.sum()/transfer_num.sum(),1,3)
99
-
100
- #test if csm values are correct
101
- @unittest.skip
102
- def test_csm_calculation(self):
103
- self.assertAlmostEqual(f.csm[:].sum()/csm_num.sum(),1,3)
104
-
105
- #test eve/eva
106
- @unittest.skip
107
- def test_eigenvalue_calculation(self):
108
- self.assertAlmostEqual(f.eva[:].sum()/eve_num.sum(),1,3)
109
- print(f.eve[:].sum(),eva_num)
110
- self.assertAlmostEqual(f.eve[:].sum()/eva_num.sum(),1,3)
111
-
112
- #test beamformer results
113
- @unittest.skip
114
- def test_beamformer_calculation(self):
115
- for beam,bfname in zip((bb, bc, be, bm, bl, bo, bs, bd, bcmf, bf, bdp, bgib),('bb', 'bc', 'be', 'bm', 'bl', 'bo', 'bs', 'bd', 'bcmf', 'bf', 'bdp', 'bgib')):
116
- with self.subTest(bfname):
117
- self.assertAlmostEqual(beam.synthetic(cfreq,1).sum()/d[bfname+'num'].sum(),1,3)
118
-
119
- if "__main__" == __name__:
120
- unittest.main() #exit=False
121
-
122
-
123
-
124
-
@@ -1,92 +0,0 @@
1
- import unittest
2
- import acoular as ac
3
- from copy import deepcopy
4
- class GridTest(unittest.TestCase):
5
-
6
- @staticmethod
7
- def get_sector_classes():
8
- # for later testing condition: sector only includes (0,0,1) point
9
- sectors = [
10
- ac.CircSector(x=0,y=0,r=0.2),
11
- ac.RectSector(x_min=-0.2,x_max=0.2,y_min=-0.2,y_max=0.2),
12
- ac.RectSector3D(x_min=-0.2,x_max=0.2,y_min=-0.2,y_max=0.2,z_min=1,z_max=1),
13
- ac.PolySector(edges=[0.2,0.2,-0.2,0.2,-0.2,-0.2,0.2,-0.2]),
14
- ac.ConvexSector(edges=[0.2,0.2,-0.2,0.2,-0.2,-0.2,0.2,-0.2]),
15
- ]
16
- multi_sector = ac.MultiSector(sectors=deepcopy(sectors))
17
- return sectors + [multi_sector]
18
-
19
- @staticmethod
20
- def get_emtpy_sector_classes():
21
- # for later testing condition: sector should not cover any grid point
22
- off = 10
23
- sectors = [
24
- ac.CircSector(x=off,y=off,r=0.2, include_border=False, default_nearest=False),
25
- ac.RectSector(
26
- x_min=-0.2+off,x_max=0.2+off,y_min=-0.2+off,y_max=0.2+off,
27
- include_border=False, default_nearest=False),
28
- ac.RectSector3D(
29
- x_min=-0.2+off,x_max=0.2+off,y_min=-0.2+off,y_max=0.2+off,z_min=1+off,z_max=1+off,
30
- include_border=False, default_nearest=False),
31
- ac.PolySector(
32
- edges=[0.2+off,0.2+off,-0.2+off,0.2+off,-0.2+off,-0.2+off,0.2+off,-0.2+off],
33
- include_border=False, default_nearest=False),
34
- ac.ConvexSector(
35
- edges=[0.2+off,0.2+off,-0.2+off,0.2+off,-0.2+off,-0.2+off,0.2+off,-0.2+off],
36
- include_border=False, default_nearest=False)]
37
- multi_sector = ac.MultiSector(
38
- sectors=deepcopy(sectors))
39
- return sectors + [multi_sector]
40
-
41
- @staticmethod
42
- def get_rectgrid():
43
- return ac.RectGrid(x_min=-1,x_max=1,y_min=-1,y_max=1,z=1,increment=1)
44
-
45
- @staticmethod
46
- def get_rectgrid3D():
47
- return ac.RectGrid3D(x_min=-1,x_max=1,y_min=-1,y_max=1,z_min=1, z_max=1,increment=1)
48
-
49
- @staticmethod
50
- def get_linegrid():
51
- return ac.LineGrid(loc=(-1,0,1), length=2, numpoints=3)
52
-
53
- @staticmethod
54
- def get_importgrid():
55
- return ac.ImportGrid(gpos_file=GridTest.get_rectgrid().gpos)
56
-
57
- @staticmethod
58
- def get_mergegrid():
59
- return ac.MergeGrid(grids=[GridTest.get_rectgrid(), GridTest.get_linegrid()])
60
-
61
- @staticmethod
62
- def get_all_grids():
63
- for grid in [GridTest.get_rectgrid, GridTest.get_rectgrid3D,
64
- GridTest.get_linegrid, GridTest.get_importgrid, GridTest.get_mergegrid]:
65
- yield grid()
66
-
67
- def test_size(self):
68
- for grid in self.get_all_grids():
69
- with self.subTest(grid.__class__.__name__):
70
- self.assertEqual(grid.size, grid.gpos.shape[-1])
71
-
72
- def test_existing_subdomain(self):
73
- for grid in self.get_all_grids():
74
- for sector in self.get_sector_classes():
75
- with self.subTest(f"Grid: {grid.__class__.__name__} Sector:{sector.__class__.__name__}"):
76
- indices = grid.subdomain(sector)
77
- self.assertEqual(indices[0].shape[0], 1)
78
-
79
- def test_empty_subdomain(self):
80
- for grid in self.get_all_grids():
81
- for sector in self.get_emtpy_sector_classes():
82
- with self.subTest(f"Grid: {grid.__class__.__name__} Sector:{sector.__class__.__name__}"):
83
- indices = grid.subdomain(sector)
84
- self.assertEqual(indices[0].shape[0], 0)
85
- if hasattr(sector, 'default_nearest'):
86
- sector.default_nearest = True
87
- indices = grid.subdomain(sector)
88
- self.assertEqual(indices[0].shape[0], 1)
89
-
90
-
91
- if __name__ == "__main__":
92
- unittest.main()
@@ -1,102 +0,0 @@
1
- import unittest
2
- import acoular as ac
3
- ac.config.global_caching = "none"
4
- import numpy as np
5
- from test_grid import GridTest
6
- from functools import partial
7
-
8
- class TestIntegrate(unittest.TestCase):
9
-
10
- f = [1000,2000]
11
-
12
- @staticmethod
13
- def get_sector_args():
14
- # for later testing condition: sector only includes (0,0,1) point
15
- return {'RectGrid': np.array([0,0,0.2]),
16
- 'RectGrid3D' : np.array([0,0,1,0,0,1]),}
17
-
18
- def get_beamformer(self, grid):
19
- rng1 = np.random.RandomState(1)
20
- src_pos = np.array([[0],[0],[1]])
21
- mics = ac.MicGeom(mpos_tot=rng1.normal(size=3*5).reshape((3,5)))
22
- steer = ac.SteeringVector(
23
- grid=ac.ImportGrid(
24
- gpos_file=src_pos),
25
- mics=mics)
26
- H = np.empty((len(self.f),mics.num_mics, 1),dtype=complex)
27
- for i,_f in enumerate(self.f): # calculate only the indices that are needed
28
- H[i] = steer.transfer(_f).T # transfer functions
29
- csm = H@H.swapaxes(2,1).conjugate()
30
- freq_data = ac.PowerSpectraImport(csm = csm, frequencies=self.f)
31
- steer.grid = grid
32
- return ac.BeamformerBase(freq_data=freq_data, steer=steer)
33
-
34
- def test_sector_class_integration_functional(self):
35
- for sector in GridTest.get_sector_classes():
36
- for grid in GridTest.get_all_grids():
37
- bf = self.get_beamformer(grid)
38
- with self.subTest(
39
- f"Grid: {grid.__class__.__name__} Sector: {sector.__class__.__name__}"):
40
- for i,f in enumerate(self.f):
41
- bf_res = bf.synthetic(f)
42
- bf_max = bf_res.max()
43
- integration_res = ac.integrate(
44
- data=bf_res,sector=sector,grid=grid)
45
- self.assertEqual(integration_res.shape, ())
46
- self.assertEqual(integration_res, bf_max)
47
-
48
- def test_sector_class_integration_class(self):
49
- for sector in GridTest.get_sector_classes():
50
- for grid in GridTest.get_all_grids():
51
- bf = self.get_beamformer(grid)
52
- with self.subTest(
53
- f"Grid: {grid.__class__.__name__} Sector:{sector.__class__.__name__}"):
54
- for i,f in enumerate(self.f):
55
- bf_res = bf.synthetic(f)
56
- bf_max = bf_res.max()
57
- integration_res = bf.integrate(sector)
58
- self.assertEqual(integration_res.shape, (len(self.f),))
59
- self.assertEqual(integration_res[i], bf_max)
60
-
61
- def test_sector_args_integration_functional(self):
62
- for grid in GridTest.get_all_grids():
63
- bf = self.get_beamformer(grid)
64
- with self.subTest(
65
- f"Grid: {grid.__class__.__name__}"):
66
- for i,f in enumerate(self.f):
67
- sector = self.get_sector_args().get(grid.__class__.__name__)
68
- bf_res = bf.synthetic(f)
69
- bf_max = bf_res.max()
70
- if sector is None: # not allowed grid for simple sector args
71
- sector = np.array([0,0,0.2]) # some random circ sector arguments
72
- integrate = partial(
73
- ac.integrate, data=bf_res, grid=grid, sector=sector)
74
- self.assertRaises(NotImplementedError, integrate)
75
- else:
76
- integration_res = ac.integrate(
77
- data=bf_res,sector=sector,grid=grid)
78
- self.assertEqual(integration_res.shape, ())
79
- self.assertEqual(integration_res, bf_max)
80
-
81
- def test_sector_args_integration_class(self):
82
- for grid in GridTest.get_all_grids():
83
- bf = self.get_beamformer(grid)
84
- with self.subTest(
85
- f"Grid: {grid.__class__.__name__}"):
86
- for i,f in enumerate(self.f):
87
- sector = self.get_sector_args().get(grid.__class__.__name__)
88
- bf_res = bf.synthetic(f)
89
- bf_max = bf_res.max()
90
- if sector is None: # not allowed grid for simple sector args
91
- sector = np.array([0,0,0.2]) # some random circ sector arguments
92
- integrate = partial(
93
- bf.integrate, sector=sector)
94
- self.assertRaises(NotImplementedError, integrate)
95
- else:
96
- integration_res = bf.integrate(sector)
97
- self.assertEqual(integration_res.shape, (len(self.f),))
98
- self.assertEqual(integration_res[i], bf_max)
99
-
100
- if __name__ == "__main__":
101
-
102
- unittest.main()
@@ -1,60 +0,0 @@
1
- import unittest
2
- from acoular import FiltWNoiseGenerator
3
- from numpy.random import RandomState
4
- from numpy import array
5
- #from parameterized import parameterized
6
-
7
- # some FIR/MA filter coefficients of a low pass
8
- MA_COEFF = array([-1.43784223e-04, -8.36125348e-05, 1.19173505e-04, 4.25496657e-04,
9
- 6.94633526e-04, 7.24177306e-04, 3.49521545e-04, -4.34584932e-04,
10
- -1.39563577e-03, -2.09179948e-03, -2.03164747e-03, -9.23555283e-04,
11
- 1.09077195e-03, 3.35008833e-03, 4.82910680e-03, 4.53234580e-03,
12
- 1.99921968e-03, -2.29961235e-03, -6.90182084e-03, -9.75295479e-03,
13
- -9.00084038e-03, -3.91590949e-03, 4.45649391e-03, 1.32770185e-02,
14
- 1.86909952e-02, 1.72542180e-02, 7.54398817e-03, -8.67689478e-03,
15
- -2.63091689e-02, -3.80338221e-02, -3.64895345e-02, -1.68613380e-02,
16
- 2.10120036e-02, 7.18301706e-02, 1.25749185e-01, 1.70866876e-01,
17
- 1.96551032e-01, 1.96551032e-01, 1.70866876e-01, 1.25749185e-01,
18
- 7.18301706e-02, 2.10120036e-02, -1.68613380e-02, -3.64895345e-02,
19
- -3.80338221e-02, -2.63091689e-02, -8.67689478e-03, 7.54398817e-03,
20
- 1.72542180e-02, 1.86909952e-02, 1.32770185e-02, 4.45649391e-03,
21
- -3.91590949e-03, -9.00084038e-03, -9.75295479e-03, -6.90182084e-03,
22
- -2.29961235e-03, 1.99921968e-03, 4.53234580e-03, 4.82910680e-03,
23
- 3.35008833e-03, 1.09077195e-03, -9.23555283e-04, -2.03164747e-03,
24
- -2.09179948e-03, -1.39563577e-03, -4.34584932e-04, 3.49521545e-04,
25
- 7.24177306e-04, 6.94633526e-04, 4.25496657e-04, 1.19173505e-04,
26
- -8.36125348e-05, -1.43784223e-04])
27
-
28
- # some IIR/AR coefficients
29
- AR_COEFF = array([1, -0.20514344, -0.00257561, 0.04522058, 0.01972377, -0.04087183,
30
- -0.05474943, -0.02935448, -0.00917827, -0.02703312, -0.04541416,
31
- -0.01972302, 0.04305152, 0.07187778, 0.02216658, -0.07962289])
32
-
33
-
34
- class Test_FiltWNoiseGenerator(unittest.TestCase):
35
-
36
- def setUp(self):
37
- self.fwn = FiltWNoiseGenerator(sample_freq=100,numsamples=400,seed=1)
38
-
39
- def test_no_coefficients(self):
40
- """test that white noise and filtered white noise is equal when no coefficients are
41
- specified"""
42
- wn_signal = RandomState(seed=1).standard_normal(400)
43
- signal = self.fwn.signal()
44
- self.assertEqual(wn_signal.sum(),signal.sum())
45
-
46
- # @parameterized.expand([
47
- # [MA_COEFF,array([]),400],
48
- # [array([]),AR_COEFF,400]
49
- # ])
50
- def test_correct_signal_length(self):
51
- """test that signal retains correct length after filtering"""
52
- parameters = [(MA_COEFF,array([]),400),(array([]),AR_COEFF,400)]
53
- for ma,ar,expected_length in parameters:
54
- self.fwn.ar=ar
55
- self.fwn.ma=ma
56
- self.assertEqual(self.fwn.signal().shape[0],expected_length)
57
-
58
- if __name__ == '__main__':
59
- unittest.main()
60
-
@@ -1,65 +0,0 @@
1
- import unittest
2
- from os.path import join
3
- import numpy as np
4
- from acoular import __file__ as bpath, config, WNoiseGenerator, PointSource, MicGeom
5
-
6
- config.global_caching = "none"
7
-
8
- # if this flag is set to True, new data will be simulated and
9
- WRITE_NEW_REFERENCE_DATA = False
10
- # new source results are generated for comparison during testing. Should always be False. Only set to
11
- # true, if it is necessary to recalculate the data, due to wanted changes of the sources.
12
-
13
- # Parameters
14
- SFREQ = 1000
15
- SEED = 1
16
- NSAMPLES = 100
17
- N1 = WNoiseGenerator(sample_freq=SFREQ, numsamples=NSAMPLES, seed=SEED)
18
- MGEOM = MicGeom(mpos_tot=[[1],[1],[1]])
19
-
20
-
21
- def get_source_result(Source, num=32):
22
- """
23
- returns the result for a given source
24
-
25
- Parameters
26
- ----------
27
- source : cls
28
- source class that is tested.
29
- num : int, optional
30
- number of samples to return. The default is 32.
31
-
32
- Returns
33
- -------
34
- array
35
- first block returned by the source result() function.
36
-
37
- """
38
- if Source == PointSource:
39
- source = Source(signal=N1, mics=MGEOM)
40
-
41
- return next(source.result(num)).astype(np.float32)
42
-
43
-
44
- class SourcesTest(unittest.TestCase):
45
- """
46
- A simple test case that verifies that the results of sources are not changing across different versions of code.
47
- """
48
-
49
- sources = [PointSource]
50
-
51
- def test_sources_result(self):
52
- """compare results of sources against previous
53
- results from .npy file"""
54
- for source in self.sources:
55
- with self.subTest(source.__name__):
56
- name = join("reference_data", f"{source.__name__}.npy")
57
- actual_data = get_source_result(source)
58
- if WRITE_NEW_REFERENCE_DATA:
59
- np.save(name, actual_data)
60
- ref_data = np.load(name)
61
- np.testing.assert_allclose(actual_data, ref_data, rtol=1e-5, atol=1e-8)
62
-
63
-
64
- if __name__ == "__main__":
65
- unittest.main()
@@ -1,38 +0,0 @@
1
-
2
- from os import path
3
- import numpy as np
4
- import acoular
5
- import unittest
6
-
7
- rng = np.random.RandomState(2)
8
- # test array
9
- #np.abs(np.imag(ps.csm)).sum() + np.real(ps.csm).sum()
10
- csm_sum = 0.5613882842200368
11
- fft_sum = 0.3690552444079589+0.05264645224899272j
12
-
13
- mg = acoular.MicGeom( mpos_tot=rng.normal(0,1,3*2).reshape(3,2))
14
- sig = acoular.WNoiseGenerator(seed=1,numsamples=1010,sample_freq=1000)
15
- p = acoular.PointSource(signal=sig,loc=(0,0,0),mics=mg)
16
- ps = acoular.PowerSpectra( source=p, block_size=128, window='Hanning',cached=False )
17
- fft = acoular.FFTSpectra(source=p,window='Hanning',block_size=128)
18
-
19
- class Test_PowerSpectra(unittest.TestCase):
20
-
21
- def test_calc_csm(self):
22
- """ test that csm result has not changed over different releases"""
23
- test_csm_sum = np.abs(np.imag(ps.csm)).sum() + np.real(ps.csm).sum()
24
- self.assertAlmostEqual(test_csm_sum,csm_sum)
25
-
26
- class Test_FFTSpectra(unittest.TestCase):
27
-
28
- def test_calc_fft(self):
29
- """ test that fft result has not changed over different releases"""
30
- test_fft_sum = 0
31
- for temp in fft.result():
32
- test_fft_sum += temp.sum()
33
- self.assertAlmostEqual(test_fft_sum,fft_sum)
34
-
35
-
36
- if __name__ == '__main__':
37
- unittest.main()
38
-
@@ -1,35 +0,0 @@
1
- from acoular import *
2
- import numpy as np
3
- from acoular import __file__ as bpath
4
- from os import path
5
- import unittest
6
-
7
- # load some array geometry
8
- micgeofile = path.join(path.split(bpath)[0], 'xml', 'array_64.xml')
9
- micgeom = MicGeom(from_file=micgeofile)
10
-
11
- num_samples = 7
12
- block_size = 5
13
-
14
- class TimeCacheTest(unittest.TestCase):
15
- global_caching_configs= ['individual','all','none','readonly','overwrite']
16
- def test_valid_cache_result(self):
17
- """
18
- manually create an incomplete cash file and then read it
19
- """
20
- for conf in self.global_caching_configs:
21
- config.global_caching= conf
22
- with self.subTest(conf):
23
- sig = WNoiseGenerator(numsamples=num_samples)
24
- ps = PointSource(signal=sig, mics=micgeom)
25
- tc = TimeCache(source=ps)
26
- for i,(block_c, block_nc) in enumerate(zip(tc.result(block_size), ps.result(block_size))):
27
- np.testing.assert_array_almost_equal(block_c,block_nc)
28
- if i == 0: break
29
-
30
- for (block_c, block_nc) in zip(tc.result(block_size), ps.result(block_size)):
31
- np.testing.assert_array_almost_equal(block_c,block_nc)
32
-
33
-
34
- if __name__=="__main__":
35
- unittest.main()
@@ -1,90 +0,0 @@
1
- import unittest
2
- from os.path import join
3
- import re
4
- import numpy as np
5
- from acoular import (
6
- config,
7
- TimeConvolve,
8
- WNoiseGenerator,
9
- PointSource,
10
- MicGeom,
11
- MaskedTimeSamples,
12
- tools
13
- )
14
- from acoular.tprocess import *
15
-
16
- WRITE_NEW_REFERENCE_DATA = False
17
-
18
- config.global_caching = "none"
19
- datafile = join('..','..','examples','example_data.h5')
20
- t1 = MaskedTimeSamples(name=datafile)
21
- t1.start = 0 # first sample, default
22
- t1.stop = 500 # last valid sample = 15999
23
- invalid = list(range(4,64)) # list of invalid channels
24
- t1.invalid_channels = invalid # use four channels
25
-
26
- # these are tested
27
- test_list = (
28
- "TimeInOut()",
29
- "TimePower()",
30
- "TimeAverage()",
31
- "TimeCumAverage()",
32
- "TimeReverse()",
33
- "Filter()",
34
- "FiltFiltOctave(band = 100.0, fraction = 'Third octave')",
35
- "FiltFiltOctave()",
36
- "FiltOctave(band = 100.0, fraction = 'Third octave')",
37
- "FiltOctave()",
38
- "TimeExpAverage(weight = 'F')",
39
- "TimeExpAverage(weight = 'S')",
40
- "TimeExpAverage(weight = 'I')",
41
- "FiltFreqWeight(weight = 'A')",
42
- "FiltFreqWeight(weight = 'C')",
43
- "FiltFreqWeight(weight = 'Z')",
44
- "OctaveFilterBank()"
45
- )
46
-
47
- def fname(s):
48
- """converts string to file name removing unsafe characters"""
49
- s1 = re.sub(r'[,.()=]', '_', s)
50
- return re.sub(r'[/\\:*?"<>|\' ]', '', s1)
51
-
52
- class TprocessTest(unittest.TestCase):
53
- """
54
- A simple test case that verifies that the results of tprocess are not changing across different versions of code.
55
- """
56
-
57
- def test_timeconvolve(self):
58
- """compare results of timeconvolve with numpy convolve"""
59
- # Parameters
60
- NSAMPLES = 25
61
- N1 = WNoiseGenerator(sample_freq=1000, numsamples=NSAMPLES, seed=1)
62
- MGEOM = MicGeom(mpos_tot=[[1], [1], [1]])
63
- P1 = PointSource(signal=N1, mics=MGEOM)
64
- KERNEL = np.random.rand(20)
65
- CONV = TimeConvolve(kernel=KERNEL, source=P1)
66
-
67
- SIG = tools.return_result(P1, num=NSAMPLES)
68
- RES = tools.return_result(CONV, num=100)
69
-
70
- for i in range(P1.numchannels):
71
- REF = np.convolve(np.squeeze(KERNEL), np.squeeze(SIG[:,i]))
72
- np.testing.assert_allclose(np.squeeze(RES[:,i]), REF, rtol=1e-5, atol=1e-8)
73
-
74
- #@unittest.skip
75
- def test_tprocess_results(self):
76
- """compare results with reference results"""
77
- for s in test_list:
78
- b = eval(s)
79
- with self.subTest(s):
80
- name = join('reference_data',f'{fname(s)}.npy')
81
- b.source = t1
82
- # compute with block size 64 and add some extra
83
- actual_data = tools.return_result(b, nmax=70, num=64)
84
- if WRITE_NEW_REFERENCE_DATA:
85
- np.save(name,actual_data)
86
- ref_data = np.load(name)
87
- np.testing.assert_allclose(actual_data, ref_data, rtol=1e-5, atol=1e-8)
88
-
89
- if __name__ == "__main__":
90
- unittest.main()