Skip to content

Commit 412ef97

Browse files
committed
add signal name processing
1 parent b96a039 commit 412ef97

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

control/modelsimp.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def hankel_singular_values(sys):
7979
def model_reduction(
8080
sys, elim_states=None, method='matchdc', elim_inputs=None,
8181
elim_outputs=None, keep_states=None, keep_inputs=None,
82-
keep_outputs=None, remove_hidden_states='unobs', warn_unstable=True):
82+
keep_outputs=None, warn_unstable=True):
8383
"""Model reduction by input, output, or state elimination.
8484
8585
This function produces a reduced-order model of a system by eliminating
@@ -146,8 +146,9 @@ def model_reduction(
146146
other checking is done, so users to be careful not to render a system
147147
unobservable or unreachable.
148148
149-
States, inputs, and outputs can be specified using integer offers.
150-
Slices can also be specified, but must use the Python ``slice()`` function.
149+
States, inputs, and outputs can be specified using integer offers or
150+
using signal names. Slices can also be specified, but must use the
151+
Python ``slice()`` function.
151152
152153
"""
153154
if not isinstance(sys, StateSpace):
@@ -164,13 +165,17 @@ def _process_elim_or_keep(elim, keep, labels, allow_both=False):
164165
def _expand_key(key):
165166
if key is None:
166167
return []
168+
elif isinstance(key, str):
169+
return labels.index(key)
170+
elif isinstance(key, list):
171+
return [_expand_key(k) for k in key]
167172
elif isinstance(key, slice):
168173
return range(len(labels))[key]
169174
else:
170-
return np.atleast_1d(key)
175+
return key
171176

172-
elim = _expand_key(elim)
173-
keep = _expand_key(keep)
177+
elim = np.atleast_1d(_expand_key(elim))
178+
keep = np.atleast_1d(_expand_key(keep))
174179

175180
if len(elim) > 0 and len(keep) > 0:
176181
if not allow_both:

control/tests/modelsimp_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def testBalredMatchDC(self):
481481
({'elim_outputs': [1, 2], 'keep_inputs': [0, 1],}, 5, 1, 2),
482482
({'keep_states': [2, 0], 'keep_outputs': [0, 1]}, 2, 2, 3),
483483
({'keep_states': slice(0, 4, 2), 'keep_outputs': slice(None, 2)}, 2, 2, 3),
484+
({'keep_states': ['x[0]', 'x[3]'], 'keep_inputs': 'u[0]'}, 2, 3, 1),
484485
({'elim_inputs': [0, 1, 2]}, 5, 3, 0), # no inputs
485486
({'elim_outputs': [0, 1, 2]}, 5, 0, 3), # no outputs
486487
({'elim_states': [0, 1, 2, 3, 4]}, 0, 3, 3), # no states

0 commit comments

Comments
 (0)