Skip to content

Commit

Permalink
Fix branch cut logic for smaller eta steps
Browse files Browse the repository at this point in the history
Smaller values in eta step were breaking the branch cut logic here.

The problem is that the arc length was not always less than 1e-4 when
the eta_step was small (such as 0.05). It was less than 1e-2, so still
close to zero, but not small enough.

Then on top of that, some of the ring break logic was not working.

To fix both of those issues, we loosen the logic to instead check to
see if nearly the whole two pi range is covered, and if there is a big
gap. If there is, then we assume it is a branch cut. And we locate the
break via the big gap.

This worked properly for eta step values from 0.01 to 1

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
  • Loading branch information
psavery committed Nov 13, 2023
1 parent afa23aa commit d5864da
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions hexrd/instrument/hedm_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -2687,33 +2687,24 @@ def _generate_ring_params(tthr, ptth, peta, eta_edges, delta_eta):
[reta_idx,
reta_idx[-1] + 1]
)
eta_bins = eta_edges[reta_bin_idx]

# ring arc lenght on panel
arc_length = angularDifference(
eta_edges[reta_bin_idx[0]],
eta_edges[reta_bin_idx[-1]]
)
arc_length = eta_edges[reta_bin_idx][-1] - eta_edges[reta_bin_idx][0]
etas_span_2pi = (arc_length / (2 * np.pi)) > 0.99

# Munge eta bins
# !!! need to work with the subset to preserve
# NaN values at panel extents!
#
# !!! MUST RE-MAP IF BRANCH CUT IS IN RANGE
#
# The logic below assumes that eta_edges span 2*pi to
# single precision
eta_bins = eta_edges[reta_bin_idx]
if arc_length < 1e-4:
# have branch cut in here
ring_gap = np.where(
reta_idx
- np.arange(len(reta_idx))
)[0]
if len(ring_gap) > 0:
# have incomplete ring
eta_stop_idx = ring_gap[0]
eta_stop = eta_edges[eta_stop_idx]
if etas_span_2pi:
eta_bins_diff = np.diff(eta_bins)
has_big_gap = eta_bins_diff.max() > np.median(eta_bins_diff) * 2

if has_big_gap:
# If there is a big gap and the eta values span nearly the
# whole two pi range, assume we have a branch cut. We must remap.

# Find the biggest gap.
eta_stop_idx = np.argmax(eta_bins_diff) + 1
eta_stop = eta_bins[eta_stop_idx]
new_period = np.cumsum([eta_stop, 2*np.pi])

# remap
retas = mapAngle(retas, new_period)
tmp_bins = mapAngle(
Expand Down

0 comments on commit d5864da

Please sign in to comment.