GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow signal names to be used for time/freq responses and subsystem indexing by murrayrm · Pull Request #1069 · python-control/python-control

Conversation

@murrayrm

@murrayrm murrayrm commented Dec 1, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR adds the ability to access response signals and subsystem inputs and outputs using signal names. As described in the documentation:

Time signal indexing:

The input, output, and state elements of the response can be access using signal names in place of integer offsets::

plt.plot(response. time, response.states['x[1]']

For multi-trace systems generated by :func:step_response and :func:impulse_response, the input name used to generate the trace can be used to access the appropriate input output pair::

plt.plot(response.time, response.outputs['y[0]', 'u[1]'])

Frequency response indexing:

Frequency response objects are also available as named properties of the response object: response.magnitude, response.phase, and response.response (for the complex response). For MIMO systems, these elements of the frequency response can be accessed using the names of the inputs and outputs::

response.magnitude['y[0]', 'u[1]']

where the signal names are based on the system that generated the frequency response.

Subsystem indexing:

Subsets of input/output pairs for LTI systems can be obtained by indexing the system using either numerical indices (including slices) or signal names::

subsys = sys[[0, 2], 0:2]
subsys = sys[['y[0]', 'y[2]'], ['u[0]', 'u[1]']]

Signal names for an indexed subsystem are preserved from the original system and the subsystem name is set according to the values of control.config.defaults['iosys.indexed_system_name_prefix'] and control.config.defaults['iosys.indexed_system_name_suffix']`. The default subsystem name is the original system name with '$indexed' appended.

Summary of changes:

  • Signals are now returned as a NamedSignal object, which is a subclass of np.ndarray that overrides the __getitem__ method to allow processing of signal names via the _parse_key method.
  • All signal/subsystem indexing now allows integers, strings (new), lists of integers or strings (new), or slices.
  • Refactored code for processing signal names to make everything consistent across time and frequency domain signals as well as state and input/output vectors. See iosys.NamedSignal._parse_key and changes in frdata.py and timeresp.py.
  • Refactored code for processing subsystem indices and made index processing consistent for StateSpace, TransferFunction, and FrequencyResponseData systems. See iosys._process_subsys_index and changes in frdata.py, statesp.py, and xferfcn.py.
  • Unit tests, docstrings, and user documentation updated to cover new functiionality.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
murrayrm added 11 commits November 30, 2024 08:53
@murrayrm
clean up _process_time_response
5d7fb42
@murrayrm
implement NamedSignal's for time responses
5df6fb7
@murrayrm
implement NamedSignal's for frequency responses
b382abf
@murrayrm
add string-based indexing of state space systems
58922ce
@murrayrm
add string-based indexing of transfer functions
e52fca6
@murrayrm
add string-based indexing of FRD systems
cca4d13
@murrayrm
fix NamedSignal.__getitem__ for new versions of NumPy + unit tests/sl…
944b6a2
…ycot
@murrayrm
update index checking + docstrings
cd3d315
@murrayrm
add documentation for indexing by name + update docstrings
df33002
@murrayrm
use common processing for state response
1903055
@murrayrm
TRV: typo in documentation
fba414d
@coveralls

coveralls commented Dec 1, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Coverage Status

coverage: 94.721% (+0.02%) from 94.697%
when pulling 7ef09a0 on murrayrm:named_signals-29Nov2024
into 57b5307 on python-control:main.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@slivingston
slivingston self-requested a review December 1, 2024 22:26
slivingston
slivingston reviewed Dec 3, 2024
View reviewed changes

@slivingston slivingston left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done with review; it will be done tomorrow. For now, I am sending minor style comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread control/iosys.py Outdated

def __array_finalize__(self, obj):
# See https://numpy.org/doc/stable/user/basics.subclassing.html
if obj is None: return

@slivingston slivingston Dec 1, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if obj is None: return
if obj is None:
return

return should go on the next line to make it more obvious what is in the if-block. Also, this is consistent with PEP 8:

Compound statements (multiple statements on the same line) are generally discouraged

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@slivingston slivingston Dec 2, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example in the NumPy docs has obj is None: return (on 1 line), but my style comment remains. I do not know why the example there has this 1-line style, but I suspect it is to keep examples short, which would also justify there being only 1 blank line after import in those examples.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread control/iosys.py Outdated
idx = idx[0]

# Convert int to slice so that numpy doesn't drop dimension
if isinstance(idx, int): idx = slice(idx, idx+1, 1)

@slivingston slivingston Dec 2, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isinstance(idx, int): idx = slice(idx, idx+1, 1)
if isinstance(idx, int):
idx = slice(idx, idx+1, 1)

Similar to my other comment, statements should be on separate lines for clarity of style (as per PEP 8).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread control/iosys.py Outdated
#
def _process_subsys_index(idx, sys_labels, slice_to_list=False):
if not isinstance(idx, (slice, list, int)):
raise TypeError(f"system indices must be integers, slices, or lists")

@slivingston slivingston Dec 2, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string does not need the f prefix, but OK to keep it if you anticipate expressions being added to it later.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread control/tests/lti_test.py Outdated
sys = ct.rss(4, 3, 3)
subsys = sys[key]

# Construct the system to be test

@slivingston slivingston Dec 2, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Construct the system to be test
# Construct the system to be tested

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread control/timeresp.py Outdated
response(tranpose=True).input

See :meth:`TimeResponseData.__call__` for more information.
See :meth:`TimeResponseData.__call__` for more information.

@slivingston slivingston Dec 2, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See :meth:`TimeResponseData.__call__` for more information.
See :meth:`TimeResponseData.__call__` for more information.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/conventions.rst Outdated
which will compute the step response for each input/output pair. See
:class:`TimeResponseData` for more details.

The input, output, and state elements of the response can be access using

@slivingston slivingston Dec 2, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The input, output, and state elements of the response can be access using
The input, output, and state elements of the response can be accessed using

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/plotting.rst Outdated
Access to frequency response data is available via the attributes
``omega``, ``magnitude``,` `phase``, and ``response``, where ``response``
represents the complex value of the frequency response at each frequency.
The ``magnitude``,` `phase``, and ``response`` arrays can be indexed using

@slivingston slivingston Dec 2, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``magnitude``,` `phase``, and ``response`` arrays can be indexed using
The ``magnitude``, ``phase``, and ``response`` arrays can be indexed using

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/conventions.rst Outdated
Comment on lines +160 to +161
`control.config.defaults['iosys.indexed_system_name_prefix']` and
`control.config.defaults['iosys.indexed_system_name_suffix']`. The default

@slivingston slivingston Dec 3, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`control.config.defaults['iosys.indexed_system_name_prefix']` and
`control.config.defaults['iosys.indexed_system_name_suffix']`. The default
``control.config.defaults['iosys.indexed_system_name_prefix']`` and
``control.config.defaults['iosys.indexed_system_name_suffix']``. The default

rst files built with Sphinx require double backtick (``) to render as in-line code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/conventions.rst Outdated
Comment on lines +112 to +113
Note: The `fresp` data member is stored as a NumPy array and cannot be
accessed with signal names. Use `response.response` to access the complex

@slivingston slivingston Dec 3, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note: The `fresp` data member is stored as a NumPy array and cannot be
accessed with signal names. Use `response.response` to access the complex
Note: The ``fresp`` data member is stored as a NumPy array and cannot be
accessed with signal names. Use ``response.response`` to access the complex

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/conventions.rst Outdated
Comment on lines +102 to +103
`response` object: `response.magnitude`, `response.phase`, and
`response.response` (for the complex response). For MIMO systems, these

@slivingston slivingston Dec 3, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`response` object: `response.magnitude`, `response.phase`, and
`response.response` (for the complex response). For MIMO systems, these
``response`` object: ``response.magnitude``, ``response.phase``, and
``response.response`` (for the complex response). For MIMO systems, these

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@murrayrm
address initial @slivingston comments
7ef09a0
slivingston
slivingston approved these changes Dec 4, 2024
View reviewed changes
@murrayrm
murrayrm merged commit 12dda4e into python-control:main Dec 4, 2024
@murrayrm murrayrm added this to the 0.10.2 milestone Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@slivingston slivingston slivingston approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

0.10.2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@murrayrm @coveralls @slivingston
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.