def test_plot_constrast_editor_setting_changed():
    # Test that changing setting works
    np.random.seed(1)
    data = np.random.random(size=(100, 100)) * 1000
    data += np.arange(100 * 100).reshape((100, 100))
    s = signals.Signal2D(data)
    s.plot()
    ceditor = ImageContrastEditor(s._plot.signal_plot)
    ceditor.span_selector.extents = (3E3, 5E3)
    ceditor.update_span_selector_traits()
    np.testing.assert_allclose(ceditor.ss_left_value, 3E3)
    np.testing.assert_allclose(ceditor.ss_right_value, 5E3)
    assert ceditor.auto
    # Do a cycle to trigger traits changed
    ceditor.auto = False
    assert not ceditor.auto
    ceditor.auto = True  # reset and clear span selector
    assert ceditor.auto
    assert not ceditor.span_selector.visible
    assert not ceditor._is_selector_visible
    assert not ceditor.line.line.get_visible()
    ceditor.span_selector.extents = (3E3, 5E3)
    ceditor.span_selector.set_visible(True)
    ceditor.update_line()
    assert ceditor._is_selector_visible
    assert ceditor.line.line.get_visible()

    assert ceditor.bins == 24
    assert ceditor.line.axis.shape == (ceditor.bins, )
    ceditor.bins = 50
    assert ceditor.bins == 50
    assert ceditor.line.axis.shape == (ceditor.bins, )

    # test other parameters
    ceditor.linthresh = 0.1
    assert ceditor.image.linthresh == 0.1

    ceditor.linscale = 0.5
    assert ceditor.image.linscale == 0.5
Beispiel #2
0
def test_close_vmin_vmax():
    data = np.random.random(10 * 10 * 10).reshape([10] * 3)
    s = hs.signals.Signal2D(data)
    s.plot()

    image_plot = s._plot.signal_plot
    display_range = (0.6, 0.9)

    ceditor = ImageContrastEditor(image_plot)

    # Simulate selecting a range on the histogram
    ceditor.span_selector.extents = display_range
    plt.pause(0.001)  # in case, interactive backend is used
    ceditor._update_image_contrast()

    # Need to use auto=False to pick up the current display when closing
    ceditor.auto = False
    ceditor.close()

    assert (image_plot.vmin, image_plot.vmax) == display_range
def test_plot_constrast_editor_auto_indices_changed():
    np.random.seed(1)
    data = np.random.random(size=(10, 10, 100, 100)) * 1000
    data += np.arange(10 * 10 * 100 * 100).reshape((10, 10, 100, 100))
    s = signals.Signal2D(data)
    s.plot()
    ceditor = ImageContrastEditor(s._plot.signal_plot)
    ceditor.span_selector.extents = (3E3, 5E3)
    ceditor.update_span_selector_traits()
    s.axes_manager.indices = (0, 1)
    # auto is None by default, the span selector need to be removed:
    assert not ceditor.span_selector.visible
    assert not ceditor._is_selector_visible
    ref_value = (100045.29840954322, 110988.10581608873)
    np.testing.assert_allclose(ceditor._get_current_range(), ref_value)

    # Change auto to False
    ceditor.auto = False
    s.axes_manager.indices = (0, 2)
    # vmin, vmax shouldn't have changed
    np.testing.assert_allclose(ceditor._get_current_range(), ref_value)
def test_close_vmin_vmax():
    data = np.random.random(10*10*10).reshape([10]*3)
    s = hs.signals.Signal2D(data)
    s.plot()

    image_plot = s._plot.signal_plot
    display_range = (0.6, 0.9)

    ceditor = ImageContrastEditor(image_plot)

    # Simulate selecting a range on the histogram
    ceditor.span_selector_switch(True)
    ceditor.span_selector.set_initial = (0, 1)
    ceditor.span_selector.range = display_range
    plt.pause(0.001) # in case, interactive backend is used
    ceditor.update_span_selector_traits()

    # Need to use auto=False to pick up the current display when closing
    ceditor.auto = False
    ceditor.close()

    assert image_plot.vmin == display_range[0]
    assert image_plot.vmax == display_range[1]
def test_image_contrast_tool():

    s = hs.signals.Signal2D(np.random.random(10000).reshape((100, 100)))
    s.plot()

    ceditor = ImageContrastEditor(s._plot.signal_plot)
    ceditor.gui(**KWARGS)

    vmin = 5
    ceditor.vmin_percentile = vmin
    assert ceditor.vmin_percentile == vmin

    vmax = 95
    ceditor.vmax_percentile = vmax
    assert ceditor.vmax_percentile == vmax
    
    auto = False
    ceditor.auto = auto
    assert ceditor.auto == auto

    for norm in ['Linear', 'Power', 'Log', 'Symlog']:
        ceditor.norm = norm
        assert ceditor.norm == norm