Loading...

Automatic Documentation

Complete guide to generating professional API documentation with Sphinx and reStructuredText.


Getting Started

VAST Orbit uses Sphinx for documentation generation and reStructuredText (RST) as the markup language. RST provides clear, readable documentation writing, and Sphinx generates HTML and other formats from RST files.

Learning Path:

  1. Read the reStructuredText (RST) syntax basics below

  2. Explore Sphinx documentation and configuration

  3. Practice with Complete Example

  4. Use Render Your Docstring to preview changes

Tip

The best way to learn is by doing. Create a test project, write RST files, and build documentation with Sphinx.


Environment Setup

Complete Sphinx Environment Configuration

This section covers setting up Sphinx to automate documentation. (Future: This will be integrated into CI/CD pipeline.)

Step-by-Step Setup:

1. Clone the Repository

git clone https://github.com/vast-data/VAST-Orbit.git
cd vastorbit

2. Create docs Folder

mkdir -p docs

3. Setup Sphinx Environment

Download and unzip the essential Sphinx files (make file and source folder) and place them in the docs folder.

4. Configure conf.py

Edit docs/source/conf.py with special attention to:

  • copyright year - Update to current year

  • release version - Match VAST Orbit version

  • rst_prolog - Content added to top of every RST file (imports, settings)

Example rst_prolog:

rst_prolog = """
.. |vo| replace:: VAST Orbit

.. ipython:: python
   :suppress:

   import vastorbit as vo
   import pandas as pd
   vo.set_option("mode", "full")
"""

5. Install Requirements

pip install -r docs/requirements.txt

6. Install VAST Orbit

# Uninstall existing version if present
pip uninstall vastorbit

# Install from source
pip install .

7. Update Directory Paths

Navigate to docs folder and run:

cd docs
python3 replace_sphinx_dir.py

This updates all directory paths inside VAST Orbit code for Sphinx.

8. Build HTML Documentation

make html

Note

You may need to install make:

apt install make

9. Clean Up Function Names

Remove “vastorbit.” prefix from function names:

python3 remove_pattern.py

This converts vastorbit.VastFrame.barVastFrame.bar

10. View Documentation

HTML files are now in docs/build directory.

Quick Rebuild Script

For convenience, use the refresh.sh script after making code/docstring changes:

./refresh.sh

Note

You may need to make it executable:

chmod +x refresh.sh

RST Syntax Guide

Headers and Subheaders

Normal Headers:

Use -------- underneath text to mark as header:

Function Name
-------------

This renders as:

Function Name


Sections and Subsections:

Use ======= for main sections and ------- for subsections:

Parameters
==========
method: str, optional
    Description here.

Subsection
----------
Some text here.

Returns
=======
float
    Return value description.

This renders as:

Parameters

method: str, optional

Description here.

Subsection

Some text here.

Returns

float

Return value description.


Centered Headers:

.. centered:: Some Centered Information!

This renders as:

Some Centered Information!


Indentation and Line Spacing

Line spacing and indentation must be carefully managed. Without line breaks, all text is treated as a single line. Use | to go to next line without adding extra space.

Example 1: Using | for compact spacing

Parameters
----------
method: str, optional
    Method used to compute the optimal h.
        | auto : Combination of Freedman Diaconis and Sturges.
        | freedman_diaconis : Freedman Diaconis
        | sturges : Sturges

This renders as:

Parameters

method: str, optional
Method used to compute the optimal h.
auto : Combination of Freedman Diaconis and Sturges.
freedman_diaconis : Freedman Diaconis
sturges : Sturges

(Notice: Each line starts with | and there’s no extra spacing between options)


Example 2: Using blank lines for spacing

Parameters
----------
method: str, optional
    Method used to compute the optimal h.
        auto : Combination of Freedman Diaconis and Sturges.

        freedman_diaconis : Freedman Diaconis

        sturges : Sturges

This renders as:

Parameters

method: str, optional
Method used to compute the optimal h.

auto : Combination of Freedman Diaconis and Sturges.

freedman_diaconis : Freedman Diaconis

sturges : Sturges

(Notice: Extra spacing between each option for better readability)


Example 3: Aligned formatting

