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

Fix align1D #2675

Merged
merged 2 commits into from Mar 15, 2021
Merged

Fix align1D #2675

merged 2 commits into from Mar 15, 2021

Conversation

ericpre
Copy link
Member

@ericpre ericpre commented Mar 13, 2021

As reported by @mwalls on gitter, the align1D is not working properly. The reason is that the data is not normalised before computing the cross correlation. I am surprised that it was not reported before!

Progress of the PR

  • Normalise by subtracting the mean before calculating the cross correlation,
  • add tests,
  • add entry to CHANGES.rst ,
  • ready for review.

Minimal example of the bug fix

scale = 0.1
g = hs.model.components1D.Gaussian(sigma=scale*5)
x = np.stack([np.linspace(-5, 5, 100)]*5)
s = hs.signals.Signal1D(g.function(x) + 1E5)
s.axes_manager[-1].scale = scale
shifts = np.random.random(len(s.axes_manager[0].axis)) * 2
shifts[0] = 0
s.shift1D(-shifts, show_progressbar=False)
shifts2 = s.estimate_shift1D(show_progressbar=False)
np.testing.assert_allclose(shifts, shifts2, rtol=0.3)

@codecov
Copy link

codecov bot commented Mar 13, 2021

Codecov Report

Merging #2675 (65958dd) into RELEASE_next_patch (8363b6e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##           RELEASE_next_patch    #2675   +/-   ##
===================================================
  Coverage               76.62%   76.62%           
===================================================
  Files                     201      201           
  Lines                   29684    29681    -3     
  Branches                 6500     6500           
===================================================
- Hits                    22744    22743    -1     
  Misses                   5177     5177           
+ Partials                 1763     1761    -2     
Impacted Files Coverage Δ
hyperspy/_signals/signal1d.py 72.95% <100.00%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8363b6e...65958dd. Read the comment docs.

@jlaehne
Copy link
Contributor

jlaehne commented Mar 15, 2021

Looks good and works on both the test provided above and on the example provided from @mwalls on gitter.

@jlaehne jlaehne merged commit 240bf42 into hyperspy:RELEASE_next_patch Mar 15, 2021
@ericpre ericpre deleted the fix_align1D branch March 15, 2021 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants