-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
20 changed files
with
832 additions
and
323 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,316 @@ | ||
|
||
|
||
<!DOCTYPE html> | ||
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--> | ||
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> | ||
<head> | ||
<meta charset="utf-8"> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<title>cmlreaders.convert — CML Data Readers 0.7.0 documentation</title> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> | ||
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> | ||
<link rel="stylesheet" href="../../_static/theme_overrides.css" type="text/css" /> | ||
<link rel="index" title="Index" href="../../genindex.html" /> | ||
<link rel="search" title="Search" href="../../search.html" /> | ||
|
||
|
||
<script src="../../_static/js/modernizr.min.js"></script> | ||
|
||
</head> | ||
|
||
<body class="wy-body-for-nav"> | ||
|
||
|
||
<div class="wy-grid-for-nav"> | ||
|
||
|
||
<nav data-toggle="wy-nav-shift" class="wy-nav-side"> | ||
<div class="wy-side-scroll"> | ||
<div class="wy-side-nav-search"> | ||
|
||
|
||
|
||
<a href="../../index.html" class="icon icon-home"> CML Data Readers | ||
|
||
|
||
|
||
</a> | ||
|
||
|
||
|
||
|
||
<div class="version"> | ||
0.7 | ||
</div> | ||
|
||
|
||
|
||
|
||
<div role="search"> | ||
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> | ||
<input type="text" name="q" placeholder="Search docs" /> | ||
<input type="hidden" name="check_keywords" value="yes" /> | ||
<input type="hidden" name="area" value="default" /> | ||
</form> | ||
</div> | ||
|
||
|
||
</div> | ||
|
||
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> | ||
|
||
|
||
|
||
|
||
|
||
|
||
<p class="caption"><span class="caption-text">Contents:</span></p> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../data_guide.html">Data Guide</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../getting_started.html">Getting Started with CML Readers</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../api.html">API</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../dev.html">Developer’s Guide</a></li> | ||
</ul> | ||
|
||
|
||
|
||
</div> | ||
</div> | ||
</nav> | ||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> | ||
|
||
|
||
<nav class="wy-nav-top" aria-label="top navigation"> | ||
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i> | ||
<a href="../../index.html">CML Data Readers</a> | ||
|
||
</nav> | ||
|
||
|
||
<div class="wy-nav-content"> | ||
|
||
<div class="rst-content"> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="navigation" aria-label="breadcrumbs navigation"> | ||
|
||
<ul class="wy-breadcrumbs"> | ||
|
||
<li><a href="../../index.html">Docs</a> »</li> | ||
|
||
<li><a href="../index.html">Module code</a> »</li> | ||
|
||
<li>cmlreaders.convert</li> | ||
|
||
|
||
<li class="wy-breadcrumbs-aside"> | ||
|
||
</li> | ||
|
||
</ul> | ||
|
||
|
||
<hr/> | ||
</div> | ||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> | ||
<div itemprop="articleBody"> | ||
|
||
<h1>Source code for cmlreaders.convert</h1><div class="highlight"><pre> | ||
<span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="k">import</span> <span class="n">List</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">Union</span> | ||
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span> | ||
|
||
|
||
<div class="viewcode-block" id="milliseconds_to_samples"><a class="viewcode-back" href="../../api.html#cmlreaders.convert.milliseconds_to_samples">[docs]</a><span class="k">def</span> <span class="nf">milliseconds_to_samples</span><span class="p">(</span><span class="n">millis</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">],</span> | ||
<span class="n">sample_rate</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">])</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span> | ||
<span class="sd">"""Covert times in milliseconds to number of samples.</span> | ||
|
||
<span class="sd"> Parameters</span> | ||
<span class="sd"> ----------</span> | ||
<span class="sd"> millis</span> | ||
<span class="sd"> Time in ms.</span> | ||
<span class="sd"> sample_rate</span> | ||
<span class="sd"> Sample rate in samples per second.</span> | ||
|
||
<span class="sd"> Returns</span> | ||
<span class="sd"> -------</span> | ||
<span class="sd"> Number of samples.</span> | ||
|
||
<span class="sd"> """</span> | ||
<span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">sample_rate</span> <span class="o">*</span> <span class="n">millis</span> <span class="o">/</span> <span class="mf">1000.</span><span class="p">)</span></div> | ||
|
||
|
||
<div class="viewcode-block" id="samples_to_milliseconds"><a class="viewcode-back" href="../../api.html#cmlreaders.convert.samples_to_milliseconds">[docs]</a><span class="k">def</span> <span class="nf">samples_to_milliseconds</span><span class="p">(</span><span class="n">samples</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> | ||
<span class="n">sample_rate</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">])</span> <span class="o">-></span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">]:</span> | ||
<span class="sd">"""Convert samples to milliseconds.</span> | ||
|
||
<span class="sd"> Parameters</span> | ||
<span class="sd"> ----------</span> | ||
<span class="sd"> samples</span> | ||
<span class="sd"> Number of samples.</span> | ||
<span class="sd"> sample_rate</span> | ||
<span class="sd"> Sample rate in samples per second.</span> | ||
|
||
<span class="sd"> Returns</span> | ||
<span class="sd"> -------</span> | ||
<span class="sd"> Samples converted to milliseconds.</span> | ||
|
||
<span class="sd"> """</span> | ||
<span class="k">return</span> <span class="mi">1000</span> <span class="o">*</span> <span class="n">samples</span> <span class="o">/</span> <span class="n">sample_rate</span></div> | ||
|
||
|
||
<div class="viewcode-block" id="milliseconds_to_events"><a class="viewcode-back" href="../../api.html#cmlreaders.convert.milliseconds_to_events">[docs]</a><span class="k">def</span> <span class="nf">milliseconds_to_events</span><span class="p">(</span><span class="n">onsets</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">]],</span> | ||
<span class="n">sample_rate</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">])</span> <span class="o">-></span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">:</span> | ||
<span class="sd">"""Take times and produce a minimal events :class:`pd.DataFrame` to load</span> | ||
<span class="sd"> EEG data with.</span> | ||
|
||
<span class="sd"> Parameters</span> | ||
<span class="sd"> ----------</span> | ||
<span class="sd"> onsets</span> | ||
<span class="sd"> Onset times in ms.</span> | ||
<span class="sd"> sample_rate</span> | ||
<span class="sd"> Sample rate in samples per second.</span> | ||
|
||
<span class="sd"> Returns</span> | ||
<span class="sd"> -------</span> | ||
<span class="sd"> events</span> | ||
<span class="sd"> A :class:`pd.DataFrame` with ``eegoffset`` as the only column.</span> | ||
|
||
<span class="sd"> """</span> | ||
<span class="n">samples</span> <span class="o">=</span> <span class="p">[</span><span class="n">milliseconds_to_samples</span><span class="p">(</span><span class="n">onset</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span> <span class="k">for</span> <span class="n">onset</span> <span class="ow">in</span> <span class="n">onsets</span><span class="p">]</span> | ||
<span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s2">"eegoffset"</span><span class="p">:</span> <span class="n">samples</span><span class="p">})</span></div> | ||
|
||
|
||
<div class="viewcode-block" id="events_to_epochs"><a class="viewcode-back" href="../../api.html#cmlreaders.convert.events_to_epochs">[docs]</a><span class="k">def</span> <span class="nf">events_to_epochs</span><span class="p">(</span><span class="n">events</span><span class="p">:</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">rel_start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">rel_stop</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> | ||
<span class="n">sample_rate</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">],</span> | ||
<span class="n">basenames</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span> | ||
<span class="p">)</span> <span class="o">-></span> <span class="n">List</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">]]:</span> | ||
<span class="sd">"""Convert events to epochs.</span> | ||
|
||
<span class="sd"> Parameters</span> | ||
<span class="sd"> ----------</span> | ||
<span class="sd"> events</span> | ||
<span class="sd"> Events to read.</span> | ||
<span class="sd"> rel_start</span> | ||
<span class="sd"> Start time relative to events in ms.</span> | ||
<span class="sd"> rel_stop</span> | ||
<span class="sd"> Stop time relative to events in ms.</span> | ||
<span class="sd"> sample_rate</span> | ||
<span class="sd"> Sample rate in Hz.</span> | ||
|
||
<span class="sd"> Returns</span> | ||
<span class="sd"> -------</span> | ||
<span class="sd"> epochs</span> | ||
<span class="sd"> A list of tuples giving absolute start and stop times in number of</span> | ||
<span class="sd"> samples.</span> | ||
|
||
<span class="sd"> """</span> | ||
<span class="n">rel_start</span> <span class="o">=</span> <span class="n">milliseconds_to_samples</span><span class="p">(</span><span class="n">rel_start</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span> | ||
<span class="n">rel_stop</span> <span class="o">=</span> <span class="n">milliseconds_to_samples</span><span class="p">(</span><span class="n">rel_stop</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span> | ||
<span class="n">offsets</span> <span class="o">=</span> <span class="n">events</span><span class="o">.</span><span class="n">eegoffset</span><span class="o">.</span><span class="n">values</span> | ||
<span class="k">if</span> <span class="n">basenames</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> | ||
<span class="n">eegfiles</span> <span class="o">=</span> <span class="n">events</span><span class="o">.</span><span class="n">eegfile</span><span class="o">.</span><span class="n">values</span> | ||
<span class="n">epochs</span> <span class="o">=</span> <span class="p">[(</span><span class="n">offset</span> <span class="o">+</span> <span class="n">rel_start</span><span class="p">,</span> <span class="n">offset</span> <span class="o">+</span> <span class="n">rel_stop</span><span class="p">,</span> | ||
<span class="n">basenames</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">eegfile</span><span class="p">))</span> | ||
<span class="k">for</span> <span class="p">(</span><span class="n">offset</span><span class="p">,</span> <span class="n">eegfile</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">offsets</span><span class="p">,</span> <span class="n">eegfiles</span><span class="p">)]</span> | ||
<span class="k">else</span><span class="p">:</span> | ||
<span class="n">epochs</span> <span class="o">=</span> <span class="p">[(</span><span class="n">offset</span> <span class="o">+</span> <span class="n">rel_start</span><span class="p">,</span> <span class="n">offset</span> <span class="o">+</span> <span class="n">rel_stop</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> | ||
<span class="k">for</span> <span class="n">offset</span> <span class="ow">in</span> <span class="n">offsets</span><span class="p">]</span> | ||
<span class="k">return</span> <span class="n">epochs</span></div> | ||
</pre></div> | ||
|
||
</div> | ||
|
||
</div> | ||
<footer> | ||
|
||
|
||
<hr/> | ||
|
||
<div role="contentinfo"> | ||
<p> | ||
© Copyright 2018. | ||
|
||
</p> | ||
</div> | ||
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. | ||
|
||
</footer> | ||
|
||
</div> | ||
</div> | ||
|
||
</section> | ||
|
||
</div> | ||
|
||
|
||
|
||
|
||
|
||
<script type="text/javascript"> | ||
var DOCUMENTATION_OPTIONS = { | ||
URL_ROOT:'../../', | ||
VERSION:'0.7.0', | ||
LANGUAGE:'None', | ||
COLLAPSE_INDEX:false, | ||
FILE_SUFFIX:'.html', | ||
HAS_SOURCE: true, | ||
SOURCELINK_SUFFIX: '.txt' | ||
}; | ||
</script> | ||
<script type="text/javascript" src="../../_static/jquery.js"></script> | ||
<script type="text/javascript" src="../../_static/underscore.js"></script> | ||
<script type="text/javascript" src="../../_static/doctools.js"></script> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> | ||
|
||
|
||
|
||
|
||
|
||
<script type="text/javascript" src="../../_static/js/theme.js"></script> | ||
|
||
|
||
<script type="text/javascript"> | ||
jQuery(function () { | ||
SphinxRtdTheme.Navigation.enable(true); | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
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.