Skip to content

Commit

Permalink
Merge pull request #3079 from ericpre/fix_scipy_option_dependencies
Browse files Browse the repository at this point in the history
Add pooch as test dependency - required to use scipy.dataset
  • Loading branch information
CSSFrancis committed Jan 13, 2023
2 parents 7f6b448 + 882fb18 commit f3e28eb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
1 change: 1 addition & 0 deletions conda_environment_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dependencies:
- pytest-xdist
- pytest-rerunfailures
- pytest-instafail
- pooch
47 changes: 27 additions & 20 deletions hyperspy/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2784,23 +2784,25 @@ def plot(self, navigator="auto", axes_manager=None, plot_markers=True,
elif self.tmp_parameters.has_item('filename'):
self._plot.signal_title = self.tmp_parameters.filename

def sum_wrapper(s, axis):
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", category=UserWarning, module='hyperspy'
)
return s.sum(axis)

def get_static_explorer_wrapper(*args, **kwargs):
if np.issubdtype(navigator.data.dtype, np.complexfloating):
return abs(navigator(as_numpy=True))
else:
return navigator(as_numpy=True)

def get_1D_sum_explorer_wrapper(*args, **kwargs):
navigator = self
# Sum over all but the first navigation axis.
am = navigator.axes_manager
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning,
module='hyperspy'
)
navigator = navigator.sum(
am.signal_axes + am.navigation_axes[1:]
)
am = self.axes_manager
navigator = sum_wrapper(
self, am.signal_axes + am.navigation_axes[1:]
)
return np.nan_to_num(to_numpy(navigator.data)).squeeze()

def get_dynamic_explorer_wrapper(*args, **kwargs):
Expand Down Expand Up @@ -2831,21 +2833,26 @@ def get_dynamic_explorer_wrapper(*args, **kwargs):
navigator = self.deepcopy()
else:
navigator = interactive(
self.sum,
self.events.data_changed,
self.axes_manager.events.any_axis_changed,
self.axes_manager.signal_axes)
f=sum_wrapper,
event=self.events.data_changed,
recompute_out_event=self.axes_manager.events.any_axis_changed,
s=self,
axis=self.axes_manager.signal_axes,
)
if navigator.axes_manager.navigation_dimension == 1:
navigator = interactive(
navigator.as_signal1D,
navigator.events.data_changed,
navigator.axes_manager.events.any_axis_changed, 0)
f=navigator.as_signal1D,
event=navigator.events.data_changed,
recompute_out_event=navigator.axes_manager.events.any_axis_changed,
spectral_axis=0,
)
else:
navigator = interactive(
navigator.as_signal2D,
navigator.events.data_changed,
navigator.axes_manager.events.any_axis_changed,
(0, 1))
f=navigator.as_signal2D,
event=navigator.events.data_changed,
recompute_out_event=navigator.axes_manager.events.any_axis_changed,
image_axes=(0, 1),
)
else:
navigator = None
# Navigator properties
Expand Down
1 change: 0 additions & 1 deletion hyperspy/tests/drawing/test_plot_roi_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def test_plot_point1D_axis_0_non_iterable(self):
self.im.plot()
p = roi.Point1DROI(0.5)
p.add_widget(signal=self.im, axes=0, color="cyan")
return self.im._plot.navigator_plot.figure

@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR,
tolerance=DEFAULT_TOL, style=STYLE_PYTEST_MPL)
Expand Down
5 changes: 3 additions & 2 deletions hyperspy/tests/drawing/test_plot_signal2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _set_signal_axes(self, axes_manager, name=t.Undefined,
return axes_manager


class TestPlotNonLinearAxis:
class TestPlotNonUniformAxis:

def setup_method(self):
dict0 = {'axis': np.arange(10)**0.5, 'name':'Non uniform 0', 'units':'A',
Expand Down Expand Up @@ -374,6 +374,7 @@ def test_plot_images_cmap_multi_signal():
test_plot1 = _TestIteratedSignal()

test_plot2 = _TestIteratedSignal()
test_plot2.signal.change_dtype(float)
test_plot2.signal *= 2 # change scale of second signal
test_plot2.signal = test_plot2.signal.inav[::-1]
test_plot2.signal.metadata.General.title = 'Descent'
Expand All @@ -391,6 +392,7 @@ def test_plot_images_cmap_multi_w_rgb():
test_plot1 = _TestIteratedSignal()

test_plot2 = _TestIteratedSignal()
test_plot2.signal.change_dtype(float)
test_plot2.signal *= 2 # change scale of second signal
test_plot2.signal.metadata.General.title = 'Ascent-2'

Expand Down Expand Up @@ -445,7 +447,6 @@ def test_plot_images_multi_signal_w_axes_replot():
tests.append(np.allclose(imi, plt.gca().images[0].get_array().data))
plt.close(fn)
assert np.alltrue(tests)
return f


@pytest.mark.parametrize("percentile", [("2.5th", "97.5th"),
Expand Down
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,16 @@
"scalebar": ["matplotlib-scalebar"],
# bug in pip: matplotib is ignored here because it is already present in
# install_requires.
"tests": ["pytest>=3.6", "pytest-mpl", "pytest-xdist", "pytest-rerunfailures", "pytest-instafail", "matplotlib>=3.1"],
"tests": [
"pytest>=3.6",
"pytest-mpl",
"pytest-xdist",
"pytest-rerunfailures",
"pytest-instafail",
"matplotlib>=3.1",
# optional dependency of scipy to use scipy.datasets
"pooch",
],
"coverage":["pytest-cov"],
# required to build the docs
"build-doc": [
Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/3079.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add pooch as test dependency, as it is required to use scipy.dataset in latest scipy (1.10) and update plotting test. Fix warning when plotting non-uniform axis

0 comments on commit f3e28eb

Please sign in to comment.