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

Remove baseline #82

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ jobs:
- name: Install HyperSpy (RELEASE_next_minor)
if: contains( matrix.LABEL, 'RnM')
run: |
pip install git+https://github.com/hyperspy/hyperspy.git@RELEASE_next_minor
# pip install git+https://github.com/hyperspy/hyperspy.git@RELEASE_next_minor
pip install "hyperspy[all] @ git+https://github.com/ericpre/hyperspy.git@remove_baselines"

- name: Install HyperSpy (RELEASE_next_patch)
if: contains( matrix.LABEL, 'RnP')
Expand Down
3 changes: 3 additions & 0 deletions hyperspy_gui_traitsui/hyperspy_extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ GUI:
hyperspy.Signal1D.remove_background:
module: hyperspy_gui_traitsui.tools
function: remove_background_traitsui
hyperspy.Signal1D.remove_baseline:
module: hyperspy_gui_traitsui.tools
function: remove_baseline_traitsui
hyperspy.SimpleMessage:
module: hyperspy_gui_traitsui.messages
function: simple_message
Expand Down
16 changes: 16 additions & 0 deletions hyperspy_gui_traitsui/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
BackgroundRemoval,
Signal2DCalibration,
)
from hyperspy.utils.baseline_removal_tool import BaselineRemoval

from hyperspy_gui_traitsui.tests.utils import KWARGS

Expand Down Expand Up @@ -69,6 +70,21 @@ def test_remove_background_tool():
assert s.isig[:500.0].data.mean() < 1


def test_remove_baseline():
pytest.importorskip("pybaselines")

s = hs.data.two_gaussians().inav[:5, :5]
s.plot()

br = BaselineRemoval(s)
br.gui(**KWARGS)
br.algorithm = "Asymmetric Least Squares"
br.algorithm = "Adaptive Smoothness Penalized Least Squares"
br.lam = 1e7
br.apply()
assert s.isig[:10].data.mean() < 5


def test_signal_2d_calibration():
s = hs.signals.Signal2D(np.zeros((100, 100)))
s.plot()
Expand Down
121 changes: 116 additions & 5 deletions hyperspy_gui_traitsui/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hyperspy_gui_traitsui.utils import add_display_arg


class SmoothingHandler(tu.Handler):
class GenericHandler(tu.Handler):

Check warning on line 12 in hyperspy_gui_traitsui/tools.py

View check run for this annotation

Codecov / codecov/patch

hyperspy_gui_traitsui/tools.py#L12

Added line #L12 was not covered by tests

def close(self, info, is_ok):
# Removes the span selector from the plot
Expand Down Expand Up @@ -263,7 +263,7 @@
# 'line_color',
),
kind='live',
handler=SmoothingHandler,
handler=GenericHandler,
buttons=OKCancelButtons,
title='Savitzky-Golay Smoothing',
)
Expand All @@ -279,7 +279,7 @@
# 'line_color',
),
kind='live',
handler=SmoothingHandler,
handler=GenericHandler,
buttons=OKCancelButtons,
title='Lowess Smoothing',)
return obj, {"view": view}
Expand All @@ -293,7 +293,7 @@
# 'line_color',
),
kind='live',
handler=SmoothingHandler,
handler=GenericHandler,
buttons=OKCancelButtons,
title='Total Variation Smoothing',)
return obj, {"view": view}
Expand All @@ -307,7 +307,7 @@
'order',
'type'),
kind='live',
handler=SmoothingHandler,
handler=GenericHandler,
buttons=OKCancelButtons,
title='Butterworth filter',)
return obj, {"view": view}
Expand Down Expand Up @@ -449,6 +449,117 @@
return obj, {"view": view}


@add_display_arg
def remove_baseline_traitsui(obj, **kwargs):
view = tu.View(

Check warning on line 454 in hyperspy_gui_traitsui/tools.py

View check run for this annotation

Codecov / codecov/patch

hyperspy_gui_traitsui/tools.py#L452-L454

Added lines #L452 - L454 were not covered by tests
tu.Item(
'algorithm',
label="Method",
),
tu.Item(
'_time_per_pixel',
style='readonly',
label="Time per pixel (ms)",
format_str='%.3g',
),
tu.Group(
tu.Group(
tu.Item(
'lam',
enabled_when="_enable_lam",
),
tu.Item(
'diff_order',
enabled_when="_enable_diff_order",
),
tu.Item(
'p',
enabled_when="_enable_p",
),
tu.Item(
'lam_1',
enabled_when="_enable_lam_1",
),
tu.Item(
'eta',
enabled_when="_enable_eta",
),
tu.Item(
'penalized_spline',
enabled_when="_enable_penalized_spline",
),
label="Whittaker",
),
tu.Group(
# Enabled when a polynomial baseline is selected
tu.Item(
'poly_order',
enabled_when="_enable_poly_order",
),
tu.Item(
'peak_ratio',
enabled_when="_enable_peak_ratio",
),
label="Polynomial",
),
tu.Group(
tu.Item(
'num_knots',
enabled_when="_enable_num_knots",
),
tu.Item(
'spline_degree',
enabled_when="_enable_spline_degree",
),
tu.Item(
'symmetric',
enabled_when="_enable_symmetric",
),
tu.Item(
'quantile',
enabled_when="_enable_quantile",
),
label="Spline",
),
tu.Group(
tu.Item(
'smooth_half_window',
enabled_when="_enable_smooth_half_window",
),
tu.Item(
'num_std',
enabled_when="_enable_num_std",
),
tu.Item(
'interp_half_window',
enabled_when="_enable_interp_half_window",
),
tu.Item(
'half_window',
enabled_when="_enable_half_window",
),
tu.Item(
'section',
enabled_when="_enable_section",
),
tu.Item(
'segments',
enabled_when="_enable_segments",
),
label="Classification",
),
),
buttons=OKCancelButtons,
handler=GenericHandler,
close_result=False, # is_ok=False when using window close button.
title='Baseline removal tool',
resizable=True,
width=300,
)
return obj, {"view": view}

Check warning on line 559 in hyperspy_gui_traitsui/tools.py

View check run for this annotation

Codecov / codecov/patch

hyperspy_gui_traitsui/tools.py#L559

Added line #L559 was not covered by tests



class SpikesRemovalHandler(tu.Handler):

def close(self, info, is_ok):
Expand Down
Loading