Skip to content
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

Update for Hyperspy 2.0 #48

Merged
merged 8 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.7', '3.9', '3.10']
PYTHON_VERSION: ['3.9', '3.10', '3.11']
LABEL: [-RnM]
PIP_ARGS: [--upgrade]
include:
- PYTHON_VERSION: '3.8'
PIP_ARGS: --pre --upgrade
LABEL: -pre_release-RnM
- PYTHON_VERSION: '3.8'
LABEL: -RnP
# - PYTHON_VERSION: '3.8'
# LABEL: -RnP

steps:
- uses: actions/checkout@v3
Expand All @@ -38,11 +38,11 @@ jobs:
python --version
pip --version

- name: Install HyperSpy (RELEASE_next_minor)
- name: Install HyperSpy (RELEASE_next_major)
shell: bash
if: contains( matrix.LABEL, 'RnM')
run: |
pip install https://github.com/hyperspy/hyperspy/archive/RELEASE_next_minor.zip
pip install https://github.com/hyperspy/hyperspy/archive/RELEASE_next_major.zip

- name: Install HyperSpy (RELEASE_next_patch)
shell: bash
Expand Down
13 changes: 8 additions & 5 deletions hyperspy_gui_ipywidgets/hyperspy_extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ GUI:
hyperspy.Preferences:
module: hyperspy_gui_ipywidgets.preferences
function: show_preferences_widget
exspy.Preferences:
module: hyperspy_gui_ipywidgets.preferences
function: show_exspy_preferences_widget
hyperspy.DataAxis:
module: hyperspy_gui_ipywidgets.axes
function: _get_axis_widgets
Expand All @@ -22,10 +25,10 @@ GUI:
hyperspy.Component:
module: hyperspy_gui_ipywidgets.model
function: get_component_widget
hyperspy.EELSCLEdge_Component:
exspy.EELSCLEdge_Component:
module: hyperspy_gui_ipywidgets.model
function: get_eelscl_widget
hyperspy.EELSSpectrum.print_edges_table:
exspy.EELSSpectrum.print_edges_table:
module: hyperspy_gui_ipywidgets.tools
function: print_edges_table_ipy
hyperspy.ScalableFixedPattern_Component:
Expand Down Expand Up @@ -85,12 +88,12 @@ GUI:
hyperspy.Model1D.fit_component:
module: hyperspy_gui_ipywidgets.model
function: fit_component_ipy
hyperspy.microscope_parameters_EELS:
exspy.microscope_parameters_EELS:
module: hyperspy_gui_ipywidgets.microscope_parameters
function: eels_microscope_parameter_ipy
hyperspy.microscope_parameters_EDS_TEM:
exspy.microscope_parameters_EDS_TEM:
module: hyperspy_gui_ipywidgets.microscope_parameters
function: eds_tem_microscope_parameter_ipy
hyperspy.microscope_parameters_EDS_SEM:
exspy.microscope_parameters_EDS_SEM:
module: hyperspy_gui_ipywidgets.microscope_parameters
function: eds_sem_microscope_parameter_ipy
42 changes: 41 additions & 1 deletion hyperspy_gui_ipywidgets/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,47 @@ def show_preferences_widget(obj, **kwargs):
(widget.children[1], "value"))
ipytabs[tab] = ipywidgets.VBox(ipytab)
# This defines the order of the tab in the widget
titles = ["General", "GUIs", "Plot", "EELS", "EDS"]
titles = ["General", "GUIs", "Plot"]
ipytabs_ = ipywidgets.Tab(
children=[ipytabs[title] for title in titles])
set_title_container(ipytabs_, titles)
save_button = ipywidgets.Button(
description="Save",
tooltip="Make changes permanent")
wdict["save_button"] = save_button

def on_button_clicked(b):
obj.save()

save_button.on_click(on_button_clicked)

container = ipywidgets.VBox([ipytabs_, save_button])
return {
"widget": container,
"wdict": wdict,
}


