I am trying to do some spectral analysis on the IBL LFP and relate that to spiking and behavioural data in the IBL but I am having issues loading the LFP even after reading the tutorials and documentation online tutorials. I have two questions.
1) Spikeglx is required to load the IBL LFP files and supposedly this is a python api, but I don’t see it. Pip install doesn’t find it either. Your tutorials don’t show how to get this either.
It seems like to me that I need a package that is not available online. Please note I’m not a member of the IBL. I have installed the ONE-api, brainbox and ibllib but I cannot get spikeglx from anywhere and it seems to be required to work with your lfp data. Is it possible to use npyx in some way instead?
Also I’m curious about where the information about things like sample rate and time offset is stored so I can align the LFP to the spiking and behavioural data later down the line. I’ve read the documentation and this is not really clear from it.
Should I just copy paste the python folder from the Spikeglx Github Repo file and use that? https://github.com/jenniferColonell/SpikeGLX_Datafile_Tools/blob/main/Python/DemoReadSGLXData/readSGLX.py
I saw there is this repository as well: https://github.com/jenniferColonell/SpikeGLX_Datafile_Tools/blob/main/Python/read_SGLX_analog.ipynb
And brainbox.io.spikeglx
as well as ibllib.io.spikeglx
both exist, but it’s not clear from the tutorial on LFP and the documentation if that’s what running import spikeglx
is getting.
In the word documentation on the ALyx files https://docs.google.com/document/d/1OqIqqakPakHXRAwceYLwFY9gOrm8_P62XIfCTnHwstg/edit on page 25 there is example code showing a way to read the lfp files into python via ibllib.io import spikeglx
but this returns an error for me:
from ibllib.io import spikeglx:
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) /home/acampbell/Stienmetz2019Reanalyzed/ExtractingSWRs/ibl_swr_data/ibl_swr_detector_testing.ipynb Cell 5 line 1 ----> 1 from ibllib.io import spikeglx ImportError: cannot import name ‘spikeglx’ from ‘ibllib.io’ (/home/acampbell/miniconda3/envs/ONE_ibl_env/lib/python3.10/site-packages/ibllib/io/init.py)
Overall it is not clear at all from the tutorial which option for this library we are meant to use. I could just try reading the file in myself which brings me to the next question:
2) LFP Preprocessing Questions (bit-to volts, accessing sampling rates, reference electrode etc etc)
If I go the route of just writing my own code to load the LFP files I want to make sure I am doing the preprocessing correctly. I’d prefer to stick to IBL recommendations rather than juryrigging my own solution, in case I miss something and mess the data up somehow.
I was downloading LFP from the figshare repo for the first dataset the IBL released (from the 2017 paper Distributed coding… Steinmetz et al., 2017) by hand and then running this:
with open(r'/space/scratch/steinmetz2019data/LFP/Tatum_2017-12-06/Tatum_2017-12-06_K2_g0_t0.imec.lf.bin', 'rb')
as fid:
probe_K0_2500hz = np.fromfile(fid, np.int16).reshape((-1, 385))
This gives me a numpy array, and then I have to make a 1d array for sampling times. For the I then multiple the values by 1.95 for the conversion bit to volts rate and subtract the median values for each channel. Not sure whether that’s the proper processing I should be doing. Don’t I need to use the reference channel as well somehow? Also I need to align the 1d array of sampling times to the clock being used by the spikes, trials, wheels (etc) objects.
I’m at the stage in my analysis where I want to automate this process of pulling data, running it through an event detector and converting the output into an Alyx formated .npy files (with events and times or intervals stored as 1d vectors) which I can then analyze against trial and spike data.