
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples\datasets\plot_greenwald2009.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_datasets_plot_greenwald2009.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_datasets_plot_greenwald2009.py:


===============================================================================
 Data from Greenwald et al. (2009)
===============================================================================

This example shows how to use the Greenwald et al. (2009) dataset.

[Greenwald2009]_ investigated the relationship between electrical stimulation amplitude
and phosphene brightness in two Argus I users.

.. important ::

        You will need to install `Pandas <https://pandas.pydata.org>`_
        (``pip install pandas``) for this dataset.

Loading the dataset
-------------------

The dataset can be loaded as a Pandas ``DataFrame``:

.. GENERATED FROM PYTHON SOURCE LINES 21-26

.. code-block:: Python


    from pulse2percept.datasets import load_greenwald2009
    data = load_greenwald2009()
    print(data)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

       subject implant electrode  task     stim_class  stim_dur         amp  brightness  pulse_dur  interphase_dur     pulse_type  threshold
    0      S05  ArgusI        B2  rate  Greenwald2009       0.2   41.328160    1.049167   0.000975        0.000975  cathodicfirst     20.688
    1      S05  ArgusI        B2  rate  Greenwald2009       0.2   29.805000    1.552139   0.000975        0.000975  cathodicfirst     20.688
    2      S05  ArgusI        B2  rate  Greenwald2009       0.2   52.713788    2.939241   0.000975        0.000975  cathodicfirst     20.688
    3      S05  ArgusI        B2  rate  Greenwald2009       0.2   38.842772    4.294906   0.000975        0.000975  cathodicfirst     20.688
    4      S05  ArgusI        B2  rate  Greenwald2009       0.2   68.637949    5.858834   0.000975        0.000975  cathodicfirst     20.688
    ..     ...     ...       ...   ...            ...       ...         ...         ...        ...             ...            ...        ...
    78     S06  ArgusI        C4  rate  Greenwald2009       0.2  225.574149   14.520485   0.000975        0.000975  cathodicfirst     22.324
    79     S06  ArgusI        C4  rate  Greenwald2009       0.2  260.380842   16.094634   0.000975        0.000975  cathodicfirst     22.324
    80     S06  ArgusI        C4  rate  Greenwald2009       0.2  316.006924   15.055972   0.000975        0.000975  cathodicfirst     22.324
    81     S06  ArgusI        C4  rate  Greenwald2009       0.2  385.931910   16.069821   0.000975        0.000975  cathodicfirst     22.324
    82     S06  ArgusI        C4  rate  Greenwald2009       0.2  248.805540   15.385459   0.000975        0.000975  cathodicfirst     22.324

    [83 rows x 12 columns]




.. GENERATED FROM PYTHON SOURCE LINES 28-33

Inspecting the DataFrame tells us that there are 83 measurements
(the rows) each with 12 different attributes (the columns).

These attributes include specifiers such as "subject", "electrode", and
"task". We can print all column names using:

.. GENERATED FROM PYTHON SOURCE LINES 33-35

.. code-block:: Python

    print(data.columns)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Index(['subject', 'implant', 'electrode', 'task', 'stim_class', 'stim_dur',
           'amp', 'brightness', 'pulse_dur', 'interphase_dur', 'pulse_type',
           'threshold'],
          dtype='object')




.. GENERATED FROM PYTHON SOURCE LINES 36-43

.. note ::

    The meaning of all column names is explained in the docstring of
    the :py:func:`~pulse2percept.datasets.load_greenwald2009` function.

For example, "amp" corresponds to the amplitude of the stimulation used
in a particular measurement:

.. GENERATED FROM PYTHON SOURCE LINES 43-46

.. code-block:: Python


    data.amp.unique()





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    array([ 41.32816 ,  29.805   ,  52.713788,  38.842772,  68.637949,
            57.0362  ,  59.197407,  91.330615, 114.180461,  98.000884,
           166.727246, 141.431308, 152.708876, 134.20109 , 193.928975,
           228.341274, 271.997642, 184.350901, 220.983349, 255.238469,
           303.374429, 365.15546 ,  62.722416,  85.345931, 116.517286,
            96.922601, 144.880569, 195.673098, 229.608371, 272.082653,
            37.061239, 311.607576, 376.528765,   9.638554,  40.963855,
            28.915663,  60.240964,  79.518072,  81.927711, 113.253012,
           154.216867, 168.674699, 236.144578, 250.60241 , 306.024096,
           375.903614, 383.13253 ,  36.619718,  39.43662 ,  53.521127,
            78.873239, 104.225352, 143.661972, 205.633803, 287.323944,
           374.647887,  36.144578,  50.60241 , 108.433735, 161.445783,
           139.759036, 197.590361, 226.506024, 265.060241, 313.253012,
           385.542169,  57.28794 ,  42.596653,  51.252164, 103.854587,
            94.841316, 141.52337 , 155.879977, 176.030006, 190.721293,
           225.712637, 225.574149, 260.380842, 316.006924, 385.93191 ,
           248.80554 ])



