{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Loading with ONE\n", "The datasets are organized into directory trees by subject, date and session number. For a\n", "given session there are data files grouped by object (e.g. 'trials'), each with a specific\n", "attribute (e.g. 'rewardVolume'). The dataset name follows the pattern 'object.attribute',\n", "for example 'trials.rewardVolume'. For more information, see the [ALF documentation](../alyx_files.html).\n", "\n", "An [experiment ID](../experiment_ids.html) (eid) is a string that uniquely identifies a session,\n", "for example a combinationof subject date and number (e.g. KS023/2019-12-10/001), a file path (e.g.\n", "C:\\Users\\Subjects\\KS023\\2019-12-10\\001), or a UUID (e.g. aad23144-0e52-4eac-80c5-c4ee2decb198).\n", "\n", "If the data don't exist locally, they will be downloaded, then loaded." ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "execution": { "iopub.execute_input": "2021-09-07T19:17:08.394242Z", "iopub.status.busy": "2021-09-07T19:17:08.393245Z", "iopub.status.idle": "2021-09-07T19:17:08.632883Z", "shell.execute_reply": "2021-09-07T19:17:08.630864Z" } }, "outputs": [], "source": [ "from pprint import pprint\n", "from one.api import ONE\n", "import one.alf.io as alfio\n", "\n", "one = ONE(base_url='https://openalyx.internationalbrainlab.org', silent=True)\n", "\n", "# To load all the data for a given object, use the load_object method:\n", "eid = 'KS023/2019-12-10/001' # subject/date/number\n", "trials = one.load_object(eid, 'trials') # Returns a dict-like object of numpy arrays" ] }, { "cell_type": "markdown", "source": [ "The attributes of returned object mirror the datasets:" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 37, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "dict_keys(['contrastLeft', 'intervals', 'response_times', 'stimOff_times', 'goCueTrigger_times', 'itiDuration', 'goCue_times', 'contrastRight', 'intervals_bpod', 'feedbackType', 'stimOn_times', 'choice', 'firstMovement_times', 'rewardVolume', 'feedback_times', 'probabilityLeft'])\n", "[1.5 1.5 1.5 0. 1.5]\n", "[1.5 1.5 1.5 0. 1.5]\n" ] } ], "source": [ "print(trials.keys())\n", "# The data can be accessed with dot syntax\n", "print(trials.rewardVolume[:5])\n", "# ... or dictionary syntax\n", "print(trials['rewardVolume'][:5])" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "All arrays in the object have the same length (the size of the first dimension) and can\n", "therefore be converted to a DataFrame:" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 38, "outputs": [], "source": [ "trials.to_df().head()\n", "\n", "# For analysis you can assert that the dimensions match using the check_dimensions property:\n", "assert trials.check_dimensions == 0" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "If we only want to load in certain attributes of an object we can use the following" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 39, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "dict_keys(['intervals', 'intervals_bpod', 'rewardVolume', 'probabilityLeft'])\n" ] } ], "source": [ "trials = one.load_object(eid, 'trials', attribute=['intervals', 'rewardVolume', 'probabilityLeft'])\n", "print(trials.keys())" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "Datasets can be individually downloaded using the `load_dataset` method. This\n", "function takes an experiment ID and a dataset name as positional args." ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": 40, "outputs": [], "source": [ "reward_volume = one.load_dataset(eid, '_ibl_trials.rewardVolume.npy') # c.f. load_object, above" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "We can use the load_datasets method to load multiple datasets at once. This method returns two\n", "lists, the first which contains the data for each dataset and the second which contains meta\n", "information about the data.\n", "\n", "