Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/RELEASE_next_patch' into RELEA…
Browse files Browse the repository at this point in the history
…SE_next_minor

# Conflicts:
#	.github/workflows/tests.yml
  • Loading branch information
ericpre committed Feb 21, 2023
2 parents ccbc655 + cf21c21 commit f83477f
Show file tree
Hide file tree
Showing 25 changed files with 897 additions and 834 deletions.
31 changes: 11 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,35 @@ jobs:
MPLBACKEND: agg
PIP_ARGS: --upgrade -e
PYTEST_ARGS: --pyargs hyperspy --reruns 3 -n 2 --instafail
PYTEST_ARGS_COVERAGE:
strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]
PYTHON_VERSION: ['3.8', '3.9']
PIP_SELECTOR: ['[all, tests]']
PIP_SELECTOR: ['[all, tests, coverage]']
include:
# test oldest supported version of main dependencies on python 3.6
# test oldest supported version of main dependencies on python 3.7
- os: ubuntu
PYTHON_VERSION: '3.7'
OLDEST_SUPPORTED_VERSION: true
DEPENDENCIES: matplotlib==3.1.3 numpy==1.17.1 scipy==1.1 imagecodecs==2020.1.31 tifffile==2020.2.16 dask==2.11.0 distributed==2.11.0 scikit-image==0.15 numba==0.52
PIP_SELECTOR: '[all, tests, coverage]'
# Hang at the end of the test suite run...
#PYTEST_ARGS_COVERAGE: --cov=. --cov-report=xml
OLDEST_SUPPORTED_VERSION: true
DEPENDENCIES: matplotlib==3.1.3 numpy==1.17.1 scipy==1.1 imagecodecs==2020.1.31 tifffile==2020.2.16 dask==2.11.0 distributed==2.11.0 scikit-image==0.15 numba==0.52 scikit-learn==1.0.1
LABEL: -oldest
# test minimum requirement
- os: ubuntu
PYTHON_VERSION: '3.8'
PIP_SELECTOR: '[tests]'
PIP_SELECTOR: '[tests, coverage]'
LABEL: -minimum
# Run coverage
- os: ubuntu
PYTHON_VERSION: '3.8'
PYTHON_VERSION: '3.7'
PIP_SELECTOR: '[all, tests, coverage]'
PYTEST_ARGS_COVERAGE: --cov=. --cov-report=xml
LABEL: -coverage
- os: ubuntu
PYTHON_VERSION: '3.7'
PIP_SELECTOR: '[all, tests]'
PYTHON_VERSION: '3.8'
PIP_SELECTOR: '[all, tests, coverage]'
- os: ubuntu
PYTHON_VERSION: '3.10'
PIP_SELECTOR: '[all, tests]'
exclude:
# redundant build (same as coverage)
- os: ubuntu
PYTHON_VERSION: '3.8'
PIP_SELECTOR: '[all, tests, coverage]'

steps:
- uses: actions/checkout@v3.3.0
Expand Down Expand Up @@ -79,8 +70,8 @@ jobs:
- name: Run test suite
run: |
pytest ${{ env.PYTEST_ARGS }} ${{ matrix.PYTEST_ARGS_COVERAGE }}
pytest ${{ env.PYTEST_ARGS }} --cov=. --cov-report=xml
- name: Upload coverage to Codecov
if: ${{ always() }} && ${{ matrix.PYTEST_ARGS_COVERAGE }}
if: ${{ always() }}
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion hyperspy/drawing/_markers/horizontal_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __repr__(self):
def update(self):
if self.auto_update is False:
return
self.marker.set_ydata(self.get_data_position('y1'))
self.marker.set_ydata([self.get_data_position('y1')])