Parameters
----------
method: str, optional
    Method used to compute the optimal h.
        auto              : Combination of Freedman Diaconis
                            and Sturges.
        freedman_diaconis : Freedman Diaconis
        sturges           : Sturges

This renders as:

Parameters

method: str, optional

Method used to compute the optimal h.

auto              : Combination of Freedman Diaconis
                    and Sturges.
freedman_diaconis : Freedman Diaconis
sturges           : Sturges

(Notice: Options are aligned for a clean, professional look)


Code Blocks

Static Code (Not Executed):

Show code without executing it:

.. code-block:: python

   import vastorbit as vo
   vo.VastFrame({"a":[1,2,3]})

This renders as:

import vastorbit as vo
vo.VastFrame({"a":[1,2,3]})

(Notice: Code is displayed but not executed - just syntax highlighting)


Code Execution

Execute and display code using the ipython directive.

Note

Requires extensions in conf.py:

  • IPython.sphinxext.ipython_directive

  • IPython.sphinxext.ipython_console_highlighting

Basic Execution:

.. ipython:: python

   import vastorbit as vo
   vo.VastFrame({"a":[1,2,3]})

This renders as:

import vastorbit as vo
vo.VastFrame({"a":[1,2,3]})

(Notice: Code is executed and output is shown, including the VastFrame table)


Suppressing Code/Output

Method 1: Suppress Entire Block

Use :suppress: directive option to hide entire code block while still executing it:

.. ipython:: python
   :suppress:

   import vastorbit as vo
   import pandas as pd
   import sys

.. ipython:: python

   print(vo.VastFrame({"a":[1,2,3]}))

This renders as:

print(vo.VastFrame({"a":[1,2,3]}))

(Notice: The import statements are completely hidden - neither code nor output is shown. Only the print statement and its output are visible.)


Method 2: Suppress Single Line

Use @suppress pseudo-directive to hide one line:

.. ipython:: python

   @suppress
   import vastorbit as vo
   print(vo.VastFrame({"a":[1,2,3]}))

This renders as:

@suppress
import vastorbit as vo
print(vo.VastFrame({"a":[1,2,3]}))

(Notice: The import line with @suppress is hidden, but the print output is still shown)

When to Use:

  • Block suppress (:suppress:): For hiding multiple import statements or setup code

  • Line suppress (@suppress): For hiding single lines within visible code blocks



Lists

Bullet List:

- Item 1
- Item 2
  - Nested item
- Item 3

This renders as:

  • Item 1

  • Item 2 - Nested item

  • Item 3


Numbered List:

1. First item
2. Second item
3. Third item

This renders as:

  1. First item

  2. Second item

  3. Third item


Plotting and Visualizations

Matplotlib Plots

The @savefig directive saves the matplotlib figure to a file and displays it in the documentation.

How it works:

  1. Create your plot with matplotlib

  2. Add @savefig filename.png on its own line, right before plt.show()

  3. The image is automatically saved to _images/ directory and embedded in the documentation

Example Code:

.. ipython:: python
   :suppress:

   import matplotlib.pyplot as plt

   # Create data
   x = [1, 2, 3, 4, 5]
   y = [2, 4, 6, 8, 10]

   # Create plot
   plt.plot(x, y, marker='o', linestyle='-')
   plt.xlabel('X-axis')
   plt.ylabel('Y-axis')
   plt.title('Simple Linear Plot')

   # Save and display the figure
   @savefig simple_plot.png
   plt.show()

This renders as:

(Notice: The code is hidden by :suppress:, but the plot is displayed. The image is also saved as simple_plot.png)


Key Points about @savefig:

  • @savefig must be on its own line, immediately before plt.show()

  • The :suppress: option hides the code from output (shows only the plot)

  • Images are saved to _images/ directory automatically

  • The saved image can be reused elsewhere with:

    .. image:: _images/simple_plot.png
    

Image File Naming Convention

Important

Naming Convention for Images:

Format: path_with_underscores_classname_functionname.png

Example: For boxplot function in core/VastFrame/_plotting.py inside vDFPlot class:

core_VastFrame__plotting_vDFPlot_boxplot.png

