diff --git a/short_tutorials/datajoint_in_30mins.ipynb b/short_tutorials/datajoint_in_30mins.ipynb new file mode 100644 index 0000000..df60d01 --- /dev/null +++ b/short_tutorials/datajoint_in_30mins.ipynb @@ -0,0 +1,2619 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 12, + "id": "41b1b9b1-8749-4459-8fe8-0e0a7e17a5f7", + "metadata": {}, + "outputs": [], + "source": [ + "import datajoint as dj\n", + "import numpy as np" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "c3ba552d-1894-41ea-ad4e-d96c828e871d", + "metadata": {}, + "source": [ + "# Connect to the database" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "284addad-c0aa-4ba5-a70d-8a238d05e6e9", + "metadata": {}, + "outputs": [], + "source": [ + "dj.config['database.host'] = '*************'\n", + "dj.config['database.user'] = '*************'\n", + "dj.config['database.password'] = '*************'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35ea1431-0762-48ec-8ed7-0744bd7d4fe6", + "metadata": {}, + "outputs": [], + "source": [ + "dj.conn()" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "e086433f-70ec-4f5d-ac4b-0fa889b53e60", + "metadata": {}, + "source": [ + "# Define and create table" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "bf55ec72-7d24-401a-bedc-eec7f52012b7", + "metadata": {}, + "outputs": [], + "source": [ + "schema_name = 'your_schema_name'\n", + "schema = dj.Schema(schema_name)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "f34fe6b8-e2be-4f37-9f75-b6ac77cc6f8d", + "metadata": {}, + "outputs": [], + "source": [ + "@schema\n", + "class Subject(dj.Manual):\n", + " definition = \"\"\"\n", + " subject_name: varchar(16)\n", + " ---\n", + " sex: enum('F', 'M', 'U')\n", + " \"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "99b43e71-a028-414e-9e97-53a431031441", + "metadata": {}, + "outputs": [], + "source": [ + "@schema\n", + "class Session(dj.Manual):\n", + " definition = \"\"\"\n", + " -> Subject\n", + " session_id: int\n", + " \"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "18f21ee6-41be-4c35-8f6d-774d7af35e81", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "%3\n", + "\n", + "\n", + "\n", + "Session\n", + "\n", + "\n", + "Session\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "Subject\n", + "\n", + "\n", + "Subject\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "Subject->Session\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dj.Diagram(schema)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "e2ba7302-01bb-4fbd-ac8a-c963e8d22926", + "metadata": {}, + "source": [ + "# Insert" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "f72e48ea-e7c0-42ab-9050-271b3c64b498", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

sex

\n", + " \n", + "
\n", + " \n", + "

Total: 0

\n", + " " + ], + "text/plain": [ + "*subject_name sex \n", + "+------------+ +-----+\n", + "\n", + " (Total: 0)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Subject()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "51ad2992-136b-48d9-827c-f587d81df10b", + "metadata": {}, + "outputs": [], + "source": [ + "Subject.insert1({'subject_name': 'bob', 'sex': 'M'})" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "4d8f666d-ecf2-44a6-8315-b25cfdd1d2a6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

sex

\n", + " \n", + "
bobM
\n", + " \n", + "

Total: 1

\n", + " " + ], + "text/plain": [ + "*subject_name sex \n", + "+------------+ +-----+\n", + "bob M \n", + " (Total: 1)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Subject()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "9010652f-aba5-44c5-a109-ba3c02eeed9f", + "metadata": {}, + "outputs": [], + "source": [ + "subject_list = [\n", + " {'subject_name': 'alice', 'sex': 'F'},\n", + " {'subject_name': 'anne', 'sex': 'F'}\n", + "]\n", + "Subject.insert(subject_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "67325168-00b7-4220-847c-8ce66a630785", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

sex

\n", + " \n", + "
aliceF
anneF
bobM
\n", + " \n", + "

Total: 3

\n", + " " + ], + "text/plain": [ + "*subject_name sex \n", + "+------------+ +-----+\n", + "alice F \n", + "anne F \n", + "bob M \n", + " (Total: 3)" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Subject()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "408c35f5-ca64-4740-8456-836f4dcecc24", + "metadata": {}, + "outputs": [], + "source": [ + "session_list = [\n", + " {'subject_name': 'bob', 'session_id': 1},\n", + " {'subject_name': 'bob', 'session_id': 2}\n", + "]\n", + "Session.insert(session_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "039482b1-941f-4cfb-9da3-0d312954d229", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
bob1
bob2
\n", + " \n", + "

Total: 2

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id \n", + "+------------+ +------------+\n", + "bob 1 \n", + "bob 2 \n", + " (Total: 2)" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Session()" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "c88b5d48-185b-40d4-8f99-de4ad068d82b", + "metadata": {}, + "source": [ + "# Table with computation" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "5a1b4ad5-530f-4e34-9724-550e02b6dba2", + "metadata": {}, + "outputs": [], + "source": [ + "@schema\n", + "class Param(dj.Lookup):\n", + " definition = \"\"\"\n", + " param_id: int\n", + " ---\n", + " multiplier: int\n", + " \"\"\" " + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "b21579e9-0976-44aa-9219-1b8ec978f81d", + "metadata": {}, + "outputs": [], + "source": [ + "@schema\n", + "class Analysis(dj.Computed):\n", + " definition = \"\"\"\n", + " -> Session\n", + " -> Param\n", + " ---\n", + " result: longblob\n", + " \"\"\"\n", + " \n", + " def make(self, key):\n", + " # print status\n", + " print(f\"Working on session_id {key['session_id']} and param_id {key['param_id']}\")\n", + " \n", + " # retrieve data from upstream\n", + " session_id = (Session & key).fetch1('session_id')\n", + " multiplier_val = (Param & key).fetch1('multiplier')\n", + " \n", + " # perform computation\n", + " result = np.ones(10) * session_id * multiplier_val\n", + " \n", + " # store the results\n", + " key['result'] = result\n", + " self.insert1(key)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "c8ae90ee-e790-483a-86bb-36b4c2f84d25", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "%3\n", + "\n", + "\n", + "\n", + "Param\n", + "\n", + "\n", + "Param\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "Analysis\n", + "\n", + "\n", + "Analysis\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "Param->Analysis\n", + "\n", + "\n", + "\n", + "\n", + "Session\n", + "\n", + "\n", + "Session\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "Session->Analysis\n", + "\n", + "\n", + "\n", + "\n", + "Subject\n", + "\n", + "\n", + "Subject\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "Subject->Session\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dj.Diagram(schema)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "22876302-5f5a-4ddc-86ec-85dc9e9b3204", + "metadata": {}, + "source": [ + "## Run the computation" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "8a96a370-0ce8-45a4-a91e-2d88572b84f3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "

param_id

\n", + " \n", + "
\n", + "

multiplier

\n", + " \n", + "
\n", + " \n", + "

Total: 0

\n", + " " + ], + "text/plain": [ + "*param_id multiplier \n", + "+----------+ +------------+\n", + "\n", + " (Total: 0)" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Param()" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "ee2a7e55-ed1b-4f7b-bccc-7b25f1c32902", + "metadata": {}, + "outputs": [], + "source": [ + "param_list = [\n", + " {'param_id': 0, 'multiplier': 1},\n", + " {'param_id': 1, 'multiplier': 16}\n", + "]\n", + "Param.insert(param_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "598a35f6-d708-49b0-b98e-8fdd6685d186", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "
\n", + "

param_id

\n", + " \n", + "
\n", + "

multiplier

\n", + " \n", + "
01
116
\n", + " \n", + "

Total: 2

\n", + " " + ], + "text/plain": [ + "*param_id multiplier \n", + "+----------+ +------------+\n", + "0 1 \n", + "1 16 \n", + " (Total: 2)" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Param()" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "ce60647f-dffc-45b9-aaf2-d2b6c9ef86c7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
\n", + "

param_id

\n", + " \n", + "
\n", + "

result

\n", + " \n", + "
\n", + " \n", + "

Total: 0

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id *param_id result \n", + "+------------+ +------------+ +----------+ +--------+\n", + "\n", + " (Total: 0)" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Analysis()" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "cfe58b04-4981-4c3a-8b39-4e959f1c5028", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Working on session_id 2 and param_id 0\n", + "Working on session_id 1 and param_id 0\n", + "Working on session_id 2 and param_id 1\n", + "Working on session_id 1 and param_id 1\n" + ] + } + ], + "source": [ + "Analysis.populate()" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "bb11eb2b-62f6-4c06-a444-bd404f4fd554", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
\n", + "

param_id

\n", + " \n", + "
\n", + "

result

\n", + " \n", + "
bob10=BLOB=
bob20=BLOB=
bob11=BLOB=
bob21=BLOB=
\n", + " \n", + "

Total: 4

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id *param_id result \n", + "+------------+ +------------+ +----------+ +--------+\n", + "bob 1 0 =BLOB= \n", + "bob 2 0 =BLOB= \n", + "bob 1 1 =BLOB= \n", + "bob 2 1 =BLOB= \n", + " (Total: 4)" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Analysis()" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "7f181cda-c910-428a-baaf-bd990149b0a6", + "metadata": {}, + "outputs": [], + "source": [ + "# populate again - nothing new to be populated\n", + "Analysis.populate()" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "7495d66c-dbb1-4af7-b6f1-54e28f086bba", + "metadata": {}, + "source": [ + "### Add new sessions and run analysis again" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "cdfeb6d4-4070-421c-a994-678dce66a6d1", + "metadata": {}, + "outputs": [], + "source": [ + "session_list = [\n", + " {'subject_name': 'alice', 'session_id': 1},\n", + " {'subject_name': 'anne', 'session_id': 2}\n", + "]\n", + "Session.insert(session_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "6b70158b-d9c8-4b70-a49d-f33f50f09678", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Working on session_id 1 and param_id 1\n", + "Working on session_id 1 and param_id 0\n", + "Working on session_id 2 and param_id 1\n", + "Working on session_id 2 and param_id 0\n" + ] + } + ], + "source": [ + "# populate again\n", + "Analysis.populate()" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "df03a0b9-7eab-4c4b-ade9-998f652c29da", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
\n", + "

param_id

\n", + " \n", + "
\n", + "

result

\n", + " \n", + "
alice10=BLOB=
anne20=BLOB=
bob10=BLOB=
bob20=BLOB=
alice11=BLOB=
anne21=BLOB=
bob11=BLOB=
bob21=BLOB=
\n", + " \n", + "

Total: 8

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id *param_id result \n", + "+------------+ +------------+ +----------+ +--------+\n", + "alice 1 0 =BLOB= \n", + "anne 2 0 =BLOB= \n", + "bob 1 0 =BLOB= \n", + "bob 2 0 =BLOB= \n", + "alice 1 1 =BLOB= \n", + "anne 2 1 =BLOB= \n", + "bob 1 1 =BLOB= \n", + "bob 2 1 =BLOB= \n", + " (Total: 8)" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Analysis()" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "c25fff8f-5b5e-44aa-b8b6-830b4acbba12", + "metadata": {}, + "source": [ + "## Query" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "2b949d17-31e0-4318-b4fa-5b848eb6e039", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
alice1
anne2
bob1
bob2
\n", + " \n", + "

Total: 4

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id \n", + "+------------+ +------------+\n", + "alice 1 \n", + "anne 2 \n", + "bob 1 \n", + "bob 2 \n", + " (Total: 4)" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Session()" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "bb33cf6a-5a1d-42b9-a5ab-ceb5afe94bfc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
\n", + "

sex

\n", + " \n", + "
alice1F
anne2F
bob1M
bob2M
\n", + " \n", + "

Total: 4

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id sex \n", + "+------------+ +------------+ +-----+\n", + "alice 1 F \n", + "anne 2 F \n", + "bob 1 M \n", + "bob 2 M \n", + " (Total: 4)" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Session * Subject" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "944053d0-9e63-4d18-84ac-18b93e827bec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
alice1
bob1
\n", + " \n", + "

Total: 2

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id \n", + "+------------+ +------------+\n", + "alice 1 \n", + "bob 1 \n", + " (Total: 2)" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Session & 'session_id = 1'" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "4eb5535e-7abc-42f2-b395-1bbd6ee4a498", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
bob1
\n", + " \n", + "

Total: 1

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id \n", + "+------------+ +------------+\n", + "bob 1 \n", + " (Total: 1)" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Session & 'subject_name = \"bob\"' & 'session_id = 1'" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "8fe4fdfd-9838-418b-a97e-666e75b5f5a7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
\n", + "

sex

\n", + " \n", + "
bob1M
\n", + " \n", + "

Total: 1

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id sex \n", + "+------------+ +------------+ +-----+\n", + "bob 1 M \n", + " (Total: 1)" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Session * Subject & 'subject_name = \"bob\"' & 'session_id = 1'" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "418ef4f4-5b42-4728-a726-8cd161d9f776", + "metadata": {}, + "source": [ + "# Fetch" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "be966b2c-16f7-4646-a503-21cbb82561db", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
\n", + "

param_id

\n", + " \n", + "
\n", + "

result

\n", + " \n", + "
alice10=BLOB=
anne20=BLOB=
bob10=BLOB=
bob20=BLOB=
alice11=BLOB=
anne21=BLOB=
bob11=BLOB=
bob21=BLOB=
\n", + " \n", + "

Total: 8

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id *param_id result \n", + "+------------+ +------------+ +----------+ +--------+\n", + "alice 1 0 =BLOB= \n", + "anne 2 0 =BLOB= \n", + "bob 1 0 =BLOB= \n", + "bob 2 0 =BLOB= \n", + "alice 1 1 =BLOB= \n", + "anne 2 1 =BLOB= \n", + "bob 1 1 =BLOB= \n", + "bob 2 1 =BLOB= \n", + " (Total: 8)" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Analysis()" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "9abceb88-a603-47e8-84e1-7e8864558355", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
\n", + "

param_id

\n", + " \n", + "
\n", + "

result

\n", + " \n", + "
\n", + "

multiplier

\n", + " \n", + "
alice11=BLOB=16
anne21=BLOB=16
bob11=BLOB=16
bob21=BLOB=16
\n", + " \n", + "

Total: 4

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id *param_id result multiplier \n", + "+------------+ +------------+ +----------+ +--------+ +------------+\n", + "alice 1 1 =BLOB= 16 \n", + "anne 2 1 =BLOB= 16 \n", + "bob 1 1 =BLOB= 16 \n", + "bob 2 1 =BLOB= 16 \n", + " (Total: 4)" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Analysis * Param & 'param_id = 1'" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "0991217c-813c-4ca8-97b8-cd755f0210b0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

session_id

\n", + " \n", + "
\n", + "

param_id

\n", + " \n", + "
\n", + "

result

\n", + " \n", + "
\n", + "

multiplier

\n", + " \n", + "
alice11=BLOB=16
anne21=BLOB=16
\n", + " \n", + "

Total: 2

\n", + " " + ], + "text/plain": [ + "*subject_name *session_id *param_id result multiplier \n", + "+------------+ +------------+ +----------+ +--------+ +------------+\n", + "alice 1 1 =BLOB= 16 \n", + "anne 2 1 =BLOB= 16 \n", + " (Total: 2)" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Analysis * Param & 'param_id = 1' & 'subject_name != \"bob\"'" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "06ee91de-4239-45fa-9917-74e8f09c228e", + "metadata": {}, + "outputs": [], + "source": [ + "query = Analysis * Param & 'param_id = 1' & 'subject_name != \"bob\"'" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "af750120-1389-42e6-a324-643f3f0d7c39", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([('alice', 1, 1, array([16., 16., 16., 16., 16., 16., 16., 16., 16., 16.]), 16),\n", + " ('anne', 2, 1, array([32., 32., 32., 32., 32., 32., 32., 32., 32., 32.]), 16)],\n", + " dtype=[('subject_name', 'O'), ('session_id', '\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
resultmultiplier
subject_namesession_idparam_id
alice11[16.0, 16.0, 16.0, 16.0, 16.0, 16.0, 16.0, 16....16
anne21[32.0, 32.0, 32.0, 32.0, 32.0, 32.0, 32.0, 32....16
\n", + "" + ], + "text/plain": [ + " result \\\n", + "subject_name session_id param_id \n", + "alice 1 1 [16.0, 16.0, 16.0, 16.0, 16.0, 16.0, 16.0, 16.... \n", + "anne 2 1 [32.0, 32.0, 32.0, 32.0, 32.0, 32.0, 32.0, 32.... \n", + "\n", + " multiplier \n", + "subject_name session_id param_id \n", + "alice 1 1 16 \n", + "anne 2 1 16 " + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query.fetch(format='frame') # returns as pandas dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "eb03eb2a-c1d0-40bc-8d15-917ed4154f8a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([array([16., 16., 16., 16., 16., 16., 16., 16., 16., 16.]),\n", + " array([32., 32., 32., 32., 32., 32., 32., 32., 32., 32.])],\n", + " dtype=object)" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query.fetch('result')" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "5840245d-3b4f-4501-9c7f-41d94395c7ab", + "metadata": {}, + "source": [ + "# Delete" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "2227ce0a-ccd0-4350-9c08-d148fae4dfcd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

sex

\n", + " \n", + "
aliceF
anneF
bobM
\n", + " \n", + "

Total: 3

\n", + " " + ], + "text/plain": [ + "*subject_name sex \n", + "+------------+ +-----+\n", + "alice F \n", + "anne F \n", + "bob M \n", + " (Total: 3)" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Subject()" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "f6dcedfa-6d70-49cb-8bf6-edd5e6aa51fc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "
\n", + "

subject_name

\n", + " \n", + "
\n", + "

sex

\n", + " \n", + "
anneF
\n", + " \n", + "

Total: 1

\n", + " " + ], + "text/plain": [ + "*subject_name sex \n", + "+------------+ +-----+\n", + "anne F \n", + " (Total: 1)" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Subject & 'subject_name = \"anne\"'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2d5def96-892b-462b-b7ff-a5ed48f3845c", + "metadata": {}, + "outputs": [], + "source": [ + "(Subject & 'subject_name = \"anne\"').delete()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.16" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/short_tutorials/datajoint_matlab_virtual_module.mlx b/short_tutorials/datajoint_matlab_virtual_module.mlx new file mode 100644 index 0000000..d87aa64 Binary files /dev/null and b/short_tutorials/datajoint_matlab_virtual_module.mlx differ