Skip to content

Commit 0d982a6

Browse files
committed
start of session 2 code
1 parent 89b288e commit 0d982a6

File tree

2 files changed

+353
-0
lines changed

2 files changed

+353
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Update your repository with new stuff\n",
8+
"#### Note this is technically not good practice here, but we'll worry about that later\n",
9+
"\n",
10+
"- Open git bash to your learning python folder\n",
11+
"\n",
12+
"- git checkout -b session2\n",
13+
"\n",
14+
"- git remote add upstream https://github.com/tne-lab/learning-python\n",
15+
"\n",
16+
"- git fetch upstream\n",
17+
"\n",
18+
"- git merge upstream/master --strategy-option theirs\n",
19+
"\n",
20+
"### Open Jupyter Notebook and open Session_2.ipynb\n",
21+
"\n",
22+
"\n",
23+
"# Today we will look at events first\n"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 10,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"loading events...\n",
36+
"events loaded in!\n",
37+
"Loading continuous data...\n",
38+
"data loaded in!\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"import os\n",
44+
"import OpenEphys\n",
45+
"\n",
46+
"cwd = os.getcwd() # Gets your current working directory\n",
47+
"\n",
48+
"pathToEvents = cwd + '\\\\data\\\\Sample_Data\\\\all_channels.events' # All events are stored here\n",
49+
" \n",
50+
"allEvents = OpenEphys.load(pathToEvents)\n",
51+
"print('events loaded in!')\n",
52+
"\n",
53+
"pathToData = cwd + '\\\\data\\\\Sample_Data\\\\100_CH1.continuous' # You can change this to look at other channels!\n",
54+
" \n",
55+
"data = OpenEphys.load(pathToData)\n",
56+
"print('data loaded in!')"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 9,
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"name": "stdout",
66+
"output_type": "stream",
67+
"text": [
68+
"<class 'dict'>\n",
69+
"header\n",
70+
"channel\n",
71+
"timestamps\n",
72+
"eventType\n",
73+
"nodeId\n",
74+
"eventId\n",
75+
"recordingNumber\n",
76+
"sampleNum\n"
77+
]
78+
}
79+
],
80+
"source": [
81+
"# What is events?\n",
82+
"print(type(allEvents))\n",
83+
"\n",
84+
"# Lets look at what is stored in here.\n",
85+
"for key in allEvents.keys():\n",
86+
" print(key)"
87+
]
88+
},
89+
{
90+
"cell_type": "markdown",
91+
"metadata": {},
92+
"source": [
93+
"## Build a class to store event data"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": null,
99+
"metadata": {},
100+
"outputs": [],
101+
"source": [
102+
"import numpy as np\n",
103+
"\n",
104+
"class Events:\n",
105+
" # Put code here (use Con class below as a reference!)\n",
106+
" \n",
107+
"class Con:\n",
108+
" def __init__(self, data):\n",
109+
" self.data = data['data'] # Volatage data\n",
110+
" self.fs = float(data['header']['sampleRate']) # Sample Rate\n",
111+
" self.interpTs(data['timestamps']) # Interpolate timestamps for all data points (Only has 1 time stamp for each buffer of 1024 data points)\n",
112+
"\n",
113+
" def interpTs(self, ts):\n",
114+
" tsStart = ts[0]\n",
115+
" tsEnd = ts[len(ts)-1]\n",
116+
" self.ts = np.linspace(tsStart, tsEnd, len(ts) * 1024) # Creates the array of timestamps\n",
117+
" i = 0\n",
118+
" for t in self.ts:\n",
119+
" self.ts[i] = t - tsStart # Zero out the timestamps, just makes it look better when graphing/explaining\n",
120+
" i = i + 1\n",
121+
" self.tsStart = tsStart # Send the ts start to event data\n",
122+
" \n",
123+
"con = Con(data)\n",
124+
"events = Events(allEvents, con.tsStart)"
125+
]
126+
},
127+
{
128+
"cell_type": "code",
129+
"execution_count": 12,
130+
"metadata": {},
131+
"outputs": [],
132+
"source": []
133+
}
134+
],
135+
"metadata": {
136+
"kernelspec": {
137+
"display_name": "Python 3",
138+
"language": "python",
139+
"name": "python3"
140+
},
141+
"language_info": {
142+
"codemirror_mode": {
143+
"name": "ipython",
144+
"version": 3
145+
},
146+
"file_extension": ".py",
147+
"mimetype": "text/x-python",
148+
"name": "python",
149+
"nbconvert_exporter": "python",
150+
"pygments_lexer": "ipython3",
151+
"version": "3.6.8"
152+
}
153+
},
154+
"nbformat": 4,
155+
"nbformat_minor": 2
156+
}

0 commit comments

Comments
 (0)