.. GENERATED FROM PYTHON SOURCE LINES 47-49

To select all the rows where the same subject was used, such as 'S05'
we can index into the DataFrame as follows:

.. GENERATED FROM PYTHON SOURCE LINES 49-52

.. code-block:: Python


    print(data[data.subject == 'S05'])





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

       subject implant electrode  task     stim_class  stim_dur         amp  brightness  pulse_dur  interphase_dur     pulse_type  threshold
    0      S05  ArgusI        B2  rate  Greenwald2009       0.2   41.328160    1.049167   0.000975        0.000975  cathodicfirst     20.688
    1      S05  ArgusI        B2  rate  Greenwald2009       0.2   29.805000    1.552139   0.000975        0.000975  cathodicfirst     20.688
    2      S05  ArgusI        B2  rate  Greenwald2009       0.2   52.713788    2.939241   0.000975        0.000975  cathodicfirst     20.688
    3      S05  ArgusI        B2  rate  Greenwald2009       0.2   38.842772    4.294906   0.000975        0.000975  cathodicfirst     20.688
    4      S05  ArgusI        B2  rate  Greenwald2009       0.2   68.637949    5.858834   0.000975        0.000975  cathodicfirst     20.688
    5      S05  ArgusI        B2  rate  Greenwald2009       0.2   57.036200    7.729260   0.000975        0.000975  cathodicfirst     20.688
    6      S05  ArgusI        B2  rate  Greenwald2009       0.2   59.197407   10.124269   0.000975        0.000975  cathodicfirst     20.688
    7      S05  ArgusI        B2  rate  Greenwald2009       0.2   91.330615   11.006435   0.000975        0.000975  cathodicfirst     20.688
    8      S05  ArgusI        B2  rate  Greenwald2009       0.2  114.180461   13.419127   0.000975        0.000975  cathodicfirst     20.688
    9      S05  ArgusI        B2  rate  Greenwald2009       0.2   98.000884   14.943760   0.000975        0.000975  cathodicfirst     20.688
    10     S05  ArgusI        B2  rate  Greenwald2009       0.2  166.727246   19.105064   0.000975        0.000975  cathodicfirst     20.688
    11     S05  ArgusI        B2  rate  Greenwald2009       0.2  141.431308   19.254384   0.000975        0.000975  cathodicfirst     20.688
    12     S05  ArgusI        B2  rate  Greenwald2009       0.2  152.708876   23.024707   0.000975        0.000975  cathodicfirst     20.688
    13     S05  ArgusI        B2  rate  Greenwald2009       0.2  134.201090   25.060170   0.000975        0.000975  cathodicfirst     20.688
    14     S05  ArgusI        B2  rate  Greenwald2009       0.2  193.928975   25.794980   0.000975        0.000975  cathodicfirst     20.688
    15     S05  ArgusI        B2  rate  Greenwald2009       0.2  228.341274   27.020974   0.000975        0.000975  cathodicfirst     20.688
    16     S05  ArgusI        B2  rate  Greenwald2009       0.2  271.997642   27.400167   0.000975        0.000975  cathodicfirst     20.688
    17     S05  ArgusI        B2  rate  Greenwald2009       0.2  184.350901   32.453460   0.000975        0.000975  cathodicfirst     20.688
    18     S05  ArgusI        B2  rate  Greenwald2009       0.2  220.983349   35.048873   0.000975        0.000975  cathodicfirst     20.688
    19     S05  ArgusI        B2  rate  Greenwald2009       0.2  255.238469   39.009775   0.000975        0.000975  cathodicfirst     20.688
    20     S05  ArgusI        B2  rate  Greenwald2009       0.2  303.374429   41.444079   0.000975        0.000975  cathodicfirst     20.688
    21     S05  ArgusI        B2  rate  Greenwald2009       0.2  365.155460   46.454148   0.000975        0.000975  cathodicfirst     20.688
    33     S05  ArgusI        C3  rate  Greenwald2009       0.2    9.638554   -0.362493   0.000975        0.000975  cathodicfirst     35.408
    34     S05  ArgusI        C3  rate  Greenwald2009       0.2   40.963855    2.566789   0.000975        0.000975  cathodicfirst     35.408
    35     S05  ArgusI        C3  rate  Greenwald2009       0.2   28.915663    7.794657   0.000975        0.000975  cathodicfirst     35.408
    36     S05  ArgusI        C3  rate  Greenwald2009       0.2   60.240964    5.854374   0.000975        0.000975  cathodicfirst     35.408
    37     S05  ArgusI        C3  rate  Greenwald2009       0.2   79.518072    9.663698   0.000975        0.000975  cathodicfirst     35.408
    38     S05  ArgusI        C3  rate  Greenwald2009       0.2   81.927711   11.922472   0.000975        0.000975  cathodicfirst     35.408
    39     S05  ArgusI        C3  rate  Greenwald2009       0.2  113.253012   13.286537   0.000975        0.000975  cathodicfirst     35.408
    40     S05  ArgusI        C3  rate  Greenwald2009       0.2  154.216867   20.555265   0.000975        0.000975  cathodicfirst     35.408
    41     S05  ArgusI        C3  rate  Greenwald2009       0.2  168.674699   21.760084   0.000975        0.000975  cathodicfirst     35.408
    42     S05  ArgusI        C3  rate  Greenwald2009       0.2  236.144578   18.570980   0.000975        0.000975  cathodicfirst     35.408
    43     S05  ArgusI        C3  rate  Greenwald2009       0.2  250.602410   24.123625   0.000975        0.000975  cathodicfirst     35.408
    44     S05  ArgusI        C3  rate  Greenwald2009       0.2  306.024096   25.118910   0.000975        0.000975  cathodicfirst     35.408
    45     S05  ArgusI        C3  rate  Greenwald2009       0.2  375.903614   28.188580   0.000975        0.000975  cathodicfirst     35.408
    46     S05  ArgusI        C3  rate  Greenwald2009       0.2  383.132530   41.573599   0.000975        0.000975  cathodicfirst     35.408
    56     S05  ArgusI        C4  rate  Greenwald2009       0.2   36.144578    0.314301   0.000975        0.000975  cathodicfirst     24.000
    57     S05  ArgusI        C4  rate  Greenwald2009       0.2   60.240964    5.162913   0.000975        0.000975  cathodicfirst     24.000
    58     S05  ArgusI        C4  rate  Greenwald2009       0.2   81.927711    8.274489   0.000975        0.000975  cathodicfirst     24.000
    59     S05  ArgusI        C4  rate  Greenwald2009       0.2   50.602410    9.866946   0.000975        0.000975  cathodicfirst     24.000
    60     S05  ArgusI        C4  rate  Greenwald2009       0.2  108.433735   12.947093   0.000975        0.000975  cathodicfirst     24.000
    61     S05  ArgusI        C4  rate  Greenwald2009       0.2  161.445783   17.944474   0.000975        0.000975  cathodicfirst     24.000
    62     S05  ArgusI        C4  rate  Greenwald2009       0.2  139.759036   22.485071   0.000975        0.000975  cathodicfirst     24.000
    63     S05  ArgusI        C4  rate  Greenwald2009       0.2  197.590361   21.739130   0.000975        0.000975  cathodicfirst     24.000
    64     S05  ArgusI        C4  rate  Greenwald2009       0.2  226.506024   30.409639   0.000975        0.000975  cathodicfirst     24.000
    65     S05  ArgusI        C4  rate  Greenwald2009       0.2  265.060241   39.419591   0.000975        0.000975  cathodicfirst     24.000
    66     S05  ArgusI        C4  rate  Greenwald2009       0.2  313.253012   45.638554   0.000975        0.000975  cathodicfirst     24.000
    67     S05  ArgusI        C4  rate  Greenwald2009       0.2  385.542169   49.575694   0.000975        0.000975  cathodicfirst     24.000




