Skip to content

Commit

Permalink
Revert "Add permanent markers"
Browse files Browse the repository at this point in the history
  • Loading branch information
francisco-dlp committed Feb 20, 2017
1 parent 908f8ad commit bd462ec
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 1,003 deletions.
Binary file removed doc/user_guide/images/permanent_marker_one.png
Binary file not shown.
87 changes: 3 additions & 84 deletions doc/user_guide/visualisation.rst
Expand Up @@ -242,7 +242,7 @@ Data files used in the following examples can be downloaded using
>>> urlretrieve(url + 'image011.tif', 'image011.tif')
.. NOTE::
See also the `SEM EDS tutorials <http://nbviewer.ipython.org/github/hyperspy/hyperspy-demos/blob/master/electron_microscopy/EDS/>`_ .
See also the `SEM EDS tutorials <http://nbviewer.ipython.org/github/hyperspy/hyperspy- demos/blob/master/electron_microscopy/EDS/>`_ .

.. NOTE::

Expand Down Expand Up @@ -347,7 +347,7 @@ Data files used in the following examples can be downloaded using
>>> urlretrieve(url + 'Ni_La_intensity.hdf5', 'Ni_La_intensity.hdf5')
.. NOTE::
See also the `EDS tutorials <http://nbviewer.ipython.org/github/hyperspy/hyperspy-demos/blob/master/electron_microscopy/EDS/>`_ .
See also the `EDS tutorials <http://nbviewer.ipython.org/github/hyperspy/hyperspy- demos/blob/master/electron_microscopy/EDS/>`_ .

Although HyperSpy does not currently support plotting when signal_dimension is
greater than 2, `Mayavi <http://docs.enthought.com/mayavi/mayavi/>`_ can be
Expand All @@ -374,7 +374,7 @@ found in :ref:`EDS lines intensity<get_lines_intensity>`.
Visualisation of isosurfaces with mayavi.

.. NOTE::
See also the `SEM EDS tutorials <http://nbviewer.ipython.org/github/hyperspy/hyperspy-demos/blob/master/electron_microscopy/EDS/>`_ .
See also the `SEM EDS tutorials <http://nbviewer.ipython.org/github/hyperspy/hyperspy- demos/blob/master/electron_microscopy/EDS/>`_ .

.. NOTE::

Expand Down Expand Up @@ -897,84 +897,3 @@ The markers can be added to the navigator as well. In the following example, eac
:width: 400

Multi-dimensional markers.

These markers can also be permanently added to a signal, which is saved in metadata.Markers:

.. code-block:: python
>>> s = hs.signals.Signal2D(np.arange(100).reshape(10, 10))
>>> marker = hs.markers.point(5, 9)
>>> s.add_marker(marker, permanent=True)
>>> s.metadata.Markers
└── point = <marker.Point, point (x=5,y=9,color=black,size=20)>
>>> s.plot(plot_markers=True)
.. figure:: images/permanent_marker_one.png
:align: center
:width: 400

Plotting with permanent markers.

Markers can be removed by deleting them from the metadata

.. code-block:: python
>>> s = hs.signals.Signal2D(np.arange(100).reshape(10, 10))
>>> marker = hs.markers.point(5, 9)
>>> s.add_marker(marker, permanent=True)
>>> s.metadata.Markers
└── point = <marker.Point, point (x=5,y=9,color=black,size=20)>
>>> del s.metadata.Markers.point
>>> s.metadata.Markers # Returns nothing
If the signal got a navigation dimension, the markers can be made to change
as a function of the navigation index. For a signal with 1 navigation axis:

.. code-block:: python
>>> s = hs.signals.Signal2D(np.arange(300).reshape(3, 10, 10))
>>> marker = hs.markers.point((5, 1, 2), (9, 8, 1), color='red')
>>> s.add_marker(marker, permanent=True)
Or for a signal with 2 navigation axes:

.. code-block:: python
>>> s = hs.signals.Signal2D(np.arange(400).reshape(2, 2, 10, 10))
>>> marker = hs.markers.point(((5, 1), (1, 2)), ((2, 6), (9, 8)))
>>> s.add_marker(marker, permanent=True)
This can be extended to 4 (or more) navigation dimensions:

.. code-block:: python
>>> s = hs.signals.Signal2D(np.arange(1600).reshape(2, 2, 2, 2, 10, 10))
>>> x = np.arange(16).reshape(2, 2, 2, 2)
>>> y = np.arange(16).reshape(2, 2, 2, 2)
>>> marker = hs.markers.point(x=x, y=y, color='red')
>>> s.add_marker(marker, permanent=True)
Many markers can added by using a for loop. Note, adding many markers
might lead to very slow plotting.

