[WIP] Fix AstroPhot docstrings to explicit RST fields for Sphinx compatibility#294
Conversation
… autodoc structure - Rewrite combine_docstrings decorator to merge params from full MRO - Add _parse_docstring helper supporting both RST and markdown formats - Convert model/mixin docstrings from markdown to RST format - Convert block math $$...$$ to .. math:: directives - Convert inline math $expr$ to :math:`expr` - Add description keys to all _parameter_specs dicts - Apply combine_docstrings to auto-generated types in radial.py/radial_psf.py - Update docs structure to use sphinx autodoc - Remove make_docs.py (replaced by autodoc approach) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use \w+ instead of \S+ when matching param/type names in body stripping - Use single dash '-' with MULTILINE flag for markdown list item matching - These address edge cases around colons in descriptions and multi-dash lines Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com> Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/d8acb003-647d-4ac3-bb3b-92de85d29ff9
|
@copilot I would like a distinction in the documentation between the "Parameters" and the "Options". Perhaps just adding |
|
@ConnorStoneAstro The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
5 similar comments
|
@ConnorStoneAstro The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@ConnorStoneAstro The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@ConnorStoneAstro The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@ConnorStoneAstro The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@ConnorStoneAstro The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@copilot I would like a distinction in the documentation between the "Parameters" and the "Options". Perhaps just adding [model param] at the end of the line for the Parameters would work. |
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com> Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/cff088e1-801d-4b12-9940-ce2887562ad3
Added a [model param] tag to all model parameters in combined docstrings so options remain untagged (commit 7013cc7). No UI changes.
Added a [model param] tag to all model parameters in combined docstrings so options remain untagged (commit 7013cc7). No UI changes. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #294 +/- ##
==========================================
+ Coverage 91.22% 91.28% +0.05%
==========================================
Files 112 112
Lines 6018 6069 +51
==========================================
+ Hits 5490 5540 +50
- Misses 528 529 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…Autostronomy/AstroPhot into copilot/fix-model-docstrings-formatting
|
@copilot Can you please update the docstrings for the image, fitting, and plotting sections as well to be in RST format. |
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com> Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/c48da40e-0846-464e-a2ea-c0274b9ae0f1
Updated docstrings in the image, fitting, and plotting sections to RST-friendly formatting and converted markdown fences/sections to RST equivalents (commit 9c23976). No UI changes. |
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com> Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/c48da40e-0846-464e-a2ea-c0274b9ae0f1
There was a problem hiding this comment.
Pull request overview
This PR restructures AstroPhot’s API documentation generation for Sphinx/Jupyter Book by moving docstrings toward RST-friendly formats, improving docstring composition across model inheritance, and replacing the previous notebook-based doc build with autodoc-driven RST pages.
Changes:
- Reworked
combine_docstringsto merge:param(and legacy markdown parameter/option sections) across the MRO into a consolidated parameter list. - Converted many model/mixin/image/fit/plot docstrings toward Sphinx-compatible RST (including
.. math::usage) and added many_parameter_specs[*]["description"]fields. - Replaced the notebook docstring tree +
make_docs.pywithdocs/source/astrophotdocs/*.rstautodoc pages and enabled MathJax in the Sphinx config.
Reviewed changes
Copilot reviewed 57 out of 57 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| make_docs.py | Removes the old notebook-based docstring extraction script. |
| docs/source/tutorials/FunctionalInterface.ipynb | Ensures timing cells block on JAX execution for accurate benchmarking; adds a hide-output tag. |
| docs/source/astrophotdocs/utils.rst | New autodoc entry page for astrophot.utils. |
| docs/source/astrophotdocs/plots.rst | New autodoc entry page for astrophot.plots. |
| docs/source/astrophotdocs/models.rst | New autodoc structure for models and model submodules. |
| docs/source/astrophotdocs/index.rst | Replaces the prior “Docstrings” landing page with an API reference index/toctree. |
| docs/source/astrophotdocs/image.rst | New autodoc entry page for astrophot.image. |
| docs/source/astrophotdocs/fit.rst | New autodoc entry page for astrophot.fit. |
| docs/source/astrophotdocs/errors.rst | New autodoc entry page for astrophot.errors. |
| docs/source/_toc.yml | Adds the new API reference section to the Jupyter Book TOC. |
| docs/source/_config.yml | Enables sphinx.ext.mathjax and sets autodoc_default_options. |
| astrophot/utils/decorators.py | Adds docstring parsing/merging logic and updates combine_docstrings to consolidate parameters across the MRO. |
| astrophot/plots/profile.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/plots/image.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/plots/diagnostic.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/models/sky_model_object.py | Converts to RST-friendly docstring and adds _parameter_specs["center"]["description"]. |
| astrophot/models/radial_psf.py | Applies combine_docstrings to dynamically generated PSF model types; adds doc for EllipseMixin. |
| astrophot/models/radial.py | Applies combine_docstrings to dynamically generated galaxy model types. |
| astrophot/models/psf_model_object.py | Converts docstrings to RST fields and adds _parameter_specs["center"]["description"]. |
| astrophot/models/point_source.py | Converts parameter docs to :param and adds _parameter_specs["flux"]["description"]. |
| astrophot/models/planesky.py | Converts math to .. math::, converts params to :param, adds _parameter_specs descriptions. |
| astrophot/models/pixelated_psf.py | Converts parameter docs to :param and adds _parameter_specs["pixels"]["description"]. |
| astrophot/models/pixelated_model.py | Converts parameter docs to :param and adds _parameter_specs descriptions. |
| astrophot/models/multi_gaussian_expansion.py | Converts math to .. math::, converts params to :param, adds _parameter_specs descriptions. |
| astrophot/models/model_object.py | Converts component docs to RST fields and adds _parameter_specs["center"]["description"]. |
| astrophot/models/mixins/transform.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions across mixins. |
| astrophot/models/mixins/spline.py | Converts docs to RST fields and adds _parameter_specs descriptions. |
| astrophot/models/mixins/sersic.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions. |
| astrophot/models/mixins/sample.py | Converts options docs to RST fields (:param ...:). |
| astrophot/models/mixins/nuker.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions. |
| astrophot/models/mixins/moffat.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions. |
| astrophot/models/mixins/king.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions. |
| astrophot/models/mixins/gaussian.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions. |
| astrophot/models/mixins/ferrer.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions. |
| astrophot/models/mixins/exponential.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions. |
| astrophot/models/mixins/brightness.py | Converts math blocks and option docs to RST fields. |
| astrophot/models/gaussian_ellipsoid.py | Converts parameter docs to RST fields and adds _parameter_specs descriptions. |
| astrophot/models/flatsky.py | Converts parameter docs to :param and adds _parameter_specs["I0"]["description"]. |
| astrophot/models/edgeon.py | Converts parameter docs to :param and adds _parameter_specs descriptions. |
| astrophot/models/bilinear_sky.py | Converts parameter docs to :param and adds _parameter_specs descriptions. |
| astrophot/models/basis_psf.py | Removes unused imports and converts parameter docs to :param. |
| astrophot/models/basis.py | Converts parameter docs to :param. |
| astrophot/models/airy.py | Converts math blocks and parameter docs to RST fields; adds _parameter_specs descriptions. |
| astrophot/image/target_image.py | Replaces MyST fenced code block with .. code-block:: python in the docstring. |
| astrophot/image/sip_image.py | Updates method docstring formatting (introduces Args: blocks). |
| astrophot/image/mixins/data_mixin.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/image/image_object.py | Converts class docstring to RST fields; updates method docstring formatting (Args:). |
| astrophot/image/func/wcs.py | Updates docstring formatting (introduces Args:/Returns: blocks). |
| astrophot/fit/scipy_fit.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/fit/mhmcmc.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/fit/mala.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/fit/lm.py | Replaces MyST fenced blocks with .. code-block:: text in the docstring. |
| astrophot/fit/iterative.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/fit/hmc.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/fit/gradient.py | Updates docstring formatting (introduces Args: blocks). |
| astrophot/fit/base.py | Updates docstring formatting (introduces Args: blocks). |
| .readthedocs.yaml | Removes the pre-build step that generated docstring notebooks via make_docs.py. |
Comments suppressed due to low confidence (14)
astrophot/fit/gradient.py:32
Args:with bullet points won’t be interpreted as parameter documentation by Sphinx autodoc in its default configuration. If you want these options to show up as parameters in the API reference, convert to:param likelihood:,:param method:, etc. (or enable Napoleon and match its supported style).
Args:
- `likelihood` (str, optional): The likelihood function to use for the optimization. Defaults to "gaussian".
- `method` (str, optional): the optimization method to use for the update step. Defaults to "NAdam".
- `optim_kwargs` (dict, optional): a dictionary of keyword arguments to pass to the pytorch optimizer.
- `patience` (int, optional): number of steps with no improvement before stopping the optimization. Defaults to 10.
astrophot/fit/hmc.py:38
- This
Args:+ bullets block won’t render as structured parameter documentation in Sphinx autodoc by default. Consider switching to RST field lists (:param max_iter:,:param epsilon:, etc.) for consistent API rendering.
Args:
- `mass_matrix_shape`: a dict that maps tuples of site names to the shape of
the corresponding mass matrix. Each tuple of site names corresponds to a block.
- `adapt_mass_matrix`: a flag to decide whether an adaptation scheme will be used.
- `options`: tensor options to construct the initial mass matrix.
astrophot/plots/diagnostic.py:28
Args:+ a bullet list is not an RST parameter field list, so autodoc will render this as plain text instead of structured parameter documentation. Consider converting to:param covariance_matrix:,:param mean:, etc. (or enable Napoleon and switch to a Napoleon-compatible format).
astrophot/fit/base.py:20- This docstring uses an
Args:section with bullets, which autodoc treats as plain text. Since this is part of the public API reference, consider converting these to RST field lists (:param model:,:param initial_state:, etc.) so Sphinx renders them as parameters.
Args:
- `model`: an AstroPhot_Model object that will have its (unlocked) parameters optimized [AstroPhot_Model]
- `initial_state`: optional initialization for the parameters as a 1D tensor [tensor]
- `relative_tolerance`: tolerance for counting success steps as: $0 < (\\chi_2^2 - \\chi_1^2)/\\chi_1^2 < \\text{tol}$ [float]
- `verbose`: verbosity level for the optimizer [int]
astrophot/fit/mala.py:30
- This docstring uses
Args:with bullet points, which won’t be rendered as structured params by Sphinx autodoc in the current config. For the API reference, consider converting these to:param chains:,:param epsilon:, etc. (or enable Napoleon and adopt its supported syntax).
Args:
- `chains`: The number of MCMC chains to run in parallel. Default is 4.
- `epsilon`: The step size for the MALA sampler. Default is 1e-2.
- `mass_matrix`: The mass matrix for the MALA sampler. If None, the identity matrix is used.
- `progress_bar`: Whether to show a progress bar during sampling. Default is True.
astrophot/fit/scipy_fit.py:26
- This docstring uses
Args:with bullet points; autodoc will render this as plain text rather than a parameter list. Consider converting to RST field lists (:param model:,:param method:, etc.) to keep the API reference structured.
Args:
- `model`: The model to fit, which should be an instance of `Model`.
- `initial_state`: Initial guess for the model parameters as a 1D tensor.
- `method`: The optimization method to use. Default is "Nelder-Mead", but can be set to any of: "Nelder-Mead", "L-BFGS-B", "TNC", "SLSQP", "Powell", or "trust-constr".
- `ndf`: Optional number of degrees of freedom for the fit. If not provided, it is calculated as the number of data points minus the number of parameters.
astrophot/plots/profile.py:41
Args:followed by a bullet list is not an RST parameter field list, sosphinx.ext.autodocwill not render these as parameters (andnapoleonis disabled indocs/source/_config.yml). Consider switching to:param ...:/:returns:fields or adopting a Napoleon-compatible Google/Numpy style consistently.
astrophot/image/mixins/data_mixin.py:24- This class docstring uses
Args:with bullet points, which Sphinx autodoc won’t treat as structured parameter docs in the current configuration. If these are meant to appear in the API reference, convert them to RST field lists (:param mask:,:param std:, etc.) or adopt a Napoleon-supported style.
Args:
- `mask`: A boolean mask indicating which pixels to ignore.
- `std`: Standard deviation of the image pixels.
- `variance`: Variance of the image pixels.
- `weight`: Weights for the image pixels.
astrophot/fit/lm.py:89
- This
.. code-block:: textdirective needs a blank line after it, and the BibTeX lines need to be indented under the directive. As written, Sphinx may not recognize this as a literal/code block.
.. code-block:: text
@article{Gavin2019,
title={The Levenberg-Marquardt algorithm for nonlinear least squares curve-fitting problems},
author={Gavin, Henri P},
journal={Department of Civil and Environmental Engineering, Duke University},
astrophot/models/basis.py:37
- The PR description mentions adding
descriptionentries to every_parameter_specsentry, butBasisModel’s_parameter_specshere still lacksdescriptionkeys. If downstream doc generation relies on these, please adddescriptionforweights,PA, andscalefor consistency with the other updated models.
"""
_model_type = "basis"
_parameter_specs = {
"weights": {"units": "unitless", "shape": (None,), "dynamic": True},
astrophot/models/basis_psf.py:31
PixelBasisPSF’s_parameter_specsstill lacks adescriptionforweights(even though many other models were updated to include it). Ifdescriptionis now expected for docstring/spec syncing, please add it here as well.
:param weights: The weights of the basis set of images in units of flux.
"""
_model_type = "basis"
_parameter_specs = {"weights": {"units": "unitless", "shape": (None,), "dynamic": True}}
astrophot/fit/lm.py:102
- Same issue for this second
.. code-block:: text: the block content should be indented relative to the directive (and separated by a blank line) so Sphinx renders it correctly.
.. code-block:: text
@article{Tanstrum2012,
author = {{Transtrum}, Mark K. and {Sethna}, James P.},
title = "{Improvements to the Levenberg-Marquardt algorithm for nonlinear least-squares minimization}",
year = 2012,
astrophot/image/target_image.py:40
- The
.. code-block:: pythondirective needs a blank line after it, and the code lines must be indented relative to the directive. As written,import astrophot as apis aligned with the directive, which will cause Sphinx to treat it as normal text (or emit a warning) instead of a literal block.
.. code-block:: python
import astrophot as ap
# Create target image
image = ap.image.Target_Image(
astrophot/plots/image.py:33
- This docstring uses an
Args:section with bullet points, which Sphinx autodoc won’t interpret as a parameter list by default (andsphinx.ext.napoleonis currently commented out). To have parameters render correctly in the API reference, prefer RST field lists like:param ...:/:returns:(or enable Napoleon and use its supported syntax).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot I would like you to update the docstrings to RST format with explicit |
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com> Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/06d20147-ecab-453e-9cbe-afad8be6827b
Done in commit f105e66: docstrings in image/fitting/plotting now use explicit RST field lists ( |
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com> Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/06d20147-ecab-453e-9cbe-afad8be6827b
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com> Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/06d20147-ecab-453e-9cbe-afad8be6827b
Updates docstrings to RST for Sphinx/Jupyter Book compatibility, merges docstrings across the MRO, and rebuilds the API docs structure with autodoc pages and MathJax support.
Changes Made
combine_docstringsto merge parameters/options from the full MRO into a single RST parameter list and add[model param]tags to distinguish model parameters from options... math::blocks).:param:,:type:,:returns:, and:rtype:(replacingArgs:/Returns:style sections).Tensor/tensortoArraywhere applicable, to reflect support for both PyTorch and JAX backends.descriptionentries to every_parameter_specsparameter.combine_docstringsto auto-generated classes inradial.pyandradial_psf.py.make_docs.pyand replaced the docstring notebook tree with Sphinx autodoc RST pages.Documentation
docs/source/astrophotdocs/*.rstautodoc pages and updatedastrophotdocs/index.rst.Testing
tests/test_image.py,tests/test_fit.py, andtests/test_plots.py.Original prompt
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.