Docstring Rules#
Use numpydoc convention. See template docstring.
For literal text, use double backticks, e.g.
``var``.Cross-references: use explicit roles with the target in single backticks, e.g.
load_fits().Roles:
:func:,:class:,:meth:,:attr:,:mod:.Use fully qualified names for external objects (
astropy.units.Quantity,numpy.ndarray).Use
~to omit the full path name.
Variadics:
In
Parameters: write*argsand**kwargs.In prose: use double backticks (e.g.
``reshape(*args)``). Bare*argsis parsed as emphasis.
Types:
dtype1 | dtype2, optional, default=value.Use resolvable names.
optionalmeans the parameter has a default value.
Blank lines: one before and after every list, directive, and code block, including between a list in a parameter description and the next parameter. Omit only at the start or end of the docstring.
Directives (
.. note::,.. warning::,.. math::): blank line after the directive line, body indented.Use
r"""only if the docstring contains backslashes (e.g.:math:). Otherwise use""".Sections: use only napoleon section titles, in this order: summary, extended description,
Parameters,Returns,Raises,Warns,See Also,Notes,Examples.Classes:
The class docstring covers the class as a whole: summary, extended description,
Parameters(arguments of__init__, which gets no docstring of its own),Attributes,Raises,See Also,Notes,Examples. Do not document anything that already has its own docstring.Attributes: only plain instance attributes that autodoc cannot see (set in__init__, no docstring of their own).Members (methods, properties, class-level attributes) document themselves. Do not list or describe them in the class docstring; this causes duplicate-object warnings and drift.
Public members: every public method and property needs at least a one-line docstring.
Private functions (
_name): not rendered by autodoc, so the rules are advisory.At minimum, write a one line sentence for standalone private functions.
Keep the Numpy section layout and type format.
Template Docstring#
def func(
*data: NDArray | u.Quantity,
axis: int = 0,
*args: tuple,
unit: str | u.UnitBase | None = None,
**kwargs
):
r"""
One-line summary.
Extended description. Cross-link objects inline:
- :func:`~visualastro.set_limits`
- :class:`~visualastro.Colorsets`
- :meth:`~visualastro.Colorsets.plot`
- :class:`~astropy.units.Quantity`
Inline math: :math:`\sigma = \mathrm{FWHM} / 2.355`.
Block math:
.. math::
F = \int_{\lambda_1}^{\lambda_2} f_\lambda \, d\lambda
.. note::
Short callout for the reader.
.. warning::
Behavior that can silently produce wrong results.
Parameters
----------
*data : numpy.ndarray | astropy.units.Quantity
One or more input arrays. Each can be either:
- ``numpy.ndarray``
- ``astropy.units.Quantity``
axis : int, optional, default=0
Axis to operate on ``data``.
unit : str | astropy.units.UnitBase | None, optional, default=None
Output unit.
**kwargs : dict
Forwarded to :meth:`matplotlib.axes.Axes.plot`.
Returns
-------
astropy.units.Quantity
Description.
Raises
------
ValueError
If ``axis`` is out of range.
Warns
-----
UserWarning
If ``data`` contains NaN.
See Also
--------
load_fits : Load an image or cube.
astropy.units.Quantity : Array with attached units.
Notes
-----
- Implementation details and caveats.
Examples
--------
>>> import visualastro as va
>>> out = va.func(data)
"""