def _plot_marker(self):
self.marker = self.ax.axhline(self.get_data_position('y1'),
Expand Down
2 changes: 1 addition & 1 deletion hyperspy/drawing/_markers/vertical_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __repr__(self):
def update(self):
if self.auto_update is False:
return
self.marker.set_xdata(self.get_data_position('x1'))
self.marker.set_xdata([self.get_data_position('x1')])

def _plot_marker(self):
self.marker = self.ax.axvline(self.get_data_position('x1'),
Expand Down
2 changes: 1 addition & 1 deletion hyperspy/drawing/_widgets/horizontal_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HorizontalLineWidget(Widget1DBase):

def _update_patch_position(self):
if self.is_on and self.patch:
self.patch[0].set_ydata(self._pos[0])
self.patch[0].set_ydata([self._pos[0]])
self.draw_patch()

def _add_patch_to(self, ax):
Expand Down
6 changes: 3 additions & 3 deletions hyperspy/drawing/_widgets/scalebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


from hyperspy.misc.math_tools import closest_nice_number

import numpy as np

class ScaleBar(object):

Expand Down Expand Up @@ -95,8 +95,8 @@ def calculate_text_position(self, pad=1 / 100.):

def calculate_size(self, max_size_ratio=0.25):
ps = self.pixel_size if self.pixel_size is not None else 1
size = closest_nice_number(ps * (self.xmax - self.xmin) *
max_size_ratio)
size = closest_nice_number(np.abs(ps * (self.xmax - self.xmin) *
max_size_ratio))
self.length = size

def remove(self):
Expand Down
2 changes: 1 addition & 1 deletion hyperspy/drawing/_widgets/vertical_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class VerticalLineWidget(Widget1DBase):

def _update_patch_position(self):
if self.is_on and self.patch:
self.patch[0].set_xdata(self._pos[0])
self.patch[0].set_xdata([self._pos[0]])
self.draw_patch()

def _add_patch_to(self, ax):
Expand Down
6 changes: 5 additions & 1 deletion hyperspy/drawing/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,11 @@ def format_coord(x, y):
ims[0].set_norm(norm)
ims[0].norm.vmax, ims[0].norm.vmin = vmax, vmin
if redraw_colorbar:
self._colorbar.draw_all()
# `draw_all` is deprecated in matplotlib 3.6.0
if Version(matplotlib.__version__) <= Version("3.6.0"):
self._colorbar.draw_all()
else:
self.figure.draw_without_rendering()
self._colorbar.solids.set_animated(
self.figure.canvas.supports_blit
)
Expand Down
59 changes: 35 additions & 24 deletions hyperspy/drawing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def __check_single_colorbar(cbar):
# Set overall figure size and define figure (if not pre-existing)
if fig is None:
w, h = plt.rcParams['figure.figsize']
dpi = plt.rcParams['figure.dpi']
dpi = plt.rcParams['figure.dpi']
if overlay and axes_decor == 'off':
shape = images[0].axes_manager.signal_shape
if pixel_size_factor is None:
Expand Down Expand Up @@ -971,7 +971,7 @@ def transparent_single_color_cmap(color):
images[0].axes_manager[0].scale):
raise ValueError("Images are not the same scale and so should"
"not be overlayed.")

if vmin is not None:
_logger.warning('`vmin` is ignored when overlaying images.')

Expand Down Expand Up @@ -1003,7 +1003,7 @@ def transparent_single_color_cmap(color):
#Set vmin and vmax
centre = next(centre_colormaps) # get next value for centreing
data = _parse_array(im)

_vmin = data.min()
_vmax = vmax[idx] if isinstance(vmax, (tuple, list)) else vmax
_vmin, _vmax = contrast_stretching(data, _vmin, _vmax)
Expand Down Expand Up @@ -1203,30 +1203,31 @@ def transparent_single_color_cmap(color):
# Replot: connect function
def on_dblclick(event):
# On the event of a double click, replot the selected subplot
if not event.inaxes:
if not event.inaxes or not event.dblclick:
return
if not event.dblclick:
return
subplots = [axi for axi in f.axes if isinstance(axi, mpl.axes.Subplot)]
inx = list(subplots).index(event.inaxes)
im = replot_ims[inx]

idx_ = axes_list.index(event.inaxes)
ax_ = axes_list[idx_]
im_ = replot_ims[idx_]

# Use some of the info in the subplot
cm = subplots[inx].images[0].get_cmap()
clim = subplots[inx].images[0].get_clim()
cm = ax_.images[0].get_cmap()
clim = ax_.images[0].get_clim()

sbar = False
if (scalelist and inx in scalebar) or scalebar == 'all':
if (scalelist and idx_ in scalebar) or scalebar == 'all':
sbar = True

im.plot(colorbar=bool(colorbar),
vmin=clim[0],
vmax=clim[1],
no_nans=no_nans,
aspect=asp,
scalebar=sbar,
scalebar_color=scalebar_color,
cmap=cm)
im_.plot(
colorbar=bool(colorbar),
vmin=clim[0],
vmax=clim[1],
no_nans=no_nans,
aspect=asp,
scalebar=sbar,
scalebar_color=scalebar_color,
cmap=cm,
)

f.canvas.mpl_connect('button_press_event', on_dblclick)

Expand Down Expand Up @@ -1306,7 +1307,12 @@ def make_cmap(colors, name='my_colormap', position=None,
cmap = mpl.colors.LinearSegmentedColormap(name, cdict, 256)

if register:
mpl.cm.register_cmap(name, cmap)
try:
# Introduced in matplotlib 3.5
mpl.colormaps.register(cmap, name=name)
except AttributeError:
# Deprecated in matplotlib 3.5
mpl.cm.register_cmap(name, cmap)
return cmap


Expand Down Expand Up @@ -1427,8 +1433,13 @@ def _reverse_legend(ax_, legend_loc_):
"""
l = ax_.get_legend()
labels = [lb.get_text() for lb in list(l.get_texts())]
handles = l.legendHandles
ax_.legend(handles[::-1], labels[::-1], loc=legend_loc_)
# "legendHandles" is deprecated in matplotlib 3.7.0 in favour of
# "legend_handles".
if Version(mpl.__version__) >= Version("3.7"):
handles = l.legend_handles
else:
handles = l.legendHandles
ax_.legend(reversed(handles), reversed(labels), loc=legend_loc_)

# Before v1.3 default would read the value from prefereces.
if style == "default":
Expand Down Expand Up @@ -1481,7 +1492,7 @@ def _reverse_legend(ax_, legend_loc_):
_make_cascade_subplot(spectra, ax, color, linestyle, padding=padding,
drawstyle=drawstyle)
if legend is not None:
plt.legend(legend, loc=legend_loc)
ax.legend(legend, loc=legend_loc)
_reverse_legend(ax, legend_loc)
if legend_picking is True:
animate_legend(fig=fig, ax=ax)
Expand Down
14 changes: 9 additions & 5 deletions hyperspy/drawing/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from __future__ import division

import matplotlib.pyplot as plt
from matplotlib.backend_bases import MouseEvent
from matplotlib.backend_bases import MouseEvent, PickEvent
import numpy as np

from hyperspy.drawing.utils import on_figure_window_close
Expand Down Expand Up @@ -198,13 +198,17 @@ def select(self):
if not self.patch or not self.is_on or not self.ax:
return

canvas = self.ax.figure.canvas
figure = self.ax.figure
# Simulate a pick event
x, y = self.patch[0].get_transform().transform_point((0, 0))
mouseevent = MouseEvent('pick_event', canvas, x, y)
# when the widget is added programatically, mouseevent can be "empty"
mouseevent = MouseEvent('pick_event', figure.canvas, x, y)
if mouseevent.button:
canvas.pick_event(mouseevent, self.patch[0])
try:
# Introduced in matplotlib 3.6 and `pick_event` deprecated
event = PickEvent('pick_event', figure, mouseevent, self.patch[0])
figure.canvas.callbacks.process('pick_event', event)
except: # Deprecated in matplotlib 3.6
figure.canvas.pick_event(mouseevent, self.patch[0])
self.picked = False

def connect(self, ax):
Expand Down

0 comments on commit f83477f

Please sign in to comment.