.. GENERATED FROM PYTHON SOURCE LINES 53-55

Likewise, we can perform the same operation when initially loading the data
as follows:

.. GENERATED FROM PYTHON SOURCE LINES 55-58

.. code-block:: Python


    print(load_greenwald2009(subjects='S05'))





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

       subject implant electrode  task     stim_class  stim_dur         amp  brightness  pulse_dur  interphase_dur     pulse_type  threshold
    0      S05  ArgusI        B2  rate  Greenwald2009       0.2   41.328160    1.049167   0.000975        0.000975  cathodicfirst     20.688
    1      S05  ArgusI        B2  rate  Greenwald2009       0.2   29.805000    1.552139   0.000975        0.000975  cathodicfirst     20.688
    2      S05  ArgusI        B2  rate  Greenwald2009       0.2   52.713788    2.939241   0.000975        0.000975  cathodicfirst     20.688
    3      S05  ArgusI        B2  rate  Greenwald2009       0.2   38.842772    4.294906   0.000975        0.000975  cathodicfirst     20.688
    4      S05  ArgusI        B2  rate  Greenwald2009       0.2   68.637949    5.858834   0.000975        0.000975  cathodicfirst     20.688
    5      S05  ArgusI        B2  rate  Greenwald2009       0.2   57.036200    7.729260   0.000975        0.000975  cathodicfirst     20.688
    6      S05  ArgusI        B2  rate  Greenwald2009       0.2   59.197407   10.124269   0.000975        0.000975  cathodicfirst     20.688
    7      S05  ArgusI        B2  rate  Greenwald2009       0.2   91.330615   11.006435   0.000975        0.000975  cathodicfirst     20.688
    8      S05  ArgusI        B2  rate  Greenwald2009       0.2  114.180461   13.419127   0.000975        0.000975  cathodicfirst     20.688
    9      S05  ArgusI        B2  rate  Greenwald2009       0.2   98.000884   14.943760   0.000975        0.000975  cathodicfirst     20.688
    10     S05  ArgusI        B2  rate  Greenwald2009       0.2  166.727246   19.105064   0.000975        0.000975  cathodicfirst     20.688
    11     S05  ArgusI        B2  rate  Greenwald2009       0.2  141.431308   19.254384   0.000975        0.000975  cathodicfirst     20.688
    12     S05  ArgusI        B2  rate  Greenwald2009       0.2  152.708876   23.024707   0.000975        0.000975  cathodicfirst     20.688
    13     S05  ArgusI        B2  rate  Greenwald2009       0.2  134.201090   25.060170   0.000975        0.000975  cathodicfirst     20.688
    14     S05  ArgusI        B2  rate  Greenwald2009       0.2  193.928975   25.794980   0.000975        0.000975  cathodicfirst     20.688
    15     S05  ArgusI        B2  rate  Greenwald2009       0.2  228.341274   27.020974   0.000975        0.000975  cathodicfirst     20.688
    16     S05  ArgusI        B2  rate  Greenwald2009       0.2  271.997642   27.400167   0.000975        0.000975  cathodicfirst     20.688
    17     S05  ArgusI        B2  rate  Greenwald2009       0.2  184.350901   32.453460   0.000975        0.000975  cathodicfirst     20.688
    18     S05  ArgusI        B2  rate  Greenwald2009       0.2  220.983349   35.048873   0.000975        0.000975  cathodicfirst     20.688
    19     S05  ArgusI        B2  rate  Greenwald2009       0.2  255.238469   39.009775   0.000975        0.000975  cathodicfirst     20.688
    20     S05  ArgusI        B2  rate  Greenwald2009       0.2  303.374429   41.444079   0.000975        0.000975  cathodicfirst     20.688
    21     S05  ArgusI        B2  rate  Greenwald2009       0.2  365.155460   46.454148   0.000975        0.000975  cathodicfirst     20.688
    22     S05  ArgusI        C3  rate  Greenwald2009       0.2    9.638554   -0.362493   0.000975        0.000975  cathodicfirst     35.408
    23     S05  ArgusI        C3  rate  Greenwald2009       0.2   40.963855    2.566789   0.000975        0.000975  cathodicfirst     35.408
    24     S05  ArgusI        C3  rate  Greenwald2009       0.2   28.915663    7.794657   0.000975        0.000975  cathodicfirst     35.408
    25     S05  ArgusI        C3  rate  Greenwald2009       0.2   60.240964    5.854374   0.000975        0.000975  cathodicfirst     35.408
    26     S05  ArgusI        C3  rate  Greenwald2009       0.2   79.518072    9.663698   0.000975        0.000975  cathodicfirst     35.408
    27     S05  ArgusI        C3  rate  Greenwald2009       0.2   81.927711   11.922472   0.000975        0.000975  cathodicfirst     35.408
    28     S05  ArgusI        C3  rate  Greenwald2009       0.2  113.253012   13.286537   0.000975        0.000975  cathodicfirst     35.408
    29     S05  ArgusI        C3  rate  Greenwald2009       0.2  154.216867   20.555265   0.000975        0.000975  cathodicfirst     35.408
    30     S05  ArgusI        C3  rate  Greenwald2009       0.2  168.674699   21.760084   0.000975        0.000975  cathodicfirst     35.408
    31     S05  ArgusI        C3  rate  Greenwald2009       0.2  236.144578   18.570980   0.000975        0.000975  cathodicfirst     35.408
    32     S05  ArgusI        C3  rate  Greenwald2009       0.2  250.602410   24.123625   0.000975        0.000975  cathodicfirst     35.408
    33     S05  ArgusI        C3  rate  Greenwald2009       0.2  306.024096   25.118910   0.000975        0.000975  cathodicfirst     35.408
    34     S05  ArgusI        C3  rate  Greenwald2009       0.2  375.903614   28.188580   0.000975        0.000975  cathodicfirst     35.408
    35     S05  ArgusI        C3  rate  Greenwald2009       0.2  383.132530   41.573599   0.000975        0.000975  cathodicfirst     35.408
    36     S05  ArgusI        C4  rate  Greenwald2009       0.2   36.144578    0.314301   0.000975        0.000975  cathodicfirst     24.000
    37     S05  ArgusI        C4  rate  Greenwald2009       0.2   60.240964    5.162913   0.000975        0.000975  cathodicfirst     24.000
    38     S05  ArgusI        C4  rate  Greenwald2009       0.2   81.927711    8.274489   0.000975        0.000975  cathodicfirst     24.000
    39     S05  ArgusI        C4  rate  Greenwald2009       0.2   50.602410    9.866946   0.000975        0.000975  cathodicfirst     24.000
    40     S05  ArgusI        C4  rate  Greenwald2009       0.2  108.433735   12.947093   0.000975        0.000975  cathodicfirst     24.000
    41     S05  ArgusI        C4  rate  Greenwald2009       0.2  161.445783   17.944474   0.000975        0.000975  cathodicfirst     24.000
    42     S05  ArgusI        C4  rate  Greenwald2009       0.2  139.759036   22.485071   0.000975        0.000975  cathodicfirst     24.000
    43     S05  ArgusI        C4  rate  Greenwald2009       0.2  197.590361   21.739130   0.000975        0.000975  cathodicfirst     24.000
    44     S05  ArgusI        C4  rate  Greenwald2009       0.2  226.506024   30.409639   0.000975        0.000975  cathodicfirst     24.000
    45     S05  ArgusI        C4  rate  Greenwald2009       0.2  265.060241   39.419591   0.000975        0.000975  cathodicfirst     24.000
    46     S05  ArgusI        C4  rate  Greenwald2009       0.2  313.253012   45.638554   0.000975        0.000975  cathodicfirst     24.000
    47     S05  ArgusI        C4  rate  Greenwald2009       0.2  385.542169   49.575694   0.000975        0.000975  cathodicfirst     24.000




