|
| 1 | +.. _Diffraction Objects Example: |
| 2 | + |
| 3 | +:tocdepth: -1 |
| 4 | + |
| 5 | +Diffraction Objects Example |
| 6 | +########################### |
| 7 | + |
| 8 | +This example will demonstrate how to use the ``DiffractionObject`` class in the |
| 9 | +``diffpy.utils.scattering_objects.diffraction_objects`` module to process and analyze diffraction data. |
| 10 | + |
| 11 | +1) We have the function ``q_to_tth`` to convert q to two theta values in degrees, and ``tth_to_q`` to do the reverse. |
| 12 | + You can use these functions with a pre-defined ``DiffractionObject``. :: |
| 13 | + |
| 14 | + # convert q to tth |
| 15 | + from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject |
| 16 | + test = DiffractionObject(wavelength=1.54) |
| 17 | + test.on_q = [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]] |
| 18 | + test.q_to_tth() |
| 19 | + |
| 20 | + This function will convert your provided q array and return a two theta array in degrees. |
| 21 | + To load the converted array, you can either call ``test.q_to_tth()`` or ``test.on_q[0]``. |
| 22 | + |
| 23 | + Similarly, use the function ``tth_to_q`` to convert two theta values in degrees to q values. :: |
| 24 | + |
| 25 | + # convert tth to q |
| 26 | + from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject |
| 27 | + test = DiffractionObject(wavelength=1.54) |
| 28 | + test.on_tth = [[0, 30, 60, 90, 120, 180], [1, 2, 3, 4, 5, 6]] |
| 29 | + test.tth_to_q() |
| 30 | + |
| 31 | + To load the converted array, you can either call ``test.tth_to_q()`` or ``test.on_tth[0]``. |
| 32 | + |
| 33 | +2) You can use these functions without specifying a wavelength. However, if so, the function will return an empty array, |
| 34 | + so we strongly encourage you to specify a wavelength when using these functions. :: |
| 35 | + |
| 36 | + from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject |
| 37 | + test = DiffractionObject() |
| 38 | + test.on_q = [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]] |
| 39 | + test.q_to_tth() |
| 40 | + |
| 41 | + In this case, the function will return an empty array on two theta. |
0 commit comments