@add_display_arg
def show_exspy_preferences_widget(obj, **kwargs):
ipytabs = {}
wdict = {}
for tab in obj.editable_traits():
tabdict = {}
wdict["tab_{}".format(tab)] = tabdict
ipytab = []
tabtraits = getattr(obj, tab).traits()
for trait_name in getattr(obj, tab).editable_traits():
trait = tabtraits[trait_name]
widget = TRAITS2IPYWIDGETS[type(trait.trait_type)](
trait, get_label(trait, trait_name))
ipytab.append(widget)
tabdict[trait_name] = widget.children[1]
link((getattr(obj, tab), trait_name),
(widget.children[1], "value"))
ipytabs[tab] = ipywidgets.VBox(ipytab)
# This defines the order of the tab in the widget
titles = ["EELS", "EDS"]
ipytabs_ = ipywidgets.Tab(
children=[ipytabs[title] for title in titles])
set_title_container(ipytabs_, titles)
Expand Down
7 changes: 3 additions & 4 deletions hyperspy_gui_ipywidgets/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_spikes_removal_tool(self):
# Add three spikes
s.data[1, 0, 1] += 2
s.data[0, 2, 29] += 1
s.data[1, 2, 14] += 1
s.data[1, 2, 14] += 5
wd = s.spikes_removal_tool(**KWARGS)["ipywidgets"]["wdict"]

def next():
Expand Down Expand Up @@ -159,10 +159,9 @@ def remove():
assert s.axes_manager.indices == (2, 1)
np.random.seed(1)
wd["add_noise"].value = True
wd["interpolator_kind"].value = "Spline"
wd["spline_order"].value = 3
remove()
assert s.data[1, 2, 14] == 0
assert s.data[1, 2, 14] <= 2
assert s.axes_manager.indices == (0, 0)

def test_constrast_editor(self):
Expand Down Expand Up @@ -242,7 +241,7 @@ def test_eels_table_tool(self):
assert wd["units"].value == 'eV'
assert wd["left"].value == 500
assert wd["right"].value == 550
assert len(wd['gb'].children) == 36 # 9 edges displayed
assert len(wd['gb'].children) == 44 # 9 edges displayed

wd['major'].value = True
wd["update"]._click_handlers(wd["update"]) # refresh the table
Expand Down
9 changes: 0 additions & 9 deletions hyperspy_gui_ipywidgets/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,6 @@ def spikes_removal_ipy(obj, **kwargs):
threshold = ipywidgets.FloatText()
add_noise = ipywidgets.Checkbox()
default_spike_width = ipywidgets.IntText()
interpolator_kind = enum2dropdown(obj.traits()["interpolator_kind"])
spline_order = ipywidgets.IntSlider(min=1, max=10)
progress_bar = ipywidgets.IntProgress(max=len(obj.coordinates) - 1)
help_text = ipywidgets.HTML(
Expand All @@ -789,7 +788,6 @@ def spikes_removal_ipy(obj, **kwargs):
wdict["threshold"] = threshold
wdict["add_noise"] = add_noise
wdict["default_spike_width"] = default_spike_width
wdict["interpolator_kind"] = interpolator_kind
wdict["spline_order"] = spline_order
wdict["progress_bar"] = progress_bar
wdict["show_diff_button"] = show_diff
Expand Down Expand Up @@ -822,9 +820,6 @@ def enable_interpolator_kind(change):
else:
for child in labeled_spline_order.children:
child.layout.display = "none"
interpolator_kind.observe(enable_interpolator_kind, "value")
link((obj, "interpolator_kind"),
(interpolator_kind, "value"))
link((obj, "threshold"), (threshold, "value"))
link((obj, "add_noise"), (add_noise, "value"))
link((obj, "default_spike_width"),
Expand All @@ -834,13 +829,9 @@ def enable_interpolator_kind(change):
# Trigger the function that controls the visibility as
# setting the default value doesn't trigger it.

class Dummy:
new = interpolator_kind.value
enable_interpolator_kind(change=Dummy())
advanced = ipywidgets.Accordion((
ipywidgets.VBox([
labelme("Add noise", add_noise),
labelme("Interpolator kind", interpolator_kind),
labelme("Default spike width", default_spike_width),
labelme("Spline order", spline_order), ]),))

Expand Down