diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2014-10-16 17:51:23 +0200 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2014-10-16 17:51:23 +0200 |
commit | 3f810c231e661e9141c9c586ebd6d9d182488c92 (patch) | |
tree | c9d807b648f780ecde5c4ea49cf222c0253d61be | |
parent | 7ff5a4afe2d7a40dce34ae187a23b7d0feba33ba (diff) |
added sphinx doc generation
-rw-r--r-- | doc/Makefile | 177 | ||||
-rw-r--r-- | doc/conf.py | 271 | ||||
-rw-r--r-- | doc/index.rst | 22 | ||||
-rw-r--r-- | doc/pyspike.rst | 38 | ||||
-rw-r--r-- | pyspike/distances.py | 147 | ||||
-rw-r--r-- | pyspike/function.py | 126 | ||||
-rw-r--r-- | pyspike/spikes.py | 58 |
7 files changed, 689 insertions, 150 deletions
diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000..5acfcec --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,177 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make <target>' where <target> is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PySpike.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PySpike.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/PySpike" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PySpike" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/doc/conf.py b/doc/conf.py new file mode 100644 index 0000000..48ebc7e --- /dev/null +++ b/doc/conf.py @@ -0,0 +1,271 @@ +# -*- coding: utf-8 -*- +# +# PySpike documentation build configuration file, created by +# sphinx-quickstart on Thu Oct 16 15:56:58 2014. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# 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. +sys.path.insert(0, os.path.abspath('../pyspike')) + +def skip(app, what, name, obj, skip, options): + if name == "__init__": + return False + return skip + +def setup(app): + app.connect("autodoc-skip-member", skip) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# 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.coverage', + 'sphinx.ext.mathjax', + 'sphinx.ext.viewcode', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'PySpike' +copyright = u'2014, Mario Mulansky' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.1' +# The full version, including alpha/beta/rc tags. +release = '0.1' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- 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 = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# 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'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'PySpikedoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'PySpike.tex', u'PySpike Documentation', + u'Mario Mulansky', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'pyspike', u'PySpike Documentation', + [u'Mario Mulansky'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'PySpike', u'PySpike Documentation', + u'Mario Mulansky', 'PySpike', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/doc/index.rst b/doc/index.rst new file mode 100644 index 0000000..b94c162 --- /dev/null +++ b/doc/index.rst @@ -0,0 +1,22 @@ +.. PySpike documentation master file, created by + sphinx-quickstart on Thu Oct 16 15:56:58 2014. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to PySpike's documentation! +=================================== + +Reference: + +.. toctree:: + :maxdepth: 2 + + pyspike + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/doc/pyspike.rst b/doc/pyspike.rst new file mode 100644 index 0000000..39adea0 --- /dev/null +++ b/doc/pyspike.rst @@ -0,0 +1,38 @@ +pyspike package +=============== + +Submodules +---------- + +pyspike.distances module +------------------------ + +.. automodule:: pyspike.distances + :members: + :undoc-members: + :show-inheritance: + +pyspike.function module +----------------------- + +.. automodule:: pyspike.function + :members: + :undoc-members: + :show-inheritance: + +pyspike.spikes module +--------------------- + +.. automodule:: pyspike.spikes + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: pyspike + :members: + :undoc-members: + :show-inheritance: diff --git a/pyspike/distances.py b/pyspike/distances.py index 3e97b77..b0af24c 100644 --- a/pyspike/distances.py +++ b/pyspike/distances.py @@ -17,15 +17,17 @@ from pyspike import PieceWiseConstFunc, PieceWiseLinFunc # isi_profile ############################################################ def isi_profile(spikes1, spikes2): - """ Computes the isi-distance profile S_isi(t) of the two given spike - trains. Retruns the profile as a PieceWiseConstFunc object. The S_isi + """ Computes the isi-distance profile :math:`S_{isi}(t)` of the two given + spike trains. Retruns the profile as a PieceWiseConstFunc object. The S_isi values are defined positive S_isi(t)>=0. The spike trains are expected to have auxiliary spikes at the beginning and end of the interval. Use the function add_auxiliary_spikes to add those spikes to the spike train. - Args: - - spikes1, spikes2: ordered arrays of spike times with auxiliary spikes. - Returns: - - PieceWiseConstFunc describing the isi-distance. + + :param spikes1: ordered array of spike times with auxiliary spikes. + :param spikes2: ordered array of spike times with auxiliary spikes. + :returns: The isi-distance profile :math:`S_{isi}(t)` + :rtype: :class:`pyspike.function.PieceWiseConstFunc` + """ # check for auxiliary spikes - first and last spikes should be identical assert spikes1[0] == spikes2[0], \ @@ -52,12 +54,15 @@ Falling back to slow python backend.") ############################################################ def isi_distance(spikes1, spikes2): """ Computes the isi-distance I of the given spike trains. The - isi-distance is the integral over the isi distance profile S_isi(t): - I = \int_^T S_isi(t) dt. - Args: - - spikes1, spikes2: ordered arrays of spike times with auxiliary spikes. - Returns: - - double value: The isi-distance I. + isi-distance is the integral over the isi distance profile + :math:`S_{isi}(t)`: + + .. math:: I = \int_0^T S_{isi}(t) dt. + + :param spikes1: ordered array of spike times with auxiliary spikes. + :param spikes2: ordered array of spike times with auxiliary spikes. + :returns: The isi-distance I. + :rtype: double """ return isi_profile(spikes1, spikes2).avrg() @@ -71,10 +76,12 @@ def spike_profile(spikes1, spikes2): values are defined positive S_spike(t)>=0. The spike trains are expected to have auxiliary spikes at the beginning and end of the interval. Use the function add_auxiliary_spikes to add those spikes to the spike train. - Args: - - spikes1, spikes2: ordered arrays of spike times with auxiliary spikes. - Returns: - - PieceWiseLinFunc describing the spike-distance. + + :param spikes1: ordered array of spike times with auxiliary spikes. + :param spikes2: ordered array of spike times with auxiliary spikes. + :returns: The spike-distance profile :math:`S_{spike}(t). + :rtype: :class:`pyspike.function.PieceWiseLinFunc` + """ # check for auxiliary spikes - first and last spikes should be identical assert spikes1[0] == spikes2[0], \ @@ -104,18 +111,20 @@ def spike_distance(spikes1, spikes2): """ Computes the spike-distance S of the given spike trains. The spike-distance is the integral over the isi distance profile S_spike(t): S = \int_^T S_spike(t) dt. - Args: - - spikes1, spikes2: ordered arrays of spike times with auxiliary spikes. - Returns: - - double value: The spike-distance S. + + :param spikes1: ordered array of spike times with auxiliary spikes. + :param spikes2: ordered array of spike times with auxiliary spikes. + :returns: The spike-distance. + :rtype: double + """ return spike_profile(spikes1, spikes2).avrg() ############################################################ -# generic_profile_multi +# _generic_profile_multi ############################################################ -def generic_profile_multi(spike_trains, pair_distance_func, indices=None): +def _generic_profile_multi(spike_trains, pair_distance_func, indices=None): """ Internal implementation detail, don't call this function directly, use isi_profile_multi or spike_profile_multi instead. @@ -153,7 +162,7 @@ def generic_profile_multi(spike_trains, pair_distance_func, indices=None): ############################################################ # multi_distance_par ############################################################ -def multi_distance_par(spike_trains, pair_distance_func, indices=None): +def _multi_distance_par(spike_trains, pair_distance_func, indices=None): """ parallel implementation of the multi-distance. Not currently used as it does not improve the performance. """ @@ -210,14 +219,15 @@ def isi_profile_multi(spike_trains, indices=None): trains. That is the average isi-distance of all pairs of spike-trains: S_isi(t) = 2/((N(N-1)) sum_{<i,j>} S_{isi}^{i,j}, where the sum goes over all pairs <i,j> - Args: - - spike_trains: list of spike trains - - indices: list of indices defining which spike trains to use, - if None all given spike trains are used (default=None) - Returns: - - A PieceWiseConstFunc representing the averaged isi distance S_isi(t) + + :param spike_trains: list of spike trains + :param indices: list of indices defining which spike trains to use, + if None all given spike trains are used (default=None) + :type state: list or None + :returns: The averaged isi profile :math:`<S_{isi}>(t)` + :rtype: :class:`pyspike.function.PieceWiseConstFunc` """ - return generic_profile_multi(spike_trains, isi_profile, indices) + return _generic_profile_multi(spike_trains, isi_profile, indices) ############################################################ @@ -226,14 +236,14 @@ def isi_profile_multi(spike_trains, indices=None): def isi_distance_multi(spike_trains, indices=None): """ computes the multi-variate isi-distance for a set of spike-trains. That is the time average of the multi-variate spike profile: - S_isi = \int_0^T 2/((N(N-1)) sum_{<i,j>} S_{isi}^{i,j}, + I = \int_0^T 2/((N(N-1)) sum_{<i,j>} S_{isi}^{i,j}, where the sum goes over all pairs <i,j> - Args: - - spike_trains: list of spike trains - - indices: list of indices defining which spike trains to use, - if None all given spike trains are used (default=None) - Returns: - - A double value representing the averaged isi distance S_isi + + :param spike_trains: list of spike trains + :param indices: list of indices defining which spike trains to use, + if None all given spike trains are used (default=None) + :returns: The time-averaged isi distance :math:`I` + :rtype: double """ return isi_profile_multi(spike_trains, indices).avrg() @@ -246,14 +256,14 @@ def spike_profile_multi(spike_trains, indices=None): trains. That is the average spike-distance of all pairs of spike-trains: S_spike(t) = 2/((N(N-1)) sum_{<i,j>} S_{spike}^{i, j}, where the sum goes over all pairs <i,j> - Args: - - spike_trains: list of spike trains - - indices: list of indices defining which spike-trains to use, - if None all given spike trains are used (default=None) - Returns: - - A PieceWiseLinFunc representing the averaged spike distance S(t) + :param spike_trains: list of spike trains + :param indices: list of indices defining which spike trains to use, + if None all given spike trains are used (default=None) + :type indices: list or None + :returns: The averaged spike profile :math:`<S_{spike}>(t)` + :rtype: :class:`pyspike.function.PieceWiseLinFunc` """ - return generic_profile_multi(spike_trains, spike_profile, indices) + return _generic_profile_multi(spike_trains, spike_profile, indices) ############################################################ @@ -264,12 +274,13 @@ def spike_distance_multi(spike_trains, indices=None): That is the time average of the multi-variate spike profile: S_{spike} = \int_0^T 2/((N(N-1)) sum_{<i,j>} S_{spike}^{i, j} dt where the sum goes over all pairs <i,j> - Args: - - spike_trains: list of spike trains - - indices: list of indices defining which spike-trains to use, - if None all given spike trains are used (default=None) - Returns: - - A double value representing the averaged spike distance S + + :param spike_trains: list of spike trains + :param indices: list of indices defining which spike trains to use, + if None all given spike trains are used (default=None) + :type indices: list or None + :returns: The averaged spike distance S. + :rtype: double """ return spike_profile_multi(spike_trains, indices).avrg() @@ -277,7 +288,7 @@ def spike_distance_multi(spike_trains, indices=None): ############################################################ # generic_distance_matrix ############################################################ -def generic_distance_matrix(spike_trains, dist_function, indices=None): +def _generic_distance_matrix(spike_trains, dist_function, indices=None): """ Internal implementation detail. Don't use this function directly. Instead use isi_distance_matrix or spike_distance_matrix. Computes the time averaged distance of all pairs of spike-trains. @@ -311,15 +322,16 @@ def generic_distance_matrix(spike_trains, dist_function, indices=None): ############################################################ def isi_distance_matrix(spike_trains, indices=None): """ Computes the time averaged isi-distance of all pairs of spike-trains. - Args: - - spike_trains: list of spike trains - - indices: list of indices defining which spike-trains to use - if None all given spike-trains are used (default=None) - Return: - - a 2D array of size len(indices)*len(indices) containing the average - pair-wise isi-distance + + :param spike_trains: list of spike trains + :param indices: list of indices defining which spike trains to use, + if None all given spike trains are used (default=None) + :type indices: list or None + :returns: 2D array with the pair wise time average isi distances + :math:`I_{ij}` + :rtype: np.array """ - return generic_distance_matrix(spike_trains, isi_distance, indices) + return _generic_distance_matrix(spike_trains, isi_distance, indices) ############################################################ @@ -327,12 +339,13 @@ def isi_distance_matrix(spike_trains, indices=None): ############################################################ def spike_distance_matrix(spike_trains, indices=None): """ Computes the time averaged spike-distance of all pairs of spike-trains. - Args: - - spike_trains: list of spike trains - - indices: list of indices defining which spike-trains to use - if None all given spike-trains are used (default=None) - Return: - - a 2D array of size len(indices)*len(indices) containing the average - pair-wise spike-distance + + :param spike_trains: list of spike trains + :param indices: list of indices defining which spike trains to use, + if None all given spike trains are used (default=None) + :type indices: list or None + :returns: 2D array with the pair wise time average spike distances + :math:`S_{ij}` + :rtype: np.array """ - return generic_distance_matrix(spike_trains, spike_distance, indices) + return _generic_distance_matrix(spike_trains, spike_distance, indices) diff --git a/pyspike/function.py b/pyspike/function.py index b161034..ed47f27 100644 --- a/pyspike/function.py +++ b/pyspike/function.py @@ -16,15 +16,16 @@ import numpy as np ############################################################## # PieceWiseConstFunc ############################################################## -class PieceWiseConstFunc: +class PieceWiseConstFunc(object): """ A class representing a piece-wise constant function. """ def __init__(self, x, y): """ Constructs the piece-wise const function. - Args: - - x: array of length N+1 defining the edges of the intervals of the pwc - function. - - y: array of length N defining the function values at the intervals. + + :param x: array of length N+1 defining the edges of the intervals of + the pwc function. + :param y: array of length N defining the function values at the + intervals. """ # convert parameters to arrays, also ensures copying self.x = np.array(x) @@ -32,19 +33,19 @@ class PieceWiseConstFunc: def copy(self): """ Returns a copy of itself - Returns: - - PieceWiseConstFunc copy + + :rtype: :class:`PieceWiseConstFunc` """ return PieceWiseConstFunc(self.x, self.y) def almost_equal(self, other, decimal=14): """ Checks if the function is equal to another function up to `decimal` precision. - Args: - - other: another PieceWiseConstFunc object - Returns: - True if the two functions are equal up to `decimal` decimals, - False otherwise + + :param: other: another :class:`PieceWiseConstFunc` + :returns: True if the two functions are equal up to `decimal` decimals, + False otherwise + :rtype: bool """ eps = 10.0**(-decimal) return np.allclose(self.x, other.x, atol=eps, rtol=0.0) and \ @@ -53,6 +54,14 @@ class PieceWiseConstFunc: def get_plottable_data(self): """ Returns two arrays containing x- and y-coordinates for immeditate plotting of the piece-wise function. + + :returns: (x_plot, y_plot) containing plottable data + :rtype: pair of np.array + + Example:: + + x, y = f.get_plottable_data() + plt.plot(x, y, '-o', label="Piece-wise const function") """ x_plot = np.empty(2*len(self.x)-2) @@ -67,9 +76,10 @@ class PieceWiseConstFunc: def avrg(self): """ Computes the average of the piece-wise const function: - a = 1/T int f(x) dx where T is the length of the interval. - Returns: - - the average a. + :math:`a = 1/T int_0^T f(x) dx` where T is the length of the interval. + + :returns: the average a. + :rtype: double """ return np.sum((self.x[1:]-self.x[:-1]) * self.y) / \ (self.x[-1]-self.x[0]) @@ -77,8 +87,9 @@ class PieceWiseConstFunc: def add(self, f): """ Adds another PieceWiseConst function to this function. Note: only functions defined on the same interval can be summed. - Args: - - f: PieceWiseConst function to be added. + + :param f: :class:`PieceWiseConstFunc` function to be added. + :rtype: None """ assert self.x[0] == f.x[0], "The functions have different intervals" assert self.x[-1] == f.x[-1], "The functions have different intervals" @@ -99,8 +110,10 @@ that PySpike is installed by running\n 'python setup.py build_ext --inplace'! \ def mul_scalar(self, fac): """ Multiplies the function with a scalar value - Args: - - fac: Value to multiply + + :param fac: Value to multiply + :type fac: double + :rtype: None """ self.y *= fac @@ -113,13 +126,13 @@ class PieceWiseLinFunc: def __init__(self, x, y1, y2): """ Constructs the piece-wise linear function. - Args: - - x: array of length N+1 defining the edges of the intervals of the pwc - function. - - y1: array of length N defining the function values at the left of the - intervals. - - y2: array of length N defining the function values at the right of - the intervals. + + :param x: array of length N+1 defining the edges of the intervals of + the pwc function. + :param y1: array of length N defining the function values at the left + of the intervals. + :param y2: array of length N defining the function values at the right + of the intervals. """ # convert to array, which also ensures copying self.x = np.array(x) @@ -128,19 +141,19 @@ class PieceWiseLinFunc: def copy(self): """ Returns a copy of itself - Returns: - - PieceWiseLinFunc copy + + :rtype: :class`PieceWiseLinFunc` """ return PieceWiseLinFunc(self.x, self.y1, self.y2) def almost_equal(self, other, decimal=14): """ Checks if the function is equal to another function up to `decimal` precision. - Args: - - other: another PieceWiseLinFunc object - Returns: - True if the two functions are equal up to `decimal` decimals, - False otherwise + + :param: other: another :class:`PieceWiseLinFunc` + :returns: True if the two functions are equal up to `decimal` decimals, + False otherwise + :rtype: bool """ eps = 10.0**(-decimal) return np.allclose(self.x, other.x, atol=eps, rtol=0.0) and \ @@ -150,6 +163,14 @@ class PieceWiseLinFunc: def get_plottable_data(self): """ Returns two arrays containing x- and y-coordinates for immeditate plotting of the piece-wise function. + + :returns: (x_plot, y_plot) containing plottable data + :rtype: pair of np.array + + Example:: + + x, y = f.get_plottable_data() + plt.plot(x, y, '-o', label="Piece-wise const function") """ x_plot = np.empty(2*len(self.x)-2) x_plot[0] = self.x[0] @@ -162,27 +183,20 @@ class PieceWiseLinFunc: def avrg(self): """ Computes the average of the piece-wise linear function: - a = 1/T int f(x) dx where T is the length of the interval. - Returns: - - the average a. + :math:`a = 1/T int_0^T f(x) dx` where T is the length of the interval. + + :returns: the average a. + :rtype: double """ return np.sum((self.x[1:]-self.x[:-1]) * 0.5*(self.y1+self.y2)) / \ (self.x[-1]-self.x[0]) - def abs_avrg(self): - """ Computes the absolute average of the piece-wise linear function: - a = 1/T int |f(x)| dx where T is the length of the interval. - Returns: - - the average a. - """ - return np.sum((self.x[1:]-self.x[:-1]) * 0.5 * - (np.abs(self.y1)+np.abs(self.y2)))/(self.x[-1]-self.x[0]) - def add(self, f): """ Adds another PieceWiseLin function to this function. Note: only functions defined on the same interval can be summed. - Args: - - f: PieceWiseLin function to be added. + + :param f: :class:`PieceWiseLinFunc` function to be added. + :rtype: None """ assert self.x[0] == f.x[0], "The functions have different intervals" assert self.x[-1] == f.x[-1], "The functions have different intervals" @@ -209,8 +223,10 @@ that PySpike is installed by running\n 'python setup.py build_ext --inplace'! \ def mul_scalar(self, fac): """ Multiplies the function with a scalar value - Args: - - fac: Value to multiply + + :param fac: Value to multiply + :type fac: double + :rtype: None """ self.y1 *= fac self.y2 *= fac @@ -218,12 +234,12 @@ that PySpike is installed by running\n 'python setup.py build_ext --inplace'! \ def average_profile(profiles): """ Computes the average profile from the given ISI- or SPIKE-profiles. - Args: - - profiles: list of PieceWiseConstFunc or PieceWiseLinFunc representing - ISI- or SPIKE-profiles to be averaged - Returns: - - avrg_profile: PieceWiseConstFunc or PieceWiseLinFunc containing the - average profile. + + :param profiles: list of :class:`PieceWiseConstFunc` or + :class:`PieceWiseLinFunc` representing ISI- or + SPIKE-profiles to be averaged. + :returns: the averages profile :math:`<S_{isi}>` or :math:`<S_{spike}>`. + :rtype: :class:`PieceWiseConstFunc` or :class:`PieceWiseLinFunc` """ assert len(profiles) > 1 diff --git a/pyspike/spikes.py b/pyspike/spikes.py index 68c8bc1..6b6e2e7 100644 --- a/pyspike/spikes.py +++ b/pyspike/spikes.py @@ -15,15 +15,16 @@ import numpy as np ############################################################ def add_auxiliary_spikes(spike_train, time_interval): """ Adds spikes at the beginning and end of the given time interval. - Args: - - spike_train: ordered array of spike times - - time_interval: A pair (T_start, T_end) of values representing the start - and end time of the spike train measurement or a single value representing - the end time, the T_start is then assuemd as 0. Auxiliary spikes will be - added to the spike train at the beginning and end of this interval, if they - are not yet present. - Returns: - - spike train with additional spikes at T_start and T_end. + + :param spike_train: ordered array of spike times + :param time_interval: A pair (T_start, T_end) of values representing the + start and end time of the spike train measurement or + a single value representing the end time, the T_start + is then assuemd as 0. Auxiliary spikes will be added + to the spike train at the beginning and end of this + interval, if they are not yet present. + :type time_interval: pair of doubles or double + :returns: spike train with additional spikes at T_start and T_end. """ try: @@ -49,12 +50,11 @@ def add_auxiliary_spikes(spike_train, time_interval): ############################################################ def spike_train_from_string(s, sep=' ', sort=True): """ Converts a string of times into an array of spike times. - Args: - - s: the string with (ordered) spike times - - sep: The separator between the time numbers, default=' '. - - sort: If True, the spike times are order via `np.sort`, default=True. - Returns: - - array of spike times + + :param s: the string with (ordered) spike times + :param sep: The separator between the time numbers, default=' '. + :param sort: If True, the spike times are order via `np.sort`, default=True + :returns: array of spike times """ if sort: return np.sort(np.fromstring(s, sep=sep)) @@ -75,15 +75,18 @@ def load_spike_trains_from_txt(file_name, time_interval=None, end of each spike train. However, if `time_interval == None`, no auxiliary spikes are added, but note that the Spike and ISI distance both require auxiliary spikes. - Args: - - file_name: The name of the text file. - - time_interval: A pair (T_start, T_end) of values representing the start - and end time of the spike train measurement or a single value representing - the end time, the T_start is then assuemd as 0. Auxiliary spikes will be - added to the spike train at the beginning and end of this interval. - - separator: The character used to seprate the values in the text file. - - comment: Lines starting with this character are ignored. - - sort: If true, the spike times are order via `np.sort`, default=True. + + :param file_name: The name of the text file. + :param time_interval: A pair (T_start, T_end) of values representing the + start and end time of the spike train measurement + or a single value representing the end time, the + T_start is then assuemd as 0. Auxiliary spikes will + be added to the spike train at the beginning and end + of this interval. + :param separator: The character used to seprate the values in the text file + :param comment: Lines starting with this character are ignored. + :param sort: If true, the spike times are order via `np.sort`, default=True + :returns: list of spike trains """ spike_trains = [] spike_file = open(file_name, 'r') @@ -102,10 +105,9 @@ def load_spike_trains_from_txt(file_name, time_interval=None, ############################################################ def merge_spike_trains(spike_trains): """ Merges a number of spike trains into a single spike train. - Args: - - spike_trains: list of arrays of spike times - Returns: - - array with the merged spike times + + :param spike_trains: list of arrays of spike times + :returns: spike train with the merged spike times """ # get the lengths of the spike trains lens = np.array([len(st) for st in spike_trains]) |