Skip to content

Commit

Permalink
Merge pull request #2930 from ericpre/signal_tool_fixes
Browse files Browse the repository at this point in the history
Signal tool fixes
  • Loading branch information
jlaehne committed Apr 21, 2022
2 parents 842d6d9 + 1db5c6a commit c1428da
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
32 changes: 20 additions & 12 deletions hyperspy/misc/label_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import itertools

import numpy as np
from hyperspy.drawing.marker import markers
from hyperspy.utils import markers


class SpectrumLabelPosition():
'''
Expand Down Expand Up @@ -96,10 +97,12 @@ def _estimate_textbox_dimension(self, dummy_text='My_g8'):
dummy_style = copy.deepcopy(self.edge_label_style)
dummy_style['bbox']['alpha'] = 0
dummy_style['alpha'] = 0
tx = markers.text.Text(x=(self.axis.low_value+self.axis.high_value)/2,
y=(self.smin+self.smax)/2,
text=self._text_parser(dummy_text),
**dummy_style)
tx = markers.text(
x=(self.axis.low_value+self.axis.high_value)/2,
y=(self.smin+self.smax)/2,
text=self._text_parser(dummy_text),
**dummy_style
)
self.signal.add_marker(tx)

dummybb = self._get_bbox_from_text_artist(tx.marker)
Expand Down Expand Up @@ -133,13 +136,18 @@ def get_markers(self, labels):
vls = []
txs = []
for xyt in xytext:
vl = markers.vertical_line_segment.VerticalLineSegment(x=xyt[0],
y1=xyt[1],
y2=xyt[2],
color=xyt[4])
tx = markers.text.Text(x=xyt[0], y=xyt[1],
text=self._text_parser(xyt[3]), color=xyt[4],
**self.edge_label_style)
vl = markers.vertical_line_segment(
x=xyt[0],
y1=xyt[1],
y2=xyt[2],
color=xyt[4]
)
tx = markers.text(
x=xyt[0],
y=xyt[1],
text=self._text_parser(xyt[3]), color=xyt[4],
**self.edge_label_style
)

vl.events.closed.connect(self.signal._edge_marker_closed)
tx.events.closed.connect(self.signal._edge_marker_closed)
Expand Down
15 changes: 12 additions & 3 deletions hyperspy/signal_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,12 @@ class ImageContrastEditor(t.HasTraits):
mpl_help = "See the matplotlib SymLogNorm for more information."
ss_left_value = t.Float()
ss_right_value = t.Float()
bins = t.Int(100, desc="Number of bins used for the histogram.")
bins = t.Int(
100,
desc="Number of bins used for the histogram.",
auto_set=False,
enter_set=True,
)
gamma = t.Range(0.1, 3.0, 1.0)
vmin_percentile = t.Range(0.0, 100.0, 0)
vmax_percentile = t.Range(0.0, 100.0, 100)
Expand Down Expand Up @@ -1069,6 +1074,10 @@ def _auto_changed(self, old, new):
self._reset(indices_changed=False, update_histogram=False)
self._clear_span_selector()

def _bins_changed(self, old, new):
if old != new:
self.update_histogram(clear_selector=False)

def _norm_changed(self, old, new):
self.image.norm = new.lower()
self._reset(auto=False, indices_changed=False,
Expand Down Expand Up @@ -1138,7 +1147,7 @@ def plot_histogram(self, max_num_bins=250):

plot_histogram.__doc__ %= HISTOGRAM_MAX_BIN_ARGS

def update_histogram(self):
def update_histogram(self, clear_selector=True):
if self._vmin == self._vmax:
return

Expand All @@ -1162,7 +1171,7 @@ def update_histogram(self):
if self.hist_data.max() != 0:
self.ax.set_ylim(0, self.hist_data.max())

if self.auto and self._is_selector_visible:
if self.auto and self._is_selector_visible and clear_selector:
# in auto mode, the displayed contrast cover the full range
# and we need to reset the span selector
# no need to clear the line, it will updated
Expand Down
6 changes: 6 additions & 0 deletions hyperspy/tests/drawing/test_plot_signal_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ def test_plot_constrast_editor_setting_changed():
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
Expand Down

0 comments on commit c1428da

Please sign in to comment.