def test_visible(self): """Test pulse truncation.""" fake_canvas = core.DrawerCanvas(stylesheet=self.style, device=self.device) fake_canvas.disable_chans = {pulse.DriveChannel(0)} fake_canvas.disable_types = {types.WaveformType.REAL} chart = core.Chart(parent=fake_canvas) test_data = drawings.ElementaryData( data_type=types.WaveformType.REAL, xvals=np.array([0]), yvals=np.array([0]), channels=[pulse.DriveChannel(0)], ) self.assertFalse(chart._check_visible(test_data)) test_data = drawings.ElementaryData( data_type=types.WaveformType.IMAG, xvals=np.array([0]), yvals=np.array([0]), channels=[pulse.DriveChannel(0)], ) self.assertFalse(chart._check_visible(test_data)) test_data = drawings.ElementaryData( data_type=types.WaveformType.IMAG, xvals=np.array([0]), yvals=np.array([0]), channels=[pulse.DriveChannel(1)], ) self.assertTrue(chart._check_visible(test_data))
def test_truncate_multiple(self): """Test pulse truncation.""" fake_canvas = core.DrawerCanvas(stylesheet=self.style, device=self.device) fake_canvas.formatter = { "margin.left_percent": 0, "margin.right_percent": 0, "axis_break.length": 20, "axis_break.max_length": 10, } fake_canvas.time_range = (2, 12) fake_canvas.time_breaks = [(4, 7), (9, 11)] chart = core.Chart(parent=fake_canvas) xvals = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) yvals = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) new_xvals, new_yvals = chart._truncate_vectors(xvals, yvals) ref_xvals = np.array([2.0, 3.0, 4.0, 4.0, 5.0, 6.0, 6.0, 7.0]) ref_yvals = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) np.testing.assert_array_almost_equal(new_xvals, ref_xvals) np.testing.assert_array_almost_equal(new_yvals, ref_yvals)
def test_truncate(self): """Test pulse truncation.""" fake_canvas = core.DrawerCanvas(stylesheet=self.style, device=self.device) fake_canvas.formatter = { 'margin.left_percent': 0, 'margin.right_percent': 0, 'axis_break.length': 20, 'axis_break.max_length': 10 } fake_canvas.time_range = (0, 20) fake_canvas.time_breaks = [(5, 10)] chart = core.Chart(parent=fake_canvas) xvals = np.array([4, 5, 6, 7, 8, 9, 10, 11]) yvals = np.array([1, 2, 3, 4, 5, 6, 7, 8]) new_xvals, new_yvals = chart._truncate_vectors(xvals, yvals) ref_xvals = np.array([4., 5., 5., 6.]) ref_yvals = np.array([1., 2., 7., 8.]) np.testing.assert_array_almost_equal(new_xvals, ref_xvals) np.testing.assert_array_almost_equal(new_yvals, ref_yvals)
def test_add_data(self): """Test add data to chart.""" fake_canvas = core.DrawerCanvas(stylesheet=self.style, device=self.device) chart = core.Chart(parent=fake_canvas) chart.add_data(self.short_pulse) self.assertEqual(len(chart._collections), 1) # the same pulse will be overwritten chart.add_data(self.short_pulse) self.assertEqual(len(chart._collections), 1) chart.add_data(self.long_pulse) self.assertEqual(len(chart._collections), 2)
def test_update(self): fake_canvas = core.DrawerCanvas(stylesheet=self.style, device=self.device) fake_canvas.formatter = { "margin.left_percent": 0, "margin.right_percent": 0, "axis_break.length": 20, "axis_break.max_length": 10, "control.auto_chart_scaling": True, "general.vertical_resolution": 1e-6, "general.max_scale": 10, "channel_scaling.pos_spacing": 0.1, "channel_scaling.neg_spacing": -0.1, } fake_canvas.time_range = (0, 20) fake_canvas.time_breaks = [(10, 15)] chart = core.Chart(fake_canvas) chart.add_data(self.short_pulse) chart.add_data(self.long_pulse) chart.add_data(self.abstract_hline) chart.update() short_pulse = chart._output_dataset[self.short_pulse.data_key] xref = np.array([0.0, 0.0, 1.0, 4.0, 5.0, 5.0]) yref = np.array([0.0, 0.5, 0.5, 0.5, 0.5, 0.0]) np.testing.assert_array_almost_equal(xref, short_pulse.xvals) np.testing.assert_array_almost_equal(yref, short_pulse.yvals) long_pulse = chart._output_dataset[self.long_pulse.data_key] xref = np.array([8.0, 8.0, 9.0, 10.0, 10.0, 14.0, 15.0, 15.0]) yref = np.array([0.0, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.0]) np.testing.assert_array_almost_equal(xref, long_pulse.xvals) np.testing.assert_array_almost_equal(yref, long_pulse.yvals) abstract_hline = chart._output_dataset[self.abstract_hline.data_key] xref = np.array([0.0, 10.0, 10.0, 15.0]) yref = np.array([0.0, 0.0, 0.0, 0.0]) np.testing.assert_array_almost_equal(xref, abstract_hline.xvals) np.testing.assert_array_almost_equal(yref, abstract_hline.yvals) self.assertEqual(chart.vmax, 1.0) self.assertEqual(chart.vmin, -0.1) self.assertEqual(chart.scale, 2.0)
def test_bind_coordinate(self): """Test bind coordinate.""" fake_canvas = core.DrawerCanvas(stylesheet=self.style, device=self.device) fake_canvas.formatter = { "margin.left_percent": 0.1, "margin.right_percent": 0.1 } fake_canvas.time_range = (500, 2000) chart = core.Chart(parent=fake_canvas) chart.vmin = -0.1 chart.vmax = 0.5 # vertical vline = [types.AbstractCoordinate.BOTTOM, types.AbstractCoordinate.TOP] vals = chart._bind_coordinate(vline) np.testing.assert_array_equal(vals, np.array([-0.1, 0.5])) # horizontal, margin is is considered hline = [types.AbstractCoordinate.LEFT, types.AbstractCoordinate.RIGHT] vals = chart._bind_coordinate(hline) np.testing.assert_array_equal(vals, np.array([350.0, 2150.0]))