.. code-block:: python
>>> s = hs.signals.Signal2D(np.arange(300).reshape(3, 10, 10))
>>> for i in range(10):
>>> marker = hs.markers.point(i, i, size=60)
>>> s.add_marker(marker, permanent=True)
Permanent markers are stored in the HDF5 file if the signal is saved:

.. code-block:: python
>>> s = hs.signals.Signal2D(np.arange(100).reshape(10, 10))
>>> marker = hs.markers.point(2, 1, color='red')
>>> s.add_marker(marker, plot_marker=False, permanent=True)
>>> s.metadata.Markers
└── point = <marker.Point, point (x=2,y=1,color=red,size=20)>
>>> s.save("storing_marker.hdf5")
>>> s1 = hs.load("storing_marker.hdf5")
>>> s1.metadata.Markers
└── point = <hyperspy.drawing._markers.point.Point object at 0x7efcfadb06d8>
6 changes: 1 addition & 5 deletions hyperspy/docstrings/plot.py
Expand Up @@ -49,11 +49,7 @@
If the signal dtype is RGB or RGBA this parameters has no
effect and is always "slider".
axes_manager : {None, axes_manager}
If None `axes_manager` is used.
plot_markers : bool, default False
Plot markers added using s.add_marker(marker, permanent=True).
Note, a large number of markers might lead to very slow plotting.
"""
If None `axes_manager` is used."""

PLOT2D_DOCSTRING = \
"""colorbar : bool, optional
Expand Down
37 changes: 16 additions & 21 deletions hyperspy/drawing/_markers/horizontal_line.py
Expand Up @@ -25,25 +25,21 @@ class HorizontalLine(MarkerBase):
Parameters
---------
y : array or float
y: array or float
The position of the line. If float, the marker is fixed.
If array, the marker will be updated when navigating. The array should
have the same dimensions in the navigation axes.
kwargs :
Keywords argument of axvline valid properties (i.e. recognized by
have the same dimensions in the nagivation axes.
kwargs:
Kewywords argument of axvline valid properties (i.e. recognized by
mpl.plot).
Example
-------
>>> import numpy as np
>>> s = hs.signals.Signal1D(np.random.random([10, 100])) * 10
>>> m = hs.plot.markers.horizontal_line(y=range(10), color='green')
>>> s.add_marker(m)
Adding a marker permanently to a signal
>>> s = hs.signals.Signal1D(np.random.random([10, 100]))
>>> m = hs.plot.markers.horizontal_line(y=5, color='green')
>>> s.add_marker(m, permanent=True)
"""

def __init__(self, y, **kwargs):
Expand All @@ -52,23 +48,22 @@ def __init__(self, y, **kwargs):
self.marker_properties = lp
self.set_data(y1=y)
self.set_marker_properties(**kwargs)
self.name = 'horizontal_line'

def __repr__(self):
string = "<marker.{}, {} (y={},color={})>".format(
self.__class__.__name__,
self.name,
self.get_data_position('y1'),
self.marker_properties['color'],
self.get_data_position('size'),
)
return(string)

def update(self):
if self.auto_update is False:
return
self.marker.set_ydata(self.get_data_position('y1'))

def _plot_marker(self):
def plot(self):
if self.ax is None:
raise AttributeError(
"To use this method the marker needs to be first add to a " +
"figure using `s._plot.signal_plot.add_marker(m)` or " +
"`s._plot.navigator_plot.add_marker(m)`")
self.marker = self.ax.axhline(self.get_data_position('y1'),
**self.marker_properties)
self.marker.set_animated(True)
try:
self.ax.hspy_fig._draw_animated()
except:
pass
44 changes: 18 additions & 26 deletions hyperspy/drawing/_markers/horizontal_line_segment.py
Expand Up @@ -26,20 +26,20 @@ class HorizontalLineSegment(MarkerBase):
"""Horizontal line segment marker that can be added to the signal figure
Parameters
----------
x1 : array or float
---------
x1: array or float
The position of the start of the line segment in x.
If float, the marker is fixed.
If array, the marker will be updated when navigating. The array should
have the same dimensions in the navigation axes.
x2 : array or float
have the same dimensions in the nagivation axes.
x2: array or float
The position of the end of the line segment in x.
see x1 arguments
y : array or float
y: array or float
The position of line segment in y.
see x1 arguments
kwargs :
Keywords argument of axvline valid properties (i.e. recognized by
kwargs:
Kewywords argument of axvline valid properties (i.e. recognized by
mpl.plot).
Example
Expand All @@ -49,12 +49,6 @@ class HorizontalLineSegment(MarkerBase):
>>> x1=20, x2=70, y=70, linewidth=4, color='red', linestyle='dotted')
>>> im.add_marker(m)
Adding a marker permanently to a signal
>>> im = hs.signals.Signal2D(np.zeros((100, 100)))
>>> m = hs.plot.markers.horizontal_line_segment(
>>> x1=10, x2=30, y=42, linewidth=4, color='red', linestyle='dotted')
>>> im.add_marker(m, permanent=True)
"""

