{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Data from Greenwald et al. (2009)\n\nThis example shows how to use the Greenwald et al. (2009) dataset.\n\n[Greenwald2009]_ investigated the relationship between electrical stimulation amplitude\nand phosphene brightness in two Argus I users.\n\n.. important ::\n\n        You will need to install [Pandas](https://pandas.pydata.org)\n        (``pip install pandas``) for this dataset.\n\n## Loading the dataset\n\nThe dataset can be loaded as a Pandas ``DataFrame``:\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pulse2percept.datasets import load_greenwald2009\ndata = load_greenwald2009()\nprint(data)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Inspecting the DataFrame tells us that there are 83 measurements\n(the rows) each with 12 different attributes (the columns).\n\nThese attributes include specifiers such as \"subject\", \"electrode\", and\n\"task\". We can print all column names using:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(data.columns)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. note ::\n\n    The meaning of all column names is explained in the docstring of\n    the :py:func:`~pulse2percept.datasets.load_greenwald2009` function.\n\nFor example, \"amp\" corresponds to the amplitude of the stimulation used\nin a particular measurement:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "data.amp.unique()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "To select all the rows where the same subject was used, such as 'S05'\nwe can index into the DataFrame as follows:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(data[data.subject == 'S05'])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Likewise, we can perform the same operation when initially loading the data\nas follows:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(load_greenwald2009(subjects='S05'))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. note ::\n\n    Please see the documentation for :py:func:`~pulse2percept.datasets.load_greenwald2009`\n    to see all available parameters for data subset loading.\n\n\n\n## Plotting the data\n\nTo see the relationship between electrical stimulation amplitude and phosphene brightness,\nlet us demonstrate partially recreating part of Figure 2 from the paper. Specifically,\nwe will look at subject S06 and electrode C4. Please note, we omit the power fits in this demonstration.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\ndata = load_greenwald2009(subjects='S06', electrodes='C4')\n\n# Adjust the x-axis scaling, and add title\nplt.xlim(0, 400)\nplt.xticks(ticks=[0, 200, 400])\nplt.xlabel(\"Current (\u00b5A)\")\n\n# Adjust the y-axis scaling, and add title\nplt.ylabel(\"Rating\")\n\nplt.title(\"S06\")\nplt.ylim(0, 25)\n\n# Add figure title\nplt.title(\"S06 Current Amplitude vs Brightness, Electrode C4\")\n\n# Plot the data\nplt.scatter(data.amp, data.brightness)\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "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.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}