NeuralEnsemble / python-neo

Neo is a package for representing electrophysiology data in Python, together with support for reading a wide range of neurophysiology file formats
http://neo.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
325 stars 248 forks source link

IntanIO problem with one file per stream format #1556

Closed Tevin-yue closed 2 months ago

Tevin-yue commented 2 months ago

Which page is the problem on? IntanIO

What is the problem? IntanIO reads problematic. The function works well with rhd files but is problematic with dat files. Here are the pictures of the result. from_raw_data neo_intan_fig1 neo_intan_fig1_1 When reading .dat file from numpy directly(Fig 1), everything goes well. But the IntanIO seems wrongly loaded data. I doubt whether the data type is causing this problem. [.rhd, uint16; .dat, int16].

Suggestions for fixing the problem Could you please provide more information about reading .dat files?

zm711 commented 2 months ago

That looks like a scaling error. I'll look into this later today. Which version one file-per channel or one file per stream?

What script did you run? I want to make sure the scaling happened correctly so I need to see what code you specifically ran to get this :)

Tevin-yue commented 2 months ago

The simulated data were generated using Intan version 3.3.1.

Here is the code:

import os
from neo import io
import matplotlib.pyplot as plt

# Load rhd file
data_rhd = io.IntanIO(r'F:\MATLAB\RHD_test\RHD_test.rhd')
raw_chunk_rhd = data_rhd.get_analogsignal_chunk(block_index=0,
                                      stream_index=0,
                                      seg_index=0)

rhd = data_rhd.rescale_signal_raw_to_float(raw_chunk_rhd, stream_index=0)
plt.plot(rhd[:,3])

#Load dat file
data_dat = io.IntanIO(r'F:\MATLAB\DAT_test\info.rhd')
raw_chunk_dat = data_dat.get_analogsignal_chunk(block_index=0,
                                      stream_index=0,
                                      seg_index=0)
dat= data_dat.rescale_signal_raw_to_float(raw_chunk_dat, stream_index=0)
plt.plot(dat[:,3])

#Load from numpy
def load_dat(filename, num_channels):
    fileinfo = os.stat(filename)
    num_samples = fileinfo.st_size // (num_channels * 2)

    with open(filename, 'rb') as f:
        v = np.fromfile(f, dtype=np.int16, count=num_channels * num_samples)
        v = v.reshape((num_samples, num_channels)).T
    v = v * 0.195
    return v
data_wiht_numpy = load_dat(r'F:\MATLAB\DAT_test\amplifier.dat', 64)
plt.plot(data_wiht_numpy[3])

The scale is correct but not the wavefoms with .dat files.

zm711 commented 2 months ago

Linked a PR that should fix it!

Tevin-yue commented 2 months ago

Great! Everything is going well. I revised the intanrawio script as you showed.