File: documentation.rst

package info (click to toggle)
brian 2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,872 kB
  • sloc: python: 51,820; cpp: 2,033; makefile: 108; sh: 72
file content (216 lines) | stat: -rw-r--r-- 8,779 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
Documentation
=============

It is very important to maintain documentation. We use the
`Sphinx documentation generator <http://www.sphinx-doc.org/en/stable/>`__
tools. The documentation is all hand written. Sphinx source files are stored in the
``docs_sphinx`` folder. The HTML files can be generated via the script
``dev/tools/docs/build_html_brian2.py`` and end
up in the ``docs`` folder.

Most of the documentation is stored directly in the Sphinx
source text files, but reference documentation for important Brian classes and
functions are kept in the documentation strings of those classes themselves.
This is automatically pulled from these classes for the reference manual
section of the documentation. The idea is to keep the definitive reference
documentation near the code that it documents, serving as both a comment for
the code itself, and to keep the documentation up to date with the code.

The reference documentation includes all classes, functions and other objects
that are defined in the modules and only documents them in the module where
they were defined. This makes it possible to document a class like
`~brian2.units.fundamentalunits.Quantity` only in `brian2.units.fundamentalunits`
and not additionally in `brian2.units` and `brian2`. This mechanism relies on
the ``__module__`` attribute, in some cases, in particular when wrapping a
function with a decorator (e.g. `~brian2.units.fundamentalunits.check_units`),
this attribute has to be set manually::

	foo.__module__ = __name__
 
Without this manual setting, the function might not be documented at all or in
the wrong module.

In addition to the reference, all the examples in the examples folder are
automatically included in the documentation.

Note that you can directly link to github issues using ``:issue:`issue number```, e.g.
writing ``:issue:`33``` links to a github issue about running benchmarks for Brian 2:
:issue:`33`. This feature should rarely be used in the main documentation, reserve its
use for release notes and important known bugs.

Docstrings
----------

Every module, class, method or function has to start with a docstring, unless
it is a private or special method (i.e. starting with ``_`` or ``__``) *and* it
is obvious what it does. For example, there is normally no need to document
``__str__`` with "Return a string representation.".

For the docstring format, we use the our own sphinx extension (in
`brian2/sphinxext`) based on
`numpydoc <https://pypi.python.org/pypi/numpydoc/>`__, allowing to write
docstrings that are well readable both in sourcecode as well as in the
rendered HTML. We generally follow the `format used by numpy
<https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard>`__

When the docstring uses variable, class or function names, these should be
enclosed in single backticks. Class and function/method names will be
automatically linked to the corresponding documentation. For classes imported
in the main brian2 package, you do not have to add the package name, e.g.
writing ```NeuronGroup``` is enough. For other classes, you have to give the
full path, e.g. ```brian2.units.fundamentalunits.UnitRegistry```. If it is
clear from the context where the class is (e.g. within the documentation of
`~brian2.units.fundamentalunits.UnitRegistry`), consider using the ``~``
abbreviation: ```~brian2.units.fundamentalunits.UnitRegistry``` displays only
the class name: `~brian2.units.fundamentalunits.UnitRegistry`. Note that you do
not have to enclose the exception name in a "Raises" or "Warns" section, or
the class/method/function name in a "See Also" section in backticks, they will
be automatically linked (putting backticks there will lead to incorrect display
or an error message),

Inline source fragments should be enclosed in  double backticks.

Class docstrings follow the same conventions as method docstrings and should
document the ``__init__`` method, the ``__init__`` method itself does not need
a docstring.

Documenting functions and methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The docstring for a function/method should start with a one-line description of
what the function does, without referring to the function name or the names of
variables. Use a "command style" for this summary, e.g. "Return the result."
instead of "Returns the result." If the signature of the function cannot be
automatically extracted because of an decorator (e.g. `check_units`), place a
signature in the very first row of the docstring, before the one-line
description.

For methods, do not document the ``self`` parameter, nor give information about
the method being static or a class method (this information will be
automatically added to the documentation).

Documenting classes
~~~~~~~~~~~~~~~~~~~
Class docstrings should use the same "Parameters" and "Returns" sections as
method and function docstrings for documenting the ``__init__`` constructor. If
a class docstring does not have any "Attributes" or "Methods" section, these
sections will be automatically generated with all documented (i.e. having a
docstring), public (i.e. not starting with `_`) attributes respectively methods
of the class. Alternatively, you can provide these sections manually. This is
useful for example in the `Quantity` class, which would otherwise include the
documentation of many `ndarray` methods, or when you want to include
documentation for functions like ``__getitem__`` which would otherwise not be
documented. When specifying these sections, you only have to state the names of
documented methods/attributes but you can also provide direct documentation.
For example::
    
    Attributes
    ----------
    foo
    bar
    baz
        This is a description.

This can be used for example for class or instance attributes which do not
have "classical" docstrings. However, you can also use a special syntax: When
defining class attributes in the class body or instance attributes in
``__init__`` you can use the following variants (here shown for instance
attributes)::

    def __init__(a, b, c):
        #: The docstring for the instance attribute a.
        #: Can also span multiple lines
        self.a = a
        
        self.b = b #: The docstring for self.b (only one line).
        
        self.c = c
        'The docstring for self.c, directly *after* its definition'
  
Long example of a function docstring
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is a very long docstring, showing all the possible sections. Most of the
time no See Also, Notes or References section is needed::

    def foo(var1, var2, long_var_name='hi') :
    """
    A one-line summary that does not use variable names or the function name.

    Several sentences providing an extended description. Refer to
    variables using back-ticks, e.g. `var1`.

    Parameters
    ----------
    var1 : array_like
        Array_like means all those objects -- lists, nested lists, etc. --
        that can be converted to an array.  We can also refer to
        variables like `var1`.
    var2 : int
        The type above can either refer to an actual Python type
        (e.g. ``int``), or describe the type of the variable in more
        detail, e.g. ``(N,) ndarray`` or ``array_like``.
    Long_variable_name : {'hi', 'ho'}, optional
        Choices in brackets, default first when optional.

    Returns
    -------
    describe : type
        Explanation
    output : type
        Explanation
    tuple : type
        Explanation
    items : type
        even more explaining

    Raises
    ------
    BadException
        Because you shouldn't have done that.

    See Also
    --------
    otherfunc : relationship (optional)
    newfunc : Relationship (optional), which could be fairly long, in which
              case the line wraps here.
    thirdfunc, fourthfunc, fifthfunc

    Notes
    -----
    Notes about the implementation algorithm (if needed).

    This can have multiple paragraphs.

    You may include some math:

    .. math:: X(e^{j\omega } ) = x(n)e^{ - j\omega n}

    And even use a greek symbol like :math:`omega` inline.

    References
    ----------
    Cite the relevant literature, e.g. [1]_.  You may also cite these
    references in the notes section above.

    .. [1] O. McNoleg, "The integration of GIS, remote sensing,
       expert systems and adaptive co-kriging for environmental habitat
       modelling of the Highland Haggis using object-oriented, fuzzy-logic
       and neural-network techniques," Computers & Geosciences, vol. 22,
       pp. 585-588, 1996.

    Examples
    --------
    These are written in doctest format, and should illustrate how to
    use the function.

    >>> a=[1,2,3]
    >>> print([x + 3 for x in a])
    [4, 5, 6]
    >>> print("a\nb")
    a
    b

    """

    pass