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.
- acoular/__init__.py +119 -54
- acoular/calib.py +29 -38
- acoular/configuration.py +132 -82
- acoular/demo/__init__.py +10 -4
- acoular/demo/acoular_demo.py +73 -55
- acoular/environments.py +270 -264
- acoular/fastFuncs.py +366 -196
- acoular/fbeamform.py +1797 -1934
- acoular/grids.py +504 -548
- acoular/h5cache.py +74 -83
- acoular/h5files.py +159 -142
- acoular/internal.py +13 -14
- acoular/microphones.py +57 -53
- acoular/sdinput.py +57 -53
- acoular/signals.py +180 -178
- acoular/sources.py +920 -724
- acoular/spectra.py +353 -363
- acoular/tbeamform.py +416 -416
- acoular/tfastfuncs.py +180 -104
- acoular/tools/__init__.py +25 -0
- acoular/tools/aiaa.py +185 -0
- acoular/tools/helpers.py +189 -0
- acoular/tools/metrics.py +165 -0
- acoular/tprocess.py +1240 -1182
- acoular/traitsviews.py +513 -501
- acoular/trajectory.py +50 -52
- acoular/version.py +5 -6
- acoular/xml/minidsp_uma-16.xml +20 -0
- acoular/xml/{minidsp_uma16.xml → minidsp_uma-16_mirrored.xml} +3 -0
- {acoular-24.3.dist-info → acoular-24.7.dist-info}/METADATA +58 -39
- acoular-24.7.dist-info/RECORD +50 -0
- {acoular-24.3.dist-info → acoular-24.7.dist-info}/WHEEL +1 -1
- acoular-24.7.dist-info/licenses/LICENSE +28 -0
- acoular/fileimport.py +0 -380
- acoular/nidaqimport.py +0 -273
- acoular/tests/reference_data/BeamformerBase.npy +0 -0
- acoular/tests/reference_data/BeamformerBaseFalse1.npy +0 -0
- acoular/tests/reference_data/BeamformerBaseFalse2.npy +0 -0
- acoular/tests/reference_data/BeamformerBaseFalse3.npy +0 -0
- acoular/tests/reference_data/BeamformerBaseFalse4.npy +0 -0
- acoular/tests/reference_data/BeamformerBaseTrue1.npy +0 -0
- acoular/tests/reference_data/BeamformerBaseTrue2.npy +0 -0
- acoular/tests/reference_data/BeamformerBaseTrue3.npy +0 -0
- acoular/tests/reference_data/BeamformerBaseTrue4.npy +0 -0
- acoular/tests/reference_data/BeamformerCMFLassoLarsBIC.npy +0 -0
- acoular/tests/reference_data/BeamformerCMFNNLS.npy +0 -0
- acoular/tests/reference_data/BeamformerCapon.npy +0 -0
- acoular/tests/reference_data/BeamformerClean.npy +0 -0
- acoular/tests/reference_data/BeamformerCleansc.npy +0 -0
- acoular/tests/reference_data/BeamformerCleant.npy +0 -0
- acoular/tests/reference_data/BeamformerCleantSq.npy +0 -0
- acoular/tests/reference_data/BeamformerCleantSqTraj.npy +0 -0
- acoular/tests/reference_data/BeamformerCleantTraj.npy +0 -0
- acoular/tests/reference_data/BeamformerDamas.npy +0 -0
- acoular/tests/reference_data/BeamformerDamasPlus.npy +0 -0
- acoular/tests/reference_data/BeamformerEig.npy +0 -0
- acoular/tests/reference_data/BeamformerEigFalse1.npy +0 -0
- acoular/tests/reference_data/BeamformerEigFalse2.npy +0 -0
- acoular/tests/reference_data/BeamformerEigFalse3.npy +0 -0
- acoular/tests/reference_data/BeamformerEigFalse4.npy +0 -0
- acoular/tests/reference_data/BeamformerEigTrue1.npy +0 -0
- acoular/tests/reference_data/BeamformerEigTrue2.npy +0 -0
- acoular/tests/reference_data/BeamformerEigTrue3.npy +0 -0
- acoular/tests/reference_data/BeamformerEigTrue4.npy +0 -0
- acoular/tests/reference_data/BeamformerFunctional.npy +0 -0
- acoular/tests/reference_data/BeamformerGIB.npy +0 -0
- acoular/tests/reference_data/BeamformerGridlessOrth.npy +0 -0
- acoular/tests/reference_data/BeamformerMusic.npy +0 -0
- acoular/tests/reference_data/BeamformerOrth.npy +0 -0
- acoular/tests/reference_data/BeamformerSODIX.npy +0 -0
- acoular/tests/reference_data/BeamformerTime.npy +0 -0
- acoular/tests/reference_data/BeamformerTimeSq.npy +0 -0
- acoular/tests/reference_data/BeamformerTimeSqTraj.npy +0 -0
- acoular/tests/reference_data/BeamformerTimeTraj.npy +0 -0
- acoular/tests/reference_data/Environment.npy +0 -0
- acoular/tests/reference_data/Example1_numerical_values_testsum.h5 +0 -0
- acoular/tests/reference_data/FiltFiltOctave__.npy +0 -0
- acoular/tests/reference_data/FiltFiltOctave_band_100_0_fraction_Thirdoctave_.npy +0 -0
- acoular/tests/reference_data/FiltFreqWeight_weight_A_.npy +0 -0
- acoular/tests/reference_data/FiltFreqWeight_weight_C_.npy +0 -0
- acoular/tests/reference_data/FiltFreqWeight_weight_Z_.npy +0 -0
- acoular/tests/reference_data/FiltOctave__.npy +0 -0
- acoular/tests/reference_data/FiltOctave_band_100_0_fraction_Thirdoctave_.npy +0 -0
- acoular/tests/reference_data/Filter__.npy +0 -0
- acoular/tests/reference_data/GeneralFlowEnvironment.npy +0 -0
- acoular/tests/reference_data/OctaveFilterBank__.npy +0 -0
- acoular/tests/reference_data/OpenJet.npy +0 -0
- acoular/tests/reference_data/PointSource.npy +0 -0
- acoular/tests/reference_data/PowerSpectra_csm.npy +0 -0
- acoular/tests/reference_data/PowerSpectra_ev.npy +0 -0
- acoular/tests/reference_data/RotatingFlow.npy +0 -0
- acoular/tests/reference_data/SlotJet.npy +0 -0
- acoular/tests/reference_data/TimeAverage__.npy +0 -0
- acoular/tests/reference_data/TimeCumAverage__.npy +0 -0
- acoular/tests/reference_data/TimeExpAverage_weight_F_.npy +0 -0
- acoular/tests/reference_data/TimeExpAverage_weight_I_.npy +0 -0
- acoular/tests/reference_data/TimeExpAverage_weight_S_.npy +0 -0
- acoular/tests/reference_data/TimeInOut__.npy +0 -0
- acoular/tests/reference_data/TimePower__.npy +0 -0
- acoular/tests/reference_data/TimeReverse__.npy +0 -0
- acoular/tests/reference_data/UniformFlowEnvironment.npy +0 -0
- acoular/tests/reference_data/beamformer_traj_time_data.h5 +0 -0
- acoular/tests/run_tests.sh +0 -18
- acoular/tests/run_tests_osx.sh +0 -16
- acoular/tests/test.npy +0 -0
- acoular/tests/test_beamformer_results.py +0 -213
- acoular/tests/test_classes.py +0 -60
- acoular/tests/test_digest.py +0 -125
- acoular/tests/test_environments.py +0 -73
- acoular/tests/test_example1.py +0 -124
- acoular/tests/test_grid.py +0 -92
- acoular/tests/test_integrate.py +0 -102
- acoular/tests/test_signals.py +0 -60
- acoular/tests/test_sources.py +0 -65
- acoular/tests/test_spectra.py +0 -38
- acoular/tests/test_timecache.py +0 -35
- acoular/tests/test_tprocess.py +0 -90
- acoular/tests/test_traj_beamformer_results.py +0 -164
- acoular/tests/unsupported/SpeedComparison/OvernightTestcasesBeamformer_nMics32_nGridPoints100_nFreqs4_nTrials10.png +0 -0
- acoular/tests/unsupported/SpeedComparison/cythonBeamformer.pyx +0 -237
- acoular/tests/unsupported/SpeedComparison/mainForCython.py +0 -103
- acoular/tests/unsupported/SpeedComparison/mainForParallelJit.py +0 -143
- acoular/tests/unsupported/SpeedComparison/setupCythonOpenMP.py +0 -63
- acoular/tests/unsupported/SpeedComparison/sharedFunctions.py +0 -153
- acoular/tests/unsupported/SpeedComparison/timeOverNMics_AllImportantMethods.png +0 -0
- acoular/tests/unsupported/SpeedComparison/timeOverNMics_faverage.png +0 -0
- acoular/tests/unsupported/SpeedComparison/vglOptimierungFAverage.py +0 -204
- acoular/tests/unsupported/SpeedComparison/vglOptimierungGaussSeidel.py +0 -182
- acoular/tests/unsupported/SpeedComparison/vglOptimierungR_BEAMFULL_INVERSE.py +0 -764
- acoular/tests/unsupported/SpeedComparison/vglOptimierungR_BEAM_OS.py +0 -231
- acoular/tests/unsupported/SpeedComparison/whatsFastestWayFor_absASquared.py +0 -48
- acoular/tests/unsupported/functionalBeamformer.py +0 -123
- acoular/tests/unsupported/precisionTest.py +0 -153
- acoular/tests/unsupported/validationOfBeamformerFuncsPOSTAcoularIntegration.py +0 -254
- acoular/tests/unsupported/validationOfBeamformerFuncsPREeAcoularIntegration.py +0 -531
- acoular/tools.py +0 -422
- acoular-24.3.dist-info/RECORD +0 -148
- acoular-24.3.dist-info/licenses/LICENSE +0 -29
- {acoular-24.3.dist-info → acoular-24.7.dist-info}/licenses/AUTHORS.rst +0 -0
acoular/h5cache.py
CHANGED
|
@@ -1,52 +1,48 @@
|
|
|
1
|
-
#
|
|
2
|
-
#pylint: disable-msg=E0611,C0111,C0103,R0901,R0902,R0903,R0904,W0232
|
|
3
|
-
#------------------------------------------------------------------------------
|
|
1
|
+
# ------------------------------------------------------------------------------
|
|
4
2
|
# Copyright (c) Acoular Development Team.
|
|
5
|
-
|
|
3
|
+
# ------------------------------------------------------------------------------
|
|
6
4
|
|
|
7
5
|
# imports from other packages
|
|
8
|
-
from __future__ import print_function
|
|
9
|
-
from traits.api import HasPrivateTraits, Bool, Str, Dict, Instance, Delegate
|
|
10
|
-
from os import path, mkdir, environ, listdir
|
|
11
|
-
from weakref import WeakValueDictionary
|
|
12
6
|
import gc
|
|
7
|
+
from os import listdir, path
|
|
8
|
+
from weakref import WeakValueDictionary
|
|
9
|
+
|
|
10
|
+
from traits.api import Bool, Delegate, Dict, HasPrivateTraits, Instance
|
|
13
11
|
|
|
14
12
|
from .configuration import Config, config
|
|
15
13
|
from .h5files import _get_cachefile_class
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Cache class that handles opening and closing 'tables.File' objects
|
|
20
|
-
"""
|
|
15
|
+
|
|
16
|
+
class HDF5Cache(HasPrivateTraits):
|
|
17
|
+
"""Cache class that handles opening and closing 'tables.File' objects."""
|
|
21
18
|
|
|
22
19
|
config = Instance(Config)
|
|
23
20
|
|
|
24
|
-
cache_dir = Delegate('config')
|
|
21
|
+
cache_dir = Delegate('config')
|
|
25
22
|
|
|
26
23
|
busy = Bool(False)
|
|
27
|
-
|
|
24
|
+
|
|
28
25
|
open_files = WeakValueDictionary()
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
|
|
27
|
+
open_file_reference = Dict()
|
|
28
|
+
|
|
32
29
|
def _idle_if_busy(self):
|
|
33
30
|
while self.busy:
|
|
34
31
|
pass
|
|
35
32
|
|
|
36
|
-
def open_cachefile(self,
|
|
37
|
-
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
def close_cachefile(self,cachefile):
|
|
41
|
-
self.
|
|
33
|
+
def open_cachefile(self, filename, mode):
|
|
34
|
+
file = _get_cachefile_class()
|
|
35
|
+
return file(path.join(self.cache_dir, filename), mode)
|
|
36
|
+
|
|
37
|
+
def close_cachefile(self, cachefile):
|
|
38
|
+
self.open_file_reference.pop(get_basename(cachefile))
|
|
42
39
|
cachefile.close()
|
|
43
|
-
|
|
44
|
-
def get_filename(self,file):
|
|
45
|
-
|
|
46
|
-
if isinstance(file,
|
|
40
|
+
|
|
41
|
+
def get_filename(self, file):
|
|
42
|
+
file_class = _get_cachefile_class()
|
|
43
|
+
if isinstance(file, file_class):
|
|
47
44
|
return get_basename(file)
|
|
48
|
-
|
|
49
|
-
return 0
|
|
45
|
+
return 0
|
|
50
46
|
|
|
51
47
|
def get_open_cachefiles(self):
|
|
52
48
|
try:
|
|
@@ -55,82 +51,77 @@ class H5cache_class(HasPrivateTraits):
|
|
|
55
51
|
return iter(self.open_files.values())
|
|
56
52
|
|
|
57
53
|
def close_unreferenced_cachefiles(self):
|
|
58
|
-
for
|
|
59
|
-
if not self.is_reference_existent(
|
|
60
|
-
# print("close unreferenced File:",get_basename(
|
|
61
|
-
self.close_cachefile(
|
|
54
|
+
for cachefile in self.get_open_cachefiles():
|
|
55
|
+
if not self.is_reference_existent(cachefile):
|
|
56
|
+
# print("close unreferenced File:",get_basename(cachefile))
|
|
57
|
+
self.close_cachefile(cachefile)
|
|
62
58
|
|
|
63
|
-
def is_reference_existent(self,file):
|
|
64
|
-
|
|
59
|
+
def is_reference_existent(self, file):
|
|
60
|
+
exist_flag = False
|
|
65
61
|
# inspect all refererres to the file object
|
|
66
|
-
gc.collect()
|
|
62
|
+
gc.collect() # clear garbage before collecting referrers
|
|
67
63
|
for ref in gc.get_referrers(file):
|
|
68
|
-
# does the file object have a referrer that has a 'h5f'
|
|
64
|
+
# does the file object have a referrer that has a 'h5f'
|
|
69
65
|
# attribute?
|
|
70
|
-
if isinstance(ref,dict) and 'h5f' in ref:
|
|
66
|
+
if isinstance(ref, dict) and 'h5f' in ref:
|
|
71
67
|
# file is still referred, must not be closed
|
|
72
|
-
|
|
68
|
+
exist_flag = True
|
|
73
69
|
break
|
|
74
|
-
return
|
|
70
|
+
return exist_flag
|
|
75
71
|
|
|
76
|
-
def is_cachefile_existent(self,
|
|
77
|
-
if
|
|
72
|
+
def is_cachefile_existent(self, filename):
|
|
73
|
+
if filename in listdir(self.cache_dir):
|
|
78
74
|
return True
|
|
79
|
-
|
|
80
|
-
return False
|
|
75
|
+
return False
|
|
81
76
|
|
|
82
|
-
def _increase_file_reference_counter(self,
|
|
83
|
-
self.
|
|
77
|
+
def _increase_file_reference_counter(self, filename):
|
|
78
|
+
self.open_file_reference[filename] = self.open_file_reference.get(filename, 0) + 1
|
|
84
79
|
|
|
85
|
-
def _decrease_file_reference_counter(self,
|
|
86
|
-
self.
|
|
80
|
+
def _decrease_file_reference_counter(self, filename):
|
|
81
|
+
self.open_file_reference[filename] = self.open_file_reference[filename] - 1
|
|
87
82
|
|
|
88
83
|
def _print_open_files(self):
|
|
89
|
-
print(list(self.
|
|
90
|
-
|
|
91
|
-
def get_cache_file(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
'''
|
|
95
|
-
|
|
96
|
-
self._idle_if_busy() #
|
|
84
|
+
print(list(self.open_file_reference.items()))
|
|
85
|
+
|
|
86
|
+
def get_cache_file(self, obj, basename, mode='a'):
|
|
87
|
+
"""Returns pytables .h5 file to h5f trait of calling object for caching."""
|
|
88
|
+
self._idle_if_busy() #
|
|
97
89
|
self.busy = True
|
|
98
90
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if
|
|
103
|
-
if
|
|
91
|
+
filename = basename + '_cache.h5'
|
|
92
|
+
obj_filename = self.get_filename(obj.h5f)
|
|
93
|
+
|
|
94
|
+
if obj_filename:
|
|
95
|
+
if obj_filename == filename:
|
|
104
96
|
self.busy = False
|
|
105
97
|
return
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
and not self.is_cachefile_existent(cacheFileName)
|
|
113
|
-
): # condition ensures that cachefile is not created in readonly mode
|
|
98
|
+
self._decrease_file_reference_counter(obj_filename)
|
|
99
|
+
|
|
100
|
+
if filename not in self.open_files: # or tables.file._open_files.filenames
|
|
101
|
+
if config.global_caching == 'readonly' and not self.is_cachefile_existent(
|
|
102
|
+
filename,
|
|
103
|
+
): # condition ensures that cachefile is not created in readonly mode
|
|
114
104
|
obj.h5f = None
|
|
115
105
|
self.busy = False
|
|
116
|
-
# self._print_open_files()
|
|
106
|
+
# self._print_open_files()
|
|
117
107
|
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
obj.h5f = self.open_files[
|
|
124
|
-
self._increase_file_reference_counter(
|
|
125
|
-
|
|
108
|
+
if config.global_caching == 'readonly':
|
|
109
|
+
mode = 'r'
|
|
110
|
+
f = self.open_cachefile(filename, mode)
|
|
111
|
+
self.open_files[filename] = f
|
|
112
|
+
|
|
113
|
+
obj.h5f = self.open_files[filename]
|
|
114
|
+
self._increase_file_reference_counter(filename)
|
|
115
|
+
|
|
126
116
|
# garbage collection
|
|
127
117
|
self.close_unreferenced_cachefiles()
|
|
128
|
-
|
|
118
|
+
|
|
129
119
|
self.busy = False
|
|
130
|
-
self._print_open_files()
|
|
120
|
+
self._print_open_files()
|
|
131
121
|
|
|
132
|
-
H5cache = H5cache_class(config=config)
|
|
133
122
|
|
|
134
|
-
|
|
135
|
-
return path.basename(file.filename)
|
|
123
|
+
H5cache = HDF5Cache(config=config)
|
|
136
124
|
|
|
125
|
+
|
|
126
|
+
def get_basename(file):
|
|
127
|
+
return path.basename(file.filename)
|
acoular/h5files.py
CHANGED
|
@@ -1,204 +1,221 @@
|
|
|
1
|
-
#
|
|
2
|
-
#pylint: disable-msg=E0611, E1101, C0103, R0901, R0902, R0903, R0904, W0232
|
|
3
|
-
#------------------------------------------------------------------------------
|
|
1
|
+
# ------------------------------------------------------------------------------
|
|
4
2
|
# Copyright (c) Acoular Development Team.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
try:
|
|
8
|
-
import tables
|
|
9
|
-
is_tables = True
|
|
10
|
-
except:
|
|
11
|
-
is_tables = False
|
|
12
|
-
pass
|
|
13
|
-
try:
|
|
14
|
-
import h5py
|
|
15
|
-
is_h5py = True
|
|
16
|
-
except:
|
|
17
|
-
is_h5py = False
|
|
3
|
+
# ------------------------------------------------------------------------------
|
|
18
4
|
|
|
19
5
|
from .configuration import config
|
|
20
6
|
|
|
21
7
|
|
|
8
|
+
class H5FileBase:
|
|
9
|
+
"""Base class for File objects that handle writing and reading of .h5 files."""
|
|
22
10
|
|
|
23
|
-
|
|
24
|
-
'''
|
|
25
|
-
Base class for File objects that handle writing and reading of .h5 files
|
|
26
|
-
'''
|
|
27
|
-
|
|
28
|
-
def create_extendable_array(self,nodename,shape,precision,group=None):
|
|
11
|
+
def create_extendable_array(self, nodename, shape, precision, group=None):
|
|
29
12
|
pass
|
|
30
|
-
|
|
31
|
-
def get_data_by_reference(self, nodename,group=None):
|
|
13
|
+
|
|
14
|
+
def get_data_by_reference(self, nodename, group=None):
|
|
32
15
|
pass
|
|
33
|
-
|
|
34
|
-
def set_node_attribute(self,node,attrname,value):
|
|
16
|
+
|
|
17
|
+
def set_node_attribute(self, node, attrname, value):
|
|
35
18
|
pass
|
|
36
19
|
|
|
37
|
-
def get_node_attribute(self,node,attrname):
|
|
20
|
+
def get_node_attribute(self, node, attrname):
|
|
38
21
|
pass
|
|
39
22
|
|
|
40
|
-
def append_data(self,node,data):
|
|
23
|
+
def append_data(self, node, data):
|
|
41
24
|
pass
|
|
42
25
|
|
|
43
|
-
def remove_data(self,nodename):
|
|
44
|
-
pass
|
|
45
|
-
|
|
46
|
-
def create_new_group(self,name,group=None):
|
|
26
|
+
def remove_data(self, nodename):
|
|
47
27
|
pass
|
|
48
28
|
|
|
49
|
-
def
|
|
50
|
-
|
|
29
|
+
def create_new_group(self, name, group=None):
|
|
30
|
+
pass
|
|
51
31
|
|
|
52
32
|
|
|
53
|
-
class H5CacheFileBase
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
33
|
+
class H5CacheFileBase:
|
|
34
|
+
"""Base class for File objects that handle writing and reading of .h5 cache files."""
|
|
35
|
+
|
|
36
|
+
compression_filter = None
|
|
37
|
+
|
|
38
|
+
def is_cached(self, nodename, group=None):
|
|
39
|
+
pass
|
|
59
40
|
|
|
60
|
-
|
|
61
|
-
def is_cached(self,nodename,group=None):
|
|
41
|
+
def create_compressible_array(self, nodename, shape, precision, group=None):
|
|
62
42
|
pass
|
|
63
|
-
|
|
64
|
-
def create_compressible_array(self,nodename,shape,precision,group=None):
|
|
65
|
-
pass
|
|
66
43
|
|
|
67
44
|
|
|
68
|
-
if
|
|
69
|
-
|
|
45
|
+
if config.have_tables:
|
|
46
|
+
import tables
|
|
47
|
+
|
|
70
48
|
precision_to_atom = {
|
|
71
|
-
'float32'
|
|
72
|
-
'complex64'
|
|
73
|
-
'float64'
|
|
74
|
-
'complex128'
|
|
75
|
-
'bool'
|
|
76
|
-
'int32'
|
|
77
|
-
'int16'
|
|
78
|
-
'int8'
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class H5FileTables(H5FileBase,tables.File):
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
49
|
+
'float32': tables.Float32Atom(),
|
|
50
|
+
'complex64': tables.ComplexAtom(8),
|
|
51
|
+
'float64': tables.Float64Atom(),
|
|
52
|
+
'complex128': tables.ComplexAtom(16),
|
|
53
|
+
'bool': tables.BoolAtom(),
|
|
54
|
+
'int32': tables.Int32Atom(),
|
|
55
|
+
'int16': tables.Int16Atom(),
|
|
56
|
+
'int8': tables.Int8Atom(),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class H5FileTables(H5FileBase, tables.File):
|
|
60
|
+
def create_extendable_array(self, nodename, shape, precision, group=None):
|
|
61
|
+
if not group:
|
|
62
|
+
group = self.root
|
|
85
63
|
atom = precision_to_atom[precision]
|
|
86
|
-
self.create_earray(group, nodename, atom, shape)
|
|
87
|
-
|
|
88
|
-
def get_data_by_reference(self, nodename,group=None):
|
|
89
|
-
if not group:
|
|
64
|
+
self.create_earray(group, nodename, atom, shape)
|
|
65
|
+
|
|
66
|
+
def get_data_by_reference(self, nodename, group=None):
|
|
67
|
+
if not group:
|
|
68
|
+
group = self.root
|
|
90
69
|
return self.get_node(group, nodename)
|
|
91
70
|
|
|
92
|
-
def set_node_attribute(self,node,attrname,value):
|
|
93
|
-
node.set_attr(attrname,value)
|
|
71
|
+
def set_node_attribute(self, node, attrname, value):
|
|
72
|
+
node.set_attr(attrname, value)
|
|
94
73
|
|
|
95
|
-
def get_node_attribute(self,node,attrname):
|
|
96
|
-
return node.
|
|
74
|
+
def get_node_attribute(self, node, attrname):
|
|
75
|
+
return node._v_attrs[attrname] # noqa: SLF001
|
|
97
76
|
|
|
98
|
-
def append_data(self,node,data):
|
|
77
|
+
def append_data(self, node, data):
|
|
99
78
|
node.append(data)
|
|
100
|
-
|
|
101
|
-
def remove_data(self,nodename):
|
|
102
|
-
self.remove_node('/',nodename,recursive=True)
|
|
103
|
-
|
|
104
|
-
def create_new_group(self,name,group=None):
|
|
105
|
-
if not group:
|
|
106
|
-
|
|
79
|
+
|
|
80
|
+
def remove_data(self, nodename):
|
|
81
|
+
self.remove_node('/', nodename, recursive=True)
|
|
82
|
+
|
|
83
|
+
def create_new_group(self, name, group=None):
|
|
84
|
+
if not group:
|
|
85
|
+
group = self.root
|
|
86
|
+
return self.create_group(group, name)
|
|
107
87
|
|
|
108
88
|
def get_child_nodes(self, nodename):
|
|
109
89
|
for childnode in self.list_nodes(nodename):
|
|
110
90
|
yield (childnode.name, childnode)
|
|
111
91
|
|
|
92
|
+
def node_to_dict(self, nodename):
|
|
93
|
+
"""Recursively convert an HDF5 node to a dictionary."""
|
|
94
|
+
node = self.get_node(nodename)
|
|
95
|
+
# initialize node-dict with node's own attributes
|
|
96
|
+
result = {attr: node._v_attrs[attr] for attr in node._v_attrs._f_list()} # noqa: SLF001
|
|
97
|
+
if isinstance(node, tables.Group):
|
|
98
|
+
# if node is a group, recursively add its children
|
|
99
|
+
for childname in node._v_children: # noqa: SLF001
|
|
100
|
+
result[childname] = self.node_to_dict(f'{nodename}/{childname}')
|
|
101
|
+
elif isinstance(node, tables.Leaf):
|
|
102
|
+
# if node contains only data, add it
|
|
103
|
+
return node
|
|
104
|
+
else:
|
|
105
|
+
return None
|
|
106
|
+
return result
|
|
112
107
|
|
|
113
108
|
class H5CacheFileTables(H5FileTables, H5CacheFileBase):
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if nodename in group:
|
|
109
|
+
compression_filter = tables.Filters(complevel=5, complib='blosc')
|
|
110
|
+
|
|
111
|
+
def is_cached(self, nodename, group=None):
|
|
112
|
+
if not group:
|
|
113
|
+
group = self.root
|
|
114
|
+
if nodename in group:
|
|
120
115
|
return True
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
116
|
+
return False
|
|
117
|
+
|
|
118
|
+
def create_compressible_array(self, nodename, shape, precision, group=None):
|
|
119
|
+
if not group:
|
|
120
|
+
group = self.root
|
|
126
121
|
atom = precision_to_atom[precision]
|
|
127
|
-
self.create_carray(group, nodename, atom, shape,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
in_file_path =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
def get_data_by_reference(self,nodename,group=None):
|
|
149
|
-
in_file_path = self._get_in_file_path(nodename,group)
|
|
122
|
+
self.create_carray(group, nodename, atom, shape, filters=self.compression_filter)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if config.have_h5py:
|
|
126
|
+
import h5py
|
|
127
|
+
|
|
128
|
+
class H5FileH5py(H5FileBase, h5py.File):
|
|
129
|
+
def _get_in_file_path(self, nodename, group=None):
|
|
130
|
+
if not group:
|
|
131
|
+
return '/' + nodename
|
|
132
|
+
return group + '/' + nodename
|
|
133
|
+
|
|
134
|
+
def create_array(self, where, name, obj):
|
|
135
|
+
self.create_dataset(f'{where}/{name}', data=obj)
|
|
136
|
+
|
|
137
|
+
def create_extendable_array(self, nodename, shape, precision, group=None):
|
|
138
|
+
in_file_path = self._get_in_file_path(nodename, group)
|
|
139
|
+
self.create_dataset(in_file_path, shape=shape, dtype=precision, maxshape=(None, shape[1]))
|
|
140
|
+
|
|
141
|
+
def get_data_by_reference(self, nodename, group=None):
|
|
142
|
+
in_file_path = self._get_in_file_path(nodename, group)
|
|
150
143
|
return self[in_file_path]
|
|
151
144
|
|
|
152
|
-
def set_node_attribute(self,node,attrname,value):
|
|
145
|
+
def set_node_attribute(self, node, attrname, value):
|
|
153
146
|
node.attrs[attrname] = value
|
|
154
147
|
|
|
155
|
-
def get_node_attribute(self,node,attrname):
|
|
148
|
+
def get_node_attribute(self, node, attrname):
|
|
156
149
|
return node.attrs[attrname]
|
|
157
150
|
|
|
158
|
-
def append_data(self,node,data):
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
node.resize(
|
|
162
|
-
node[
|
|
163
|
-
|
|
164
|
-
def remove_data(self,nodename,group=None):
|
|
165
|
-
in_file_path = self._get_in_file_path(nodename,group)
|
|
151
|
+
def append_data(self, node, data):
|
|
152
|
+
old_shape = node.shape
|
|
153
|
+
new_shape = (old_shape[0] + data.shape[0], data.shape[1])
|
|
154
|
+
node.resize(new_shape)
|
|
155
|
+
node[old_shape[0] : new_shape[0], :] = data
|
|
156
|
+
|
|
157
|
+
def remove_data(self, nodename, group=None):
|
|
158
|
+
in_file_path = self._get_in_file_path(nodename, group)
|
|
166
159
|
del self[in_file_path]
|
|
167
160
|
|
|
168
|
-
def create_new_group(self,name,group=None):
|
|
169
|
-
in_file_path = self._get_in_file_path(name,group)
|
|
170
|
-
self.create_group(in_file_path)
|
|
161
|
+
def create_new_group(self, name, group=None):
|
|
162
|
+
in_file_path = self._get_in_file_path(name, group)
|
|
163
|
+
self.create_group(in_file_path)
|
|
171
164
|
return in_file_path
|
|
172
165
|
|
|
173
166
|
def get_child_nodes(self, nodename):
|
|
174
167
|
for childnode in self[nodename]:
|
|
175
168
|
yield (childnode, self[f'{nodename}/{childnode}'])
|
|
176
169
|
|
|
170
|
+
def node_to_dict(self, nodename):
|
|
171
|
+
"""Recursively convert an HDF5 node to a dictionary."""
|
|
172
|
+
node = self[nodename]
|
|
173
|
+
# initialize node-dict with node's own attributes
|
|
174
|
+
result = {attr: node.attrs[attr] for attr in node.attrs}
|
|
175
|
+
if isinstance(node, h5py.Group):
|
|
176
|
+
# if node is a group, recursively add its children
|
|
177
|
+
for childname in node:
|
|
178
|
+
result[childname] = self.node_to_dict(f'{nodename}/{childname}')
|
|
179
|
+
elif isinstance(node, h5py.Dataset):
|
|
180
|
+
# if node contains only data, add it
|
|
181
|
+
return node
|
|
182
|
+
else:
|
|
183
|
+
return None
|
|
184
|
+
return result
|
|
177
185
|
|
|
178
186
|
class H5CacheFileH5py(H5CacheFileBase, H5FileH5py):
|
|
187
|
+
compression_filter = 'lzf'
|
|
188
|
+
# compression_filter = 'blosc' # unavailable...
|
|
179
189
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if not group: group = '/'
|
|
185
|
-
if group+nodename in self:
|
|
190
|
+
def is_cached(self, nodename, group=None):
|
|
191
|
+
if not group:
|
|
192
|
+
group = '/'
|
|
193
|
+
if group + nodename in self:
|
|
186
194
|
return True
|
|
187
|
-
|
|
188
|
-
return False
|
|
189
|
-
|
|
190
|
-
def create_compressible_array(self,nodename,shape,precision,group=None):
|
|
191
|
-
in_file_path = self._get_in_file_path(nodename,group)
|
|
192
|
-
self.create_dataset(in_file_path, dtype=precision, shape=shape,
|
|
193
|
-
compression=self.compressionFilter,
|
|
194
|
-
chunks=True)
|
|
195
|
+
return False
|
|
195
196
|
|
|
197
|
+
def create_compressible_array(self, nodename, shape, precision, group=None):
|
|
198
|
+
in_file_path = self._get_in_file_path(nodename, group)
|
|
199
|
+
self.create_dataset(
|
|
200
|
+
in_file_path,
|
|
201
|
+
dtype=precision,
|
|
202
|
+
shape=shape,
|
|
203
|
+
compression=self.compression_filter,
|
|
204
|
+
chunks=True,
|
|
205
|
+
)
|
|
196
206
|
|
|
197
207
|
|
|
198
208
|
def _get_h5file_class():
|
|
199
|
-
if config.h5library
|
|
200
|
-
|
|
209
|
+
if config.h5library in ['pytables', 'tables']:
|
|
210
|
+
return H5FileTables
|
|
211
|
+
if config.h5library == 'h5py':
|
|
212
|
+
return H5FileH5py
|
|
213
|
+
return None
|
|
214
|
+
|
|
201
215
|
|
|
202
216
|
def _get_cachefile_class():
|
|
203
|
-
if config.h5library
|
|
204
|
-
|
|
217
|
+
if config.h5library in ['pytables', 'tables']:
|
|
218
|
+
return H5CacheFileTables
|
|
219
|
+
if config.h5library == 'h5py':
|
|
220
|
+
return H5CacheFileH5py
|
|
221
|
+
return None
|
acoular/internal.py
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
#
|
|
2
|
-
#------------------------------------------------------------------------------
|
|
1
|
+
# ------------------------------------------------------------------------------
|
|
3
2
|
# Copyright (c) Acoular Development Team.
|
|
4
|
-
|
|
3
|
+
# ------------------------------------------------------------------------------
|
|
5
4
|
|
|
6
5
|
from hashlib import md5
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
def digest(obj, name='digest'):
|
|
9
|
+
str_ = [str(obj.__class__).encode('UTF-8')]
|
|
10
10
|
for do_ in obj.trait(name).depends_on:
|
|
11
11
|
vobj = obj
|
|
12
12
|
try:
|
|
13
|
-
for i in do_.split('.'):
|
|
13
|
+
for i in do_.split('.'):
|
|
14
14
|
vobj = list(vobj.trait_get(i.rstrip('[]')).values())[0]
|
|
15
|
-
str_.append(str(vobj).encode(
|
|
16
|
-
except:
|
|
15
|
+
str_.append(str(vobj).encode('UTF-8'))
|
|
16
|
+
except: # noqa: E722
|
|
17
17
|
pass
|
|
18
|
-
return '_' + md5(''.
|
|
18
|
+
return '_' + md5(b''.join(str_)).hexdigest()
|
|
19
|
+
|
|
19
20
|
|
|
20
|
-
def ldigest(
|
|
21
|
+
def ldigest(obj_list):
|
|
21
22
|
str_ = []
|
|
22
|
-
for i in
|
|
23
|
+
for i in obj_list:
|
|
23
24
|
str_.append(str(i.digest).encode('UTF-8'))
|
|
24
|
-
return '_' + md5(''.
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
return '_' + md5(b''.join(str_)).hexdigest()
|