From ab24a9e5a05b2d601042ab5e852a467beb4416b2 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Mon, 19 Jun 2023 23:29:02 +0000 Subject: [PATCH 1/3] add short tutorials --- short_tutorials/datajoint_in_30mins.ipynb | 2651 +++++++++++++++++ .../datajoint_matlab_virtual_module.mlx | Bin 0 -> 3688 bytes 2 files changed, 2651 insertions(+) create mode 100644 short_tutorials/datajoint_in_30mins.ipynb create mode 100644 short_tutorials/datajoint_matlab_virtual_module.mlx diff --git a/short_tutorials/datajoint_in_30mins.ipynb b/short_tutorials/datajoint_in_30mins.ipynb new file mode 100644 index 0000000..4bc5505 --- /dev/null +++ b/short_tutorials/datajoint_in_30mins.ipynb @@ -0,0 +1,2651 @@ +{ + "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": 14, + "id": "35ea1431-0762-48ec-8ed7-0744bd7d4fe6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "DataJoint connection (connected) rochester-workshop@rds.datajoint.io:3306" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "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": 54, + "id": "2d5def96-892b-462b-b7ff-a5ed48f3845c", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "[2023-06-19 23:23:10,641][INFO]: Deleting 2 rows from `rochester-workshop_thinh`.`__analysis`\n", + "[2023-06-19 23:23:11,159][INFO]: Deleting 1 rows from `rochester-workshop_thinh`.`session`\n", + "[2023-06-19 23:23:11,673][INFO]: Deleting 1 rows from `rochester-workshop_thinh`.`subject`\n", + "[2023-06-19 23:23:19,040][WARNING]: Deletes cancelled\n" + ] + }, + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "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 0000000000000000000000000000000000000000..d87aa64a40618e18f0656a0721fe4161e3e64b2e GIT binary patch literal 3688 zcma)<2{csw8^?!XkUiN&mNLkaW$@Y!im?n?^4ganjCE{TA}LFj?8StTT_!>li3}=B zjV0TVz1K2i-}0Z%`=0m3sm}l2bMNn-d+zf+_kQm8_dL%J4g->%0RRA$#DfIKh1=3lbU((Gw!4Bct;0_MgjI)##kHa(D}ZmOtv6x$#FDX@x(+-K;*u zd{ofPNQ2ZO!kYzE-wJLEfpoGcBpPCdv6iM9-~TKr7D1jX?9QL*{B#EtooM$&abBhz zZlzn4p`!r1F7!B?*O`g8%ED6J?aC-kes(r&1>eUJU0o6{`r0c6C`EgHQ{h=@sNxj4 z(DEOJGy#(?sjjc6^2;iy7e1@72kO<+>cWaf?#hg>9NfrN@s58iwknm4;jdw3W|(K> zxLE|M@)6xh|CGbP@7613I|(!Z_6LF|`_545oP!_Odynqb99&i_>TaW)a@y+|XeUT2 zw;Fz%v&;T?P9p>ZlU44HnOA}rZXOOJzk%RH%A)^Lu3!IS0!*aLO$Go^1I_?!d=N;K zxY&;~34nq4*zv6*Kcm6c>y|@EGu1WC|RVfSVVT-EHBAK-v*LcZJ|>R6v{O@jSA9$bv8s-IV0cf z2w2DtpEgK>6xE=1voF1OTWrSa7olV-*>2f%q@b8E~}P>?8}I_X6rO?^F~ z(>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 From: Thinh Nguyen Date: Mon, 19 Jun 2023 23:30:43 +0000 Subject: [PATCH 2/3] minor cleanup --- short_tutorials/datajoint_in_30mins.ipynb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/short_tutorials/datajoint_in_30mins.ipynb b/short_tutorials/datajoint_in_30mins.ipynb index 4bc5505..ac5e56d 100644 --- a/short_tutorials/datajoint_in_30mins.ipynb +++ b/short_tutorials/datajoint_in_30mins.ipynb @@ -34,21 +34,10 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "35ea1431-0762-48ec-8ed7-0744bd7d4fe6", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "DataJoint connection (connected) rochester-workshop@rds.datajoint.io:3306" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "dj.conn()" ] From fc776005dd25c7da06a658f5a6080aaa98746dd1 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Mon, 19 Jun 2023 23:33:54 +0000 Subject: [PATCH 3/3] minor cleanup --- short_tutorials/datajoint_in_30mins.ipynb | 25 ++--------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/short_tutorials/datajoint_in_30mins.ipynb b/short_tutorials/datajoint_in_30mins.ipynb index ac5e56d..df60d01 100644 --- a/short_tutorials/datajoint_in_30mins.ipynb +++ b/short_tutorials/datajoint_in_30mins.ipynb @@ -2586,31 +2586,10 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "id": "2d5def96-892b-462b-b7ff-a5ed48f3845c", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "[2023-06-19 23:23:10,641][INFO]: Deleting 2 rows from `rochester-workshop_thinh`.`__analysis`\n", - "[2023-06-19 23:23:11,159][INFO]: Deleting 1 rows from `rochester-workshop_thinh`.`session`\n", - "[2023-06-19 23:23:11,673][INFO]: Deleting 1 rows from `rochester-workshop_thinh`.`subject`\n", - "[2023-06-19 23:23:19,040][WARNING]: Deletes cancelled\n" - ] - }, - { - "data": { - "text/plain": [ - "1" - ] - }, - "execution_count": 54, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "(Subject & 'subject_name = \"anne\"').delete()" ]