Documenting VisualAstro#
To contribute to VisualAstro, install it in editable mode from a local clone. Contributing requires git and, to open pull requests, a GitHub account.
First, fork the repository
on GitHub, then clone your fork and add the original repository as upstream:
git clone https://github.com/<your-username>/VisualAstro.git
cd VisualAstro
git remote add upstream https://github.com/elkogerville/VisualAstro.git
Requirements#
Make sure VisualAstro is installed via a developer install by navigating into the package root:
cd visualastro/
pip install -e ".[docs]"
Requires Python 3.11 and the packages listed under the docs extra in pyproject.toml.
Building Locally#
To create a clean build from scratch:
cd docs
rm -rf _build reference/generated
make html
open _build/html/index.html
For docstring or file content edits only:
make html.For new pages, renamed objects,
conf.pyor template changes: clean build as above.The build must finish with 0 warnings.
Documenting a New Function or Class#
Export it in
src/visualastro/__init__.py.Write a NumPy-style docstring (see docstring rules).
Add its bare name to an
autosummaryblock in the matchingdocs/reference/<topic>.rst:.. currentmodule:: visualastro .. autosummary:: :nosignatures: load_fits
List each object in exactly one page. Duplicates raise warnings.
Rebuild and fix all warnings.
Adding a Reference Page#
Create
docs/reference/<topic>.rstwith a title, a.. currentmodule:: visualastroline and one or moreautosummaryblocks grouped by purpose.Add
<topic>to the toctree indocs/reference/index.rst.Run a clean build.
Adding a Guide or Tutorial#
Create the
.rstfile indocs/ordocs/tutorials/.List it, without extension, in the nearest
toctree.Store images in
docs/_static/images/and reference them as/_static/images/<name>.pngwith an:alt:entry.
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 add document anything that already has a 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)
"""
Pre-Commit Checklist#
Clean local build with 0 warnings.
docs/_build/anddocs/reference/generated/not committed.New files listed in a toctree.
Images committed to
docs/_static/.