Skip to content

update docs to use use numpydoc + linkcode #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions control/descfcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ def describing_function_plot(
given by the first value of the tuple and frequency given by the
second value.

Example
-------
Examples
--------
>>> H_simple = ct.tf([8], [1, 2, 2, 1])
>>> F_saturation = ct.descfcn.saturation_nonlinearity(1)
>>> amp = np.linspace(1, 4, 10)
Expand Down
4 changes: 2 additions & 2 deletions control/freqplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ def nyquist_plot(
if `return_contour` is Tue. To obtain the Nyquist curve values,
evaluate system(s) along contour.

Additional Parameters
---------------------
Other Parameters
----------------
arrows : int or 1D/2D array of floats, optional
Specify the number of arrows to plot on the Nyquist curve. If an
integer is passed. that number of equally spaced arrows will be
Expand Down
12 changes: 8 additions & 4 deletions control/iosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,10 @@ def input_output_response(
number of states in the system, the initial condition will be padded
with zeros.

t_eval : array-list, optional
List of times at which the time response should be computed.
Defaults to ``T``.

return_x : bool, optional
If True, return the state vector when assigning to a tuple (default =
False). See :func:`forced_response` for more details.
Expand Down Expand Up @@ -2713,8 +2717,8 @@ def interconnect(syslist, connections=None, inplist=None, outlist=None,
generated and if `True` then warnings are always generated.


Example
-------
Examples
--------
>>> P = control.LinearIOSystem(
>>> control.rss(2, 2, 2, strictly_proper=True), name='P')
>>> C = control.LinearIOSystem(control.rss(2, 2, 2), name='C')
Expand Down Expand Up @@ -2914,8 +2918,8 @@ def summing_junction(
Linear input/output system object with no states and only a direct
term that implements the summing junction.

Example
-------
Examples
--------
>>> P = control.tf2io(ct.tf(1, [1, 0]), inputs='u', outputs='y')
>>> C = control.tf2io(ct.tf(10, [1, 1]), inputs='e', outputs='u')
>>> sumblk = control.summing_junction(inputs=['r', '-y'], output='e')
Expand Down
11 changes: 6 additions & 5 deletions control/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,12 @@ def damp(sys, doprint=True):
poles: array
Pole locations

Algorithm
---------
See Also
--------
pole

Notes
-----
If the system is continuous,
wn = abs(poles)
Z = -real(poles)/poles.
Expand All @@ -320,9 +324,6 @@ def damp(sys, doprint=True):
wn = abs(s)
Z = -real(s)/wn.

See Also
--------
pole
"""
wn, damping, poles = sys.damp()
if doprint:
Expand Down
2 changes: 1 addition & 1 deletion control/sisotool.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def rootlocus_pid_designer(plant, gain='P', sign=+1, input_signal='r',
Whether to create Sisotool interactive plot.

Returns
----------
-------
closedloop : class:`StateSpace` system
The closed-loop system using initial gains.

Expand Down
4 changes: 0 additions & 4 deletions control/statefbk.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ def place(A, B, p):
--------
place_varga, acker

Notes
-----
The return type for 2D arrays depends on the default class set for
state space operations. See :func:`~control.use_numpy_matrix`.
"""
from scipy.signal import place_poles

Expand Down
2 changes: 1 addition & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ classes.pdf: classes.fig; fig2dev -Lpdf $< $@

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
html pdf: Makefile $(FIGS)
html pdf clean: Makefile $(FIGS)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
78 changes: 76 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# -- Project information -----------------------------------------------------

project = u'Python Control Systems Library'
copyright = u'2020, python-control.org'
copyright = u'2022, python-control.org'
author = u'Python Control Developers'

# Version information - read from the source code
Expand All @@ -56,7 +56,7 @@
extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.napoleon',
'sphinx.ext.intersphinx', 'sphinx.ext.imgmath',
'sphinx.ext.autosummary', 'nbsphinx',
'sphinx.ext.autosummary', 'nbsphinx', 'numpydoc', 'sphinx.ext.linkcode'
]

# scan documents for autosummary directives and generate stub pages for each.
Expand Down Expand Up @@ -139,6 +139,80 @@
#
# html_sidebars = {}

# -----------------------------------------------------------------------------
# Source code links (from numpy)
# -----------------------------------------------------------------------------

import inspect
from os.path import relpath, dirname

def linkcode_resolve(domain, info):
"""
Determine the URL corresponding to Python object
"""
if domain != 'py':
return None

modname = info['module']
fullname = info['fullname']

submod = sys.modules.get(modname)
if submod is None:
return None

obj = submod
for part in fullname.split('.'):
try:
obj = getattr(obj, part)
except Exception:
return None

# strip decorators, which would resolve to the source of the decorator
# possibly an upstream bug in getsourcefile, bpo-1764286
try:
unwrap = inspect.unwrap
except AttributeError:
pass
else:
obj = unwrap(obj)

# Get the filename for the function
try:
fn = inspect.getsourcefile(obj)
except Exception:
fn = None
if not fn:
return None

# Ignore re-exports as their source files are not within the numpy repo
module = inspect.getmodule(obj)
if module is not None and not module.__name__.startswith("control"):
return None

try:
source, lineno = inspect.getsourcelines(obj)
except Exception:
lineno = None

fn = relpath(fn, start=dirname(control.__file__))

if lineno:
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
else:
linespec = ""

base_url = "https://github.com/python-control/python-control/blob/"
if 'dev' in control.__version__ or 'post' in control.__version__:
return base_url + "main/control/%s%s" % (fn, linespec)
else:
return base_url + "%s/control/%s%s" % (
control.__version__, fn, linespec)

# Don't automaticall show all members of class in Methods & Attributes section
numpydoc_show_class_members = False

# Don't create a Sphinx TOC for the lists of class methods and attributes
numpydoc_class_members_toctree = False

# -- Options for HTMLHelp output ---------------------------------------------

Expand Down