Skip to content

Commit

Permalink
new version release
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrockhill committed Oct 22, 2020
1 parent 9eeabbe commit 80db31c
Show file tree
Hide file tree
Showing 78 changed files with 1,452 additions and 630 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Installation Instructions

4) Run ``pip install pd-parser`` in a terminal.

5) Install mne-bids bleeding edge: run ``pip install git+https://github.com/mne-tools/mne-bids.git``
5) Install the bleeding edge ``mne-bids``: run ``pip install git+https://github.com/mne-tools/mne-bids.git``


Getting Started
Expand Down
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 5fefbff0bc56e2ce58e62dae2547c3b0
config: a34f014baffc3a18f2e4451097838d56
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
==========================
01. Find Photodiode Events
==========================
======================
Find Photodiode Events
======================
In this example, we use ``pd-parser`` to find photodiode events and
align them to behavior. Then, we save the data to BIDS format.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""
==================================================
Manually Recover Events Not Found by the Algorithm
==================================================
In this example, we use ``pd-parser`` to find photodiode events that
have corrupted pre-event baselines, photodiode plateaus or post-event
baselines but not corrupted onsets or offsets.
Note that it might be a good idea not to recover these events
as there might be noise in the data around this time.
"""

# Authors: Alex Rockhill <[email protected]>
#
# License: BSD (3-clause)

###############################################################################
# Simulate data and use it to make a raw object:
#
# We'll make an `mne.io.Raw` object so that we can save out some random
# data with a photodiode event channel in it in fif format (a commonly used
# electrophysiology data format).
import os.path as op
import numpy as np
import mock

import mne
from mne.utils import _TempDir

import pd_parser
from pd_parser.parse_pd import _to_tsv

import matplotlib.pyplot as plt

out_dir = _TempDir()

# simulate photodiode data
np.random.seed(29)
n_events = 300
# let's make our photodiode events on random uniform from 0.25 to 0.75 seconds
n_secs_on = np.random.random(n_events) * 0.5 + 0.25
raw, beh_df, events, _ = \
pd_parser.simulate_pd_data(n_events=n_events, n_secs_on=n_secs_on,
prop_corrupted=0.0)
sfreq = np.round(raw.info['sfreq']).astype(int)

# corrupt some events
corrupted_indices = [8, 144, 234]
amount = raw._data.max()
fig, axes = plt.subplots(1, len(corrupted_indices), figsize=(8, 4))
fig.suptitle('Corrupted Events')
axes[0].set_ylabel('voltage')
for j, i in enumerate(events[corrupted_indices, 0]):
if j == 0:
raw._data[0, i - sfreq // 3: i - sfreq // 4] = -amount
elif j == 1:
raw._data[0, i + sfreq // 4: i + sfreq // 3] = -amount
else:
raw._data[0, i + 2 * sfreq // 3: i + 4 * sfreq // 4] = amount
axes[j].plot(np.linspace(-1, 2, 3 * sfreq),
raw._data[0, i - sfreq: i + sfreq * 2])
axes[j].set_xlabel('time (s)')


# make fake electrophysiology data
info = mne.create_info(['ch1', 'ch2', 'ch3'], raw.info['sfreq'],
['seeg'] * 3)
raw2 = mne.io.RawArray(np.random.random((3, raw.times.size)) * 1e-6, info)
raw2.info['lowpass'] = raw.info['lowpass'] # these must match to combine
raw.add_channels([raw2])
# bids needs these data fields
raw.info['dig'] = None
raw.info['line_freq'] = 60

# save to disk as required by ``pd-parser``
fname = op.join(out_dir, 'sub-1_task-mytask_raw.fif')
raw.save(fname)
# add some offsets to the behavior so it's a bit more realistic
offsets = np.random.randn(n_events) * 0.001
beh_df['time'] = np.array(beh_df['time']) + offsets
behf = op.join(out_dir, 'sub-1_task-mytask_beh.tsv')
_to_tsv(behf, beh_df)


###############################################################################
# Find the photodiode events relative to the behavioral timing of interest:
#
# This function will use the default parameters to find and align the
# photodiode events, recovering the events that we just corrupted.
#
# Note that the mock function mocks user input so when you run the example,
# you want to delete that line and unindent the next line, and then provide
# your own input depending on whether you want to keep the events or not.

with mock.patch('builtins.input', return_value='y'):
pd_parser.parse_pd(fname, pd_event_name='Stim On', behf=behf,
pd_ch_names=['pd'], beh_col='time', recover=True)

###############################################################################
# Find cessations of the photodiode deflections
#
# Since we manually intervened for the onsets, on those same trials, we'll
# have to manually intervene for the offsets.
#
# On the documentation webpage, this is example is not interactive,
# but if you download it as a jupyter notebook and run it or copy the code
# into a console running python (ipython recommended), you can see how to
# interact with the photodiode data to pick reasonable parameters by
# following the instructions.

pd_parser.add_pd_off_events(fname, off_event_name='Stim Off')
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n==========================\n01. Find Photodiode Events\n==========================\nIn this example, we use ``pd-parser`` to find photodiode events and\nalign them to behavior. Then, we save the data to BIDS format.\n"
"\n# Find Photodiode Events\n\nIn this example, we use ``pd-parser`` to find photodiode events and\nalign them to behavior. Then, we save the data to BIDS format.\n"
]
},
{
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Manually Recover Events Not Found by the Algorithm\n\nIn this example, we use ``pd-parser`` to find photodiode events that\nhave corrupted pre-event baselines, photodiode plateaus or post-event\nbaselines but not corrupted onsets or offsets.\nNote that it might be a good idea not to recover these events\nas there might be noise in the data around this time.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Authors: Alex Rockhill <[email protected]>\n#\n# License: BSD (3-clause)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Simulate data and use it to make a raw object:\n\nWe'll make an `mne.io.Raw` object so that we can save out some random\ndata with a photodiode event channel in it in fif format (a commonly used\nelectrophysiology data format).\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os.path as op\nimport numpy as np\nimport mock\n\nimport mne\nfrom mne.utils import _TempDir\n\nimport pd_parser\nfrom pd_parser.parse_pd import _to_tsv\n\nimport matplotlib.pyplot as plt\n\nout_dir = _TempDir()\n\n# simulate photodiode data\nnp.random.seed(29)\nn_events = 300\n# let's make our photodiode events on random uniform from 0.25 to 0.75 seconds\nn_secs_on = np.random.random(n_events) * 0.5 + 0.25\nraw, beh_df, events, _ = \\\n pd_parser.simulate_pd_data(n_events=n_events, n_secs_on=n_secs_on,\n prop_corrupted=0.0)\nsfreq = np.round(raw.info['sfreq']).astype(int)\n\n# corrupt some events\ncorrupted_indices = [8, 144, 234]\namount = raw._data.max()\nfig, axes = plt.subplots(1, len(corrupted_indices), figsize=(8, 4))\nfig.suptitle('Corrupted Events')\naxes[0].set_ylabel('voltage')\nfor j, i in enumerate(events[corrupted_indices, 0]):\n if j == 0:\n raw._data[0, i - sfreq // 3: i - sfreq // 4] = -amount\n elif j == 1:\n raw._data[0, i + sfreq // 4: i + sfreq // 3] = -amount\n else:\n raw._data[0, i + 2 * sfreq // 3: i + 4 * sfreq // 4] = amount\n axes[j].plot(np.linspace(-1, 2, 3 * sfreq),\n raw._data[0, i - sfreq: i + sfreq * 2])\n axes[j].set_xlabel('time (s)')\n\n\n# make fake electrophysiology data\ninfo = mne.create_info(['ch1', 'ch2', 'ch3'], raw.info['sfreq'],\n ['seeg'] * 3)\nraw2 = mne.io.RawArray(np.random.random((3, raw.times.size)) * 1e-6, info)\nraw2.info['lowpass'] = raw.info['lowpass'] # these must match to combine\nraw.add_channels([raw2])\n# bids needs these data fields\nraw.info['dig'] = None\nraw.info['line_freq'] = 60\n\n# save to disk as required by ``pd-parser``\nfname = op.join(out_dir, 'sub-1_task-mytask_raw.fif')\nraw.save(fname)\n# add some offsets to the behavior so it's a bit more realistic\noffsets = np.random.randn(n_events) * 0.001\nbeh_df['time'] = np.array(beh_df['time']) + offsets\nbehf = op.join(out_dir, 'sub-1_task-mytask_beh.tsv')\n_to_tsv(behf, beh_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find the photodiode events relative to the behavioral timing of interest:\n\nThis function will use the default parameters to find and align the\nphotodiode events, recovering the events that we just corrupted.\n\nNote that the mock function mocks user input so when you run the example,\nyou want to delete that line and unindent the next line, and then provide\nyour own input depending on whether you want to keep the events or not.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"with mock.patch('builtins.input', return_value='y'):\n pd_parser.parse_pd(fname, pd_event_name='Stim On', behf=behf,\n pd_ch_names=['pd'], beh_col='time', recover=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find cessations of the photodiode deflections\n\nSince we manually intervened for the onsets, on those same trials, we'll\nhave to manually intervene for the offsets.\n\nOn the documentation webpage, this is example is not interactive,\nbut if you download it as a jupyter notebook and run it or copy the code\ninto a console running python (ipython recommended), you can see how to\ninteract with the photodiode data to pick reasonable parameters by\nfollowing the instructions.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"pd_parser.add_pd_off_events(fname, off_event_name='Stim Off')"
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n=====================================\n02. Find Photodiode On and Off Events\n=====================================\nIn this example, we use ``pd-parser`` to find photodiode events and\nalign both the onset of the deflection and the cessation to\nto behavior.\n"
"\n# Find Photodiode On and Off Events\n\nIn this example, we use ``pd-parser`` to find photodiode events and\nalign both the onset of the deflection and the cessation to\nto behavior.\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
=====================================
02. Find Photodiode On and Off Events
=====================================
=================================
Find Photodiode On and Off Events
=================================
In this example, we use ``pd-parser`` to find photodiode events and
align both the onset of the deflection and the cessation to
to behavior.
Expand Down
Binary file added docs/_images/sphx_glr_plot_recover_events_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/sphx_glr_plot_recover_events_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/sphx_glr_plot_recover_events_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/sphx_glr_plot_recover_events_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/sphx_glr_plot_recover_events_006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/sphx_glr_plot_recover_events_007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/sphx_glr_plot_recover_events_008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/sphx_glr_plot_recover_events_009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &#8212; pd-parser 0.2 documentation</title>
<title>Overview: module code &#8212; pd-parser 0.3 documentation</title>
<link rel="stylesheet" href="../_static/bootstrap-sphinx.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../_static/gallery.css" />
Expand Down Expand Up @@ -39,7 +39,7 @@
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.html">
pd-parser 0.2</a>
pd-parser 0.3</a>
<span class="navbar-text navbar-version pull-left"><b></b></span>
</div>

Expand Down
Loading

0 comments on commit 80db31c

Please sign in to comment.