-
Notifications
You must be signed in to change notification settings - Fork 206
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
Add support for specifying axes for the navigator and "streak" navigator #3309
base: RELEASE_next_minor
Are you sure you want to change the base?
Add support for specifying axes for the navigator and "streak" navigator #3309
Conversation
…ation dimension only; Deprecate support for navigator with signal dimension, to be removed in hyperspy 3.0
@CSSFrancis, this PR changes which navigation axes are displayed in the image navigator, because it simplify the code - at the least with the approach currently used! ;) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## RELEASE_next_minor #3309 +/- ##
======================================================
+ Coverage 80.31% 80.58% +0.26%
======================================================
Files 147 147
Lines 21854 21871 +17
Branches 5140 5146 +6
======================================================
+ Hits 17553 17624 +71
+ Misses 3088 3033 -55
- Partials 1213 1214 +1 ☔ View full report in Codecov by Sentry. |
Hmmm, in my case I have a bunch of 5D STEM data where the axes are <x, y, time | kx, ky>. We could represent the data as My original thought was that we should make it so that if someone passes a navigator which has a signal and navigation axes then that plot should become the interactive navigator with the signal updating and the navigator static. This gives the most flexibility and you could possibly stack navigators to have 6,7 etc dimensions. |
I guess that doesn't really get at the core of the problem which is that sometimes you want to have a plot that updates along the outer most dimension. You could add in a |
d2fdac4
to
be5d726
Compare
Yes, this is the right way to approach it and it makes the implementation more straightforward. This is done, as per example above.
Actually, it may be possible without too much trouble, but we can leave that for another day! 😉 |
be5d726
to
89f0aa8
Compare
89f0aa8
to
282f443
Compare
@jlaehne, do you think that this PR would help with the representation of streak data as discussed in LumiSpy/lumispy#20? @LMSC-NTappy, does it look useful to you? |
@ericpre Definitely looks useful to me. Thanks! Just a question: would Also, that's just a detail but I am not certain that naming the "streak" denomination is optimal as this way of displaying the data will have uses beyond streak maps. |
Thanks @Attolight-NTappy!
In the example above, axis 0 is a navigation axes and axis 2 is the first signal axes, using "name" of the axis is more clear - I updated the example accordingly. Using an axes from signal space is only supported for Signal1D - because for Signal2D, it is not sensible as it would be the same as the signal plot!
Indeed, I was not sure if "steak" was a good wording, but I couldn't think of anything better. In the context of EELS, I have seen it being used to visualise energy shift over time. |
Sorry I was away and am rather busy right now. But I will do my best to have a look and play with some real data with this branch asap. |
a8cb0a0
to
7d16d1e
Compare
Makes sense to me ! Unfortunately, I don't have a suggestion for another word than "streak" on top of my head. Something like "linescan" maybe? I think it would be useful to use a word that links intuitively with "map" |
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.
@ericpre This looks really good!
As far as implementations go I think that this is much cleaner than previous which is good, but we might want to think about how we want to do this in the future to be a bit kinder to ourselves.
I think that ultimately we want a couple of things:
- Markers which update with the navigator.
- Multiple Navigators for higher dimensional datasets.
I think that lends itself to passing navigators with both signal and navigation axes so it might be good to leave that as an option.
@@ -3044,30 +3070,35 @@ def sum_wrapper(s, axis): | |||
) | |||
return s.sum(axis) | |||
|
|||
def get_static_explorer_wrapper(*args, **kwargs): | |||
def get_static_explorer(*args, **kwargs): | |||
data = np.nan_to_num(to_numpy(navigator.data)) |
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.
Is there a reason to convert the nan to a number for plotting? Nan's are actually quite useful when you are overlaying two plots as the nan part of the image is transparent.
Of course we don't currently have a way to layer images but I actually have thought about something like passing two navigators and overlaying the two images. For something like orientation mapping it might be nice to overlay the phase with an alpha of like .5 and then have the values where no phase is found be nan.
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 reason is that if there is a single np.nan
, the sum will np.nan
:
import numpy as np
a = np.empty(10)
a[0] = np.nan
print(np.sum(a))
gives
nan
By default, np.nan_to_num
set the nan
values to zero but it is possible to set to something else, which should give enough flexibility for what you have in mind, when implemented.
navigation_shape == shape | ||
or navigation_shape[:2] == shape | ||
or (navigation_shape[0],) == shape | ||
if navigator.axes_manager.signal_dimension > 0: |
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.
Is it going to be weird if we deprecate this and then bring this back at some point?
I would like to support navigators with signal dimensions eventually.
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.
I can have a look: It may possible without too much trouble. Can you elaborate how do you see working?
Something as:
s = hs.signals.Signal1D(np.arange(5*10*20*40).reshape((20, 10, 5, 40)))
s2 = s.sum(-1).as_signal1D(-1)
s.plot(navigator=s2)
Where the s
pointer will also be added to the signal dimension of s2
?
As we need to check the consistent in shape between the signal dimension of the provided navigator signal (s2
) and the corresponding navigation dimension(s) of s
, how do we define which navigation dimension of s
should it be matched to?
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.
Okay so I'll start with the example that is most relevant to me:
If you have a time resolved 4D STEM dataset you might want something like this:
import hyperspy.api as hs
import numpy as np
time_series_navigator = hs.signals.Signal2D(np.arange(5*10*10).reshape((5, 10,10))) # <Signal2D, title: , dimensions: (5|10, 10)>
full5Ddata = hs.signals.Signal2D(np.arange(5*10*10*128*128).reshape((5, 10,10, 128,128))) # <Signal2D, title: , dimensions: (10, 10, 5|128, 128)>
updating_nav_pos = np.empty(5, dtype=object)
for i in np.ndindex(updating_nav_pos.shape):
updating_nav_pos[i] = np.random.random((np.random.randint(3,5), 2))
p1 = hs.plot.markers.Points(updating_nav_pos)
full5Ddata.plot(navigator=time_series_navigator) # plots three figures the navigator for time_series_navigator, the signal for time_series_navigator and the signal for full5Ddata
time_series_navigator.add_marker(p1) # add an updating navigator to the navigator plot
With the output being something like:
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 shouldn't be too difficult from the standpoint of writing new code, but tracking everything is going be a bit of a pain so I might end up coming back to it in a bit once I get the time.
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.
@CSSFrancis, I removed the deprecation.
A bug I had when plotting with this PR: In the case of the navigator map and image shown above, when I move the position on the navigator, the axes labels in the image plot are suddenly lost. |
@CSSFrancis, I had a look and it is getting a bit messy with the current implementation. I think that this should be done after the plotting have refactor to allow resizable pointer and to decoupled from the
@jlaehne: unrelated to this PR, recently, I noticed that the colorbar intermittently disappear and this seems to be related to blitting and the issue you are referring may falling in this case. Can you please provide the code to reproduce it? |
@ericpre I would agree. I think the plotting could be cleaned up a bit. I looked at it too and realized that it is a bit more complicated than I thought as well to add that feature. Any chance you want make an issue and maybe we can start to develop a step by step road map for things we want to do with the plotting? |
|
7d16d1e
to
8d9e544
Compare
@jlaehne, as mentioned in LumiSpy/lumispy#204 (comment), this PR allow plotting streak images with additional navigation dimension.
Progress of the PR
upcoming_changes
folder (seeupcoming_changes/README.rst
),readthedocs
doc build of this PR (link in github checks)Minimal example of the bug fix or the new feature