-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug iterate signal with markers #1968
Changes from 6 commits
c10c091
4e4e98b
edbcbf6
84753ec
87182ca
c906e6b
ee9cbb5
1f296a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
import pytest | ||
|
||
from hyperspy.misc.test_utils import update_close_figure, sanitize_dict | ||
from hyperspy.signals import Signal2D, Signal1D | ||
from hyperspy.signals import Signal2D, Signal1D, BaseSignal | ||
from hyperspy.utils import markers, stack | ||
from hyperspy.drawing.marker import dict2marker | ||
from hyperspy.datasets.example_signals import EDS_TEM_Spectrum | ||
|
@@ -472,4 +472,42 @@ def test_plot_eds_lines(): | |
s.plot(True) | ||
s.axes_manager.navigation_axes[0].index = 1 | ||
return s._plot.signal_plot.figure | ||
|
||
|
||
@update_close_figure | ||
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'] | ||
return ims | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test compares the markers from the sub-signal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree but, why does it have to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ups! certainly not. I will remove that together with the update_close_figure. Thanks for reviewing! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you refer to the
import BaseSignal
? I use a basesignal to test intest_iterate_markers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I meand
@update_close_figure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is needed to close the figure that is created when
add_marker
is called.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, it seems it is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the purpose of this in other tests is to test if closing the plot closes the markers without issue. Having it here may make this test fail if that gets broken what may be confusing. However, @ericpre should know better.