|
| 1 | +.. _Transforms Example: |
| 2 | + |
| 3 | +:tocdepth: -1 |
| 4 | + |
| 5 | +Transforms Example |
| 6 | +################## |
| 7 | + |
| 8 | +This example will demonstrate how to use the functions in the |
| 9 | +``diffpy.utils.transforms`` module to process and analyze diffraction data. |
| 10 | + |
| 11 | +1) Converting from ``q`` to ``2theta`` or ``d``: |
| 12 | + If you have a 1D ``q``-array, you can use the ``q_to_tth`` and ``q_to_d`` functions |
| 13 | + to convert it to ``2theta`` or ``d``. :: |
| 14 | + |
| 15 | + # Example: convert q to 2theta |
| 16 | + from diffpy.utils.transformers import q_to_tth |
| 17 | + wavelength = 0.71 |
| 18 | + q = np.array([0, 0.2, 0.4, 0.6, 0.8, 1]) |
| 19 | + tth = q_to_tth(q, wavelength) |
| 20 | + |
| 21 | + # Example: convert q to d |
| 22 | + from diffpy.utils.transformers import q_to_d |
| 23 | + q = np.array([0, 0.2, 0.4, 0.6, 0.8, 1]) |
| 24 | + d = q_to_d(q) |
| 25 | + |
| 26 | +(2) Converting from ``2theta`` to ``q`` or ``d``: |
| 27 | + For a 1D ``2theta`` array, you can convert it to ``q`` or ``d`` in a similar way. :: |
| 28 | + |
| 29 | + # Example: convert 2theta to q |
| 30 | + from diffpy.utils.transformers import tth_to_q |
| 31 | + wavelength = 0.71 |
| 32 | + tth = np.array([0, 30, 60, 90, 120, 180]) |
| 33 | + q = tth_to_q(tth, wavelength) |
| 34 | + |
| 35 | + # Example: convert 2theta to d |
| 36 | + from diffpy.utils.transformers import tth_to_d |
| 37 | + wavelength = 0.71 |
| 38 | + tth = np.array([0, 30, 60, 90, 120, 180]) |
| 39 | + d = tth_to_d(tth, wavelength) |
| 40 | + |
| 41 | +(3) Converting from ``d`` to ``q`` or ``2theta``: |
| 42 | + For a 1D ``d`` array, you can convert it to ``q`` or ``2theta``. :: |
| 43 | + |
| 44 | + # Example: convert d to q |
| 45 | + from diffpy.utils.transformers import tth_to_q |
| 46 | + d = np.array([1.0, 0.8, 0.6, 0.4, 0.2]) |
| 47 | + q = d_to_q(d) |
| 48 | + |
| 49 | + # Example: convert d to 2theta |
| 50 | + from diffpy.utils.transformers import d_to_tth |
| 51 | + wavelength = 0.71 |
| 52 | + d = np.array([1.0, 0.8, 0.6, 0.4, 0.2]) |
| 53 | + tth = d_to_tth(d, wavelength) |
0 commit comments