Skip to content

Commit

Permalink
Fix applying powder masks
Browse files Browse the repository at this point in the history
Since the `rbnds` are no longer sorted in start/stop pairs, we have
to add some logic to handle it better.

We don't want to go back to the start/stop pair setup because it
was error-prone and would make overlay rendering a little slower.

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed Nov 10, 2023
1 parent 715a565 commit cf9b726
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions hexrdgui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,30 @@ def action_edit_apply_powder_mask_to_polar(self):
data = []
for overlay in powder_overlays:
for _, val in overlay.data.items():
a = iter(val['rbnds'])
for start, end in zip(a, a):
# We will only apply masks for ranges that have both a
# start and a stop.
start_end_pairs = {}
for i, indices in enumerate(val['rbnd_indices']):
for idx in indices:
# Get the pair for this HKL index
pairs = start_end_pairs.setdefault(idx, [])
if len(pairs) == 2:
# We already got this one (this shouldn't happen)
continue

pairs.append(val['rbnds'][i])

# We only want to use the ranges once each.
# Since we found a use of this range already,
# just break.
break

for key in list(start_end_pairs):
# Remove any ranges that have a missing half
if len(start_end_pairs[key]) < 2:
del start_end_pairs[key]

for start, end in start_end_pairs.values():
ranges = np.append(start, np.flip(end, axis=0), axis=0)
ranges = np.append(ranges, [ranges[0]], axis=0)
data.append(ranges[~np.isnan(ranges).any(axis=1)])
Expand Down

0 comments on commit cf9b726

Please sign in to comment.