Skip to content

Commit 5d7fb42

Browse files
committed
clean up _process_time_response
1 parent 57b5307 commit 5d7fb42

2 files changed

Lines changed: 32 additions & 42 deletions

File tree

control/nlsys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ def __call__(sys, u, params=None, squeeze=None):
193193

194194
# Evaluate the function on the argument
195195
out = sys._out(0, np.array((0,)), np.asarray(u))
196-
_, out = _process_time_response(
197-
None, out, issiso=sys.issiso(), squeeze=squeeze)
196+
out = _process_time_response(
197+
out, issiso=sys.issiso(), squeeze=squeeze)
198198
return out
199199

200200
def __mul__(self, other):

control/timeresp.py

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ def outputs(self):
567567
:type: 1D, 2D, or 3D array
568568
569569
"""
570-
t, y = _process_time_response(
571-
self.t, self.y, issiso=self.issiso,
570+
y = _process_time_response(
571+
self.y, issiso=self.issiso,
572572
transpose=self.transpose, squeeze=self.squeeze)
573573
return y
574574

@@ -631,8 +631,8 @@ def inputs(self):
631631
if self.u is None:
632632
return None
633633

634-
t, u = _process_time_response(
635-
self.t, self.u, issiso=self.issiso,
634+
u = _process_time_response(
635+
self.u, issiso=self.issiso,
636636
transpose=self.transpose, squeeze=self.squeeze)
637637
return u
638638

@@ -1265,81 +1265,71 @@ def forced_response(sysdata, T=None, U=0., X0=0., transpose=False, params=None,
12651265

12661266
# Process time responses in a uniform way
12671267
def _process_time_response(
1268-
tout, yout, issiso=False, transpose=None, squeeze=None):
1268+
signal, issiso=False, transpose=None, squeeze=None):
12691269
"""Process time response signals.
12701270
12711271
This function processes the outputs (or inputs) of time response
12721272
functions and processes the transpose and squeeze keywords.
12731273
12741274
Parameters
12751275
----------
1276-
T : 1D array
1277-
Time values of the output. Ignored if None.
1278-
1279-
yout : ndarray
1280-
Response of the system. This can either be a 1D array indexed by time
1281-
(for SISO systems), a 2D array indexed by output and time (for MIMO
1282-
systems with no input indexing, such as initial_response or forced
1283-
response) or a 3D array indexed by output, input, and time.
1276+
signal : ndarray
1277+
Data to be processed. This can either be a 1D array indexed by
1278+
time (for SISO systems), a 2D array indexed by output and time (for
1279+
MIMO systems with no input indexing, such as initial_response or
1280+
forced response) or a 3D array indexed by output, input, and time.
12841281
12851282
issiso : bool, optional
12861283
If ``True``, process data as single-input, single-output data.
12871284
Default is ``False``.
12881285
12891286
transpose : bool, optional
1290-
If True, transpose all input and output arrays (for backward
1291-
compatibility with MATLAB and :func:`scipy.signal.lsim`). Default
1292-
value is False.
1287+
If True, transpose data (for backward compatibility with MATLAB and
1288+
:func:`scipy.signal.lsim`). Default value is False.
12931289
12941290
squeeze : bool, optional
12951291
By default, if a system is single-input, single-output (SISO) then the
1296-
output response is returned as a 1D array (indexed by time). If
1292+
signals are returned as a 1D array (indexed by time). If
12971293
squeeze=True, remove single-dimensional entries from the shape of the
1298-
output even if the system is not SISO. If squeeze=False, keep the
1299-
output as a 3D array (indexed by the output, input, and time) even if
1294+
signal even if the system is not SISO. If squeeze=False, keep the
1295+
signal as a 3D array (indexed by the output, input, and time) even if
13001296
the system is SISO. The default value can be set using
13011297
config.defaults['control.squeeze_time_response'].
13021298
13031299
Returns
13041300
-------
1305-
T : 1D array
1306-
Time values of the output.
1307-
1308-
yout : ndarray
1309-
Response of the system. If the system is SISO and squeeze is not
1310-
True, the array is 1D (indexed by time). If the system is not SISO or
1311-
squeeze is False, the array is either 2D (indexed by output and time)
1312-
or 3D (indexed by input, output, and time).
1301+
output: ndarray
1302+
Processd signal. If the system is SISO and squeeze is not True,
1303+
the array is 1D (indexed by time). If the system is not SISO or
1304+
squeeze is False, the array is either 2D (indexed by output and
1305+
time) or 3D (indexed by input, output, and time).
13131306
13141307
"""
13151308
# If squeeze was not specified, figure out the default (might remain None)
13161309
if squeeze is None:
13171310
squeeze = config.defaults['control.squeeze_time_response']
13181311

13191312
# Figure out whether and how to squeeze output data
1320-
if squeeze is True: # squeeze all dimensions
1321-
yout = np.squeeze(yout)
1322-
elif squeeze is False: # squeeze no dimensions
1313+
if squeeze is True: # squeeze all dimensions
1314+
signal = np.squeeze(signal)
1315+
elif squeeze is False: # squeeze no dimensions
13231316
pass
1324-
elif squeeze is None: # squeeze signals if SISO
1317+
elif squeeze is None: # squeeze signals if SISO
13251318
if issiso:
1326-
if yout.ndim == 3:
1327-
yout = yout[0][0] # remove input and output
1319+
if signal.ndim == 3:
1320+
signal = signal[0][0] # remove input and output
13281321
else:
1329-
yout = yout[0] # remove input
1322+
signal = signal[0] # remove input
13301323
else:
13311324
raise ValueError("Unknown squeeze value")
13321325

13331326
# See if we need to transpose the data back into MATLAB form
13341327
if transpose:
1335-
# Transpose time vector in case we are using np.matrix
1336-
tout = np.transpose(tout)
1337-
13381328
# For signals, put the last index (time) into the first slot
1339-
yout = np.transpose(yout, np.roll(range(yout.ndim), 1))
1329+
signal = np.transpose(signal, np.roll(range(signal.ndim), 1))
13401330

1341-
# Return time, output, and (optionally) state
1342-
return tout, yout
1331+
# Return output
1332+
return signal
13431333

13441334

13451335
def step_response(

0 commit comments

Comments
 (0)