Multiple plots in one function:

  • core_VastFrame__plotting_vDFPlot_boxplot_1.png

  • core_VastFrame__plotting_vDFPlot_boxplot_2.png

  • core_VastFrame__plotting_vDFPlot_boxplot_3.png


VAST Orbit Plots

Matplotlib Backend:

.. ipython:: python
   :suppress:

   import vastorbit as vo
   data = vo.VastFrame({"counts":[1,1,1,2,2,3]})
   @savefig vastorbit_plot.png
   data.bar("counts")

This renders as:

(Notice: VAST Orbit plot saved as PNG and displayed inline)


Plotly Backend:

For Plotly charts, you need to save as HTML and include it:

.. ipython:: python
   :suppress:

   import vastorbit as vo
   vo.set_option("plotting_lib","plotly")
   data = vo.VastFrame({"counts":[1,1,1,2,2,3]})
   fig = data.bar("counts")
   fig.write_html("figures/plotly_bar.html")

.. raw:: html
   :file: /Users/badr.ouali/Documents/VastOrbit-master/docs/figures/plotly_bar.html

Note

Important Differences:

  • Matplotlib: Save as PNG with @savefig filename.png

  • Plotly: Save as HTML with fig.write_html() and include with .. raw:: html


Advanced HTML Output

For advanced graphics (VastFrame output, Plotly charts, interactive tables), use this methodology:

  1. Generate HTML representation with ._repr_html_() or .write_html()

  2. Save as HTML file in figures/ directory

  3. Load and display HTML file with .. raw:: html directive

VastFrame Output:

.. ipython:: python
   :suppress:

   import vastorbit as vo
   html_file = open("figures/vastframe_output.html", "w")
   html_file.write(vo.VastFrame({"a":[1,2,3]})._repr_html_())
   html_file.close()

.. raw:: html
   :file: /Users/badr.ouali/Documents/VastOrbit-master/docs/figures/vastframe_output.html

(This embeds the interactive VastFrame table directly in the documentation)


Plotly Correlation Matrix:

.. ipython:: python
   :suppress:

   from vastorbit.datasets import load_titanic
   titanic = load_titanic()
   fig = titanic.corr(method = "spearman")
   fig.write_html("figures/plotly_corr.html")

.. raw:: html
   :file: /Users/badr.ouali/Documents/VastOrbit-master/docs/figures/plotly_corr.html

(This embeds an interactive Plotly correlation heatmap)


HTML File Naming Convention

Important

Naming Convention for HTML Files:

Same as images: path_with_underscores_classname_functionname.html

File Paths - Two Different Conventions:

  1. When saving (in Python code): Use relative path "figures/filename.html"

  2. When loading (in raw html directive): Use absolute path /Users/badr.ouali/Documents/VastOrbit-master/docs/figures/filename.html

Example:

# Saving (relative path)
fig.write_html("figures/core_VastFrame_corr.html")
# Loading (absolute path)
.. raw:: html
   :file: /Users/badr.ouali/Documents/VastOrbit-master/docs/figures/core_VastFrame_corr.html

Tables

CSV Table Directive

Easiest method for creating tables:

.. csv-table:: **Table Title**
   :header: Column Header, Another Column
   :widths: 30, 70

   Row 1 Value, Value in Row 1
   Row 2 Value, Value in Row 2
   Row 3 Value, Value in Row 3

This renders as:

Table Title

Column Header

Another Column

Row 1 Value

Value in Row 1

Row 2 Value

Value in Row 2

Row 3 Value

Value in Row 3


Manual Table Format

More control but more complex:

+---------------+------------------+
| Column Header | Another Column   |
+===============+==================+
| Row 1 Value   | Value in Row 1   |
+---------------+------------------+
| Row 2 Value   | Value in Row 2   |
+---------------+------------------+
| Row 3 Value   | Value in Row 3   |
+---------------+------------------+

This renders as:

Column Header

Another Column

Row 1 Value

Value in Row 1

Row 2 Value

Value in Row 2

Row 3 Value

Value in Row 3


Admonitions and Directives

See Also

.. seealso::

   :py:mod:`~vastorbit.VastFrame.bar`
      Documentation of the bar chart function.

This renders as:

See also

bar

Documentation of the bar chart function.


