Note
Go to the end to download the full example code.
Baseline Removal#
This example shows how to remove a baseline from a 1D signal using the pybaselines library.
Create a signal
import hyperspy.api as hs
s = hs.data.two_gaussians()
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/rsciio/utils/rgb_tools.py:62: VisibleDeprecationWarning: The module `rsciio.utils.rgb_tools` has been renamed to `rsciio.utils.rgb` and it will be removed in version 1.0. Use `RGB_DTYPES` instead
warnings.warn(
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/rsciio/utils/rgb_tools.py:62: VisibleDeprecationWarning: The module `rsciio.utils.rgb_tools` has been renamed to `rsciio.utils.rgb` and it will be removed in version 1.0.
warnings.warn(
Remove baseline using remove_baseline():
s2 = s.remove_baseline(method="aspls", lam=1E7, inplace=False)
0%| | 0/51 [00:00<?, ?it/s]
2%|▏ | 1/51 [00:04<03:34, 4.28s/it]
25%|██▌ | 13/51 [00:05<00:11, 3.38it/s]
29%|██▉ | 15/51 [00:05<00:11, 3.19it/s]
53%|█████▎ | 27/51 [00:06<00:03, 7.61it/s]
100%|██████████| 51/51 [00:06<00:00, 8.38it/s]
Plot the signal and its baseline:
(s + (s-s2) * 1j).plot()
# Choose the second figure as gallery thumbnail:
# sphinx_gallery_thumbnail_number = 2
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/rsciio/utils/rgb_tools.py:62: VisibleDeprecationWarning: The module `rsciio.utils.rgb_tools` has been renamed to `rsciio.utils.rgb` and it will be removed in version 1.0.
warnings.warn(
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/rsciio/utils/rgb_tools.py:62: VisibleDeprecationWarning: The module `rsciio.utils.rgb_tools` has been renamed to `rsciio.utils.rgb` and it will be removed in version 1.0.
warnings.warn(
Total running time of the script: (0 minutes 7.481 seconds)

