34
34
35
35
import numpy
36
36
import numpy as np
37
+ from numpy .testing import suppress_warnings
37
38
from numpy import (real , atleast_1d , atleast_2d , squeeze , asarray , zeros ,
38
39
dot , transpose , ones , zeros_like , linspace , nan_to_num )
39
40
import copy
@@ -1769,6 +1770,10 @@ def lsim2(system, U=None, T=None, X0=None, **kwargs):
1769
1770
Simulate output of a continuous-time linear system, by using
1770
1771
the ODE solver `scipy.integrate.odeint`.
1771
1772
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
+
1772
1777
Parameters
1773
1778
----------
1774
1779
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):
1812
1817
1813
1818
Notes
1814
1819
-----
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
1818
1823
for `scipy.integrate.odeint` for the full list of arguments.
1819
1824
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
+
1820
1830
If (num, den) is passed in for ``system``, coefficients for both the
1821
1831
numerator and denominator should be specified in descending exponent
1822
1832
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):
1885
1895
>>> plt.show()
1886
1896
1887
1897
"""
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
+
1888
1902
if isinstance (system , lti ):
1889
1903
sys = system ._as_ss ()
1890
1904
elif isinstance (system , dlti ):
@@ -1929,7 +1943,7 @@ def lsim2(system, U=None, T=None, X0=None, **kwargs):
1929
1943
1930
1944
def fprime (x , t , sys , ufunc ):
1931
1945
"""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 ))))
1933
1947
xout = integrate .odeint (fprime , X0 , T , args = (sys , ufunc ), ** kwargs )
1934
1948
yout = dot (sys .C , transpose (xout )) + dot (sys .D , transpose (U ))
1935
1949
else :
@@ -2103,10 +2117,8 @@ def lsim(system, U, T, X0=None, interp=True):
2103
2117
return T , squeeze (yout ), squeeze (xout )
2104
2118
2105
2119
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." )
2110
2122
2111
2123
if no_input :
2112
2124
# Zero input: just use matrix exponential
@@ -2279,6 +2291,10 @@ def impulse2(system, X0=None, T=None, N=None, **kwargs):
2279
2291
"""
2280
2292
Impulse response of a single-input, continuous-time linear system.
2281
2293
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
+
2282
2298
Parameters
2283
2299
----------
2284
2300
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):
2322
2338
The solution is generated by calling `scipy.signal.lsim2`, which uses
2323
2339
the differential equation solver `scipy.integrate.odeint`.
2324
2340
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
+
2325
2346
If (num, den) is passed in for ``system``, coefficients for both the
2326
2347
numerator and denominator should be specified in descending exponent
2327
2348
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):
2334
2355
root: ``x''(t) + 2*x'(t) + x(t) = u(t)``
2335
2356
2336
2357
>>> from scipy import signal
2358
+
2337
2359
>>> system = ([1.0], [1.0, 2.0, 1.0])
2360
+
2338
2361
>>> t, y = signal.impulse2(system)
2339
2362
>>> import matplotlib.pyplot as plt
2340
2363
>>> plt.plot(t, y)
2341
2364
2342
2365
"""
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
+
2343
2370
if isinstance (system , lti ):
2344
2371
sys = system ._as_ss ()
2345
2372
elif isinstance (system , dlti ):
@@ -2361,7 +2388,12 @@ def impulse2(system, X0=None, T=None, N=None, **kwargs):
2361
2388
# Move the impulse in the input to the initial conditions, and then
2362
2389
# solve using lsim2().
2363
2390
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 )
2365
2397
return Tr , Yr
2366
2398
2367
2399
@@ -2394,9 +2426,6 @@ def step(system, X0=None, T=None, N=None):
2394
2426
yout : 1D ndarray
2395
2427
Step response of system.
2396
2428
2397
- See Also
2398
- --------
2399
- scipy.signal.step2
2400
2429
2401
2430
Notes
2402
2431
-----
@@ -2442,6 +2471,10 @@ def step2(system, X0=None, T=None, N=None, **kwargs):
2442
2471
it uses the function `scipy.signal.lsim2` to compute the step
2443
2472
response.
2444
2473
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
+
2445
2478
Parameters
2446
2479
----------
2447
2480
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):
2479
2512
2480
2513
Notes
2481
2514
-----
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
+
2482
2520
If (num, den) is passed in for ``system``, coefficients for both the
2483
2521
numerator and denominator should be specified in descending exponent
2484
2522
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):
2489
2527
--------
2490
2528
>>> from scipy import signal
2491
2529
>>> import matplotlib.pyplot as plt
2530
+
2492
2531
>>> lti = signal.lti([1.0], [1.0, 1.0])
2493
2532
>>> t, y = signal.step2(lti)
2533
+
2494
2534
>>> plt.plot(t, y)
2495
2535
>>> plt.xlabel('Time [s]')
2496
2536
>>> plt.ylabel('Amplitude')
2497
2537
>>> plt.title('Step response for 1. Order Lowpass')
2498
2538
>>> plt.grid()
2499
2539
2500
2540
"""
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
+
2501
2545
if isinstance (system , lti ):
2502
2546
sys = system ._as_ss ()
2503
2547
elif isinstance (system , dlti ):
@@ -2512,7 +2556,12 @@ def step2(system, X0=None, T=None, N=None, **kwargs):
2512
2556
else :
2513
2557
T = asarray (T )
2514
2558
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 )
2516
2565
return vals [0 ], vals [1 ]
2517
2566
2518
2567
@@ -3358,10 +3407,9 @@ def place_poles(A, B, poles, method="YT", rtol=1e-3, maxiter=30):
3358
3407
# don't annoy him
3359
3408
err_msg = (
3360
3409
"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 } ."
3363
3411
)
3364
- warnings .warn (err_msg )
3412
+ warnings .warn (err_msg , stacklevel = 2 )
3365
3413
3366
3414
# reconstruct transfer_matrix to match complex conjugate pairs,
3367
3415
# ie transfer_matrix_j/transfer_matrix_j+1 are
0 commit comments