Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5acb956

Browse filesBrowse files
DEP: lsim2 deprecated in favor of lsim (scipy#15929)
likewise for step2 & impulse2
1 parent 0f73f92 commit 5acb956
Copy full SHA for 5acb956

File tree

Expand file treeCollapse file tree

4 files changed

+184
-119
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+184
-119
lines changed

‎doc/source/conf.py

Copy file name to clipboardExpand all lines: doc/source/conf.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@
316316
plot_pre_code = """
317317
import warnings
318318
for key in (
319+
'lsim2 is deprecated', # Deprecation of scipy.signal.lsim2
320+
'impulse2 is deprecated', # Deprecation of scipy.signal.impulse2
321+
'step2 is deprecated', # Deprecation of scipy.signal.step2
319322
'scipy.misc' # scipy.misc deprecated in v1.10.0; use scipy.datasets
320323
):
321324
warnings.filterwarnings(action='ignore', message='.*' + key + '.*')

‎scipy/signal/_ltisys.py

Copy file name to clipboardExpand all lines: scipy/signal/_ltisys.py
+64-16Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import numpy
3636
import numpy as np
37+
from numpy.testing import suppress_warnings
3738
from numpy import (real, atleast_1d, atleast_2d, squeeze, asarray, zeros,
3839
dot, transpose, ones, zeros_like, linspace, nan_to_num)
3940
import copy
@@ -1769,6 +1770,10 @@ def lsim2(system, U=None, T=None, X0=None, **kwargs):
17691770
Simulate output of a continuous-time linear system, by using
17701771
the ODE solver `scipy.integrate.odeint`.
17711772
1773+
.. deprecated:: 1.11.0
1774+
Function `lsim2` is deprecated in favor of the faster `lsim` function.
1775+
`lsim2` will be removed in SciPy 1.13.
1776+
17721777
Parameters
17731778
----------
17741779
system : an instance of the `lti` class or a tuple describing the system.
@@ -1812,11 +1817,16 @@ def lsim2(system, U=None, T=None, X0=None, **kwargs):
18121817
18131818
Notes
18141819
-----
1815-
This function uses `scipy.integrate.odeint` to solve the
1816-
system's differential equations. Additional keyword arguments
1817-
given to `lsim2` are passed on to `odeint`. See the documentation
1820+
This function uses `scipy.integrate.odeint` to solve the system's
1821+
differential equations. Additional keyword arguments given to `lsim2`
1822+
are passed on to `scipy.integrate.odeint`. See the documentation
18181823
for `scipy.integrate.odeint` for the full list of arguments.
18191824
1825+
As `lsim2` is now deprecated, users are advised to switch to the faster
1826+
and more accurate `lsim` function. Keyword arguments for
1827+
`scipy.integrate.odeint` are not supported in `lsim`, but not needed in
1828+
general.
1829+
18201830
If (num, den) is passed in for ``system``, coefficients for both the
18211831
numerator and denominator should be specified in descending exponent
18221832
order (e.g. ``s^2 + 3s + 5`` would be represented as ``[1, 3, 5]``).
@@ -1885,6 +1895,10 @@ def lsim2(system, U=None, T=None, X0=None, **kwargs):
18851895
>>> plt.show()
18861896
18871897
"""
1898+
warnings.warn("lsim2 is deprecated and will be removed from scipy 1.13. "
1899+
"Use the feature-equivalent lsim function.",
1900+
DeprecationWarning, stacklevel=2)
1901+
18881902
if isinstance(system, lti):
18891903
sys = system._as_ss()
18901904
elif isinstance(system, dlti):
@@ -1929,7 +1943,7 @@ def lsim2(system, U=None, T=None, X0=None, **kwargs):
19291943

19301944
def fprime(x, t, sys, ufunc):
19311945
"""The vector field of the linear system."""
1932-
return dot(sys.A, x) + squeeze(dot(sys.B, nan_to_num(ufunc([t]))))
1946+
return dot(sys.A, x) + squeeze(dot(sys.B, nan_to_num(ufunc(t))))
19331947
xout = integrate.odeint(fprime, X0, T, args=(sys, ufunc), **kwargs)
19341948
yout = dot(sys.C, transpose(xout)) + dot(sys.D, transpose(U))
19351949
else:
@@ -2103,10 +2117,8 @@ def lsim(system, U, T, X0=None, interp=True):
21032117
return T, squeeze(yout), squeeze(xout)
21042118

21052119
dt = T[1] - T[0]
2106-
if not np.allclose((T[1:] - T[:-1]) / dt, 1.0):
2107-
warnings.warn("Non-uniform timesteps are deprecated. Results may be "
2108-
"slow and/or inaccurate.", DeprecationWarning)
2109-
return lsim2(system, U, T, X0)
2120+
if not np.allclose(np.diff(T), dt):
2121+
raise ValueError("Time steps are not equally spaced.")
21102122

21112123
if no_input:
21122124
# Zero input: just use matrix exponential
@@ -2279,6 +2291,10 @@ def impulse2(system, X0=None, T=None, N=None, **kwargs):
22792291
"""
22802292
Impulse response of a single-input, continuous-time linear system.
22812293
2294+
.. deprecated:: 1.11.0
2295+
Function `impulse2` is deprecated in favor of the faster `impulse`
2296+
function. `impulse2` will be removed in SciPy 1.13.
2297+
22822298
Parameters
22832299
----------
22842300
system : an instance of the LTI class or a tuple of array_like
@@ -2322,6 +2338,11 @@ def impulse2(system, X0=None, T=None, N=None, **kwargs):
23222338
The solution is generated by calling `scipy.signal.lsim2`, which uses
23232339
the differential equation solver `scipy.integrate.odeint`.
23242340
2341+
As `impulse2` is now deprecated, users are advised to switch to the faster
2342+
and more accurate `impulse` function. Keyword arguments for
2343+
`scipy.integrate.odeint` are not supported in `impulse`, but not needed in
2344+
general.
2345+
23252346
If (num, den) is passed in for ``system``, coefficients for both the
23262347
numerator and denominator should be specified in descending exponent
23272348
order (e.g. ``s^2 + 3s + 5`` would be represented as ``[1, 3, 5]``).
@@ -2334,12 +2355,18 @@ def impulse2(system, X0=None, T=None, N=None, **kwargs):
23342355
root: ``x''(t) + 2*x'(t) + x(t) = u(t)``
23352356
23362357
>>> from scipy import signal
2358+
23372359
>>> system = ([1.0], [1.0, 2.0, 1.0])
2360+
23382361
>>> t, y = signal.impulse2(system)
23392362
>>> import matplotlib.pyplot as plt
23402363
>>> plt.plot(t, y)
23412364
23422365
"""
2366+
warnings.warn("impulse2 is deprecated and will be removed from "
2367+
"scipy 1.13. Use the feature-equivalent impulse function.",
2368+
DeprecationWarning, stacklevel=2)
2369+
23432370
if isinstance(system, lti):
23442371
sys = system._as_ss()
23452372
elif isinstance(system, dlti):
@@ -2361,7 +2388,12 @@ def impulse2(system, X0=None, T=None, N=None, **kwargs):
23612388
# Move the impulse in the input to the initial conditions, and then
23622389
# solve using lsim2().
23632390
ic = B + X0
2364-
Tr, Yr, Xr = lsim2(sys, T=T, X0=ic, **kwargs)
2391+
with suppress_warnings() as sup:
2392+
sup.filter(DeprecationWarning,
2393+
"lsim2 is deprecated and will be removed from scipy 1.13. "
2394+
"Use the feature-equivalent lsim function.")
2395+
2396+
Tr, Yr, Xr = lsim2(sys, T=T, X0=ic, **kwargs)
23652397
return Tr, Yr
23662398

23672399

@@ -2394,9 +2426,6 @@ def step(system, X0=None, T=None, N=None):
23942426
yout : 1D ndarray
23952427
Step response of system.
23962428
2397-
See Also
2398-
--------
2399-
scipy.signal.step2
24002429
24012430
Notes
24022431
-----
@@ -2442,6 +2471,10 @@ def step2(system, X0=None, T=None, N=None, **kwargs):
24422471
it uses the function `scipy.signal.lsim2` to compute the step
24432472
response.
24442473
2474+
.. deprecated:: 1.11.0
2475+
Function `step2` is deprecated in favor of the faster `step` function.
2476+
`step2` will be removed in SciPy 1.13.
2477+
24452478
Parameters
24462479
----------
24472480
system : an instance of the LTI class or a tuple of array_like
@@ -2479,6 +2512,11 @@ def step2(system, X0=None, T=None, N=None, **kwargs):
24792512
24802513
Notes
24812514
-----
2515+
As `step2` is now deprecated, users are advised to switch to the faster
2516+
and more accurate `step` function. Keyword arguments for
2517+
`scipy.integrate.odeint` are not supported in `step`, but not needed in
2518+
general.
2519+
24822520
If (num, den) is passed in for ``system``, coefficients for both the
24832521
numerator and denominator should be specified in descending exponent
24842522
order (e.g. ``s^2 + 3s + 5`` would be represented as ``[1, 3, 5]``).
@@ -2489,15 +2527,21 @@ def step2(system, X0=None, T=None, N=None, **kwargs):
24892527
--------
24902528
>>> from scipy import signal
24912529
>>> import matplotlib.pyplot as plt
2530+
24922531
>>> lti = signal.lti([1.0], [1.0, 1.0])
24932532
>>> t, y = signal.step2(lti)
2533+
24942534
>>> plt.plot(t, y)
24952535
>>> plt.xlabel('Time [s]')
24962536
>>> plt.ylabel('Amplitude')
24972537
>>> plt.title('Step response for 1. Order Lowpass')
24982538
>>> plt.grid()
24992539
25002540
"""
2541+
warnings.warn("step2 is deprecated and will be removed from scipy 1.13. "
2542+
"Use the feature-equivalent step function.",
2543+
DeprecationWarning, stacklevel=2)
2544+
25012545
if isinstance(system, lti):
25022546
sys = system._as_ss()
25032547
elif isinstance(system, dlti):
@@ -2512,7 +2556,12 @@ def step2(system, X0=None, T=None, N=None, **kwargs):
25122556
else:
25132557
T = asarray(T)
25142558
U = ones(T.shape, sys.A.dtype)
2515-
vals = lsim2(sys, U, T, X0=X0, **kwargs)
2559+
2560+
with suppress_warnings() as sup:
2561+
sup.filter(DeprecationWarning,
2562+
"lsim2 is deprecated and will be removed from scipy 1.13. "
2563+
"Use the feature-equivalent lsim function.")
2564+
vals = lsim2(sys, U, T, X0=X0, **kwargs)
25162565
return vals[0], vals[1]
25172566

25182567

@@ -3358,10 +3407,9 @@ def place_poles(A, B, poles, method="YT", rtol=1e-3, maxiter=30):
33583407
# don't annoy him
33593408
err_msg = (
33603409
"Convergence was not reached after maxiter iterations.\n"
3361-
"You asked for a relative tolerance of %f we got %f" %
3362-
(rtol, cur_rtol)
3410+
f"You asked for a tolerance of {rtol}, we got {cur_rtol}."
33633411
)
3364-
warnings.warn(err_msg)
3412+
warnings.warn(err_msg, stacklevel=2)
33653413

33663414
# reconstruct transfer_matrix to match complex conjugate pairs,
33673415
# ie transfer_matrix_j/transfer_matrix_j+1 are

‎scipy/signal/tests/test_cont2discrete.py

Copy file name to clipboardExpand all lines: scipy/signal/tests/test_cont2discrete.py
+7-11Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import pytest
77
from scipy.signal import cont2discrete as c2d
8-
from scipy.signal import dlsim, ss2tf, ss2zpk, lsim2, lti
9-
from scipy.signal import tf2ss, impulse2, dimpulse, step2, dstep
8+
from scipy.signal import dlsim, ss2tf, ss2zpk, lsim, lti
9+
from scipy.signal import tf2ss, impulse, dimpulse, step, dstep
1010

1111
# Author: Jeffrey Armstrong <jeff@approximatrix.com>
1212
# March 29, 2011
@@ -294,9 +294,8 @@ def u(t):
294294
dt = t[1] - t[0]
295295
u1 = u(t)
296296

297-
# Use lsim2 to compute the solution to the continuous system.
298-
t, yout, xout = lsim2((a, b, c, d), T=t, U=u1, X0=x0,
299-
rtol=1e-9, atol=1e-11)
297+
# Use lsim to compute the solution to the continuous system.
298+
t, yout, xout = lsim((a, b, c, d), T=t, U=u1, X0=x0)
300299

301300
# Convert the continuous system to a discrete approximation.
302301
dsys = c2d((a, b, c, d), dt, method='bilinear')
@@ -390,15 +389,12 @@ class TestC2dInvariants:
390389
(tf2ss(0.1, [1, 1, 2, 1]), 0.5, 10),
391390
]
392391

393-
# Some options for lsim2 and derived routines
394-
tolerances = {'rtol': 1e-9, 'atol': 1e-11}
395-
396392
# Check that systems discretized with the impulse-invariant
397393
# method really hold the invariant
398394
@pytest.mark.parametrize("sys,sample_time,samples_number", cases)
399395
def test_impulse_invariant(self, sys, sample_time, samples_number):
400396
time = np.arange(samples_number) * sample_time
401-
_, yout_cont = impulse2(sys, T=time, **self.tolerances)
397+
_, yout_cont = impulse(sys, T=time)
402398
_, yout_disc = dimpulse(c2d(sys, sample_time, method='impulse'),
403399
n=len(time))
404400
assert_allclose(sample_time * yout_cont.ravel(), yout_disc[0].ravel())
@@ -407,14 +403,14 @@ def test_impulse_invariant(self, sys, sample_time, samples_number):
407403
@pytest.mark.parametrize("sys,sample_time,samples_number", cases)
408404
def test_step_invariant(self, sys, sample_time, samples_number):
409405
time = np.arange(samples_number) * sample_time
410-
_, yout_cont = step2(sys, T=time, **self.tolerances)
406+
_, yout_cont = step(sys, T=time)
411407
_, yout_disc = dstep(c2d(sys, sample_time, method='zoh'), n=len(time))
412408
assert_allclose(yout_cont.ravel(), yout_disc[0].ravel())
413409

414410
# Linear invariant should hold for FOH discretized systems
415411
@pytest.mark.parametrize("sys,sample_time,samples_number", cases)
416412
def test_linear_invariant(self, sys, sample_time, samples_number):
417413
time = np.arange(samples_number) * sample_time
418-
_, yout_cont, _ = lsim2(sys, T=time, U=time, **self.tolerances)
414+
_, yout_cont, _ = lsim(sys, T=time, U=time)
419415
_, yout_disc, _ = dlsim(c2d(sys, sample_time, method='foh'), u=time)
420416
assert_allclose(yout_cont.ravel(), yout_disc.ravel())

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.