Skip to content

Commit b28cd6a

Browse files
committed
Add preliminary pyfai morph
1 parent c4dd740 commit b28cd6a

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

docs/source/funcxy.rst

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,102 @@ scaling factor ``bgscale``.
2626

2727
We will showcase an example of how one would refine over the
2828
``PDFGetter`` parameters using ``funcxy`` to obtain a PDF.
29-
.. code-block::
3029

31-
from diffpy.pdfgetx.pdfgetter import PDFGetter
32-
from diffpy.morph.morphpy import morph_arrays
33-
from diffpy.utils.parsers.loaddata import loadData
30+
Let's say you have a measured I(Q) with Q in angstroms of a lead
31+
nanoparticle (composition PbS) named ``sample.chi`` taken on a
32+
glass background. We want to match a target calculated PDF G(r)
33+
stored in a file named ``target.cgr``.
34+
Let's also say we have a measured I(Q) of the
35+
glass background ``background.chi``.
36+
.. code-block:: python
3437
38+
from diffpy.pdfgetx.pdfgetter import PDFGetter
39+
from diffpy.morph.morphpy import morph_arrays
40+
from diffpy.utils.parsers.loaddata import loadData
3541
42+
pg = PDFGetter()
43+
44+
backgroundfile = loadData("background.chi")
45+
composition = "PbS"
46+
47+
48+
def wrap(x, y, **kwargs):
49+
xy_out = pg.__call__(
50+
x=x, y=y, dataformat="QA",
51+
composition=composition,
52+
backgroundfile=backgroundfile,
53+
**kwargs
54+
)
55+
r = xy_out[0]
56+
gr = xy_out[1]
57+
return (r, gr)
58+
59+
60+
sample_iq = loadData("sample.chi")
61+
target_gr = loadData("target.cgr")
62+
params_to_morph = {
63+
"bgscale": 1.0,
64+
"qmin": 0.0, "qmax": 25.0,
65+
"qmaxinst": 25.0, "rpoly": 0.9
66+
}
67+
68+
morph_info, morph_table = morph_arrays(
69+
sample_iq, target_gr,
70+
funcxy=(wrap, params_to_morph)
71+
)
72+
73+
74+
You can now plot ``morph_table`` against your ``target_gr`` to see
75+
how well your morphing refinement of the PDF-getting parameters
76+
as done!
77+
To see what the refined values of the parameters are,
78+
print out ``morph_info``.
79+
You can freely add and remove entries in
80+
``params_to_morph`` to include or not include them as
81+
parameters to refine over.
82+
83+
If you expect to see thermal effect differences between your
84+
measured PDF and ``target_gr``, you can also include
85+
the ``stretch``, ``scale``, and ``smear`` morphs in your
86+
call to ``morph_arrays``.
3687

3788

3889
Performing Detector Calibration with PyFai
3990
==========================================
91+
When performing azimuthal integration, it is important to
92+
ensure your beam center and detector distances are calibrated.
93+
However, it is possible that they have shifted
94+
across measurements. Here, we will use morphing to the rescue!
95+
96+
Let's say we just measured a diffraction pattern stored
97+
as a NumPy object in ``diffraction_image.npy``, but some
98+
of the detector geometries are off.
99+
Before this measurement, you measured an amazing
100+
I(Q) pattern ``target.chi`` with a perfectly calibrated
101+
sample-to-detector distance and beam center.
102+
We will use morphing to try to recalibrate.
103+
104+
.. code-block:: python
105+
106+
import numpy as np
107+
import pyFAI.integrator.azimuthal as pyfai
108+
import pyFAI.detectors as pfd
109+
from diffpy.morph.morphpy import morph_arrays
110+
from diffpy.utils.parsers.loaddata import loadData
111+
112+
pattern_2d = np.load("diffraction_image.npy")
113+
wavelength = #
114+
pixel1 = #
115+
pixel2 = #
116+
117+
ai = pyfai.AzimuthalIntegrator()
118+
ai.wavelength = wavelength
119+
detector = pfd.Detector()
120+
detector.max_shape = pattern_2d.shape
121+
122+
def wrap(x, y, sample_to_detector_dist, cent_offset_x, cent_offset_y):
123+
detector.pixel1 = pixel1
124+
detector.pixel2 = pixel2
125+
126+
127+
ai.detector = detector

0 commit comments

Comments
 (0)