def test_fetch_beyeler2019():
    data = datasets.fetch_beyeler2019(shuffle=False)

    npt.assert_equal(isinstance(data, pd.DataFrame), True)
    columns = [
        'subject', 'amp', 'area', 'compactness', 'date', 'eccentricity',
        'electrode', 'filename', 'freq', 'image', 'orientation', 'pdur',
        'stim_class', 'x_center', 'y_center', 'img_shape'
    ]
    for expected_col in columns:
        npt.assert_equal(expected_col in data.columns, True)

    npt.assert_equal(data.shape, (400, 16))
    npt.assert_equal(data.subject.unique(), ['S1', 'S2', 'S3', 'S4'])
    npt.assert_equal(list(data[data.subject == 'S1'].img_shape.unique()[0]),
                     [384, 384])
    npt.assert_equal(list(data[data.subject != 'S1'].img_shape.unique()[0]),
                     [768, 1024])

    # Shuffle dataset (index will always be range(400), but rows are shuffled):
    data = datasets.fetch_beyeler2019(shuffle=True, random_state=42)
    npt.assert_equal(data.loc[0, 'subject'], 'S3')
    npt.assert_equal(data.loc[0, 'electrode'], 'A2')
    npt.assert_equal(data.loc[399, 'subject'], 'S2')
    npt.assert_equal(data.loc[399, 'electrode'], 'D4')

    with mock.patch.dict("sys.modules", {"pandas": {}}):
        with pytest.raises(ImportError):
            reload(datasets)
            datasets.fetch_beyeler2019()
Example #2
0
can be downloaded from the Open Science Framework (OSF).

By default, the dataset will be stored in a local directory
‘~/pulse2percept_data/’ within your user directory (but a different path can be
specified).
This way, the datasets is only downloaded once, and future calls to the fetch
function will load the dataset from your local copy.

The data itself will be provided as a Pandas ``DataFrame``:

"""
# sphinx_gallery_thumbnail_number = 2

from pulse2percept.datasets import fetch_beyeler2019

data = fetch_beyeler2019()
print(data)

###############################################################################
#
# Inspecting the DataFrame tells us that there are 400 phosphene drawings
# (the rows) each with 16 different attributes (the columns).
#
# These attributes include specifiers such as "subject", "electrode", and
# "image". We can print all column names using:

data.columns

###############################################################################
# .. note ::
#
def _is_beyeler2019_not_available():
    try:
        datasets.fetch_beyeler2019(download_if_missing=False)
        return False
    except IOError:
        return True