test_ligo_quad¶
tests.quad_damping.test_ligo_quad
Unit tests and examples for damping the LIGO QUAD suspensions
Provided by Kevin Kuns
Functions
Converts a LIGO damping filter from ZPK to statespace and back to test numerical stability |
|
|
Damp the undamped LIGO QUAD state space model |
Details
- test_convert_zpk_ss()[source]¶
Converts a LIGO damping filter from ZPK to statespace and back to test numerical stability
code
docstring
""" Converts a LIGO damping filter from ZPK to statespace and back to test numerical stability """
1def test_convert_zpk_ss(): 2 3 fname = fjoin('damping_filters.h5') 4 zpk = load(fname).L 5 dprint('testing!') 6 filt_zpk = SISO.zpk(zpk.z, zpk.p, zpk.k) 7 filt_ss = filt_zpk.asSS 8 filt_zpk2 = filt_ss.asZPK 9 10 # TODO - no reason to think these sets are sorted the same way for a direct comparison 11 dprint(np.allclose(filt_zpk.z, filt_zpk2.z)) 12 # TODO - no reason to think these sets are sorted the same way for a direct comparison 13 dprint(np.allclose(filt_zpk.p, filt_zpk2.p)) 14 # this should be True 15 dprint(np.isclose(filt_zpk.k, filt_zpk2.k))
pytest information
This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:
tests.quad_damping.test_ligo_quad.test_convert_zpk_ssThe full name is useful when building documentation, to link a reference to this page using
:func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.test_convert_zpk_ss
output
status: passed duration: 0.094s Captured stderr call 'testing!' False False True
- test_damp_quad(quad_type)[source]¶
Damp the undamped LIGO QUAD state space model
Tests calculation of frequency responses and conversion of the resulting damped state space plant to ZPK
code
docstring
""" Damp the undamped LIGO QUAD state space model Tests calculation of frequency responses and conversion of the resulting damped state space plant to ZPK """
1@pytest.mark.parametrize('quad_type', ['quad_full', 'quad_small']) 2def test_damp_quad(quad_type): 3 4 # load quad state space 5 ss_data = load(fjoin(quad_type + '.h5')) 6 udamp_plant = MIMO.MIMOStateSpace( 7 ss_data.A, ss_data.B, ss_data.C, ss_data.D, 8 inputs=dict(ss_data.inputs), outputs=dict(ss_data.outputs), 9 ) 10 11 # load ZPK damping filters and convert to state space 12 zpk_data = load(fjoin('damping_filters.h5')) 13 damp_filts = Bunch() 14 for dof, zpk in zpk_data.items(): 15 damp_filts[dof] = SISO.zpk(zpk.z, zpk.p, zpk.k).asSS 16 17 # Need to make the SISO damping filters into 1-1 MIMO filters with specified 18 # inputs and outputs for making the feedback connections 19 damp_plant = MIMO.ssjoinsum( 20 udamp_plant, 21 damp_filts.L.mimo('M0.L.o', 'M0.L.i'), 22 damp_filts.T.mimo('M0.T.o', 'M0.T.i'), 23 damp_filts.V.mimo('M0.V.o', 'M0.V.i'), 24 damp_filts.P.mimo('M0.P.o', 'M0.P.i'), 25 damp_filts.Y.mimo('M0.Y.o', 'M0.Y.i'), 26 damp_filts.R.mimo('M0.R.o', 'M0.R.i'), 27 ) 28 # connect the displacements to the inputs to the damping filters 29 # and then connect the outputs from the filters to the drives 30 connections = [ 31 ('M0.L.i', 'M0.disp.L'), ('M0.drive.L', 'M0.L.o'), 32 ('M0.T.i', 'M0.disp.T'), ('M0.drive.T', 'M0.T.o'), 33 ('M0.V.i', 'M0.disp.V'), ('M0.drive.V', 'M0.V.o'), 34 ('M0.P.i', 'M0.disp.P'), ('M0.drive.P', 'M0.P.o'), 35 ('M0.Y.i', 'M0.disp.Y'), ('M0.drive.Y', 'M0.Y.o'), 36 ('M0.R.i', 'M0.disp.R'), ('M0.drive.R', 'M0.R.o'), 37 ] 38 # make the feedback and balance for numerical stability 39 damp_plant = damp_plant.feedback_connect(connections=connections) 40 udamp_plant = udamp_plant.balance() 41 damp_plant = damp_plant.balance() 42 43 # plot some transfer functions 44 F_Hz = np.geomspace(0.05, 10, 1000) 45 dprint('Calculating undamped L3') 46 udamp_fresp_L3 = udamp_plant.siso('L3.disp.L', 'L3.drive.L').fresponse(f=F_Hz).tf 47 dprint('Calculating damped L3') 48 damp_fresp_L3 = damp_plant.siso('L3.disp.L', 'L3.drive.L').fresponse(f=F_Hz).tf 49 dprint('Calculating undamped M0') 50 udamp_fresp_M0 = udamp_plant.siso('M0.disp.L', 'M0.drive.L').fresponse(f=F_Hz).tf 51 dprint('Calculating damped M0') 52 damp_fresp_M0 = damp_plant.siso('M0.disp.L', 'M0.drive.L').fresponse(f=F_Hz).tf 53 54 fig = plotTF(F_Hz, udamp_fresp_L3, label='Undamped') 55 plotTF(F_Hz, damp_fresp_L3, *fig.axes, label='Damped', ls='--') 56 fig.axes[0].legend() 57 fig.axes[0].set_title('L3 to L3') 58 fig.savefig(tjoin('L3.pdf')) 59 60 fig = plotTF(F_Hz, udamp_fresp_M0, label='Undamped') 61 plotTF(F_Hz, damp_fresp_M0, *fig.axes, label='Damped', ls='--') 62 fig.axes[0].legend() 63 fig.axes[0].set_title('M0 to M0') 64 fig.savefig(tjoin('M0.pdf')) 65 66 # make zpk filters and convert back to SS 67 for (to, fr) in zip(['L3.disp.L', 'M0.disp.L'], ['L3.drive.L', 'M0.drive.L']): 68 siso_udamp = damp_plant.siso(to, fr) 69 siso_damp = udamp_plant.siso(to, fr) 70 zpk_udamp = siso_udamp.asZPK 71 zpk_damp = siso_damp.asZPK 72 zpk_udamp.asSS 73 zpk_damp.asSS
pytest information
This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:
tests.quad_damping.test_ligo_quad.test_damp_quadThe full name is useful when building documentation, to link a reference to this page using
:func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.test_damp_quad[quad_full]
output
status: passed duration: 275.147s Captured stderr call 'Calculating undamped L3' 'Calculating damped L3' 'Calculating undamped M0' 'Calculating damped M0'
test_damp_quad[quad_small]
output
status: passed duration: 2.907s Captured stderr call 'Calculating undamped L3' 'Calculating damped L3' 'Calculating undamped M0' 'Calculating damped M0'