{ "cells": [ { "cell_type": "markdown", "id": "9e1307f0", "metadata": {}, "source": [ "# Searching with ONE\n", "ONE contains a method that allows you to search for sessions of interest. The possible search terms can be listed using," ] }, { "cell_type": "code", "execution_count": 19, "id": "f1059dad", "metadata": { "ExecuteTime": { "end_time": "2023-08-16T11:44:35.816915300Z", "start_time": "2023-08-16T11:44:35.703297300Z" }, "execution": { "iopub.execute_input": "2021-09-07T19:19:07.354046Z", "iopub.status.busy": "2021-09-07T19:19:07.354046Z", "iopub.status.idle": "2021-09-07T19:19:08.591171Z", "shell.execute_reply": "2021-09-07T19:19:08.590390Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('dataset', 'date_range', 'laboratory', 'number', 'projects', 'subject', 'task_protocol')\n" ] } ], "source": [ "from one.api import ONE\n", "one = ONE(base_url='https://openalyx.internationalbrainlab.org')\n", "\n", "print(one.search_terms())" ] }, { "cell_type": "markdown", "id": "c687995a", "metadata": {}, "source": [ "We can search for sessions within a specified date range (inclusive)" ] }, { "cell_type": "code", "execution_count": 20, "id": "615b849e", "metadata": { "ExecuteTime": { "end_time": "2023-08-16T11:44:35.947082400Z", "start_time": "2023-08-16T11:44:35.717260100Z" }, "execution": { "iopub.execute_input": "2021-09-07T19:19:08.613510Z", "iopub.status.busy": "2021-09-07T19:19:08.612190Z", "iopub.status.idle": "2021-09-07T19:19:08.622008Z", "shell.execute_reply": "2021-09-07T19:19:08.621194Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['ef91b4d0-02a3-48c4-b6ad-610d346e5f68', 'b4e3383c-6cdb-49af-81a1-39b8f88aa5fd']\n" ] } ], "source": [ "from pprint import pprint\n", "eids = one.search(date_range=['2021-01-01', '2021-01-01'])\n", "pprint(eids)" ] }, { "cell_type": "markdown", "id": "cb4b412ba3f5369c", "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } }, "source": [ "A single date can be provided instead of a range. Also to define only the upper or lower date bound, set the other element to None." ] }, { "cell_type": "code", "execution_count": 21, "id": "df0e2477078cc019", "metadata": { "ExecuteTime": { "end_time": "2023-08-16T11:44:35.994954600Z", "start_time": "2023-08-16T11:44:35.779919900Z" }, "collapsed": false, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "assert one.search(date_range=['2021-01-01', '2021-01-01']) == one.search(date_range='2021-01-01')" ] }, { "cell_type": "markdown", "id": "e0b16d83", "metadata": {}, "source": [ "To get more information about the sessions we can add a details=True flag" ] }, { "cell_type": "code", "execution_count": 22, "id": "1cac7162", "metadata": { "ExecuteTime": { "end_time": "2023-08-16T11:44:36.007920Z", "start_time": "2023-08-16T11:44:35.859110200Z" }, "execution": { "iopub.execute_input": "2021-09-07T19:19:08.638650Z", "iopub.status.busy": "2021-09-07T19:19:08.636895Z", "iopub.status.idle": "2021-09-07T19:19:08.658966Z", "shell.execute_reply": "2021-09-07T19:19:08.657556Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[{'date': datetime.date(2021, 1, 1),\n", " 'lab': 'wittenlab',\n", " 'number': 2,\n", " 'projects': 'witten_learning_dop',\n", " 'subject': 'fip_12',\n", " 'task_protocol': '_iblrig_tasks_FPChoiceWorld6.4.2'},\n", " {'date': datetime.date(2021, 1, 1),\n", " 'lab': 'wittenlab',\n", " 'number': 2,\n", " 'projects': 'witten_learning_dop',\n", " 'subject': 'fip_11',\n", " 'task_protocol': '_iblrig_tasks_FP_biasedChoiceWorld6.4.2'}]\n" ] } ], "source": [ "eids, details = one.search(date_range=['2021-01-01', '2021-01-01'], details=True)\n", "pprint(details)" ] }, { "cell_type": "markdown", "id": "7e312800", "metadata": {}, "source": [ "Multiple search terms can also be combined, for example we can search for any sessions from the subject SWC_043 that contain the datasets spikes.times and spikes.clusters" ] }, { "cell_type": "code", "execution_count": 23, "id": "98802da6", "metadata": { "ExecuteTime": { "end_time": "2023-08-16T11:44:36.149540700Z", "start_time": "2023-08-16T11:44:35.904985700Z" }, "execution": { "iopub.execute_input": "2021-09-07T19:19:08.670654Z", "iopub.status.busy": "2021-09-07T19:19:08.668862Z", "iopub.status.idle": "2021-09-07T19:19:08.689760Z", "shell.execute_reply": "2021-09-07T19:19:08.690757Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['4ecb5d24-f5cc-402c-be28-9d0f7cb14b3a',\n", " 'c6db3304-c906-400c-aa0f-45dd3945b2ea',\n", " '88d24c31-52e4-49cc-9f32-6adbeb9eba87',\n", " '6fb1e12c-883b-46d1-a745-473cde3232c8',\n", " '695a6073-eae0-49e0-bb0f-e9e57a9275b9',\n", " '6f09ba7e-e3ce-44b0-932b-c003fb44fb89',\n", " 'f3ce3197-d534-4618-bf81-b687555d1883']\n" ] } ], "source": [ "eids = one.search(subject='SWC_043', dataset=['spikes.times', 'spikes.clusters'])\n", "pprint(eids)" ] }, { "cell_type": "markdown", "id": "8b568b6f5d92cc22", "metadata": { "collapsed": false }, "source": [ "More search terms are available when making [remote queries](../one_modes.html) (using the remote\n", "Alyx database instead of the local cache). You can view all the remote search terms with the\n", "'remote' arg:" ] }, { "cell_type": "code", "execution_count": 24, "id": "478524e9a00663b5", "metadata": { "ExecuteTime": { "end_time": "2023-08-16T11:44:36.150538600Z", "start_time": "2023-08-16T11:44:36.014900200Z" }, "collapsed": false, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "one.search_terms('remote')\n", "eids = one.search(performance_gte=70, query_type='remote')" ] }, { "cell_type": "markdown", "id": "8df01601c3a47ec6", "metadata": { "collapsed": false }, "source": [ "