From ce68e8cf688f37d4feb1efe09c8f4168a0bfca26 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Thu, 5 Oct 2023 14:09:39 +0200 Subject: [PATCH 1/4] Added d space unit in A --- pyFAI/gui/utils/test/test_unitutils.py | 4 ++++ pyFAI/gui/utils/unitutils.py | 3 +++ pyFAI/units.py | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/pyFAI/gui/utils/test/test_unitutils.py b/pyFAI/gui/utils/test/test_unitutils.py index 3ccad58f9..4aab6da79 100644 --- a/pyFAI/gui/utils/test/test_unitutils.py +++ b/pyFAI/gui/utils/test/test_unitutils.py @@ -50,6 +50,10 @@ def testFrom2ThRad__Q_A(self): result = unitutils.from2ThRad(0.1, units.Q_A, wavelength=1.03321e-10) self.assertAlmostEqual(result, 0.6078, places=3) + def testFrom2ThRad__RecD_A(self): + result = unitutils.from2ThRad(0.1, units.RecD_A, wavelength=1.03321e-10) + self.assertAlmostEqual(result, 10.3364, places=3) + def testFrom2ThRad__Q_NM(self): result = unitutils.from2ThRad(0.1, units.Q_NM, wavelength=1.03321e-10) self.assertAlmostEqual(result, 6.0786, places=3) diff --git a/pyFAI/gui/utils/unitutils.py b/pyFAI/gui/utils/unitutils.py index 2c5ced213..17d28b224 100644 --- a/pyFAI/gui/utils/unitutils.py +++ b/pyFAI/gui/utils/unitutils.py @@ -116,6 +116,9 @@ def from2ThRad(twoTheta, unit, wavelength=None, directDist=None, ai=None): else: beamCentre_m = ai.getFit2D()["directDist"] * 1e-3 # convert in m return beamCentre_m * numpy.tan(twoTheta) * unit.scale + elif unit.space == "d": + q_m = (4.0 * numpy.pi / wavelength) * numpy.sin(0.5 * twoTheta) + return (2 * numpy.pi / q_m) * unit.scale elif unit.space == "d*2": rec_d2_nm = (2e-9 / wavelength * numpy.sin(0.5 * twoTheta)) ** 2 return rec_d2_nm * unit.scale diff --git a/pyFAI/units.py b/pyFAI/units.py index fe8a15f06..d2d18f694 100644 --- a/pyFAI/units.py +++ b/pyFAI/units.py @@ -193,6 +193,7 @@ def eq_q(x, y, z, wavelength): formula_2th = "arctan2(sqrt(x * x + y * y), z)" formula_chi = "arctan2(y, x)" formula_q = "4.0e-9*π/λ*sin(arctan2(sqrt(x * x + y * y), z)/2.0)" +formula_d = "λ*sin(arctan2(sqrt(x * x + y * y), z)/2.0)/2.0e-9" formula_d2 = "(2.0e-9/λ*sin(arctan2(sqrt(x * x + y * y), z)/2.0))**2" formula_qx = "4.0e-9*π/λ*sin(arctan2(x, z)/2.0)" formula_qy = "4.0e-9*π/λ*sin(arctan2(y, z)/2.0)" @@ -256,6 +257,16 @@ def eq_q(x, y, z, wavelength): short_name="q", unit_symbol=r"\AA^{-1}") +register_radial_unit("d_A", + center="qArray", + delta="deltaQ", + scale=1e10, + label=r"Recip. spacing sq. $d$ ($\AA$)", + equation=lambda x, y, z, wavelength: ((2.0 * numpy.pi) / (1e9 * eq_q(x, y, z, wavelength))), + formula=formula_d, + short_name="d", + unit_symbol=r"\AA") + register_radial_unit("d*2_A^-2", center="rd2Array", delta="deltaRd2", @@ -390,6 +401,7 @@ def to_unit(obj, type_=None): TTH_DEG = TTH = RADIAL_UNITS["2th_deg"] R = R_MM = RADIAL_UNITS["r_mm"] R_M = RADIAL_UNITS["r_m"] +RecD_A = RADIAL_UNITS["d_A"] RecD2_NM = RADIAL_UNITS["d*2_nm^-2"] RecD2_A = RADIAL_UNITS["d*2_A^-2"] l_m = LENGTH_UNITS["m"] From 1b8f705b48c9c5d0f27cc2c83a033c9bd0f2d513 Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Fri, 6 Oct 2023 15:33:30 +0200 Subject: [PATCH 2/4] fix units --- pyFAI/units.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pyFAI/units.py b/pyFAI/units.py index d2d18f694..f177f05c5 100644 --- a/pyFAI/units.py +++ b/pyFAI/units.py @@ -192,9 +192,9 @@ def eq_q(x, y, z, wavelength): formula_r = "sqrt(x * x + y * y)" formula_2th = "arctan2(sqrt(x * x + y * y), z)" formula_chi = "arctan2(y, x)" -formula_q = "4.0e-9*π/λ*sin(arctan2(sqrt(x * x + y * y), z)/2.0)" -formula_d = "λ*sin(arctan2(sqrt(x * x + y * y), z)/2.0)/2.0e-9" -formula_d2 = "(2.0e-9/λ*sin(arctan2(sqrt(x * x + y * y), z)/2.0))**2" +formula_q = "4.0e-9*π/λ*sin(0.5*arctan2(sqrt(x * x + y * y), z))" +formula_d = "0.5*λ/sin(0.5*arctan2(sqrt(x * x + y * y), z))" +formula_d2 = "(2.0e-9/λ*sin(0.5*arctan2(sqrt(x * x + y * y), z)))**2" formula_qx = "4.0e-9*π/λ*sin(arctan2(x, z)/2.0)" formula_qy = "4.0e-9*π/λ*sin(arctan2(y, z)/2.0)" @@ -257,11 +257,25 @@ def eq_q(x, y, z, wavelength): short_name="q", unit_symbol=r"\AA^{-1}") +register_radial_unit("d_m", + scale=1, + label=r"d-spacing $d$ ($m$)", + equation=lambda x, y, z, wavelength: ((2.0 * numpy.pi) / (1e9 * eq_q(x, y, z, wavelength))), + formula=formula_d, + short_name="d", + unit_symbol=r"m") + +register_radial_unit("d_nm", + scale=1e9, + label=r"d-spacing $d$ ($nm$)", + equation=lambda x, y, z, wavelength: ((2.0 * numpy.pi) / (1e9 * eq_q(x, y, z, wavelength))), + formula=formula_d, + short_name="d", + unit_symbol=r"nm") + register_radial_unit("d_A", - center="qArray", - delta="deltaQ", scale=1e10, - label=r"Recip. spacing sq. $d$ ($\AA$)", + label=r"d-spacing $d$ ($\AA$)", equation=lambda x, y, z, wavelength: ((2.0 * numpy.pi) / (1e9 * eq_q(x, y, z, wavelength))), formula=formula_d, short_name="d", From e4e910fce29e1e881c4f9bae4cdfd0b73e2a3240 Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Mon, 9 Oct 2023 14:53:48 +0200 Subject: [PATCH 3/4] Correct unit name --- pyFAI/gui/utils/test/test_unitutils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyFAI/gui/utils/test/test_unitutils.py b/pyFAI/gui/utils/test/test_unitutils.py index 4aab6da79..9a79f86ae 100644 --- a/pyFAI/gui/utils/test/test_unitutils.py +++ b/pyFAI/gui/utils/test/test_unitutils.py @@ -50,8 +50,8 @@ def testFrom2ThRad__Q_A(self): result = unitutils.from2ThRad(0.1, units.Q_A, wavelength=1.03321e-10) self.assertAlmostEqual(result, 0.6078, places=3) - def testFrom2ThRad__RecD_A(self): - result = unitutils.from2ThRad(0.1, units.RecD_A, wavelength=1.03321e-10) + def testFrom2ThRad__D_A(self): + result = unitutils.from2ThRad(0.1, units.D_A, wavelength=1.03321e-10) self.assertAlmostEqual(result, 10.3364, places=3) def testFrom2ThRad__Q_NM(self): From 32c96ee94b5233426822579e235ae01060d98a23 Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Mon, 9 Oct 2023 14:55:31 +0200 Subject: [PATCH 4/4] rename unit name --- pyFAI/units.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyFAI/units.py b/pyFAI/units.py index f177f05c5..5f325de92 100644 --- a/pyFAI/units.py +++ b/pyFAI/units.py @@ -415,7 +415,9 @@ def to_unit(obj, type_=None): TTH_DEG = TTH = RADIAL_UNITS["2th_deg"] R = R_MM = RADIAL_UNITS["r_mm"] R_M = RADIAL_UNITS["r_m"] -RecD_A = RADIAL_UNITS["d_A"] +D_A = RADIAL_UNITS["d_A"] +D_NM = RADIAL_UNITS["d_nm"] +D_M = RADIAL_UNITS["d_m"] RecD2_NM = RADIAL_UNITS["d*2_nm^-2"] RecD2_A = RADIAL_UNITS["d*2_A^-2"] l_m = LENGTH_UNITS["m"]