Пример #1
0
 def test_get_data_shape_point(self):
     m0 = markers.point(5, 5)
     m1 = markers.point((5, 10), (5, 10))
     m2 = markers.point(((12, 2, 9), (1, 2, 3)), ((2, 5, 1), (3, 9, 2)))
     m3 = markers.vertical_line(((12, 2), (2, 5), (9, 2)))
     m4 = markers.point(5, 5)
     m4.data['x1'][()] = np.array(None, dtype=object)
     m4.data['y1'][()] = np.array(None, dtype=object)
     m5 = markers.vertical_line(9)
     m6 = markers.rectangle(1, 5, 6, 8)
     m7 = markers.rectangle((1, 2), (5, 6), (6, 7), (8, 9))
     m8 = markers.point(
         np.arange(256).reshape(2, 2, 2, 2, 2, 2, 2, 2),
         np.arange(256).reshape(2, 2, 2, 2, 2, 2, 2, 2))
     m9 = markers.arrow(2, 3, 4, 5)
     m10 = markers.arrow((2, 3), (4, 5), (6, 7), (8, 9))
     m11 = markers.ellipse(4, 5, 2, 3)
     m12 = markers.ellipse((2, 3), (4, 5), (6, 7), (8, 9))
     assert m0._get_data_shape() == ()
     assert m1._get_data_shape() == (2,)
     assert m2._get_data_shape() == (2, 3)
     assert m3._get_data_shape() == (3, 2)
     with pytest.raises(ValueError):
         assert m4._get_data_shape() == ()
     assert m5._get_data_shape() == ()
     assert m6._get_data_shape() == ()
     assert m7._get_data_shape() == (2,)
     assert m8._get_data_shape() == (2, 2, 2, 2, 2, 2, 2, 2)
     assert m9._get_data_shape() == ()
     assert m10._get_data_shape() == (2,)
     assert m11._get_data_shape() == ()
     assert m12._get_data_shape() == (2,)
Пример #2
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)
Пример #3
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
Пример #4
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
Пример #5
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'])
Пример #6
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
Пример #7
0
def _test_plot_rectange_markers():
    # Create test image 100x100 pixels:
    im = Signal2D(np.arange(100).reshape([10, 10]))

    # Add four line markers:
    m1 = markers.line_segment(
        x1=2, y1=2, x2=7, y2=2, color='red', linewidth=3)
    m2 = markers.line_segment(
        x1=2, y1=2, x2=2, y2=7, color='red', linewidth=3)
    m3 = markers.line_segment(
        x1=2, y1=7, x2=7, y2=7, color='red', linewidth=3)
    m4 = markers.line_segment(
        x1=7, y1=2, x2=7, y2=7, color='red', linewidth=3)

    # Add rectangle marker at same position:
    m = markers.rectangle(x1=2, x2=7, y1=2, y2=7,
                          linewidth=4, color='blue', ls='dotted')

    # Plot image and add markers to img:
    im.plot()
    im.add_marker(m)
    im.add_marker(m1)
    im.add_marker(m2)
    im.add_marker(m3)
    im.add_marker(m4)
    return im
Пример #8
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
Пример #9
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)
Пример #10
0
 def test_get_data_shape_point(self):
     m0 = markers.point(5, 5)
     m1 = markers.point((5, 10), (5, 10))
     m2 = markers.point(((12, 2, 9), (1, 2, 3)), ((2, 5, 1), (3, 9, 2)))
     m3 = markers.vertical_line(((12, 2), (2, 5), (9, 2)))
     m4 = markers.point(5, 5)
     m4.data['x1'][()] = np.array(None, dtype=np.object)
     m4.data['y1'][()] = np.array(None, dtype=np.object)
     m5 = markers.vertical_line(9)
     m6 = markers.rectangle(1, 5, 6, 8)
     m7 = markers.rectangle((1, 2), (5, 6), (6, 7), (8, 9))
     m8 = markers.point(
         np.arange(256).reshape(2, 2, 2, 2, 2, 2, 2, 2),
         np.arange(256).reshape(2, 2, 2, 2, 2, 2, 2, 2))
     assert m0._get_data_shape() == ()
     assert m1._get_data_shape() == (2,)
     assert m2._get_data_shape() == (2, 3)
     assert m3._get_data_shape() == (3, 2)
     with pytest.raises(ValueError):
         assert m4._get_data_shape() == ()
     assert m5._get_data_shape() == ()
     assert m6._get_data_shape() == ()
     assert m7._get_data_shape() == (2,)
     assert m8._get_data_shape() == (2, 2, 2, 2, 2, 2, 2, 2)
Пример #11
0
 def test_save_load_rectangle_marker(self, tmp_path, file):
     filename = tmp_path / file
     s = self.s
     x1, x2, y1, y2 = 2, 4, 1, 3
     color = 'yellow'
     linewidth = 5
     name = "rectangle_test"
     m = markers.rectangle(
         x1=x1, x2=x2, y1=y1, y2=y2, 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())
