cannot read in sampling frequency from .h5 files

85 views
Skip to first unread message

coolco...@gmail.com

unread,
May 2, 2019, 12:47:16 PM5/2/19
to Acoular-users
Dear Acoular Team,

I just got fresh measurement data and reformed them in .h5-format file with the help of MatLab (the function hdf5write).

However, I got the following error message when trying to read the file using the function MaskedTimeSamples.

Exception occurred in traits notification handler for object: <acoular.sources.MaskedTimeSamples object at 0x0000000005957EB8>, trait: basename, old value: None, new value: test03_WN
Traceback (most recent call last):
 
File "C:\Users\xiaomin.lai\AppData\Local\Continuum\anaconda3\lib\site-packages\traits\trait_notifiers.py", line 519, in _dispatch_change_event
   
self.dispatch( handler, *args )
 
File "C:\Users\xiaomin.lai\AppData\Local\Continuum\anaconda3\lib\site-packages\traits\trait_notifiers.py", line 482, in dispatch
    handler
( *args )
 
File "C:\Users\xiaomin.lai\AppData\Local\Continuum\anaconda3\lib\site-packages\acoular\sources.py", line 299, in load_data
   
self.sample_freq = self.data.get_attr('sample_freq')
 
File "C:\Users\xiaomin.lai\AppData\Local\Continuum\anaconda3\lib\site-packages\traits\trait_handlers.py", line 172, in error
    value
)
traits
.trait_errors.TraitError: The 'sample_freq' trait of a MaskedTimeSamples instance must be a float, but a value of array([8192.]) <class 'numpy.ndarray'> was specified.


For trouble shooting I compared two .h5 files, "example_data.h5" from Example 1 in Acoular and my generated .h5 file.
I imported them into MatLab and check the sample frequencies, only to find them structurally the same.

Could you please give me a hint, why the sample frequency in my generated .h5 file cannot be read correctly, although my file is structurally the same with the example?

Your help will be truly appreciated!

Best regards,
Shelmy

Simon Jekosch

unread,
May 3, 2019, 11:18:32 AM5/3/19
to Acoular-users
Hey Shelmy,

your saved your sample frequency as a numpy array instead of a float. The Trait is expected to be a float for the sample frequency. Since your array only consists of one float you can you access the value directly:
 
a = array([8192.])
a
[0] = 8192.0
isinstance
(a[0], float)

should return True.


Regards,
Simon



coolco...@gmail.com

unread,
May 3, 2019, 3:41:50 PM5/3/19
to Acoular-users
Thanks Prof. Sarradj and Simon! I generated .h5 file using Python (h5py) instead of MatLab and it worked fine. 
Reply all
Reply to author
Forward
0 new messages