Skip to content

Commit

Permalink
Merge branch 'pyxem:main' into multi-phase-marker-support
Browse files Browse the repository at this point in the history
  • Loading branch information
viljarjf authored Oct 24, 2024
2 parents 98c8cde + 7446071 commit f1ae201
Show file tree
Hide file tree
Showing 38 changed files with 240 additions and 1,876 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.


Unreleased
==========
Added
-----
- Added Examples for general plotting functions focusing on plotting diffraction patterns (#1108)

Removed
-------
- Removed Dependency on pyfai. Azimuthal integration is all handled internally (#1103)

2024-06-10 - version 0.19.1
===========================
Fixed
Expand Down
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
"navigation_with_keys": True,
"show_toc_level": 2,
"use_edit_page_button": True,
"announcement": "Check out the new "
"<a href='https://pyxem.readthedocs.io/en/latest/examples/index.html'>Examples Gallery!</a> ",
"switcher": {
"json_url": "https://pyxem.readthedocs.io/en/latest/_static/switcher.json",
"version_match": version_match,
Expand Down
2 changes: 0 additions & 2 deletions doc/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ explanations of the functionality.
:toctree: generated
:template: custom-module-template.rst

detectors
data
components
dummy_data
generators
libraries
signals
Expand Down
3 changes: 3 additions & 0 deletions examples/dpc/README.rst
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.
3 changes: 3 additions & 0 deletions examples/plotting/README.rst
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.
84 changes: 84 additions & 0 deletions examples/plotting/fast_plotting_tricks.py
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
50 changes: 50 additions & 0 deletions examples/plotting/plotting_a_diffraction_pattern.py
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.
2 changes: 1 addition & 1 deletion examples/processing/determining_ellipticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

s.unit = "k_nm^-1"
s.beam_energy = 200
s.set_ai(affine=affine)
s.calibration.affine = affine
az = s.get_azimuthal_integral2d(npt=100, inplace=False)
corr = s.apply_affine_transformation(affine, inplace=False)

Expand Down
2 changes: 0 additions & 2 deletions pyxem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
except ImportError:
CUPY_INSTALLED = False
from pyxem import components
from pyxem import detectors
from pyxem import signals
from pyxem import generators
from pyxem import data
Expand All @@ -39,7 +38,6 @@

__all__ = [
"components",
"detectors",
"generators",
"signals",
"data",
Expand Down
6 changes: 6 additions & 0 deletions pyxem/common.py
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
2 changes: 2 additions & 0 deletions pyxem/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
sped_ag,
pdcusi_insitu,
)
from pyxem.data.simulated_dpc import simulated_stripes

__all__ = [
"au_grating",
Expand All @@ -65,6 +66,7 @@
"si_grains",
"si_grains_simple",
"si_rotations_line",
"simulated_stripes",
"fe_multi_phase_grains",
"fe_fcc_phase",
"fe_bcc_phase",
Expand Down
30 changes: 0 additions & 30 deletions pyxem/detectors/__init__.py

This file was deleted.

65 changes: 0 additions & 65 deletions pyxem/detectors/generic_flat_detector.py

This file was deleted.

53 changes: 0 additions & 53 deletions pyxem/detectors/medipix_256x256.py

This file was deleted.

Loading

0 comments on commit f1ae201

Please sign in to comment.