Skip to content

Commit

Permalink
Merge pull request #1612 from HEXRD/simplify-powder-overlays
Browse files Browse the repository at this point in the history
Simplify powder overlay generation
  • Loading branch information
psavery authored Nov 9, 2023
2 parents 35f8ff5 + 72af3ad commit 97c5fbb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
15 changes: 4 additions & 11 deletions hexrdgui/image_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ def draw_powder_overlay(self, artist_key, axis, data, style,
# Override with highlight style
current_style = highlight_style['data']

x, y = self.extract_ring_coords(pr)
x, y = pr.T
artist, = axis.plot(x, y, **current_style)
artists.append(artist)

# Add the rbnds too
for ind, pr in zip(rbnd_indices, rbnds):
x, y = self.extract_ring_coords(pr)
x, y = pr.T
current_style = copy.deepcopy(ranges_style)
if any(x in highlight_indices for x in ind):
# Override with highlight style
Expand All @@ -355,7 +355,7 @@ def draw_powder_overlay(self, artist_key, axis, data, style,
if self.azimuthal_integral_axis is not None:
az_axis = self.azimuthal_integral_axis
for pr in rings:
x, _ = self.extract_ring_coords(pr)
x = pr[:, 0]
if len(x) == 0:
# Skip over rings that are out of bounds
continue
Expand All @@ -367,7 +367,7 @@ def draw_powder_overlay(self, artist_key, axis, data, style,

# Add the rbnds too
for ind, pr in zip(rbnd_indices, rbnds):
x, _ = self.extract_ring_coords(pr)
x = pr[:, 0]
if len(x) == 0:
# Skip over rbnds that are out of bounds
continue
Expand Down Expand Up @@ -570,13 +570,6 @@ def draw_auto_picked_data(self):
self.update_auto_picked_data()
self.draw_idle()

def extract_ring_coords(self, data):
if self.mode == ViewType.cartesian:
# These are in x, y coordinates. Do not swap them.
return data[:, 0], data[:, 1]

return data[:, 1], data[:, 0]

def clear_saturation(self):
for t in self.saturation_texts:
t.remove()
Expand Down
25 changes: 10 additions & 15 deletions hexrdgui/overlays/powder_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,19 @@ def generate_ring_points(self, instr, tths, etas, panel, display_mode):
skipped_tth.append(i)
continue

# Swap columns, convert to degrees
ang_crds[:, [0, 1]] = np.degrees(ang_crds[:, [1, 0]])
# Convert to degrees
ang_crds = np.degrees(ang_crds)

# fix eta period
ang_crds[:, 0] = xfcapi.mapAngle(
ang_crds[:, 0], self.eta_period, units='degrees'
ang_crds[:, 1] = xfcapi.mapAngle(
ang_crds[:, 1], self.eta_period, units='degrees'
)

# sort points for monotonic eta
eidx = np.argsort(ang_crds[:, 0])
eidx = np.argsort(ang_crds[:, 1])
ang_crds = ang_crds[eidx, :]

diff = np.diff(ang_crds[:, 0])
diff = np.diff(ang_crds[:, 1])
if len(diff) == 0:
skipped_tth.append(i)
continue
Expand All @@ -374,8 +374,8 @@ def generate_ring_points(self, instr, tths, etas, panel, display_mode):
# append to list with nan padding
ring_pts.append(np.vstack([ang_crds, nans_row]))
elif display_mode == ViewType.stereo:
# Swap back, convert to radians
ang_crds[:, [0, 1]] = np.radians(ang_crds[:, [1, 0]])
# Convert back to radians
ang_crds = np.radians(ang_crds)

# Convert the ang_crds to stereo ij
stereo_ij = angles_to_stereo(
Expand All @@ -384,10 +384,6 @@ def generate_ring_points(self, instr, tths, etas, panel, display_mode):
HexrdConfig().stereo_size,
)

# FIXME: why??
# swap i and j
stereo_ij[:, [0, 1]] = stereo_ij[:, [1, 0]]

# append to list with nan padding
ring_pts.append(np.vstack([stereo_ij, nans_row]))

Expand All @@ -398,9 +394,8 @@ def generate_ring_points(self, instr, tths, etas, panel, display_mode):
if panel.distortion is not None:
xys = panel.distortion.apply_inverse(xys)

# Convert to pixel coordinates
# ??? keep in pixels?
xys = panel.cartToPixel(xys)
# Convert to pixel coordinates and swap columns
xys = panel.cartToPixel(xys)[:, [1, 0]]

diff_tol = np.radians(self.delta_eta) + 1e-4
ring_breaks = np.where(
Expand Down

0 comments on commit 97c5fbb

Please sign in to comment.