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

Better DPC Visualization #1031

Open
CSSFrancis opened this issue Mar 14, 2024 · 3 comments
Open

Better DPC Visualization #1031

CSSFrancis opened this issue Mar 14, 2024 · 3 comments

Comments

@CSSFrancis
Copy link
Member

Is your feature request related to a problem? Please describe.
@magnunor do you have any suggestions for how to better visualize DPC measurements in pyxem? It would be nice to have something like:
image

Where we could overlay some displacement on the navigator. @ericpre Any thoughts as well?

Describe the solution you'd like
It looks like most of the color wheels are some version of https://matplotlib.org/stable/api/collections_api.html#matplotlib.collections.QuadMesh which means this should work out quite nicely :).

@CSSFrancis
Copy link
Member Author

For example:

import hyperspy.api as hs
import numpy as np


n = 360  #the number of secants for the mesh
t = np.linspace(0,2*np.pi,n)   #theta values
r = np.linspace(.6,1,2)        #radius values change 0.6 to 0 for full circle

y= np.sin(t[:,np.newaxis])*r[np.newaxis,:]/10
x= np.cos(t[:,np.newaxis])*r[np.newaxis,:]/10
coords = np.stack([x, y], axis=-1)

quad= hs.plot.markers.Markers(collection=matplotlib.collections.QuadMesh, coordinates=coords,
                              array=t[1:], cmap="hsv",
                              transform="axes",offset_transform="axes", 
                              offsets=[[.8,.8]], alpha=1)
                              
                              
s = hs.signals.Signal2D(np.ones((100,100,10,10)))

im = np.random.randint(1,360,(100,100))
nav = hs.signals.Signal2D(im)

s.plot(navigator=nav, navigator_kwds=dict(cmap="hsv", colorbar=False))

s.add_marker(quad, plot_on_signal=False)
image

@CSSFrancis
Copy link
Member Author

Just playing around with other things...

import hyperspy.api as hs
import numpy as np


t = np.linspace(0,2*np.pi,n)   #theta values
r = np.linspace(.6,1,2)        #radius values change 0.6 to 0 for full circle

y= np.linspace(0,1, 11)
x= np.linspace(0,1, 11)

xx,yy = np.meshgrid(x,y)

coords = np.stack([xx, yy], axis=-1)
t = np.zeros((10,10))
t[t==0]=np.nan
rr,cc =disk((5,5), radius=5)
t[rr, cc]=np.random.rand(len(rr))

quad= hs.plot.markers.Markers(collection=matplotlib.collections.QuadMesh, coordinates=coords,
                              array=t, cmap="hsv",
                          transform="axes",offset_transform="display", 
                              offsets=[[0,0]], alpha=0.8)
                              
s = hs.signals.Signal2D(np.random.rand(100,100,10,10))

im = np.random.randint(1,360,(100,100))
nav = hs.signals.Signal2D(im)

s.plot( navigator_kwds=dict(cmap="hsv", colorbar=False))

s.add_marker(quad, plot_on_signal=True)
image

@magnunor
Copy link
Collaborator

Agreed! This is really nice. Similar functionality exist with in the
DPCSignal.get_color_image_with_indicator` method: https://github.com/pyxem/pyxem/blob/main/pyxem/signals/differential_phase_contrast.py#L568

However, it is a a bit sub-optimal, as it returns a matplotlib figure.

The overlay can be added to DPCSignal.get_color_signal: https://github.com/pyxem/pyxem/blob/main/pyxem/signals/differential_phase_contrast.py#L495


The color wheel itself is made here: https://github.com/pyxem/pyxem/blob/main/pyxem/utils/pixelated_stem_tools.py#L214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants