Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added d space unit in A #1970

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__RecD_A(self):
result = unitutils.from2ThRad(0.1, units.RecD_A, wavelength=1.03321e-10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/RecD_A/D_A/ see comment in units.py

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
30 changes: 28 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,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"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be D_A since the unit is in real space, not in Recreciprocal space. Would be nice to declare D_NM and D_M as well.

RecD2_NM = RADIAL_UNITS["d*2_nm^-2"]
RecD2_A = RADIAL_UNITS["d*2_A^-2"]
l_m = LENGTH_UNITS["m"]
Expand Down
Loading