Beispiel #1
0
 def test_save_load_permanent_marker_all_types(self):
     x1, y1, x2, y2 = 5, 2, 1, 8
     s = Signal2D(np.arange(100).reshape(10, 10))
     m0_list = [
         markers.point(x=x1, y=y1),
         markers.horizontal_line(y=y1),
         markers.horizontal_line_segment(x1=x1, x2=x2, y=y1),
         markers.line_segment(x1=x1, x2=x2, y1=y1, y2=y2),
         markers.rectangle(x1=x1, x2=x2, y1=y1, y2=y2),
         markers.text(x=x1, y=y1, text="test"),
         markers.vertical_line(x=x1),
         markers.vertical_line_segment(x=x1, y1=y1, y2=y2),
     ]
     for m in m0_list:
         s.add_marker(m, permanent=True)
     with tempfile.TemporaryDirectory() as tmp:
         filename = tmp + '/testallmarkersfile.hdf5'
     s.save(filename)
     s1 = load(filename)
     markers_dict = s1.metadata.Markers
     m0_dict_list = []
     m1_dict_list = []
     for m in m0_list:
         m0_dict_list.append(san_dict(m._to_dictionary()))
         m1_dict_list.append(
             san_dict(markers_dict.get_item(m.name)._to_dictionary()))
     assert len(list(s1.metadata.Markers)) == 8
     for m0_dict, m1_dict in zip(m0_dict_list, m1_dict_list):
         assert m0_dict == m1_dict
Beispiel #2
0
 def test_save_load_permanent_marker_all_types(self, tmp_path, file):
     filename = tmp_path / file
     s = self.s
     x1, y1, x2, y2 = 5, 2, 1, 8
     m0_list = [
         markers.point(x=x1, y=y1),
         markers.horizontal_line(y=y1),
         markers.horizontal_line_segment(x1=x1, x2=x2, y=y1),
         markers.line_segment(x1=x1, x2=x2, y1=y1, y2=y2),
         markers.rectangle(x1=x1, x2=x2, y1=y1, y2=y2),
         markers.text(x=x1, y=y1, text="test"),
         markers.vertical_line(x=x1),
         markers.vertical_line_segment(x=x1, y1=y1, y2=y2),
     ]
     for m in m0_list:
         s.add_marker(m, permanent=True)
     s.save(filename)
     s1 = load(filename)
     markers_dict = s1.metadata.Markers
     m0_dict_list = []
     m1_dict_list = []
     for m in m0_list:
         m0_dict_list.append(san_dict(m._to_dictionary()))
         m1_dict_list.append(
             san_dict(markers_dict.get_item(m.name)._to_dictionary()))
     assert len(list(s1.metadata.Markers)) == 8
     for m0_dict, m1_dict in zip(m0_dict_list, m1_dict_list):
         assert m0_dict == m1_dict
Beispiel #3
0
def test_plot_markers_mpl_options():
    # check if required parameters are shown in repr
    _test_plot_markers_repr(markers.arrow(10, 20, 30, 40),
                            ['x1', 'y1', 'x2', 'y2',
                             'edgecolor', 'arrowstyle'])
    _test_plot_markers_repr(markers.ellipse(10, 20, 30, 40, color='red'),
                            ['x', 'y', 'width', 'height',
                             'edgecolor'])
    _test_plot_markers_repr(markers.horizontal_line(10),
                            ['y', 'color'])
    _test_plot_markers_repr(markers.horizontal_line_segment(10, 20, 30),
                            ['x1', 'x2', 'y', 'color'])
    _test_plot_markers_repr(markers.line_segment(10, 20, 30,40),
                            ['x1', 'x2', 'y1', 'y2', 'color'])
    _test_plot_markers_repr(markers.point(10, 20),
                            ['x', 'x', 'color', 'size'])
    m = markers.rectangle(10, 20, 30, 40, color='red')
    _test_plot_markers_repr(m, ['edgecolor'])
    # check if 'color' property is converted to 'edgecolor'
    assert 'color' not in m.marker_properties
    assert 'edgecolor' in m.marker_properties
    assert m.marker_properties['edgecolor'] == 'red'

    _test_plot_markers_repr(markers.text(10,20,"test"),
                            ['x', 'y', 'text', 'color'])
    _test_plot_markers_repr(markers.vertical_line(10),
                            ['x', 'color'])
    m = markers.vertical_line_segment(10, 20, 30)
    _test_plot_markers_repr(m,['x', 'y1', 'y2', 'color'])
