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 a211eaa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 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
6 changes: 3 additions & 3 deletions skued/image/center.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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
Expand All @@ -40,8 +40,8 @@ def autocenter(im, mask=None):
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 a211eaa

Please sign in to comment.