-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9eeabbe
commit 80db31c
Showing
78 changed files
with
1,452 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 modified
BIN
+4.19 KB
(140%)
docs/_downloads/238cd1236e2081ff7294485992514de3/auto_examples_python.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions
6
docs/_downloads/332eafcd55124069bc52ae95a623ffe2/plot_find_pd_events.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
docs/_downloads/3b9b6f3cd8645b6f7e8cdb8a4aee6517/plot_recover_events.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+5.6 KB
(140%)
docs/_downloads/4e9f78ce2ee5ecb258e35211a260857e/auto_examples_jupyter.zip
Binary file not shown.
108 changes: 108 additions & 0 deletions
108
docs/_downloads/5258f1bb54b38679ec8488158187b98c/plot_recover_events.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
docs/_downloads/fb5c5b7987665badd299d9a46518fdc1/plot_find_pd_on_and_off.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.