.. GENERATED FROM PYTHON SOURCE LINES 59-72

.. note ::

    Please see the documentation for :py:func:`~pulse2percept.datasets.load_greenwald2009`
    to see all available parameters for data subset loading.



Plotting the data
-----------------

To see the relationship between electrical stimulation amplitude and phosphene brightness,
let us demonstrate partially recreating part of Figure 2 from the paper. Specifically,
we will look at subject S06 and electrode C4. Please note, we omit the power fits in this demonstration.

.. GENERATED FROM PYTHON SOURCE LINES 72-93

.. code-block:: Python


    import matplotlib.pyplot as plt
    data = load_greenwald2009(subjects='S06', electrodes='C4')

    # Adjust the x-axis scaling, and add title
    plt.xlim(0, 400)
    plt.xticks(ticks=[0, 200, 400])
    plt.xlabel("Current (µA)")

    # Adjust the y-axis scaling, and add title
    plt.ylabel("Rating")

    plt.title("S06")
    plt.ylim(0, 25)

    # Add figure title
    plt.title("S06 Current Amplitude vs Brightness, Electrode C4")

    # Plot the data
    plt.scatter(data.amp, data.brightness)
    plt.show()



.. image-sg:: /examples/datasets/images/sphx_glr_plot_greenwald2009_001.png
   :alt: S06 Current Amplitude vs Brightness, Electrode C4
   :srcset: /examples/datasets/images/sphx_glr_plot_greenwald2009_001.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.176 seconds)


.. _sphx_glr_download_examples_datasets_plot_greenwald2009.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_greenwald2009.ipynb <plot_greenwald2009.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_greenwald2009.py <plot_greenwald2009.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_greenwald2009.zip <plot_greenwald2009.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
