-
Notifications
You must be signed in to change notification settings - Fork 84
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
Improving Masked Correlation Methods #750
base: main
Are you sure you want to change the base?
Conversation
I've been playing around a bit with GPU stuff recently; in my opinion the
The main issue one has to keep in mind is that copying the data from memory or disk to the GPU and back is expensive, so ideally one does a copy, does all the processing on the GPU, and then copies back. Creating a cupy array from numpy/disk does this automatically, creating a numpy array from cupy sends it back. It does not make sense for each operation to send the data to the GPU and back, so hyperspy signals should support cupy arrays natively as |
@din14970 Thanks for the comment. For the most part I think I am more interested in the second case. My datasets are in the 10-100+ Gb in size so there isn't really an easy way out for me as I can't load the data entirely onto a GPU, or even into RAM for that fact. I think the best case scenario is just adding in the line I might try and mess around with this to see if I can't get this to just run right out of the box just dropping in a Cupy array rather than a numpy one. |
@pc494 I think that this one should be ready to go. I'm going to hold off on adding any GPU enabled stuff for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a bit of cleaning up in terms of the docstrings.
pyxem/signals/polar_diffraction2d.py
Outdated
pad_axes=(-1, -2), | ||
inplace=False, | ||
**kwargs): | ||
r"""Returns cross correlation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring could do with being more specific, as there are a number of subtly different "cross correlations" in the literature.
inplace=False, | ||
**kwargs): | ||
r"""Returns cross correlation. | ||
Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these no longer match the function signature.
Angular correlation with a static matst for | ||
|
||
""" | ||
correlation = self.map(cross_correlate, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would put this inside the if clause for clarity
overlap_ratio=0.3): | ||
""" | ||
Masked normalized cross-correlation between two arrays. | ||
Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these don't agree with the function signature
pad_axis=(-1), | ||
overlap_ratio=0.3): | ||
""" | ||
Masked normalized cross-correlation between two arrays. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the latex form of the equation would help clarity here
@CSSFrancis there are just a few small things here to close this one out, are you able to do them, or should someone else pick it up? |
@dnjohnstone I was planning on doing this quickly today. I've got most of the changes done, just needed to find the time to clean it up some more. |
After looking at this a little bit more I think that this might better be added to skimage than into pyxem. I will start a PR there and see if there is any interest adding to skimage before copying the code into pyxem. |
This PR should be closed with the addition into scikit-image below. All further correlation methods should just call the cross_correlate_masked function from skimage. scikit-image/scikit-image#5573 Holding off for now until this is merged... |
name: Improving Masked Correlation Methods
about: I think that pyXem might be benefited by a couple of general correlation methods which can be worked to improved rather than having multiple different spots where correlations are calculated. This PR attempts to create a general method (or set of methods) which can be called.
Checklist
What does this PR do? Please describe and/or link to an open issue.
This code expands the ability of correlating two images to give much more flexibility in how the correlation method is called. More specifically this method allows for:
I think there is also a possibility that this will help out with some of the code in indexation_utils. After this PR I want to write a template matching function that matches a full template in polar coordinates.
Work in progress?
Because these methods are mostly FFT's they could be greatly improved by finding a GPU implementation. I might try to play around with adding in GPU support but it might be that the GPU implementation has to be upstreamed to the map function.