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

Background window fixes and improvement #86

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

ericpre
Copy link
Member

@ericpre ericpre commented Sep 18, 2024

Fix #79.

Progress of the PR

  • Raise error when windows is out of the range of the signal,
  • fix plotting windows with navigation dimension >=2,
  • [n/a] docstring updated (if appropriate),
  • [n/a] update user guide (if appropriate),
  • added tests,
  • add a changelog entry in the upcoming_changes folder (see upcoming_changes/README.rst),
  • Check formatting of the changelog entry (and eventual user guide changes) in the docs/readthedocs.org:exspy build of this PR (link in github checks)
  • ready for review.

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.

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ericpre
Copy link
Member Author

ericpre commented Sep 18, 2024

@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 ericpre added this to the v0.3 milestone Sep 18, 2024
@ericpre ericpre added bug Something isn't working enhancement New feature or request needs review labels Sep 18, 2024
Copy link
Member

@CSSFrancis CSSFrancis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericpre This looks good to me although the scaling not being linear is a bit concerning and probably should be investigated...

Comment on lines +1159 to +1164
# convert to ragged array to comply with requirement for
# navigation position dependent markers
# 2000 x 2000 navigation shape takes ~2s
# 1000 x 1000 navigation shape takes ~0.5s
# 500 x 500 navigation shape takes ~0.01s
segments = np.empty(self.axes_manager.navigation_shape, dtype=object)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this doesnt scale linearly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, maybe it would be good to check if using lazy markers help here, I would assume so but off the top of my head, I don't remember how they work!

@ericpre
Copy link
Member Author

ericpre commented Oct 8, 2024

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).

@ericpre ericpre force-pushed the background_window_improvement branch from 4b844b0 to 88d752e Compare October 8, 2024 09:20
@ericpre ericpre merged commit 58cf3cd into hyperspy:main Oct 8, 2024
18 checks passed
@CSSFrancis
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request needs review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Background Window Plotting not working with 2D signal
2 participants