Skip to content

Commit 4a6ad7b

Browse files
author
Thinh Nguyen
committed
ephys tutorial completed
1 parent 4670fb4 commit 4a6ad7b

File tree

8 files changed

+5396
-13
lines changed

8 files changed

+5396
-13
lines changed

electrophysiology/02-Imported and Computed Tables - Completed.ipynb

Lines changed: 5302 additions & 0 deletions
Large diffs are not rendered by default.

electrophysiology/02-Imported and Computed Tables.ipynb renamed to electrophysiology/02-Imported and Computed Tables - Interactive.ipynb

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"cell_type": "markdown",
6161
"metadata": {},
6262
"source": [
63-
"Now we would like to continue working with the tables we defined in the previous notebook. To do so, we would need the classes for each table: `Mouse` and `Session`. We can either redefine it here, but for your convenience, we have included the schema and table class definitions in a package called `workshop.session2`, from which you can import the classes as well as the schema object. We will use the schema object again to define more tables."
63+
"Now we would like to continue working with the tables we defined in the previous notebook. To do so, we would need the classes for each table: `Mouse` and `Session`. We can either redefine it here, but for your convenience, we have included the schema and table class definitions in a package called `tutorial_pipeline.mouse_session`, from which you can import the classes as well as the schema object. We will use the schema object again to define more tables."
6464
]
6565
},
6666
{
@@ -69,7 +69,9 @@
6969
"metadata": {},
7070
"outputs": [],
7171
"source": [
72-
"from workshop.session2 import schema, Mouse, Session"
72+
"import sys\n",
73+
"sys.path.append(\"..\")\n",
74+
"from tutorial_pipeline.mouse_session import schema, Mouse, Session"
7375
]
7476
},
7577
{
@@ -94,7 +96,7 @@
9496
"cell_type": "markdown",
9597
"metadata": {},
9698
"source": [
97-
"The `session2.py` also fills each table with data to make sure we are all on the same page."
99+
"The `mouse_session.py` also fills each table with data to make sure we are all on the same page."
98100
]
99101
},
100102
{
@@ -258,7 +260,7 @@
258260
"cell_type": "markdown",
259261
"metadata": {},
260262
"source": [
261-
"So this particular file contains a NumPy array of length 1000. This represents a (simulated) recording of raw electric activity from a single neuron over 1000 time bins."
263+
"So this particular file contains a NumPy array of size 1 x 1000. This represents a (simulated) recording of raw electric activity from neuron(s) (1st dimension) over 1000 time bins (2nd dimesion)."
262264
]
263265
},
264266
{
@@ -274,7 +276,7 @@
274276
"source": [
275277
"We now would like to have all these recorded `Neuron` represented and stored in our data pipeline.\n",
276278
"\n",
277-
"Since we only record a single neuron from each session, a `Neuron` can be uniquely identified by knowing the `Session` it was recorded in. For each `Neuron`, we want to store the neural activity found in the data file."
279+
"Since there may be multiple neurons recorded from each session, a `Neuron` can be uniquely identified by knowing the `Session` it was recorded in, as well as its `neuron_id`. For each `Neuron`, we want to store the neural activity found in the data file."
278280
]
279281
},
280282
{
@@ -287,6 +289,7 @@
287289
"class Neuron(dj.Imported):\n",
288290
" definition = \"\"\"\n",
289291
" -> Session\n",
292+
" neuron_id: int\n",
290293
" ---\n",
291294
" activity: longblob # electric activity of the neuron\n",
292295
" \"\"\""
@@ -319,7 +322,7 @@
319322
"cell_type": "markdown",
320323
"metadata": {},
321324
"source": [
322-
"Note that our `Neuron` class inherits from `dj.Imported` instaed of `dj.Manual` like others. This is because **this table's content will depend on data imported from an external file**. The `Manual` vs `Imported` are said to specify the **tier of the table**."
325+
"Note that our `Neuron` class inherits from `dj.Imported` instead of `dj.Manual` like others. This is because **this table's content will depend on data imported from an external file**. The `Manual` vs `Imported` are said to specify the **tier of the table**."
323326
]
324327
},
325328
{
@@ -491,14 +494,18 @@
491494
"\n",
492495
" # load the data\n",
493496
" data = np.load(data_file)\n",
497+
" \n",
498+
" for idx, d in enumerate(data):\n",
499+
" # add the index of the 1st dimension as neuron_id\n",
500+
" key['neuron_id'] = idx\n",
501+
" \n",
502+
" # add the loaded data as the \"activity\" column\n",
503+
" key['activity'] = d\n",
494504
"\n",
495-
" # add the loaded data as the \"activity\" column\n",
496-
" key['activity'] = data\n",
505+
" # insert the key into self\n",
506+
" self.insert1(key)\n",
497507
"\n",
498-
" # insert the key into self\n",
499-
" self.insert1(key)\n",
500-
"\n",
501-
" print('Populated a neuron for mouse_id={mouse_id} on session_date={session_date}'.format(**key))"
508+
" print('Populated neuron={neuron_id} for mouse_id={mouse_id} on session_date={session_date}'.format(**key))"
502509
]
503510
},
504511
{
@@ -533,6 +540,13 @@
533540
"Neuron()"
534541
]
535542
},
543+
{
544+
"cell_type": "markdown",
545+
"metadata": {},
546+
"source": [
547+
"As you can obviously see, in these example datasets, we only have data for one neuron per session. "
548+
]
549+
},
536550
{
537551
"cell_type": "markdown",
538552
"metadata": {},
@@ -1524,7 +1538,7 @@
15241538
"name": "python",
15251539
"nbconvert_exporter": "python",
15261540
"pygments_lexer": "ipython3",
1527-
"version": "3.6.2"
1541+
"version": "3.7.0"
15281542
}
15291543
},
15301544
"nbformat": 4,
48 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.

