-
Notifications
You must be signed in to change notification settings - Fork 0
/
openephys_to_nwb_tutorial.py
69 lines (49 loc) · 2.79 KB
/
openephys_to_nwb_tutorial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""openephys_to_nwb_tutorial.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1SjbCxu6qAFuxVOYOIcmcnCWk9l9IdVC0
"""
from google.colab import drive
drive.mount('/content/drive')
import sys
sys.path.append('/content/drive/My Drive/Colab Notebooks')
!git clone https://github.com/alishaar/OpenEphys_to_NWB.git
!pip install -r /content/OpenEphys_to_NWB/requirements.txt
"""# Metadata file explained
session.description = 'NA'; //description of the recording session\
session.start_time = '31-Jul-2021 180230'; //start time of the recording session\
session.device_name = 'NA';//name of the recording device used in the session\
electrode_group.name = 'NA';//name of the group of electordes associated with the recordings taken in the files you wish to convert to nwb\
electrode_group.description = 'NA';//a description of the elecrode group\
electrode_group.location = 'NA';//location (e.g. region of the brain) of the group of electrodes\
electrode1_metadata.id = 1;// id of the first electrode (should just be 1 for first, 2 for second etc.)\
electrode1_metadata.x = 1;//x coordinate of the first electrode\
electrode1_metadata.y = 2;//y coordinate\
electrode1_metadata.z = 3;//z coordinate\
electrode1_metadata.impedance = 1;//impedance value of first electrode\
electrode1_metadata.location = 'NA';//location (e.g. region of the brain) of the first electrode\
electrode1_metadata.filtering = 'NA';//any filtering used for the first electrode data (e.g band pass filter range etc.)\
file_electrodes.100_CH1.continuous = [0];//the rest stores which electrodes in the list coorespond to the data for each file we wish to convert\
file_electrodes.100_CH2.continuous = [0];\
file_electrodes.STp111.0n0 (1).spikes = [0];\
file_electrodes.STp111.0n1 (1).spikes = [1];
metadata file should be prepared beforhand and stored in the open ephys directory as "metadata.txt"
If no metadata.txt file is found, a default will be used, which sets most fields to NA.
"""
!python /content/OpenEphys_to_NWB/main.py --source source_file_path --destination destination_file_path
"""clone the repo, and run on a directory."""
from pynwb import NWBHDF5IO
io = NWBHDF5IO( destination_file_path , 'r')
nwbfile = io.read()
"""open the saved nwb file"""
ephys_ts = nwbfile.acquisition["100_CH1"]
print(ephys_ts)
ephys_ts = nwbfile.acquisition["'ST p111.0 n0'"]
print(ephys_ts)
"""each open ephys file is stored as a seperate acquisition object in the nwb file.
* continuous data files: processor ID_channel name (e.g. 100_CH1)
* spike data files: electrode type (SE = single electrode, ST = stereotrode, TT = tetrode), the source processor (e.g., p104.0), and the electrode index (e.g., n0, n1, etc.). (e.g. 'ST p111.0 n0')
"""
dat = ephys_ts.data
print(dat[:])