@@ -537,7 +537,7 @@ def test_discrete_time_impulse(self, tsystem):
537537 sysdt = sys .sample (dt , 'impulse' )
538538 np .testing .assert_array_almost_equal (impulse_response (sys , t )[1 ],
539539 impulse_response (sysdt , t )[1 ])
540-
540+
541541 def test_discrete_time_impulse_input (self ):
542542 # discrete time impulse input, Only one active input for each trace
543543 A = [[.5 , 0.25 ],[.0 , .5 ]]
@@ -1318,3 +1318,54 @@ def test_step_info_nonstep():
13181318 assert step_info ['Peak' ] == 1
13191319 assert step_info ['PeakTime' ] == 0
13201320 assert isclose (step_info ['SteadyStateValue' ], 0.96 )
1321+
1322+
1323+ def test_signal_labels ():
1324+ # Create a system response for a SISO system
1325+ sys = ct .rss (4 , 1 , 1 )
1326+ response = ct .step_response (sys )
1327+
1328+ # Make sure access via strings works
1329+ np .testing .assert_equal (response .inputs ['u[0]' ], response .inputs [0 ])
1330+ np .testing .assert_equal (response .states ['x[2]' ], response .states [2 ])
1331+
1332+ # Make sure access via lists of strings works
1333+ np .testing .assert_equal (
1334+ response .states [['x[1]' , 'x[2]' ]], response .states [[1 , 2 ]])
1335+
1336+ # Make sure errors are generated if key is unknown
1337+ with pytest .raises (ValueError , match = "unknown signal name 'bad'" ):
1338+ response .inputs ['bad' ]
1339+
1340+ with pytest .raises (ValueError , match = "unknown signal name 'bad'" ):
1341+ response .states [['x[1]' , 'bad' ]]
1342+
1343+ # Create a system response for a MIMO system
1344+ sys = ct .rss (4 , 2 , 2 )
1345+ response = ct .step_response (sys )
1346+
1347+ # Make sure access via strings works
1348+ np .testing .assert_equal (
1349+ response .outputs ['y[0]' , 'u[1]' ],
1350+ response .outputs [0 , 1 ])
1351+ np .testing .assert_equal (
1352+ response .states ['x[2]' , 'u[0]' ], response .states [2 , 0 ])
1353+
1354+ # Make sure access via lists of strings works
1355+ np .testing .assert_equal (
1356+ response .states [['x[1]' , 'x[2]' ], 'u[0]' ],
1357+ response .states [[1 , 2 ], 0 ])
1358+
1359+ np .testing .assert_equal (
1360+ response .outputs [['y[1]' ], ['u[1]' , 'u[0]' ]],
1361+ response .outputs [[1 ], [1 , 0 ]])
1362+
1363+ # Make sure errors are generated if key is unknown
1364+ with pytest .raises (ValueError , match = "unknown signal name 'bad'" ):
1365+ response .inputs ['bad' ]
1366+
1367+ with pytest .raises (ValueError , match = "unknown signal name 'bad'" ):
1368+ response .states [['x[1]' , 'bad' ]]
1369+
1370+ with pytest .raises (ValueError , match = r"unknown signal name 'x\[2\]'" ):
1371+ response .states ['x[1]' , 'x[2]' ] # second index = input name
0 commit comments