forked from pyxem/pyxem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pyxem:main' into multi-phase-marker-support
- Loading branch information
Showing
38 changed files
with
240 additions
and
1,876 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Differential Phase Contrast (DPC) | ||
================================= | ||
Below is a gallery of examples on how to do Differential Phase Contrast (DPC) in pyxem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Plotting | ||
======== | ||
Below is a gallery of examples on how to plot data in pyxem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
Fast Plotting Tricks | ||
==================== | ||
Sometimes you want to quickly plot a diffraction pattern but things seem slow, | ||
this mostly happens with "large" data that is loaded Lazily. | ||
There are a couple of different ways that plotting in hyperspy/pyxem can be slow: | ||
1. The data is too large and the navigator is being recalculated every time you plot. (i.e. calling s.plot() | ||
takes a long time to render) | ||
2. Dragging the navigator is slow and laggy. | ||
""" | ||
|
||
from pyxem.data import fe_multi_phase_grains | ||
import numpy as np | ||
import hyperspy.api as hs | ||
|
||
s = fe_multi_phase_grains().as_lazy() | ||
|
||
# %% | ||
# Pre Computing a Navaigator | ||
# -------------------------- | ||
# To solve the first problem, you can: | ||
# | ||
# 1. Precompute the navigator using the :meth:`hyperspy.api.signals.plot` method or | ||
# the :meth:`hyperspy._signals.LazySignal.compute_navigator` method | ||
# which will compute the navigator and store it in the signal. This will make plotting faster. | ||
|
||
s.compute_navigator() | ||
print(s.navigator) | ||
|
||
# %% | ||
# Setting a Navigator | ||
# ------------------- | ||
# 2. You can also set the navigator directly using `s.navigator = ...` if you have a navigator | ||
# that you want to use. This is useful if a virtual image is created along with the signal when | ||
# the data is acquired. This will also save the navigator in the metadata. This is similar to the | ||
# :meth:`hyperspy._signals.LazySignal.compute_navigator`method of the signal and | ||
# will be saved when the signal is saved. | ||
|
||
dummy_navigator = hs.signals.Signal2D(np.ones((20, 20))) # just a dummy navigator | ||
s.navigator = dummy_navigator | ||
# or | ||
s.plot(navigator=dummy_navigator) | ||
|
||
# %% | ||
# Using a Slider to Navigate | ||
# -------------------------- | ||
# 3. You also don't need to plot the navigator every time you plot the signal. You can set | ||
# `navigator = "slider"` to avoid plotting the navigator altogether and just use the sliders. | ||
|
||
s.plot(navigator="slider") | ||
|
||
|
||
# %% | ||
# Using the QT Backend and Blitting | ||
# --------------------------------- | ||
# To solve the second problem, you can: | ||
# | ||
# 1. Use the Qt backend by running `%matplotlib qt` in a Jupyter notebook cell. This will make the | ||
# navigator much more responsive using "blitting" which only updates the parts of the plot that | ||
# have changed. Note that the QT backend is not available in Google Colab or when running in a | ||
# Jupyter notebook on a remote server. | ||
# | ||
# Using Shift + Click to Jump | ||
# --------------------------- | ||
# 2. You can use the Shift + Click feature to "Jump" to a specific location in the navigator. | ||
# This is useful if you want to quickly move to a specific location in the navigator without | ||
# dragging the navigator and loading all the data in between. | ||
# | ||
# 3. You can also set the navigator point using the `axes_manager.indices` attribute. | ||
|
||
s.axes_manager.indices = (5, 5) # jump to the center of the navigator | ||
s.plot() | ||
|
||
# %% | ||
# Saving the Data | ||
# --------------- | ||
# 4. Finally, you can always consider saving the data in a more performant format like `.zspy` | ||
# This will make loading the data faster which will in turn make plotting faster! | ||
s.save("fast_and_compressed.zspy") | ||
|
||
hs.load("fast_and_compressed.zspy").plot() # reload the data and plot it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Plotting a Diffraction Pattern | ||
============================== | ||
This is sometimes not as straightforward as it seems because you might have a zero | ||
beam that is too bright and regions of the diffraction pattern that are too dark. | ||
""" | ||
|
||
from pyxem.data import fe_multi_phase_grains | ||
|
||
mulit_phase = fe_multi_phase_grains() | ||
|
||
# %% | ||
# We can plot easily using the `plot` method. This will show the diffraction pattern | ||
# but the plot is static and not interactive. Additionally, the zero beam is too bright | ||
# and the high k values are too dark. | ||
|
||
mulit_phase.plot() | ||
|
||
# %% | ||
# Plotting the diffraction pattern with a logarithmic scale can help to see the high k values | ||
# But because most of the values are zero, the contrast is not great and is too stretched. | ||
|
||
mulit_phase.plot(norm="log") | ||
|
||
# %% | ||
# You can also use the `symlog` norm to plot the diffraction pattern with a logarithmic scale | ||
# but with a linear scale around zero. This can be useful to see the zero beam and the high k values. | ||
# additionally you can visualize negative and positive values as well. | ||
|
||
mulit_phase.plot(norm="symlog") | ||
|
||
# %% | ||
# We can also set vmin and vmax to control the contrast. This can be useful to see the high k values. | ||
# A very useful feature is the ability to plot the diffraction pattern with vmax set to the 99th percentile. | ||
# This sets the maximum value to the 99th percentile of the data. In general this works better than setting | ||
# norm='log' if you have zero values in the diffraction pattern. | ||
|
||
mulit_phase.plot(vmax="99th") | ||
|
||
# %% | ||
# We can also use a gamma correction to control and optimize the contrast. | ||
|
||
mulit_phase.plot(norm="power", gamma=0.4) | ||
|
||
|
||
# %% | ||
# Note: that any of the plots are interactive if you add: | ||
# %matplotlib ipympl or %matplotlib qt at the beginning of a Jupyter notebook cell. | ||
# %matplotlib inline will make the plots static. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import numpy | ||
|
||
if numpy.__version__ >= "1.25.0": | ||
from numpy.exceptions import VisibleDeprecationWarning | ||
else: | ||
from numpy import VisibleDeprecationWarning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.