Skip to content

Commit

Permalink
DOC: added tutorial for autocenter
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Jan 13, 2021
1 parent 95f9ea8 commit 3f38346
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
46 changes: 46 additions & 0 deletions docs/tutorials/image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,52 @@ The :func:`diffread` function will transparently distinguish between those forma

.. _alignment:

Automatic center-finding
========================

Many analyses involving diffraction patterns require the knowledge of the center. For this purpose, ``scikit-ued``
provides :func:`autocenter`. It can be used trivially as follows:

>>> from skued import diffread, autocenter
>>> import numpy as np
>>>
>>> im = diffread('docs/tutorials/Cr_1.tif')
>>>
>>> # Invalid pixels are masked with a False
>>> mask = np.ones_like(ref, dtype = np.bool)
>>> mask[0:1250, 975:1225] = False
>>>
>>> center = autocenter(im, mask=mask)

Let's take a look at the result. The center is shown with a red dot:

.. plot::

from skued import diffread, autocenter
import matplotlib.pyplot as plt

im = diffread('Cr_1.tif')

mask = np.ones_like(im, dtype = np.bool)
mask[0:1250, 975:1225] = False

# Reduce size of images because of memory usage of ReadTheDocs
im = im[::3, ::3]
mask = mask[::3, ::3]

rc, cc = autocenter(im, mask=mask)

fig, ax1 = plt.subplots(figsize = (3,3))
ax1.imshow(im, vmin = 0, vmax = 200, cmap='inferno')
ax1.scatter(cc, rc, color='r')

ax1.get_xaxis().set_visible(False)
ax1.get_yaxis().set_visible(False)

plt.tight_layout()
plt.show()


Diffraction pattern alignment
=============================

Expand Down
18 changes: 9 additions & 9 deletions skued/image/center.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ def autocenter(im, mask=None):
Returns
-------
r, c : 2-tupe of ints
Indices of the center, such that `im[r, c]` is the intensity value at
Indices of the center, such that ``im[r, c]`` is the intensity value at
the center of the pattern.
Notes
-----
The procedure in this routine is an extension of [1]. First, the center-of-mass
of the image intensity profile is found. This approximate center is
then used to radially-invert the image, with the coordinate transform
:math:`(r, \\theta) \\to (-r, \\theta)`. Diffraction patterns reflect this
inversion symmetry, and so the shift between the original and inverted image
is the correction to the approximate center found in the first step.
The procedure in this routine is an extension of the one in the reference below.
It has been adapted for both single-crystal and polycrystalline diffraction patterns
The continuous inversion symmetry is encoded as the coordinate transformation
:math:`(r, \\theta) \\to (-r, \\theta)`. The shift between the image and inverted image
is the correction to the approximate center found by calculating the intensity
center-of-mass.
References
----------
.. [1] Liu, Lai Chung. Chemistry in Action: Making Molecular Movies with Ultrafast
Electron Diffraction and Data Science, Chapter 2. Springer Nature, 2020.
Liu, Lai Chung. Chemistry in Action: Making Molecular Movies with Ultrafast
Electron Diffraction and Data Science, Chapter 2. Springer Nature, 2020.
"""

im = np.asfarray(im)
Expand Down

0 comments on commit 3f38346

Please sign in to comment.