style_guide.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. .. _style_guide:
  2. ********************************
  3. Coding Style Guide with Examples
  4. ********************************
  5. This guide follows mostly:
  6. https://github.com/numpy/numpy/blob/master/doc/example.py.
  7. In the Python code blocks below, some remarks are included using JavaScript
  8. style notation <!-- comment -->. They provide additional information regarding
  9. the code that is being presented as example.
  10. Module docstring
  11. ----------------
  12. The module should start with its own docstring in the first line.
  13. The example below illustrates show it should be implemented.
  14. .. code-block:: python
  15. """
  16. Here comes the module description
  17. Detailed introduction and tutorial of method goes here.
  18. You can even link tutorials here, if appropriate.
  19. If you have references you can insert them here, otherwise in the corresponding
  20. functions, methods or classes.
  21. For a working example see
  22. :py:mod:`unitary_event_analysis.py<elephant.unitary_event_analysis>`
  23. """
  24. Function docstring. Naming conventions
  25. --------------------------------------
  26. The function below illustrates how arguments and functions should be named
  27. throughout Elephant.
  28. .. code-block:: python
  29. def pair_of_signals_example(spiketrain_i, spiketrain_j):
  30. # Add '_i' and '_j' suffixes to a pair of signals, spiketrains or any
  31. # other variables that come in pairs.
  32. def perfect_naming_of_parameters(spiketrains, spiketrain, reference_spiketrain,
  33. target_spiketrain, signal, signals, max_iterations,
  34. min_threshold, n_bins, n_surrogates, bin_size, max_size,
  35. time_limits, time_range, t_start, t_stop, period, order,
  36. error, capacity, source_matrix, cov_matrix,
  37. selection_method='aic'
  38. ):
  39. r"""
  40. Full example of the docstring and naming conventions.
  41. Function names should be in lowercase, with words written in full, and
  42. separated by underscores. Exceptions are for common abbreviations, such
  43. as "psd" or "isi". But words such as "coherence" must be written in full,
  44. and not truncated (e.g. "cohere").
  45. If the truncation or abbreviation not in conformity to this naming
  46. convention was adopted to maintain similarity to a function used
  47. extensively in another language or package, mention this in the "Notes"
  48. section, like the comment below:
  49. <!--
  50. Notes
  51. -----
  52. This function is similar to `welch_cohere` function in MATLAB.
  53. -->
  54. The rationale for the naming of each parameter in this example will be
  55. explained in the relevant "Parameters" section. Class parameters and
  56. attributes also follow the same naming convention.
  57. Parameters
  58. ----------
  59. <!-- As a general rule, each word is written in full lowercase, separated
  60. by underscores. Special cases apply according to the examples below -->
  61. spiketrains : neo.SpikeTrain or list of neo.SpikeTrain
  62. Within Elephant, this is how to name an input parameter that contains
  63. at least one spike train. The parameter name is in plural (i.e.,
  64. `spiketrains`). The function will deal with converting a single
  65. `neo.SpikeTrain` to a list of `neo.SpikeTrain` if needed.
  66. Note that although these are two words, they are NOT separated by
  67. underscore because Neo does not use underscore, and Elephant must keep
  68. compatibility. Do not use names such as `sts`, `spks`, or
  69. `spike_trains`.
  70. spiketrain: neo.SpikeTrain
  71. If the function EXPLICITLY requires only a single spike train, then
  72. the parameter should be named in singular (i.e., `spiketrain`). Do
  73. not use names such as `st`, `spk`, or `spike_train`.
  74. reference_spiketrain : neo.SpikeTrain
  75. If a function uses more than one parameter with single spike trains,
  76. then each parameter name begins with a meaningful name,
  77. followed by "_spiketrain" in singular form.
  78. target_spiketrain: neo.SpikeTrain
  79. Second parameter that is a single spike train. Note that the difference
  80. from `reference_spiketrain` is indicated by a meaningful name at the
  81. beginning.
  82. signal : neo.AnalogSignal
  83. If a single `neo.AnalogSignal` object is passed to the function, even if
  84. it contains several signals (arrays).
  85. signals : list of neo.AnalogSignal
  86. If the parameter is a container that has at least one `neo.AnalogSignal`
  87. object. The name of the parameter is `signals` (plural).
  88. max_iterations : int
  89. Parameters that represent a maximum value should start with "max_"
  90. prefix, followed by the description as a full word. Therefore, do not
  91. use names such as `max_iter` or `maxiter`.
  92. min_threshold : float
  93. Same case as for maximum. Parameters that represent a minimum value
  94. should start with "min_" prefix, followed by the description as a full
  95. word. Therefore, do not use names such as `min_thr` or `minthr`.
  96. n_bins : int
  97. Parameters that represent a number should start with the prefix "n_".
  98. Do not use `numbins`, `bin_number`, or `num_bins`. The prefix should
  99. be followed by a meaningful word in full.
  100. n_surrogates : int
  101. The description should always be meaningful an without abbreviations.
  102. Therefore, do not use terms as `n` or `n_surr`, that are not
  103. immediately understood.
  104. bin_size : pq.Quantity or int
  105. Separate the words by underscore. Do not use `bin_size`. Old functions
  106. which use `binsize` are deprecated.
  107. max_size : float
  108. Another example showing that words should be separated by underscores.
  109. This intersects with the naming convention for a maximum value.
  110. time_limits: list or tuple
  111. For parameters that define minimum and maximum values as a list or
  112. tuple (e.g., [-2, 2]), the parameter must start with a meaningful
  113. word followed by the suffix "_limits". Preferentially, one should use
  114. two separated parameters (e.g., `max_time` and `min_time` following
  115. the convention for maximum and minimum already mentioned). But should
  116. the function require the definition of limits in this form, use the
  117. name `_limits` and not `_range` (see next parameter).
  118. time_range: list
  119. For parameters that behave like a Python range (e.g. [1, 2, 3, 4])), in
  120. the sense that it is a sequence, not only the lower and upper limits
  121. as in the example above, the parameter should start with a meaningful
  122. name followed by the suffix "_range".
  123. t_start : pq.Quantity
  124. Standard name within Elephant for defining starting times.
  125. t_stop : pq.Quantity
  126. Standard name within Elephant for defining stopping times.
  127. period : pq.Quantity
  128. Oscillation period.
  129. Always use informative names. In this case, one could name the
  130. parameter as simply as `T`, since this is standard for referring to
  131. periods. If the function is implementing computations based on a paper
  132. that has a formula with a variable "T", acknowledge this after
  133. describing the formula in the docstring. Therefore, write a sentence
  134. like "`period` refers to :math:`T`"
  135. If the Elephant function uses an external function (such as from
  136. `scipy`), and such function has an argument named `T`, also
  137. acknowledge this in the docstring. Therefore, write a sentence like
  138. "`period` is forwarded as argument `T` of `scipy.uses_T` function".
  139. If the external function already has an informative parameter name
  140. (such as `period`), the same parameter name can be used in the Elephant
  141. function if forwarded.
  142. If several input parameters are forwarded or are members
  143. of a formula, the docstring can present them together as a list.
  144. But always use informative names, not single letter names if this is
  145. how they are described in the paper or implemented in another function.
  146. order : int
  147. Order of the Butterworth filter.
  148. This is an example of how the `N` parameter of `scipy.signal.butter`
  149. function could be provided by the user of the Elephant function.
  150. The docstring would present a text similar to
  151. "`order` is passed as the `N` argument for `scipy.signal.butter` function".
  152. Also, in the code implementation, use keyword arguments to make this
  153. explicit (see the implementation of the function below)
  154. error : float
  155. In the case the function has an input parameter that corresponds to a
  156. greek letter in a formula (in a paper, for instance) always use the
  157. meaning of the greek letter. Therefore, should :math:`\epsilon` refer
  158. to the error in the formula, the parameter should be named `error`. As
  159. already mentioned, this is acknowledged in the docstring after the
  160. description of the formula.
  161. capacity : float
  162. Capacity value.
  163. When using parameters based on a paper (which, e.g., derives some
  164. formula), and the parameter's name in this paper is a single letter
  165. (such as `C` for capacity), always use the meaning
  166. of the letter. Therefore, the parameter should be named `capacity`,
  167. not `C`. Acknowledge this in the docstring as already mentioned.
  168. source_matrix: np.ndarray
  169. Parameters that are matrices should end with the suffix "_matrix", and
  170. start with a meaningful name.
  171. cov_matrix: np.ndarray
  172. A few exceptions allow the use of abbreviations instead of full words
  173. in the name of the parameter. These are:
  174. * "cov" for "covariance" (e.g., `cov_matrix`)
  175. * "lfp" for "local_field_potential" (e.g. `lfp_signal`)
  176. * "corr" for "correlation" (e.g. `corr_matrix`).
  177. THESE EXCEPTIONS ARE NOT ACCEPTED FOR FUNCTION NAMES. Therefore, a
  178. parameter would be named `cov_matrix`, but the function would be named
  179. `calculate_covariance_matrix`. If the function name becomes very long,
  180. then an alias may be created and described appropriately in the "Notes"
  181. section, as mentioned above. For aliases, see example below.
  182. selection_method : {'aic', 'bic'}
  183. Metric for selecting the autoregressive model.
  184. If 'aic', uses the Akaike Information Criterion (AIC).
  185. If 'bic', uses Bayesian Information Criterion (BIC).
  186. Default: 'bic', because it is more reliable than AIC due to the
  187. mathematical properties (see Notes [3]).
  188. <!-- Note that the default value that comes in the last line is
  189. followed by comma and a brief reasoning for defining the default
  190. `selection_method`). -->
  191. <!-- Other remarks:
  192. 1. Do not use general parameter names, such as `data` or `matrix`.
  193. 2. Do not use general result names, such as `result` or `output`.
  194. 3. Avoid capitalization (such as the examples mentioned for parameters
  195. such as `T` for period, or `C` for capacity or a correlation matrix.
  196. -->
  197. Returns
  198. -------
  199. frequency : float
  200. The frequency of the signal.
  201. filtered_signal : np.ndarray
  202. Signal filtered using Butterworth filter.
  203. Notes
  204. -----
  205. 1. Frequency is defined as:
  206. .. math::
  207. f = \frac{1}{T}
  208. `period` corresponds to :math:`T`
  209. 2. `order` is passed as the `N` parameter when calling
  210. `scipy.signal.butter`.
  211. 3. According to [1]_, BIC should be used instead of AIC for this
  212. computation. The brief rationale is .......
  213. References
  214. ----------
  215. .. [1] Author, "Why BIC is better than AIC for AR model", Statistics,
  216. vol. 1, pp. 1-15, 1996.
  217. """
  218. # We use Butterworth filter from scipy to perform some calculation.
  219. # Note that parameter `N` is passed using keys, taking the value of the
  220. # `order` input parameter
  221. filtered_signal = scipy.signal.butter(N=order, ...)
  222. # Here we calculate a return value using a function variable. Note that
  223. # this variable is named in the "Returns" section
  224. frequency = 1 / period
  225. return frequency, filtered_signal
  226. Class docstring
  227. ---------------
  228. Class docstrings follow function docstring format. Here is an example.
  229. .. code-block:: python
  230. class MyClass(object): # Classes use CamelCase notation
  231. """
  232. One line description of class.
  233. Long description of class, may span several lines. Possible sections are
  234. the same as for a function doc, with additional "Attributes" and "Methods"
  235. after "Parameters" (cf. numpydoc guide). Do not put a blank line after
  236. section headers, do put a blank line at the end of a long docstring.
  237. When explaining the algorithm, you can use mathematical notation, e.g.:
  238. .. math::
  239. E = m c^2
  240. To insert an equation use `.. math::` and surround the whole expression in
  241. blank lines. To use math notation in-line, write :math:`E` corresponds to
  242. energy and :math:`m` to mass. Embed expressions after `:math:` in
  243. backticks, e.g. :math:`x^2 + y^2 = z^2`.
  244. To refer to a paper in which formula is described, use the expression
  245. "see [1]_" - it will become an interactive link on the readthedocs website.
  246. The underscore after the closing bracket is mandatory for the link to
  247. work.
  248. To refer to a note in the "Notes" section, simply write "see Notes [1]".
  249. Variable, module, function, and class names should be written
  250. between single back-ticks (`kernels.AlphaKernel`), NOT *bold*.
  251. For common modules such as Numpy and Quantities, use the notation
  252. according to the import statement. For example:
  253. "this function uses `np.diff`", not "uses `numpy.diff`".
  254. Prefixes for common packages in Elephant are the following:
  255. 1. Neo objects = neo (e.g. `neo.SpikeTrain`)
  256. 2. Numpy = np (e.g. `np.ndarray`)
  257. 3. Quantities = pq (e.g. `pq.Quantity`)
  258. For other objects, list the full path to the object (e.g., for the
  259. BinnedSpikeTrain, this would be `elephant.conversion.BinnedSpikeTrain`)
  260. For None and NaNs, do not use backticks. NaN is referred as np.NaN (i.e.,
  261. with the Numpy prefix "np").
  262. Use backticks also when referring to arguments of a function (e.g., `x` or
  263. `y`), and :attr:`attribute_name` when referring to attributes of a class
  264. object in docstrings of this class.
  265. To refer to attributes of other objects, write
  266. `other_object.relevant_attribute` (e.g. `neo.SpikeTrain.t_stop`).
  267. When mentioning a function from other module, type `other_module.function`
  268. (without parentheses after the function name; e.g., `scipy.signal.butter`).
  269. If you refer values to True/False/None, do not use backticks, unless an
  270. emphasis is needed. In this case, write `True` and not bold, like **True**.
  271. Parameters
  272. ----------
  273. <!-- List the arguments of the constructor (__init__) here!
  274. Arguments must come in the same order as in the constructor or function -->
  275. parameter : int or float
  276. Description of parameter `parameter`. Enclose variables in single
  277. backticks. The colon must be preceded by a space.
  278. no_type_parameter
  279. Colon omitted if the type is absent.
  280. x : float
  281. The X coordinate.
  282. y : float
  283. The Y coordinate.
  284. Default: 1.0. <!-- not "Default is 1.0." (it is just a convention) -->
  285. z : float or int or pq.Quantity
  286. This is Z coordinate.
  287. If it can take multiple types, separate them by "or", do not use commas
  288. (numpy style).
  289. If different actions will happen depending on the type of `z`, explain
  290. it briefly here, not in the main text of the function/class docstring.
  291. s : {'valid', 'full', 'other'}
  292. This is the way to describe a list of possible argument values, if the
  293. list is discrete and predefined (typically concerns strings).
  294. If 'valid', the function performs some action.
  295. If 'full', the function performs another action.
  296. If 'other', the function will ignore the value defined in `z`.
  297. Default: 'valid'.
  298. spiketrains : neo.SpikeTrain or list of neo.SpikeTrain or np.ndarray
  299. When the parameter can be a container (such as list or tuple), you can
  300. specify the type of elements using "of". But use the Python type name
  301. (do not add "s" to make it plural; e.g., do not write
  302. "list of neo.SpikeTrains" or "list of neo.SpikeTrain objects").
  303. counts_matrix : (N, M) np.ndarray
  304. This is the way to indicate dimensionality of the required array
  305. (i.e.,if the function only works with 2D-arrays). `N` corresponds to
  306. the number of rows and `M` to the number of columns. Refer to the same
  307. `N` and `M` to describe the dimensions of the returned values when
  308. they are determined by the dimensions of the parameter.
  309. is_true : bool
  310. True, if 1.
  311. False, if 0.
  312. Default: True.
  313. other_parameter : int
  314. Some value.
  315. If value is None and the function takes some specific action (e.g.,
  316. calculate some value based on the other inputs), describe here.
  317. Default: None.
  318. Attributes
  319. ----------
  320. <!-- Here list the attributes of class object which are not simply copies
  321. of the constructor parameters. Property decorators (@property) are also
  322. considered attributes -->
  323. a : list
  324. This is calculated based on `x` and `y`.
  325. b : int
  326. This is calculated on the way, during some operations.
  327. Methods
  328. -------
  329. <!-- Here list the most important/useful class methods (not all the
  330. methods) -->
  331. Returns
  332. -------
  333. <!-- This section is rarely used in class docstrings, but often in
  334. function docs. Follow the general recommendation of numpydoc.
  335. If there is more than one returned value, use variable names for the
  336. returned value, like `error_matrix` below. -->
  337. error_matrix : np.ndarray
  338. A matrix is stored in a variable called `error_matrix`, containing
  339. errors estimated from some calculations. The function "return"
  340. statement then returns the variable (e.g. "return error_matrix").
  341. Format is the same as for any parameter in section "Parameters".
  342. Use meaningful names, not general names such as `output` or `result`.
  343. list
  344. The returned object is created on the fly and is never assigned to
  345. a variable (e.g. "return [1, 2, 3]"). Simply name the type and
  346. describe the content. This should be used only if the function returns
  347. a single value.
  348. dict
  349. key_1 : type
  350. Description of key_1, formatted the same as in "Parameters".
  351. key_2 : type
  352. Description of key_2
  353. particular_matrix : (N, N, M) np.ndarray
  354. The dimensionality of this array depends on the dimensionality of
  355. `counts_matrix` input parameter. Note that `N` and `M` are used since
  356. these were the names of the dimensions of `counts_matrix` in the
  357. "Parameters" section.
  358. list_variable : list of np.ndarray
  359. Returns a list of numpy arrays.
  360. signal : int
  361. Description of `signal`.
  362. Raises
  363. ------
  364. <!-- List the errors explicitly raised by the constructor (raise
  365. statements), even if they are in fact raised by other Elephant functions
  366. called inside the constructor. Enumerate them in alphabetical order. -->
  367. TypeError
  368. If `x` is an `int` or None.
  369. If `y` is not a `float`.
  370. ValueError
  371. If this and that happens.
  372. Warns
  373. -----
  374. <!-- Here apply the same rules as for "Raises". -->
  375. UserWarning
  376. If something may be wrong but does not prevent execution of the code.
  377. The default warning type is UserWarning.
  378. Warning
  379. -------
  380. <!-- Here write a message to the users to warn them about something
  381. important.
  382. Do not enumerate Warnings in this section! -->
  383. See Also
  384. --------
  385. <!-- Here refer to relevant functions (also from other modules). Follow
  386. numpydoc recommendations.
  387. If the function name is not self-explanatory, you can add a brief
  388. explanation using a colon separated by space.
  389. This items will be placed as links to the documentation of the function
  390. referred.
  391. -->
  392. statistics.isi
  393. scipy.signal.butter : Butterworth filter
  394. Notes
  395. -----
  396. <!-- Here you can add some additional explanations etc. If you have several
  397. short notes (at least two), use a list -->
  398. 1. First remark.
  399. 2. Second much longer remark, which will span several lines. To refer to a
  400. note in other parts of the docstring, use a phrase like "See Notes [2]".
  401. To make sure that the list displays correctly, keep the indentation to
  402. match the first word after the point (as in this text).
  403. 3. If you want to explain why the default value of an argument is
  404. something particular, you can give a more elaborate explanation here.
  405. 4. If the function has an alias (see the last function in this file), the
  406. information about it should be in this section in the form:
  407. Alias: bla.
  408. Aliases should be avoided.
  409. 5. Information about validation should be here, and insert bibliographic
  410. citation in the "References". Also specify in parenthesis the unit test
  411. that implements the validation. Example:
  412. "This function reproduces the paper Riehle et al., 1997 [2]_.
  413. (`UETestCase.test_Riehle_et_al_97_UE`)."
  414. 6. Do not create new section names, because they will not be displayed.
  415. Place the relevant information here instead.
  416. 7. This is an optional section that provides additional information about
  417. the code, possibly including a discussion of the algorithm. This
  418. section may include mathematical equations, written in LaTeX format.
  419. Inline: :math:`x^2`. An equation:
  420. .. math::
  421. x(n) * y(n) \Leftrightarrow X(e^{j\omega } )Y(e^{j\omega } )
  422. 8. Python may complain about backslashes in math notation in docstrings.
  423. To prevent the complains, precede the whole docstring with "r" (raw
  424. string).
  425. 9. Images are allowed, but should not be central to the explanation;
  426. users viewing the docstring as text must be able to comprehend its
  427. meaning without resorting to an image viewer. These additional
  428. illustrations are included using:
  429. .. image:: filename
  430. References
  431. ----------
  432. .. [1] Smith J., "Very catchy title," Elephant 1.0.0, 2020. The ".." in
  433. front makes the ref referencable in other parts of the docstring.
  434. The indentation should match the level of the first word AFTER the
  435. number (in this case "Smith").
  436. Examples
  437. --------
  438. <!-- If applicable, provide some brief description of the example, then
  439. leave a blank line.
  440. If the second example uses an import that was already used in the first
  441. example, do not write the import again.
  442. Examples should be very brief, and should avoid plotting. If plotting
  443. is really needed, use simple matplotlib plots, that take only few lines.
  444. More complex examples, that require lots of plotting routines (e.g.,
  445. similar to Jupyter notebooks), should be placed as tutorials, with links
  446. in the docstring. Examples should not load any data, but only use easy
  447. generated data.
  448. Finally, avoid using abbreviations in examples, such as
  449. "import elephant.conversion as conv" -->
  450. >>> import neo
  451. >>> import numpy as np
  452. >>> import quantities as pq
  453. ...
  454. ... # This is a way to make a blank line within the example code.
  455. >>> st = neo.SpikeTrain([0, 1, 2, 3] * pq.ms, t_start=0 * pq.ms,
  456. ... t_stop=10 * pq.ms, sampling_rate=1 * pq.Hz)
  457. ... # Use "..." also as a continuation line.
  458. >>> print(st)
  459. SpikeTrain
  460. Here provide a brief description of a second example. Separate examples
  461. with a blank line even if you do not add any description.
  462. >>> import what_you_need
  463. ...
  464. >>> st2 = neo.SpikeTrain([5, 6, 7, 8] * pq.ms, t_start=0 * pq.ms,
  465. ... t_stop=10 * pq.ms, sampling_rate=1 * pq.Hz)
  466. >>> sth = what_you_need.function(st2)
  467. >>> sth_else = what_you_need.interesting_function(sth)
  468. """
  469. def __init__(self, parameter):
  470. """
  471. Constructor
  472. (actual documentation is in class documentation, see above!)
  473. """
  474. self.parameter = parameter
  475. self.function_a() # creates new attribute of self 'a'
  476. def function_a(self, parameter, no_type_parameter, spiketrains,
  477. is_true=True, string_parameter='C', other_parameter=None):
  478. """
  479. One-line short description of the function.
  480. Long description of the function. Details of what the function is doing
  481. and how it is doing it. Used to clarify functionality, not to discuss
  482. implementation detail or background theory, which should rather be
  483. explored in the "Notes" section below. You may refer to the parameters
  484. and the function name, but detailed parameter descriptions still
  485. belong in the "Parameters" section.
  486. Parameters
  487. ----------
  488. <!-- See class docstring above -->
  489. Returns
  490. -------
  491. <!-- See class docstring above -->
  492. Raises
  493. ------
  494. <!-- See class docstring above.
  495. List only exceptions explicitly raised by the function -->
  496. Warns
  497. -----
  498. <!-- See class docstring above. -->
  499. See Also
  500. --------
  501. <!-- See class docstring above -->
  502. Notes
  503. -----
  504. <!-- See class docstring above -->
  505. References
  506. ----------
  507. <!-- See class docstring above -->
  508. Examples
  509. --------
  510. <!-- See class docstring above -->
  511. """
  512. # Variables use underscore notation
  513. dummy_variable = 1
  514. a = 56 # This mini comment uses two spaces after the code!
  515. # Textual strings use double quotes
  516. error = "An error occurred. Please fix it!"
  517. # Textual strings are usually meant to be printed, returned etc.
  518. # Non-textual strings use single quotes
  519. default_character = 'a'
  520. # Non textual strings are single characters, dictionary keys and other
  521. # strings not meant to be returned or printed.
  522. # Normal comments are proceeded by a single space, and begin with a
  523. # capital letter
  524. dummy_variable += 1
  525. # Longer comments can have several sentences. These should end with a
  526. # period. Just as in this example.
  527. dummy_variable += 1
  528. # Class functions need only 1 blank line.
  529. # This function is deprecated. Add a warning!
  530. def function_b(self, **kwargs):
  531. """
  532. This is a function that does b.
  533. .. deprecated:: 0.4
  534. `function_b` will be removed in elephant 1.0, it is replaced by
  535. `function_c` because the latter works also with Numpy Ver. 1.6.
  536. Parameters
  537. ----------
  538. kwargs : dict
  539. kwarg1 : type
  540. Same style as docstring of class `MyClass`.
  541. kwarg2 : type
  542. Same style as docstring of class `MyClass`.
  543. """
  544. pass