|
60 | 60 | "cell_type": "markdown", |
61 | 61 | "metadata": {}, |
62 | 62 | "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." |
64 | 64 | ] |
65 | 65 | }, |
66 | 66 | { |
|
69 | 69 | "metadata": {}, |
70 | 70 | "outputs": [], |
71 | 71 | "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" |
73 | 75 | ] |
74 | 76 | }, |
75 | 77 | { |
|
94 | 96 | "cell_type": "markdown", |
95 | 97 | "metadata": {}, |
96 | 98 | "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." |
98 | 100 | ] |
99 | 101 | }, |
100 | 102 | { |
|
258 | 260 | "cell_type": "markdown", |
259 | 261 | "metadata": {}, |
260 | 262 | "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)." |
262 | 264 | ] |
263 | 265 | }, |
264 | 266 | { |
|
274 | 276 | "source": [ |
275 | 277 | "We now would like to have all these recorded `Neuron` represented and stored in our data pipeline.\n", |
276 | 278 | "\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." |
278 | 280 | ] |
279 | 281 | }, |
280 | 282 | { |
|
287 | 289 | "class Neuron(dj.Imported):\n", |
288 | 290 | " definition = \"\"\"\n", |
289 | 291 | " -> Session\n", |
| 292 | + " neuron_id: int\n", |
290 | 293 | " ---\n", |
291 | 294 | " activity: longblob # electric activity of the neuron\n", |
292 | 295 | " \"\"\"" |
|
319 | 322 | "cell_type": "markdown", |
320 | 323 | "metadata": {}, |
321 | 324 | "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**." |
323 | 326 | ] |
324 | 327 | }, |
325 | 328 | { |
|
491 | 494 | "\n", |
492 | 495 | " # load the data\n", |
493 | 496 | " 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", |
494 | 504 | "\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", |
497 | 507 | "\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))" |
502 | 509 | ] |
503 | 510 | }, |
504 | 511 | { |
|
533 | 540 | "Neuron()" |
534 | 541 | ] |
535 | 542 | }, |
| 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 | + }, |
536 | 550 | { |
537 | 551 | "cell_type": "markdown", |
538 | 552 | "metadata": {}, |
|
1524 | 1538 | "name": "python", |
1525 | 1539 | "nbconvert_exporter": "python", |
1526 | 1540 | "pygments_lexer": "ipython3", |
1527 | | - "version": "3.6.2" |
| 1541 | + "version": "3.7.0" |
1528 | 1542 | } |
1529 | 1543 | }, |
1530 | 1544 | "nbformat": 4, |
|
0 commit comments