Deprecation Warning

.. deprecated:: 3.8
   This feature is deprecated and will be removed in version 4.0.

This renders as:

Deprecated since version 3.8: This feature is deprecated and will be removed in version 4.0.


Notes, Warnings, and More

.. note::
   This is a note with important information.

.. tip::
   This is a helpful tip for users.

.. hint::
   This is a hint to guide users.

.. important::
   This is important information that users must know.

.. warning::
   This is a warning about potential issues.

.. danger::
   This is a danger warning for critical situations.

This renders as:

Note

This is a note with important information.

Tip

This is a helpful tip for users.

Hint

This is a hint to guide users.

Important

This is important information that users must know.

Warning

This is a warning about potential issues.

Danger

This is a danger warning for critical situations.


Docstring Standards

NumPy Style Template

VAST Orbit follows NumPy docstring conventions. Here’s a complete template:

def function_name(param1: str, param2: int = 0) -> dict:
    """
    Brief one-line description of the function.

    Longer description providing more details about the function's
    purpose, behavior, and any important notes. This can span
    multiple lines and include detailed explanations.

    Parameters
    ----------
    param1 : str
        Description of the first parameter. Explain what it does,
        any constraints or requirements, and expected format.
    param2 : int, optional
        Description of the second parameter. Explain its purpose
        and behavior. Default value is 0.

    Returns
    -------
    dict
        Description of the return value. Explain the structure
        and contents of what's returned, including key names
        and value types if returning a dictionary.

    Raises
    ------
    ValueError
        If param1 is empty or invalid.
    TypeError
        If param2 is not an integer.

    Examples
    --------
    Basic usage example:

    .. code-block:: python

       result = function_name("test", 5)
       print(result)

    Advanced usage with actual execution:

    .. ipython:: python

       result = function_name("advanced", param2=10)
       result

    See Also
    --------
    related_function : Brief description of how it relates
    another_function : Another related function
    :py:func:`~vastorbit.module.other_function` : Cross-reference

    Notes
    -----
    Any additional notes, implementation details, algorithm
    explanations, or important considerations for users.

    This section can include:

    - Performance characteristics
    - Edge cases to be aware of
    - Best practices

    References
    ----------
    .. [1] Author Name, "Paper Title", Journal, Year.
    .. [2] Book Author, "Book Title", Publisher, Year.
    """

Best Practices

Key Points:

  • Use NumPy docstring style consistently across all functions

  • Include complete type hints in function signature (e.g., param: str)

  • Provide at least one working example that users can copy-paste

  • Cross-reference related functions with :py:func: directive

  • Keep descriptions clear, concise, and user-focused

  • Use proper RST formatting in docstrings (code blocks, lists, etc.)

  • Test that all examples actually work before committing

Common Sections (in order):

  1. Short Summary - One-line description

  2. Extended Summary - Detailed explanation (optional but recommended)

  3. Parameters - All function arguments with types and descriptions

  4. Returns - What the function returns with type and description

  5. Raises - Exceptions that may be raised (optional)

  6. Examples - Working code examples (at least one required)

  7. See Also - Related functions (optional)

  8. Notes - Additional information (optional)

  9. References - Citations if applicable (optional)

Parameter Description Format:

parameter_name : type
    Description of the parameter. Can span multiple lines
    with proper indentation. Include constraints, default
    behavior, and any important notes.

Example of good vs bad:

Bad:

def process_data(x, y):
    """Process data."""
    return x + y

Good:

def process_data(x: float, y: float) -> float:
    """
    Add two numbers together.

    Parameters
    ----------
    x : float
        First number to add.
    y : float
        Second number to add.

    Returns
    -------
    float
        Sum of x and y.

    Examples
    --------
    .. ipython:: python

       process_data(2.5, 3.5)
    """
    return x + y

Useful Resources

reStructuredText (RST):

Sphinx:

Python Documentation:

VAST Orbit Specific:


Tip

Learning Strategy:

  1. Start by copying well-documented functions as templates

  2. Check bar() for a reference example

  3. Build documentation locally with make html and preview changes

  4. Compare your rendered output with existing documentation

  5. Iterate until it looks professional and matches the style guide

See also