CYHSM / DeepInsight

A general framework for interpreting wide-band neural activity
MIT License
156 stars 32 forks source link

Question regarding wavelet transform #11

Open DaoraZ opened 3 years ago

DaoraZ commented 3 years ago

Hi Dr. Frey, Thank you for your article. As your results are amazing I wanted to give Deepinsight a try on my lab data. However, I encouter an issue concerning the preprocessing of the input data. After running the deepinsight.preprocess.preprocess_input( ) function with our electrophysiology data (which have a 30.000Hz sampling rate), the result of the wavelet transform is unexpected. The frequency bands used to compute the wavelet transform return as follows:

deepinsight.preprocess.preprocess_input(fp_deepinsight, input_data, sampling_rate=sampling_rate, channels=channels) 
hdf5_file = h5py.File(fp_deepinsight, mode='r')
frequencies = np.round(hdf5_file['inputs/fourier_frequencies'], 3)
print(list(frequencies))

It returns: [inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, 58.6, 41.44, 29.3, 20.72, 14.65, 10.36, 7.324, 5.18, 3.662, 2.59]

I assume that the wavelet transform functions automatically determines the best frequency bands to perform the transform, so I do not understand the origin of these "inf" values. Do you have any idea about what is wrong, or on how to constrain the frequency bands ?

Thank you in advance, Allan Muller

CYHSM commented 3 years ago

That seems strange, can not reproduce it here. Can you try to cast it to float32 before printing? Something like this: print(np.array(hdf5_file['inputs/fourier_frequencies']).astype(np.float32))

For future reference, it is likely related to this line: https://github.com/CYHSM/DeepInsight/blob/96b96456744602808d2ffd61b0e6694ccc8fb164/deepinsight/preprocess.py#L65

DaoraZ commented 3 years ago

You were right, it looks like it was just a display problem. When cast to float32 the frequency bands appear as expected. It was just due to the np.round() function I suppose:

hdf5_file = h5py.File(fp_deepinsight, mode='r') print(np.array(hdf5_file['inputs/fourier_frequencies']).astype(np.float32)) [1.50000000e+04 1.06080000e+04 7.50000000e+03 5.30400000e+03 3.75000000e+03 2.65200000e+03 1.87500000e+03 1.32600000e+03 9.37500000e+02 6.63000000e+02 4.68750000e+02 3.31500000e+02 2.34375000e+02 1.65750000e+02 1.17187500e+02 8.28750000e+01 5.85937500e+01 4.14375000e+01 2.92968750e+01 2.07187500e+01 1.46484375e+01 1.03593750e+01 7.32421875e+00 5.17968750e+00 3.66210938e+00 2.58984375e+00]

print(list(hdf5_file['inputs/fourier_frequencies'])) [15000.0, 10610.0, 7500.0, 5304.0, 3750.0, 2652.0, 1875.0, 1326.0, 937.5, 663.0, 468.8, 331.5, 234.4, 165.8, 117.2, 82.9, 58.6, 41.44, 29.3, 20.72, 14.65, 10.36, 7.324, 5.18, 3.662, 2.59]

print(np.round(hdf5_file['inputs/fourier_frequencies'], 3)) [ inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf 58.6 41.44 29.3 20.72 14.65 10.36 7.324 5.18 3.662 2.59 ]

Thank you for the help.