tutorial_pipeline/mouse_session.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import datajoint as dj
2+
3+
4+
# fail-safe user name retrieval
5+
username = dj.conn().conn_info['user']
6+
schema = dj.schema('{}_tutorial_pipeline'.format(username))
7+
8+
9+
# Table definitions
10+
11+
@schema
12+
class Mouse(dj.Manual):
13+
definition = """
14+
# Experimental animals
15+
mouse_id : int # Unique animal ID
16+
---
17+
dob=null : date # date of birth
18+
sex="unknown" : enum('M','F','unknown') # sex
19+
"""
20+
21+
22+
@schema
23+
class Session(dj.Manual):
24+
definition = """
25+
# Experiment session
26+
-> Mouse
27+
session_date : date # date
28+
---
29+
experiment_setup : int # experiment setup ID
30+
experimenter : varchar(100) # experimenter name
31+
data_path='' : varchar(255) #
32+
"""
33+
34+
35+
# Insert the following data into the table
36+
37+
mouse_data = [
38+
{'dob': "2017-03-01", 'mouse_id': 0, 'sex': 'M'},
39+
{'dob': "2016-11-19", 'mouse_id': 1, 'sex': 'M'},
40+
{'dob': "2016-11-20", 'mouse_id': 2, 'sex': 'unknown'},
41+
{'dob': "2016-12-25", 'mouse_id': 5, 'sex': 'F'},
42+
{'dob': "2017-01-01", 'mouse_id': 10, 'sex': 'F'},
43+
{'dob': "2017-01-03", 'mouse_id': 11, 'sex': 'F'},
44+
{'dob': "2017-05-12", 'mouse_id': 100, 'sex': 'F'}
45+
]
46+
47+
session_data = [
48+
{'experiment_setup': 0,
49+
'experimenter': 'Edgar Y. Walker',
50+
'mouse_id': 0,
51+
'session_date': "2017-05-15"},
52+
{'experiment_setup': 0,
53+
'experimenter': 'Edgar Y. Walker',
54+
'mouse_id': 0,
55+
'session_date': "2017-05-19"},
56+
{'experiment_setup': 1,
57+
'experimenter': 'Fabian Sinz',
58+
'mouse_id': 5,
59+
'session_date': "2017-01-05"},
60+
{'experiment_setup': 100,
61+
'experimenter': 'Jacob Reimer',
62+
'mouse_id': 100,
63+
'session_date': "2017-05-25"}
64+
]
65+
66+
Mouse.insert(mouse_data, skip_duplicates=True)
67+
Session.insert(session_data, skip_duplicates=True)

0 commit comments

Comments
 (0)