Skip to content

Commit

Permalink
Merge pull request #1970 from vallsv/added-d-unit
Browse files Browse the repository at this point in the history
Added d space unit in A
  • Loading branch information
kif authored Oct 9, 2023
2 parents c3b4821 + 32c96ee commit 154585b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pyFAI/gui/utils/test/test_unitutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__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):
result = unitutils.from2ThRad(0.1, units.Q_NM, wavelength=1.03321e-10)
self.assertAlmostEqual(result, 6.0786, places=3)
Expand Down
3 changes: 3 additions & 0 deletions pyFAI/gui/utils/unitutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions pyFAI/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +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_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)"

Expand Down Expand Up @@ -256,6 +257,30 @@ 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",
scale=1e10,
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",
unit_symbol=r"\AA")

register_radial_unit("d*2_A^-2",
center="rd2Array",
delta="deltaRd2",
Expand Down Expand Up @@ -390,6 +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"]
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"]
Expand Down

0 comments on commit 154585b

Please sign in to comment.