Skip to content

Commit

Permalink
DOC: kinematic example
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Jan 16, 2021
1 parent 3e0ce33 commit ce4cf96
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
43 changes: 43 additions & 0 deletions docs/tutorials/simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Contents
========

* :ref:`powdersim`
* :ref:`kinematicsim`
* :ref:`electrostatic`

.. _powdersim:
Expand Down Expand Up @@ -57,6 +58,48 @@ After plot formatting:
plt.ylabel('Diffracted intensity (A.u.)')
plt.title('Polycrystalline graphite diffraction')


.. _kinematicsim:

Kinematical single-crystal simulation
=====================================
Single-crystal kinematical diffraction simulation is available via the :func:`kinematicsim` function:

>>> from crystals import Crystal
>>> from skued import kinematicsim
>>> import numpy as np
>>>
>>> extent = np.linspace(-10, 10, num=1024)
>>> kx, ky = np.meshgrid(extent, extent)
>>> kk = np.sqrt(kx**2 + ky**2)
>>>
>>> crystal = Crystal.from_database('C') # graphite
>>> I = kinematicsim(crystal, kx=kx, ky=ky, energy=50)

.. plot::

from crystals import Crystal
from skued import kinematicsim
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter

extent = np.linspace(-10, 10, num=1024)
kx, ky = np.meshgrid(extent, extent)
kk = np.sqrt(kx**2 + ky**2)

I = kinematicsim(Crystal.from_database("C"), kx=kx, ky=ky, energy=50)
I[kk < 1] = 0.0

# Clean up the image a bit
I[:] = gaussian_filter(I, sigma=3)

fig, ax = plt.subplots(1,1, figsize=(4.5, 4.5))
ax.imshow(I, vmax=0.9*I.max(), cmap='inferno')
ax.axis('off')

plt.show()

.. _electrostatic:

Electrostatic Potential Simulation
Expand Down
4 changes: 2 additions & 2 deletions skued/simulation/kinematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def kinematicsim(crystal, kx, ky, energy=90):
Parameters
----------
crystal : skued.Crystal
crystal : crystals.Crystal
Crystal from which to scatter.
kx, ky : `~numpy.ndarray`, shape (N,M)
Momenta mesh where to calculate the diffraction pattern [:math:`Å^{-1}`]
Expand All @@ -49,7 +49,7 @@ def kinematicsim(crystal, kx, ky, energy=90):
extent_y,
indexing="xy",
)
kx_, ky_ = fft.fft2freq(xx, yy, indexing="xy")
kx_, ky_ = fft2freq(xx, yy, indexing="xy")
k = np.hypot(kx_, ky_)

potential = pelectrostatic(crystal, xx, yy)
Expand Down

0 comments on commit ce4cf96

Please sign in to comment.