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
acoular/h5cache.py CHANGED
@@ -1,52 +1,48 @@
1
- # -*- coding: utf-8 -*-
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
- class H5cache_class(HasPrivateTraits):
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
- openFileReferenceCount = dict()
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,cacheFileName,mode):
37
- File = _get_cachefile_class()
38
- return File(path.join(self.cache_dir, cacheFileName), mode)
39
-
40
- def close_cachefile(self,cachefile):
41
- self.openFileReferenceCount.pop(get_basename(cachefile))
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
- File = _get_cachefile_class()
46
- if isinstance(file, 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
- else:
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 openCacheFile in self.get_open_cachefiles():
59
- if not self.is_reference_existent(openCacheFile):
60
- # print("close unreferenced File:",get_basename(openCacheFile))
61
- self.close_cachefile(openCacheFile)
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
- existFlag = False
59
+ def is_reference_existent(self, file):
60
+ exist_flag = False
65
61
  # inspect all refererres to the file object
66
- gc.collect() #clear garbage before collecting referrers
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
- existFlag = True
68
+ exist_flag = True
73
69
  break
74
- return existFlag
70
+ return exist_flag
75
71
 
76
- def is_cachefile_existent(self,cacheFileName):
77
- if cacheFileName in listdir(self.cache_dir):
72
+ def is_cachefile_existent(self, filename):
73
+ if filename in listdir(self.cache_dir):
78
74
  return True
79
- else:
80
- return False
75
+ return False
81
76
 
82
- def _increase_file_reference_counter(self, cacheFileName):
83
- self.openFileReferenceCount[cacheFileName] = self.openFileReferenceCount.get(cacheFileName, 0) + 1
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, cacheFileName):
86
- self.openFileReferenceCount[cacheFileName] = self.openFileReferenceCount[cacheFileName] - 1
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.openFileReferenceCount.items()))
90
-
91
- def get_cache_file( self, obj, basename, mode='a' ):
92
- '''
93
- returns pytables .h5 file to h5f trait of calling object for caching
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
- cacheFileName = basename + '_cache.h5'
100
- objFileName = self.get_filename(obj.h5f)
101
-
102
- if objFileName:
103
- if objFileName == cacheFileName:
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
- else: # in case the base name has changed ( different source )
107
- self._decrease_file_reference_counter(objFileName)
108
-
109
- if cacheFileName not in self.open_files: # or tables.file._open_files.filenames
110
- if (
111
- config.global_caching == 'readonly'
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
- else:
119
- if config.global_caching == 'readonly': mode = 'r'
120
- f = self.open_cachefile(cacheFileName,mode)
121
- self.open_files[cacheFileName] = f
122
-
123
- obj.h5f = self.open_files[cacheFileName]
124
- self._increase_file_reference_counter(cacheFileName)
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
- def get_basename(file):
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
- # -*- coding: utf-8 -*-
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
- class H5FileBase(object):
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 get_node_children(self, group):
50
- yield
29
+ def create_new_group(self, name, group=None):
30
+ pass
51
31
 
52
32
 
53
- class H5CacheFileBase(object):
54
- '''
55
- Base class for File objects that handle writing and reading of .h5 cache files
56
- '''
57
-
58
- compressionFilter = None
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 is_tables:
69
-
45
+ if config.have_tables:
46
+ import tables
47
+
70
48
  precision_to_atom = {
71
- 'float32' : tables.Float32Atom(),
72
- 'complex64' : tables.ComplexAtom(8),
73
- 'float64' : tables.Float64Atom(),
74
- 'complex128' : tables.ComplexAtom(16),
75
- 'bool' : tables.BoolAtom(),
76
- 'int32' : tables.Int32Atom(),
77
- 'int16' : tables.Int16Atom(),
78
- 'int8' : tables.Int8Atom(),
79
- }
80
-
81
- class H5FileTables(H5FileBase,tables.File):
82
-
83
- def create_extendable_array(self,nodename,shape,precision,group=None):
84
- if not group: group = self.root
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: group = self.root
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.get_attr(attrname)
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: group = self.root
106
- return self.create_group(group,name)
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
- compressionFilter = tables.Filters(complevel=5, complib='blosc')
116
-
117
- def is_cached(self,nodename,group=None):
118
- if not group: group = self.root
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
- else:
122
- return False
123
-
124
- def create_compressible_array(self,nodename,shape,precision,group=None):
125
- if not group: group = self.root
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
- filters=self.compressionFilter)
129
-
130
-
131
-
132
- if is_h5py:
133
-
134
- class H5FileH5py(H5FileBase,h5py.File):
135
-
136
- def _get_in_file_path(self,nodename,group=None):
137
- if not group: return '/'+nodename
138
- else: return group+'/'+nodename
139
-
140
- def create_array(self,where, name, obj):
141
- self.create_dataset(f'{where}/{name}',data=obj)
142
-
143
- def create_extendable_array(self,nodename,shape,precision,group=None):
144
- in_file_path = self._get_in_file_path(nodename,group)
145
- self.create_dataset(in_file_path, shape=shape, dtype=precision,
146
- maxshape=(None,shape[1]))
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
- oldShape = node.shape
160
- newShape = (oldShape[0] + data.shape[0], data.shape[1])
161
- node.resize(newShape)
162
- node[oldShape[0]:newShape[0],:] = data
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
- compressionFilter = "lzf"
181
- # compressionFilter = 'blosc' # unavailable...
182
-
183
- def is_cached(self,nodename,group=None):
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
- else:
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 == "pytables": return H5FileTables
200
- elif config.h5library == "h5py": return H5FileH5py
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 == "pytables": return H5CacheFileTables
204
- elif config.h5library == "h5py": return H5CacheFileH5py
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
- # coding=UTF-8
2
- #------------------------------------------------------------------------------
1
+ # ------------------------------------------------------------------------------
3
2
  # Copyright (c) Acoular Development Team.
4
- #------------------------------------------------------------------------------
3
+ # ------------------------------------------------------------------------------
5
4
 
6
5
  from hashlib import md5
7
6
 
8
- def digest( obj, name='digest'):
9
- str_ = [str(obj.__class__).encode("UTF-8")]
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("UTF-8"))
16
- except:
15
+ str_.append(str(vobj).encode('UTF-8'))
16
+ except: # noqa: E722
17
17
  pass
18
- return '_' + md5(''.encode("UTF-8").join(str_)).hexdigest()
18
+ return '_' + md5(b''.join(str_)).hexdigest()
19
+
19
20
 
20
- def ldigest(l):
21
+ def ldigest(obj_list):
21
22
  str_ = []
22
- for i in l:
23
+ for i in obj_list:
23
24
  str_.append(str(i.digest).encode('UTF-8'))
24
- return '_' + md5(''.encode("UTF-8").join(str_)).hexdigest()
25
-
26
-
25
+ return '_' + md5(b''.join(str_)).hexdigest()