Skip to content

Commit 7d69d35

Browse files
committed
Add links to tutorials
1 parent b28cd6a commit 7d69d35

File tree

3 files changed

+79
-10
lines changed

3 files changed

+79
-10
lines changed

docs/source/funcxy.rst

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Using funcxy with Commonly-Used Diffraction Software
44
####################################################
5+
56
The general xy morph ``funcxy`` can be used to tune parameters
67
of many popular diffraction software functions.
78

@@ -11,6 +12,7 @@ and `PyFai <https://pyfai.readthedocs.io/en/stable/>`_.
1112

1213
Getting a Better PDF with PDFgetx3
1314
==================================
15+
1416
In PDFgetx3, the ``PDFGetter`` takes in a 1D diffraction
1517
pattern I(Q) and returns a PDF G(r).
1618

@@ -33,6 +35,7 @@ glass background. We want to match a target calculated PDF G(r)
3335
stored in a file named ``target.cgr``.
3436
Let's also say we have a measured I(Q) of the
3537
glass background ``background.chi``.
38+
3639
.. code-block:: python
3740
3841
from diffpy.pdfgetx.pdfgetter import PDFGetter
@@ -65,13 +68,12 @@ glass background ``background.chi``.
6568
"qmaxinst": 25.0, "rpoly": 0.9
6669
}
6770
68-
morph_info, morph_table = morph_arrays(
71+
morph_info, morphed_gr = morph_arrays(
6972
sample_iq, target_gr,
7073
funcxy=(wrap, params_to_morph)
7174
)
7275
73-
74-
You can now plot ``morph_table`` against your ``target_gr`` to see
76+
You can now plot ``morphed_gr`` against your ``target_gr`` to see
7577
how well your morphing refinement of the PDF-getting parameters
7678
as done!
7779
To see what the refined values of the parameters are,
@@ -88,6 +90,7 @@ call to ``morph_arrays``.
8890

8991
Performing Detector Calibration with PyFai
9092
==========================================
93+
9194
When performing azimuthal integration, it is important to
9295
ensure your beam center and detector distances are calibrated.
9396
However, it is possible that they have shifted
@@ -96,10 +99,24 @@ across measurements. Here, we will use morphing to the rescue!
9699
Let's say we just measured a diffraction pattern stored
97100
as a NumPy object in ``diffraction_image.npy``, but some
98101
of the detector geometries are off.
102+
Our azimuthally integrated ``sample.chi`` looks a bit off.
99103
Before this measurement, you measured an amazing
100104
I(Q) pattern ``target.chi`` with a perfectly calibrated
101105
sample-to-detector distance and beam center.
102-
We will use morphing to try to recalibrate.
106+
We will use morphing to try to match the integration of
107+
the 2D pattern to the target 1D function.
108+
109+
For the integration, we will need some information, such as
110+
the wavelength of the beam,
111+
the size of each pixel in the 2D image
112+
(``pixel1`` is the horizontal length in meters and
113+
``pixel2`` is the vertical length in meters),
114+
and a guess of the beam center.
115+
This information can be found on the
116+
`PyFai documentation <https://pyfai.readthedocs.io/en/stable/usage/cookbook/integration_with_python.html>`_.
117+
For our example, let's say we have a ``1024``x``1024`` pixel image
118+
where each pixel is a ``100`` micron by ``100`` micron region, and
119+
our wavelength was ``1.11`` angstroms.
103120

104121
.. code-block:: python
105122
@@ -110,18 +127,55 @@ We will use morphing to try to recalibrate.
110127
from diffpy.utils.parsers.loaddata import loadData
111128
112129
pattern_2d = np.load("diffraction_image.npy")
113-
wavelength = #
114-
pixel1 = #
115-
pixel2 = #
130+
wavelength = 0.1110e-9 # in m
131+
pixel1 = 1e-4 # in m
132+
pixel2 = 1e-4 # in m
133+
cent_x = 511 # in number of pixels
134+
cent_y = 511 # in number of pixels
116135
117136
ai = pyfai.AzimuthalIntegrator()
118137
ai.wavelength = wavelength
119138
detector = pfd.Detector()
120139
detector.max_shape = pattern_2d.shape
121140
141+
122142
def wrap(x, y, sample_to_detector_dist, cent_offset_x, cent_offset_y):
123143
detector.pixel1 = pixel1
124144
detector.pixel2 = pixel2
145+
ai.detector = detector
125146
147+
ai.setFit2D(
148+
directDist=sample_to_detector_dist,
149+
centerX=cent_x+cent_offset_x,
150+
centerY=cent_y+cent_offset_y
151+
)
126152
127-
ai.detector = detector
153+
return ai.integrate1D_ng(
154+
pattern_2d,
155+
npt=1000, unit="q_A^-1",
156+
method="mean"
157+
)
158+
159+
160+
params_to_morph = {
161+
"sample_to_detector_dist": 60, # in mm
162+
"cent_offset_x": 0, # in number of pixels
163+
"cent_offset_y": 0 # in number of pixels
164+
}
165+
166+
sample_chi = loadData("sample.chi")
167+
target_chi = loadData("target.chi")
168+
169+
morph_info, morphed_chi = morph_arrays(
170+
sample_chi, target_chi,
171+
funcxy=(wrap, params_to_morph)
172+
)
173+
174+
You can now plot ``morphed_chi`` against your ``target_chi``
175+
to see if the refinement has helped in the calibration!
176+
To see the calibrated values, you can print out ``morph_info``.
177+
178+
If you would like to morph over other PyFai parameters
179+
(e.g. ``rot1``, ``tilt``, ``wavelength``),
180+
you can adjust the wrapper function ``wrap`` to take in
181+
these parameters.

docs/source/morphpy.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ This page is intended for those acquainted with the basic morphs
1010
described in the aforementioned quickstart tutorial who want to use ``diffpy.morph`` in their
1111
Python scripts.
1212

13+
For those looking to use the Python-specific morph ``MorphFuncxy`` (described below)
14+
with commonly used diffraction software like `PDFgetx3 <https://www.diffpy.org/products/pdfgetx.html>`_
15+
and `PyFai <https://pyfai.readthedocs.io/en/stable/>`_ are directed to the
16+
`funcxy tutorials <funcxy.html>`__.
17+
1318
Python Morphing Functions
1419
=========================
1520

@@ -408,8 +413,10 @@ This is equivalent to applying a ``MorphFuncx`` and ``MorphFuncy``
408413
simultaneously.
409414

410415
This morph is useful when you want to apply operations that modify both
411-
the grid and function value. A PDF-specific example includes computing
412-
PDFs from 1D diffraction data (see paragraph at the end of this section).
416+
the grid and function value.
417+
Examples of using ``MorphFuncxy`` with ``PyFai`` azimuthal integration
418+
and ``PDFgetx3`` PDF calculation are included `here <funcxy.html>`__.
419+
413420

414421
For this tutorial, we will go through two examples. One simple one
415422
involving shifting a function in the ``x`` and ``y`` directions, and

docs/source/tutorials.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Tutorials for these are included below. The files required for these tutorials c
88

99
For a full list of options offered by ``diffpy.morph``, please run ``diffpy.morph --help`` on the command line.
1010

11+
Using MorphFuncxy
12+
=================
13+
14+
Examples of how to use the general morph ``MorphFuncxy`` with commonly used
15+
diffraction software like `PDFgetx3 <https://www.diffpy.org/products/pdfgetx.html>`_
16+
and `PyFai <https://pyfai.readthedocs.io/en/stable/>`_ are directed to the
17+
`funcxy tutorials <funcxy.html>`__.
18+
1119
Performing Multiple Morphs
1220
==========================
1321

0 commit comments

Comments
 (0)