30 sim = object.__new__(aoSim)
34 sim._t = np.array([0.0], dtype=np.float32)
35 sim._dt = np.array([0.01], dtype=np.float32)
36 sim._current_disturbance = np.zeros((2, 1), dtype=np.float32)
37 sim._current_dm_state = np.zeros((2, 1), dtype=np.float32)
39 sim.log = logging.getLogger()
40 sim._dm_command_history = np.zeros((sim._lag + 1, sim._nmodes, 1), dtype=np.float32)
42 sim._dm =
DummyImage(np.array([[0.5], [1.5]], dtype=np.float32))
55 sim._dm_command_history[0] = np.array([[0.1], [0.2]], dtype=np.float32)
56 sim._dm_command_history[1] = np.array([[0.3], [0.4]], dtype=np.float32)
60 np.testing.assert_array_equal(sim._current_dm_state, np.array([[0.1], [0.2]], dtype=np.float32))
61 np.testing.assert_array_equal(sim._dm_command_history[0], np.array([[0.3], [0.4]], dtype=np.float32))
62 np.testing.assert_array_equal(sim._dm_command_history[-1, :, 0], np.array([0.5, 1.5], dtype=np.float32))
67 sim._current_dm_state = np.array([[0.2], [0.3]], dtype=np.float32)
68 sim._t = np.array([0.25], dtype=np.float32)
70 sim.update_disturbance()
71 assert sim._disturbance.get_data()
is not None
74 np.testing.assert_array_equal(sim.err, sim._current_disturbance + sim._current_dm_state)
75 np.testing.assert_array_equal(sim._wfs.get_data(), sim.err)
80 sim._dm_command_history[0] = np.array([[0.1], [0.1]], dtype=np.float32)
81 sim._dm_command_history[1] = np.array([[0.0], [0.0]], dtype=np.float32)
83 t_before = sim._t.copy()
86 np.testing.assert_allclose(sim._t, t_before + sim._dt)
87 assert sim._wfs.get_data()
is not None
88 assert sim._disturbance.get_data()
is not None
94 sim._t = np.array([1.5], dtype=np.float32)
95 sim._current_disturbance = np.array([[0.5], [0.3]], dtype=np.float32)
96 sim._current_dm_state = np.array([[0.2], [0.4]], dtype=np.float32)
97 sim._dm_command_history = np.ones((sim._lag + 1, sim._nmodes, 1), dtype=np.float32)
100 existing_property = {
'toggle': constants.SwitchState.OFF}
101 new_message = {
'toggle': constants.SwitchState.ON}
104 sim.update_property =
lambda prop:
None
105 print(sim._dm_command_history)
106 sim.handle_reset(existing_property, new_message)
109 np.testing.assert_array_equal(sim._t, np.array([0.0], dtype=np.float32))
110 np.testing.assert_array_equal(sim._current_disturbance, np.zeros((2, 1), dtype=np.float32))
111 np.testing.assert_array_equal(sim._current_dm_state, np.zeros((2, 1), dtype=np.float32))
112 print(sim._dm_command_history)
113 np.testing.assert_array_equal(sim._dm_command_history, np.zeros((sim._lag + 1, sim._nmodes, 1), dtype=np.float32))
116 np.testing.assert_array_equal(sim._wfs.get_data(), np.zeros((2, 1), dtype=np.float32))
117 np.testing.assert_array_equal(sim._disturbance.get_data(), np.zeros((2, 1), dtype=np.float32))
118 np.testing.assert_array_equal(sim._dm.get_data(), np.zeros((2, 1), dtype=np.float32))
121 assert existing_property[
'toggle'] == constants.SwitchState.OFF