Skip to content

Commit

Permalink
Invalidate sample layer past critical beta
Browse files Browse the repository at this point in the history
xy points on the detector past the critical beta have very high values
and start appearing unrealistic. Just set any values to nan that are past
the critical beta.

Note that we are not invalidating map values past the critical beta for
now, because they actually appear okay when warping the polar view. This
is because they move too far and disappear (which is actually what we
want when warping to the polar view).

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed Apr 19, 2024
1 parent 67a876d commit 7cf2145
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions hexrd/xrdutil/phutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
class SampleLayerDistortion:
def __init__(self, panel,
layer_standoff, layer_thickness,
pinhole_thickness):
pinhole_thickness, pinhole_radius):
self._panel = panel
self._layer_standoff = layer_standoff
self._layer_thickness = layer_thickness
self._pinhole_thickness = pinhole_thickness
self._pinhole_radius = pinhole_radius

@property
def panel(self):
Expand Down Expand Up @@ -60,12 +61,21 @@ def pinhole_thickness(self):
def pinhole_thickness(self, x):
self._pinhole_thickness = float(x)

@property
def pinhole_radius(self):
return self._pinhole_radius

@pinhole_radius.setter
def pinhole_radius(self, x):
self._pinhole_radius = float(x)

def apply(self, xy_pts, return_nominal=True):
"""
"""
return tth_corr_sample_layer(self.panel, xy_pts,
self.layer_standoff, self.layer_thickness,
self.pinhole_thickness,
self.pinhole_radius,
return_nominal=return_nominal)


Expand Down Expand Up @@ -133,7 +143,8 @@ def apply(self, xy_pts, return_nominal=True):

def tth_corr_sample_layer(panel, xy_pts,
layer_standoff, layer_thickness,
pinhole_thickness, return_nominal=True):
pinhole_thickness, pinhole_radius,
return_nominal=True):
"""
Compute the Bragg angle distortion associated with a specific sample
layer in a pinhole camera.
Expand All @@ -152,13 +163,18 @@ def tth_corr_sample_layer(panel, xy_pts,
The thickness of the sample layer in mm.
pinhole_thickness : scalar
The thickenss (height) of the pinhole (cylinder) in mm
pinhole_radius : scalar
The radius of the pinhole in mm.
Returns
-------
TYPE
DESCRIPTION.
"""
# Compute the critical beta angle. Anything past this is invalid.
critical_beta = np.arctan(2 * pinhole_radius / pinhole_thickness)

source_distance = panel.xrs_dist

xy_pts = np.atleast_2d(xy_pts)
Expand All @@ -173,6 +189,8 @@ def tth_corr_sample_layer(panel, xy_pts,

dhats = xfcapi.unitRowVector(panel.cart_to_dvecs(xy_pts))
cos_beta = -dhats[:, 2]
# Invalidate values past the critical beta
cos_beta[np.arccos(cos_beta) > critical_beta] = np.nan
cos_tthn = np.cos(ref_tth)
sin_tthn = np.sin(ref_tth)
tth_corr = np.arctan(sin_tthn/(source_distance*cos_beta/zs - cos_tthn))
Expand All @@ -185,7 +203,7 @@ def tth_corr_sample_layer(panel, xy_pts,

def tth_corr_map_sample_layer(instrument,
layer_standoff, layer_thickness,
pinhole_thickness):
pinhole_thickness, pinhole_radius):
"""
Compute the Bragg angle distortion fields for an instrument associated
with a specific sample layer in a pinhole camera.
Expand All @@ -201,6 +219,8 @@ def tth_corr_map_sample_layer(instrument,
The thickness of the sample layer in mm.
pinhole_thickness : scalar
The thickenss (height) of the pinhole (cylinder) in mm
pinhole_radius : scalar
The radius of the pinhole in mm.
Returns
-------
Expand All @@ -215,6 +235,11 @@ def tth_corr_map_sample_layer(instrument,
attribute of the same name.
"""
# We currently don't invalidate tth values after the critical beta for
# this map, because it actually looks okay for warping to the polar
# view. But that is something we could do in the future:
# critical_beta = np.arctan(2 * pinhole_radius / pinhole_thickness)

zs = layer_standoff + 0.5*layer_thickness + 0.5*pinhole_thickness
tth_corr = dict.fromkeys(instrument.detectors)
for det_key, panel in instrument.detectors.items():
Expand All @@ -223,6 +248,8 @@ def tth_corr_map_sample_layer(instrument,
xy_data = np.vstack((px.flatten(), py.flatten())).T
dhats = xfcapi.unitRowVector(panel.cart_to_dvecs(xy_data))
cos_beta = -dhats[:, 2]
# Invalidate values past the critical beta
# cos_beta[np.arccos(cos_beta) > critical_beta] = np.nan
cos_tthn = np.cos(ref_ptth.flatten())
sin_tthn = np.sin(ref_ptth.flatten())
tth_corr[det_key] = np.arctan(
Expand All @@ -247,7 +274,7 @@ def tth_corr_pinhole(panel, xy_pts,
pinhole_thickness : scalar
The thickenss (height) of the pinhole (cylinder) in mm
pinhole_radius : scalar
The radius ofhte pinhole in mm.
The radius of the pinhole in mm.
Returns
-------
Expand Down

0 comments on commit 7cf2145

Please sign in to comment.