Beispiel #4
0
 def test_add_several_permanent_markers(self):
     s = Signal1D(np.arange(10))
     m_point = markers.point(x=5, y=5)
     m_line = markers.line_segment(x1=5, x2=10, y1=5, y2=10)
     m_vline = markers.vertical_line(x=5)
     m_vline_segment = markers.vertical_line_segment(x=4, y1=3, y2=6)
     m_hline = markers.horizontal_line(y=5)
     m_hline_segment = markers.horizontal_line_segment(x1=1, x2=9, y=5)
     m_rect = markers.rectangle(x1=1, x2=3, y1=5, y2=10)
     m_text = markers.text(x=1, y=5, text="test")
     m_arrow = markers.arrow(x1=4, y1=5, x2=6, y2=6, arrowstyle='<->')
     m_ellipse = markers.ellipse(x=10, y=11, width=4, height=6)
     s.add_marker(m_point, permanent=True)
     s.add_marker(m_line, permanent=True)
     s.add_marker(m_vline, permanent=True)
     s.add_marker(m_vline_segment, permanent=True)
     s.add_marker(m_hline, permanent=True)
     s.add_marker(m_hline_segment, permanent=True)
     s.add_marker(m_rect, permanent=True)
     s.add_marker(m_text, permanent=True)
     s.add_marker(m_arrow, permanent=True)
     s.add_marker(m_ellipse, permanent=True)
     assert len(list(s.metadata.Markers)) == 10
     with pytest.raises(ValueError):
         s.add_marker(m_rect, permanent=True)
Beispiel #5
0
 def test_save_load_permanent_marker_all_types(self):
     x1, y1, x2, y2 = 5, 2, 1, 8
     s = Signal2D(np.arange(100).reshape(10, 10))
     m0_list = [
         markers.point(x=x1, y=y1),
         markers.horizontal_line(y=y1),
         markers.horizontal_line_segment(x1=x1, x2=x2, y=y1),
         markers.line_segment(x1=x1, x2=x2, y1=y1, y2=y2),
         markers.rectangle(x1=x1, x2=x2, y1=y1, y2=y2),
         markers.text(x=x1, y=y1, text="test"),
         markers.vertical_line(x=x1),
         markers.vertical_line_segment(x=x1, y1=y1, y2=y2),
     ]
     for m in m0_list:
         s.add_marker(m, permanent=True)
     with tempfile.TemporaryDirectory() as tmp:
         filename = tmp + '/testallmarkersfile.hdf5'
     s.save(filename)
     s1 = load(filename)
     markers_dict = s1.metadata.Markers
     m0_dict_list = []
     m1_dict_list = []
     for m in m0_list:
         m0_dict_list.append(san_dict(m._to_dictionary()))
         m1_dict_list.append(
             san_dict(markers_dict.get_item(m.name)._to_dictionary()))
     assert len(list(s1.metadata.Markers)) == 8
     for m0_dict, m1_dict in zip(m0_dict_list, m1_dict_list):
         assert m0_dict == m1_dict
Beispiel #6
0
    def test_dict2marker(self):
        m_point0 = markers.point(x=5, y=5)
        m_point1 = markers.point(x=(5, 10), y=(1, 5))
        m_line = markers.line_segment(x1=5, x2=10, y1=5, y2=10)
        m_vline = markers.vertical_line(x=5)
        m_vline_segment = markers.vertical_line_segment(x=4, y1=3, y2=6)
        m_hline = markers.horizontal_line(y=5)
        m_hline_segment = markers.horizontal_line_segment(x1=1, x2=9, y=5)
        m_rect = markers.rectangle(x1=1, x2=3, y1=5, y2=10)
        m_text = markers.text(x=1, y=5, text="test")

        m_point0_new = dict2marker(m_point0._to_dictionary(), m_point0.name)
        m_point1_new = dict2marker(m_point1._to_dictionary(), m_point1.name)
        m_line_new = dict2marker(m_line._to_dictionary(), m_line.name)
        m_vline_new = dict2marker(m_vline._to_dictionary(), m_vline.name)
        m_vline_segment_new = dict2marker(
            m_vline_segment._to_dictionary(), m_vline_segment.name)
        m_hline_new = dict2marker(m_hline._to_dictionary(), m_hline.name)
        m_hline_segment_new = dict2marker(
            m_hline_segment._to_dictionary(), m_hline_segment.name)
        m_rect_new = dict2marker(m_rect._to_dictionary(), m_rect.name)
        m_text_new = dict2marker(m_text._to_dictionary(), m_text.name)

        m_point0_dict = sanitize_dict(m_point0._to_dictionary())
        m_point1_dict = sanitize_dict(m_point1._to_dictionary())
        m_line_dict = sanitize_dict(m_line._to_dictionary())
        m_vline_dict = sanitize_dict(m_vline._to_dictionary())
        m_vline_segment_dict = sanitize_dict(m_vline_segment._to_dictionary())
        m_hline_dict = sanitize_dict(m_hline._to_dictionary())
        m_hline_segment_dict = sanitize_dict(m_hline_segment._to_dictionary())
        m_rect_dict = sanitize_dict(m_rect._to_dictionary())
        m_text_dict = sanitize_dict(m_text._to_dictionary())

        m_point0_new_dict = sanitize_dict(m_point0_new._to_dictionary())
        m_point1_new_dict = sanitize_dict(m_point1_new._to_dictionary())
        m_line_new_dict = sanitize_dict(m_line_new._to_dictionary())
        m_vline_new_dict = sanitize_dict(m_vline_new._to_dictionary())
        m_vline_segment_new_dict = sanitize_dict(
            m_vline_segment_new._to_dictionary())
        m_hline_new_dict = sanitize_dict(m_hline_new._to_dictionary())
        m_hline_segment_new_dict = sanitize_dict(
            m_hline_segment_new._to_dictionary())
        m_rect_new_dict = sanitize_dict(m_rect_new._to_dictionary())
        m_text_new_dict = sanitize_dict(m_text_new._to_dictionary())
        assert m_point0_dict == m_point0_new_dict
        assert m_point1_dict == m_point1_new_dict
        assert m_line_dict == m_line_new_dict
        assert m_vline_dict == m_vline_new_dict
        assert m_vline_segment_dict == m_vline_segment_new_dict
        assert m_hline_dict == m_hline_new_dict
        assert m_hline_segment_dict == m_hline_segment_new_dict
        assert m_rect_dict == m_rect_new_dict
        assert m_text_dict == m_text_new_dict
