Skip to content

Commit

Permalink
Add sphinx docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackz314 committed Apr 14, 2021
1 parent 4c49758 commit ff6bc1b
Show file tree
Hide file tree
Showing 19 changed files with 342 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,4 @@ dmypy.json
# Cython debug symbols
cython_debug/

/docs/generated/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# eeglabio

Python I/O support for EEGLAB files
I/O support for EEGLAB files in Python.

### Installation

Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
9 changes: 9 additions & 0 deletions docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:special-members: __contains__,__getitem__,__iter__,__len__,__add__,__sub__,__mul__,__div__,__neg__,__hash__
:members:

.. _sphx_glr_backreferences_{{ fullname }}:
7 changes: 7 additions & 0 deletions docs/_templates/autosummary/function.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autofunction:: {{ objname }}

.. _sphx_glr_backreferences_{{ fullname }}:
21 changes: 21 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=============
API Reference
=============

This is the reference for classes (``CamelCase`` names) and functions
(``underscore_case`` names) of eeglabio.

.. container:: d-none

:py:mod:`eeglabio`:

.. automodule:: eeglabio
:no-members:
:no-inherited-members:

.. toctree::
:maxdepth: 2

raw
epochs
utils
78 changes: 78 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
currdir = os.path.dirname(__file__)
sys.path.append(os.path.abspath(os.path.join(currdir, '..')))

import eeglabio

# -- Project information -----------------------------------------------------

project = 'eeglabio'
copyright = '2021, Jack Zhang'
author = 'Jack Zhang'

# The full version, including alpha/beta/rc tags
release = eeglabio.__version__


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.intersphinx',
'numpydoc',
'sphinx_copybutton',
]

intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'numpy': ('https://numpy.org/devdocs', None),
'scipy': ('https://scipy.github.io/devdocs', None),
'mne': ('https://mne.tools/dev', None)
}

numpydoc_attributes_as_param_list = True
numpydoc_xref_param_type = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

autosummary_generate = True

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = "pydata_sphinx_theme"
html_theme_options = {
"github_url": "https://github.com/jackz314/eeglabio",
"show_prev_next": True,
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
17 changes: 17 additions & 0 deletions docs/epochs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Epochs
======


:py:mod:`eeglabio.epochs`:

.. automodule:: eeglabio.epochs
:no-members:
:no-inherited-members:

.. currentmodule:: eeglabio.epochs

.. autosummary::
:toctree: generated/

export_set
20 changes: 20 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Example Usage with `MNE <http://mne.tools/>`_
=============================================

Export from :class:`mne.Epochs` to EEGLAB (``.set``):

.. code-block:: python
import mne
from eeglabio.utils import export_mne_epochs
epochs = mne.Epochs(...)
export_mne_epochs(epochs, "file_name.set")
Export from :class:`mne.io.Raw` to EEGLAB (``.set``):

.. code-block:: python
import mne
from eeglabio.utils import export_mne_raw
raw = mne.io.read_raw(...)
export_mne_raw(raw, "file_name.set")
23 changes: 23 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. eeglabio documentation master file, created by
sphinx-quickstart on Tue Apr 13 18:47:08 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
I/O support for `EEGLAB <https://eeglab.org/>`_ files in Python
===============================================================

.. toctree::
:maxdepth: 3
:caption: Contents:

Installation <install>
Examples <examples>
API Reference <api>


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
15 changes: 15 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Installation
============

eeglabio requires Python version 3.6 or higher.
You can install MNE-Python using ``pip`` from `PyPI <http://pypi.org/project/eeglabio>`_:

.. code-block:: console
pip install eeglabio # dependencies are numpy, scipy
Alternatively, from `Test PyPI <http://test.pypi.org/project/eeglabio>`_:

.. code-block:: console
pip install -i https://test.pypi.org/simple/ eeglabio
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
17 changes: 17 additions & 0 deletions docs/raw.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Raw
===


:py:mod:`eeglabio.raw`:

.. automodule:: eeglabio.raw
:no-members:
:no-inherited-members:

.. currentmodule:: eeglabio.raw

.. autosummary::
:toctree: generated/

export_set
20 changes: 20 additions & 0 deletions docs/utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Utils
=====


:py:mod:`eeglabio.utils`:

.. automodule:: eeglabio.utils
:no-members:
:no-inherited-members:

.. currentmodule:: eeglabio.utils

.. autosummary::
:toctree: generated/

cart_to_eeglab
cart_to_eeglab_sph
export_mne_epochs
export_mne_raw
3 changes: 2 additions & 1 deletion eeglabio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ._version import __version__
from . import epochs
from . import raw
from . import utils

__all__ = [epochs, raw]
__all__ = ['epochs', 'raw', 'utils']
14 changes: 9 additions & 5 deletions eeglabio/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def export_set(fname, data, sfreq, events, tmin, tmax, ch_names,
----------
fname : str
Name of the export file.
data : np.ndarray, shape (n_epochs, n_channels, n_samples)
data : numpy.ndarray, shape (n_epochs, n_channels, n_samples)
Data array containing epochs. Follows the same format as
MNE Epochs' data array.
sfreq : int
sample frequency of data
events : np.ndarray, shape (n_events, 3)
events : numpy.ndarray, shape (n_events, 3)
Event array, the first column contains the event time in samples,
the second column contains the value of the stim channel immediately
before the event/step, and the third column contains the event id.
Expand All @@ -32,13 +32,17 @@ def export_set(fname, data, sfreq, events, tmin, tmax, ch_names,
event_id : dict
Names of conditions corresponding to event ids (last column of events).
If None, event names will default to string versions of the event ids.
ch_locs : np.ndarray, shape (n_channels, 3)
ch_locs : numpy.ndarray, shape (n_channels, 3)
Array containing channel locations in Cartesian coordinates (x, y, z)
See Also
--------
.raw.export_set
Notes
-----
Channel locations are expanded to the full EEGLAB format
For more details see .io.utils.cart_to_eeglab_full_coords
Channel locations are expanded to the full EEGLAB format.
For more details see :func:`.utils.cart_to_eeglab_sph`.
"""

data = data * 1e6 # convert to microvolts
Expand Down
12 changes: 8 additions & 4 deletions eeglabio/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None):
----------
fname : str
Name of the export file.
data : np.ndarray, shape (n_epochs, n_channels, n_samples)
data : numpy.ndarray, shape (n_epochs, n_channels, n_samples)
Data array containing epochs. Follows the same format as
MNE Epochs' data array.
sfreq : int
sample frequency of data
ch_names : list of str
Channel names.
ch_locs : np.ndarray, shape (n_channels, 3)
ch_locs : numpy.ndarray, shape (n_channels, 3)
Array containing channel locations in Cartesian coordinates (x, y, z)
annotations : list, shape (3, n_annotations)
List containing three annotation subarrays:
Expand All @@ -28,10 +28,14 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None):
third array (float) is duration (in seconds)
This roughly follows MNE's Annotations structure.
See Also
--------
.epochs.export_set
Notes
-----
Channel locations are expanded to the full EEGLAB format
For more details see .utils.cart_to_eeglab_full_coords
Channel locations are expanded to the full EEGLAB format.
For more details see :func:`.utils.cart_to_eeglab_sph`.
"""

data = data * 1e6 # convert to microvolts
Expand Down
Loading

0 comments on commit ff6bc1b

Please sign in to comment.