Пример #12
0
def test_plot_markers_zorder(reversed_order):
    s = Signal2D(np.full((10,10),20))
    s.axes_manager[0].name='x'
    s.axes_manager[0].scale=10
    s.axes_manager[1].scale=10
    s.plot()

    marker_list = [
        markers.rectangle(35, 45, 65, 75, edgecolor="yellow", facecolor="cyan", zorder=3),
        markers.text(10, 20, "Text", color="white", size=30, zorder=4),
        markers.ellipse(40, 60, 30, 25, edgecolor='white', facecolor='red', linewidth=4, zorder=8),
        markers.arrow(10, 10, 50, 50, arrowstyle='<|-|>', edgecolor='white', facecolor='red', linewidth=1, shrinkA=2, shrinkB=2, zorder=8.5),
        markers.arrow(10, 15, 50, 60, arrowstyle='<->', edgecolor='red', facecolor='red', linewidth=3, shrinkA=2, shrinkB=2, zorder=2.8),
        markers.rectangle(10, 20, 60, 70, edgecolor="red", facecolor="green", fill=True, zorder=2.7),
        markers.text(50, 60, "Text", color="white", backgroundcolor="blue", size=40, zorder=6.6),
        markers.ellipse(70, 40, 30, 25, edgecolor='blue', facecolor='red', fill=True, linewidth=4, zorder=7.5),
        markers.line_segment(50, 10, 40, 80, color='cyan', linewidth=3, zorder=3.2),
    ]

    if reversed_order:
        marker_list.reverse()
    s.add_marker(marker_list)

    return s._plot.signal_plot.figure
Пример #13
0
 def test_save_load_rectangle_marker(self):
     x1, x2, y1, y2 = 2, 4, 1, 3
     color = 'yellow'
     linewidth = 5
     name = "rectangle_test"
     s = Signal2D(np.arange(100).reshape(10, 10))
     m = markers.rectangle(
         x1=x1, x2=x2, y1=y1, y2=y2, color=color, linewidth=linewidth)
     m.name = name
     s.add_marker(m, permanent=True)
     with tempfile.TemporaryDirectory() as tmp:
         filename = tmp + '/test_save_rectangle_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())
Пример #14
0
 def test_save_load_rectangle_marker(self):
     x1, x2, y1, y2 = 2, 4, 1, 3
     color = 'yellow'
     linewidth = 5
     name = "rectangle_test"
     s = Signal2D(np.arange(100).reshape(10, 10))
     m = markers.rectangle(
         x1=x1, x2=x2, y1=y1, y2=y2, color=color, linewidth=linewidth)
     m.name = name
     s.add_marker(m, permanent=True)
     with tempfile.TemporaryDirectory() as tmp:
         filename = tmp + '/test_save_rectangle_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())
Пример #15
0
def test_iterate_markers():
    from skimage.feature import peak_local_max
    import scipy.misc
    ims = BaseSignal(scipy.misc.face()).as_signal2D([1, 2])
    index = np.array([peak_local_max(im.data, min_distance=100,
                                     num_peaks=4) for im in ims])
    # Add multiple markers
    for i in range(4):
        xs = index[:, i, 1]
        ys = index[:, i, 0]
        m = markers.point(x=xs, y=ys, color='red')
        ims.add_marker(m, plot_marker=True, permanent=True)
        m = markers.text(x=10 + xs, y=10 + ys, text=str(i), color='k')
        ims.add_marker(m, plot_marker=True, permanent=True)
    xs = index[:, :, 1]
    ys = index[:, :, 0]
    x1 = np.min(xs, 1)
    y1 = np.min(ys, 1)
    x2 = np.max(xs, 1)
    y2 = np.max(ys, 1)
    m = markers.rectangle(x1, y1, x2, y2, color='green')
    ims.add_marker(m, plot_marker=True, permanent=True)
    m = markers.arrow(x1, y1, x2, y2, arrowstyle='<->',edgecolor='red')
    ims.add_marker(m, plot_marker=True, permanent=True)
    m = markers.ellipse((x1+x2)/2, (y1+y2)/2, x2-x1, y2-y1,
                      edgecolor='yellow')
    ims.add_marker(m, plot_marker=True, permanent=True)

    for im in ims:
        m_original = ims.metadata.Markers
        m_iterated = im.metadata.Markers
        for key in m_original.keys():
            mo = m_original[key]
            mi = m_iterated[key]
            assert mo.__class__.__name__ == mi.__class__.__name__
            assert mo.name == mi.name
            assert mo.get_data_position('x1') == mi.get_data_position('x1')
            assert mo.get_data_position('y1') == mi.get_data_position('y1')
            assert mo.get_data_position('text') == mi.get_data_position('text')
            for propkey in mo.marker_properties:
                assert mo.marker_properties[propkey] == \
                    mi.marker_properties[propkey]
Пример #16
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)
Пример #17
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)
Пример #18
0
def test_iterate_markers():
    from skimage.feature import peak_local_max
    import scipy.misc
    ims = BaseSignal(scipy.misc.face()).as_signal2D([1, 2])
    index = np.array([peak_local_max(im.data, min_distance=100,
                                     num_peaks=4) for im in ims])
    # Add multiple markers
    for i in range(4):
        xs = index[:, i, 1]
        ys = index[:, i, 0]
        m = markers.point(x=xs, y=ys, color='red')
        ims.add_marker(m, plot_marker=True, permanent=True)
        m = markers.text(x=10 + xs, y=10 + ys, text=str(i), color='k')
        ims.add_marker(m, plot_marker=True, permanent=True)
    xs = index[:, :, 1]
    ys = index[:, :, 0]
    m = markers.rectangle(np.min(xs, 1),
                          np.min(ys, 1),
                          np.max(xs, 1),
                          np.max(ys, 1),
                          color='green')
    ims.add_marker(m, plot_marker=True, permanent=True)

    for im in ims:
        m_original = ims.metadata.Markers
        m_iterated = im.metadata.Markers
        for key in m_original.keys():
            mo = m_original[key]
            mi = m_iterated[key]
            assert mo.__class__.__name__ == mi.__class__.__name__
            assert mo.name == mi.name
            assert mo.get_data_position('x1') == mi.get_data_position('x1')
            assert mo.get_data_position('y1') == mi.get_data_position('y1')
            assert mo.get_data_position('text') == mi.get_data_position('text')
            assert mo.marker_properties['color'] == \
                mi.marker_properties['color']