Beispiel #7
0
def test_markers_auto_update():
    # test data for fixed marker
    pos = [1, 2, 3, 4]
    # test data for auto_update marker
    pos_list = np.array([[1, 3, 5], [2, 4, 6]])
    pos_2d = [pos_list + pos[i] for i in range(4)]

    s = Signal2D(np.arange(2 * 3 * 4 * 5).reshape(2, 3, 4, 5))
    marker_list = []
    for _auto_update, _pos in [(False, pos), (True, pos_2d)]:
        _markers = [
            markers.vertical_line(_pos[0]),
            markers.horizontal_line(_pos[0]),
            markers.vertical_line_segment(*(_pos[0:3])),
            markers.horizontal_line_segment(*(_pos[0:3])),
            markers.rectangle(*_pos),
            markers.ellipse(*_pos),
            markers.arrow(*_pos),
            markers.line_segment(*_pos),
            markers.point(_pos[0], _pos[1]),
            markers.text(_pos[0], _pos[1], "test"),
        ]
        for marker in _markers:
            assert marker.auto_update is _auto_update
        marker_list += _markers
    assert len(marker_list) == 20
    s.add_marker(marker_list)
    for iy, temp_marker_list in enumerate(pos_list):
        for ix, value in enumerate(temp_marker_list):
            s.axes_manager.indices = (ix, iy)
            for marker in marker_list:
                _xy = [marker.get_data_position(ax) for ax in ('x1','y1','x2','y2')]
                if marker.auto_update is False:
                    _xy2 = pos
                else:
                    _xy2 = [pos_2d[i][iy, ix] for i in range(4)]
                _name = marker.name
                if marker.auto_update is False:
                    if _name == 'vertical_line':
                        assert _xy2[0] == _xy[0]
                    elif _name == 'horizontal_line':
                        assert _xy2[0] == _xy[1]
                    elif _name == 'vertical_line_segment':
                        assert _xy2[0:3] == [_xy[i] for i in (0,1,3)]
                    elif _name == 'horizontal_line_segment':
                        assert _xy2[0:3] == [_xy[i] for i in (0,2,1)]
                    elif _name in ('rectangle', 'ellipse', 'arrow', 'line_segment'):
                        assert _xy2 == _xy
                    elif _name in ('point', 'text'):
                        assert _xy2[0:2] == _xy[0:2]
                    else:
                        raise ValueError('Unknown marker : ' + _name)
Beispiel #8
0
def _test_plot_line_markers():
    im = Signal2D(np.arange(100 * 100).reshape((100, 100)))
    m0 = markers.vertical_line_segment(x=20, y1=30, y2=70, linewidth=4,
                                       color='red', linestyle='dotted')
    im.add_marker(m0)
    m1 = markers.horizontal_line_segment(x1=30, x2=20, y=80, linewidth=8,
                                         color='blue', linestyle='-')
    im.add_marker(m1)
    m2 = markers.vertical_line(50, linewidth=12, color='green')
    im.add_marker(m2)
    m3 = markers.horizontal_line(50, linewidth=10, color='yellow')
    im.add_marker(m3)
    return im
