From 72af3adb68c17ab3484c7532be79ee0637c132f0 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Thu, 9 Nov 2023 12:50:36 -0600 Subject: [PATCH] Simplify powder overlay generation This skips swapping columns in the powder overlay generation so that we do not have to swap columns again when we are drawing. This simplifies the logic and speeds it up a little bit. Signed-off-by: Patrick Avery --- hexrdgui/image_canvas.py | 15 ++++----------- hexrdgui/overlays/powder_overlay.py | 25 ++++++++++--------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/hexrdgui/image_canvas.py b/hexrdgui/image_canvas.py index 33e11a0dd..417929c9b 100644 --- a/hexrdgui/image_canvas.py +++ b/hexrdgui/image_canvas.py @@ -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 @@ -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 @@ -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 @@ -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() diff --git a/hexrdgui/overlays/powder_overlay.py b/hexrdgui/overlays/powder_overlay.py index 58fa3db14..e176ac949 100644 --- a/hexrdgui/overlays/powder_overlay.py +++ b/hexrdgui/overlays/powder_overlay.py @@ -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 @@ -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( @@ -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])) @@ -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(