hyperspy / exspy

EDS and EELS data analysis with HyperSpy
https://hyperspy.org/exspy
GNU General Public License v3.0
11 stars 10 forks source link

Background window fixes and improvement #86

Closed ericpre closed 1 month ago

ericpre commented 2 months ago

Fix #79.

Progress of the PR

Minimal example of the bug fix or the new feature

import exspy
import numpy as np

s = exspy.data.EDS_TEM_FePt_nanoparticles()

# create a signal with navgation dimension >= 2
rng = np.random.default_rng()
[s * v*10 for v in rng.random((10))]
s = hs.stack([s * v*10 for v in rng.random((10))])
s = hs.stack([s * v*10 for v in rng.random((5))])

bw = s.estimate_background_windows(line_width=[5.0, 2.0])
iw = s.estimate_integration_windows(windows_width=3)

s.plot(True, background_windows=bw, integration_windows=iw)

Raise the following error:

    s.plot(True, background_windows=bw, integration_windows=iw)

  File ~\Dev\exspy\exspy\signals\eds.py:933 in plot
    self._plot_xray_lines(

  File ~\Dev\exspy\exspy\signals\eds.py:989 in _plot_xray_lines
    self._add_background_windows_markers(

  File ~\Dev\exspy\exspy\signals\eds.py:1140 in _add_background_windows_markers
    segments = np.array(segments)

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 3 dimensions. The detected shape was (4, 2, 2) + inhomogeneous part.
codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.82%. Comparing base (de1eade) to head (88d752e). Report is 4 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #86 +/- ## ========================================== + Coverage 88.70% 88.82% +0.12% ========================================== Files 77 77 Lines 7453 7475 +22 Branches 1200 1205 +5 ========================================== + Hits 6611 6640 +29 + Misses 572 567 -5 + Partials 270 268 -2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ericpre commented 2 months ago

@CSSFrancis, can you please have a look at this PR, it seems that the migration to new markers API didn't support navigation dimension >=2.

ericpre commented 1 month ago

Going to merge for now to fix this regression and in the interest of making a release. The lazy marker approach should be explored to see if it helps for large navigation space (>1E6 coordinate).

CSSFrancis commented 1 month ago

Going to merge for now to fix this regression and in the interest of making a release.

The lazy marker approach should be explored to see if it helps for large navigation space (>1E6 coordinate).

Yea we are struggling with this in pyxem as well 😅 something about creating a large ragged array is very slow in numpy. Hopefully that is something that the awkward package could fix or we could try using numba.