Beispiel #9
0
 def test_save_load_horizontal_line_marker(self, tmp_path, file):
     filename = tmp_path / file
     s = self.s
     y = 8
     color = 'blue'
     linewidth = 2.5
     name = "horizontal_line_test"
     m = markers.horizontal_line(y=y, color=color, linewidth=linewidth)
     m.name = name
     s.add_marker(m, permanent=True)
     s.save(filename)
     s1 = load(filename)
     m1 = s1.metadata.Markers.get_item(name)
     assert san_dict(m1._to_dictionary()) == san_dict(m._to_dictionary())
Beispiel #10
0
 def test_save_load_horizontal_line_marker(self):
     y = 8
     color = 'blue'
     linewidth = 2.5
     name = "horizontal_line_test"
     s = Signal2D(np.arange(100).reshape(10, 10))
     m = markers.horizontal_line(y=y, color=color, linewidth=linewidth)
     m.name = name
     s.add_marker(m, permanent=True)
     with tempfile.TemporaryDirectory() as tmp:
         filename = tmp + '/test_save_horizontal_line_marker.hdf5'
     s.save(filename)
     s1 = load(filename)
     m1 = s1.metadata.Markers.get_item(name)
     assert san_dict(m1._to_dictionary()) == san_dict(m._to_dictionary())
Beispiel #11
0
 def test_save_load_horizontal_line_marker(self):
     y = 8
     color = 'blue'
     linewidth = 2.5
     name = "horizontal_line_test"
     s = Signal2D(np.arange(100).reshape(10, 10))
     m = markers.horizontal_line(y=y, color=color, linewidth=linewidth)
     m.name = name
     s.add_marker(m, permanent=True)
     with tempfile.TemporaryDirectory() as tmp:
         filename = tmp + '/test_save_horizontal_line_marker.hdf5'
     s.save(filename)
     s1 = load(filename)
     m1 = s1.metadata.Markers.get_item(name)
     assert san_dict(m1._to_dictionary()) == san_dict(m._to_dictionary())
Beispiel #12
0
 def test_add_several_permanent_markers(self):
     s = Signal1D(np.arange(10))
     m_point = markers.point(x=5, y=5)
     m_line = markers.line_segment(x1=5, x2=10, y1=5, y2=10)
     m_vline = markers.vertical_line(x=5)
     m_vline_segment = markers.vertical_line_segment(x=4, y1=3, y2=6)
     m_hline = markers.horizontal_line(y=5)
     m_hline_segment = markers.horizontal_line_segment(x1=1, x2=9, y=5)
     m_rect = markers.rectangle(x1=1, x2=3, y1=5, y2=10)
     m_text = markers.text(x=1, y=5, text="test")
     s.add_marker(m_point, permanent=True)
     s.add_marker(m_line, permanent=True)
     s.add_marker(m_vline, permanent=True)
     s.add_marker(m_vline_segment, permanent=True)
     s.add_marker(m_hline, permanent=True)
     s.add_marker(m_hline_segment, permanent=True)
     s.add_marker(m_rect, permanent=True)
     s.add_marker(m_text, permanent=True)
     assert len(list(s.metadata.Markers)) == 8
     with pytest.raises(ValueError):
         s.add_marker(m_rect, permanent=True)
Beispiel #13
0
 def test_add_several_permanent_markers(self, mpl_cleanup):
     s = Signal1D(np.arange(10))
     m_point = markers.point(x=5, y=5)
     m_line = markers.line_segment(x1=5, x2=10, y1=5, y2=10)
     m_vline = markers.vertical_line(x=5)
     m_vline_segment = markers.vertical_line_segment(x=4, y1=3, y2=6)
     m_hline = markers.horizontal_line(y=5)
     m_hline_segment = markers.horizontal_line_segment(x1=1, x2=9, y=5)
     m_rect = markers.rectangle(x1=1, x2=3, y1=5, y2=10)
     m_text = markers.text(x=1, y=5, text="test")
     s.add_marker(m_point, permanent=True)
     s.add_marker(m_line, permanent=True)
     s.add_marker(m_vline, permanent=True)
     s.add_marker(m_vline_segment, permanent=True)
     s.add_marker(m_hline, permanent=True)
     s.add_marker(m_hline_segment, permanent=True)
     s.add_marker(m_rect, permanent=True)
     s.add_marker(m_text, permanent=True)
     assert len(list(s.metadata.Markers)) == 8
     with pytest.raises(ValueError):
         s.add_marker(m_rect, permanent=True)