def __init__(self, x1, x2, y, **kwargs):
Expand All @@ -63,27 +57,25 @@ def __init__(self, x1, x2, y, **kwargs):
self.marker_properties = lp
self.set_data(x1=x1, x2=x2, y1=y)
self.set_marker_properties(**kwargs)
self.name = 'horizontal_line_segment'

def __repr__(self):
string = "<marker.{}, {} (x1={},x2={},y={},color={})>".format(
self.__class__.__name__,
self.name,
self.get_data_position('x1'),
self.get_data_position('x2'),
self.get_data_position('y1'),
self.marker_properties['color'],
)
return(string)

def update(self):
if self.auto_update is False:
return
self._update_segment()

def _plot_marker(self):
def plot(self):
if self.ax is None:
raise AttributeError(
"To use this method the marker needs to be first add to a " +
"figure using `s._plot.signal_plot.add_marker(m)` or " +
"`s._plot.navigator_plot.add_marker(m)`")
self.marker = self.ax.vlines(0, 0, 1, **self.marker_properties)
self._update_segment()
self.marker.set_animated(True)
try:
self.ax.hspy_fig._draw_animated()
except:
pass

def _update_segment(self):
segments = self.marker.get_segments()
Expand Down
48 changes: 19 additions & 29 deletions hyperspy/drawing/_markers/line_segment.py
Expand Up @@ -24,23 +24,23 @@ class LineSegment(MarkerBase):
"""Line segment marker that can be added to the signal figure
Parameters
----------
x1 : array or float
---------
x1: array or float
The position of the start of the line segment in x.
If float, the marker is fixed.
If array, the marker will be updated when navigating. The array should
have the same dimensions in the navigation axes.
y1 : array or float
have the same dimensions in the nagivation axes.
y1: array or float
The position of the start of the line segment in y.
see x1 arguments
x2 : array or float
x2: array or float
The position of the end of the line segment in x.
see x1 arguments
y2 : array or float
y2: array or float
The position of the end of the line segment in y.
see x1 arguments
kwargs :
Keywords argument of axvline valid properties (i.e. recognized by
kwargs:
Kewywords argument of axvline valid properties (i.e. recognized by
mpl.plot).
Example
Expand All @@ -51,13 +51,6 @@ class LineSegment(MarkerBase):
>>> linewidth=4, color='red', linestyle='dotted')
>>> im.add_marker(m)
Permanently adding a marker to a signal
>>> im = hs.signals.Signal2D(np.zeros((100, 100)))
>>> m = hs.plot.markers.line_segment(
>>> x1=10, x2=30, y1=50, y2=70,
>>> linewidth=4, color='red', linestyle='dotted')
>>> im.add_marker(m, permanent=True)
"""

def __init__(self, x1, y1, x2, y2, **kwargs):
Expand All @@ -66,32 +59,29 @@ def __init__(self, x1, y1, x2, y2, **kwargs):
self.marker_properties = lp
self.set_data(x1=x1, y1=y1, x2=x2, y2=y2)
self.set_marker_properties(**kwargs)
self.name = 'line_segment'

def __repr__(self):
string = "<marker.{}, {} (x1={},x2={},y1={},y2={},color={})>".format(
self.__class__.__name__,
self.name,
self.get_data_position('x1'),
self.get_data_position('x2'),
self.get_data_position('y1'),
self.get_data_position('y2'),
self.marker_properties['color'],
)
return(string)

def update(self):
if self.auto_update is False:
return
self._update_segment()

def _plot_marker(self):
def plot(self):
if self.ax is None:
raise AttributeError(
"To use this method the marker needs to be first add to a " +
"figure using `s._plot.signal_plot.add_marker(m)` or " +
"`s._plot.navigator_plot.add_marker(m)`")
x1 = self.get_data_position('x1')
x2 = self.get_data_position('x2')
y1 = self.get_data_position('y1')
y2 = self.get_data_position('y2')
self.marker = self.ax.plot((x1, x2), (y1, y2),
**self.marker_properties)[0]
self.marker.set_animated(True)
try:
self.ax.hspy_fig._draw_animated()
except:
pass

def _update_segment(self):
x1 = self.get_data_position('x1')
Expand Down

0 comments on commit bd462ec

Please sign in to comment.