def calc_coords(self, indices=None, drop_zero=False, frame_shape=None, r=0): ''' Shorthand to calculate peak coordinates. Parameters ---------- indices : numpy.ndarray Indices to calculate coordinates for. Both an array of (y, x) pairs and the output of np.mgrid are supported. drop_zero : bool Drop the zero order peak. This is important for virtual darkfield imaging. frame_shape : Tuple[int, int] If set, the peaks are filtered with :meth:`~libertem.analysis.gridmatching.within_frame` r : float Radius for :meth:`~libertem.analysis.gridmatching.within_frame` Returns ------- numpy.ndarray A list of (y, x) coordinate pairs for peaks Raises ------ ValueError If the shape of :code:`indices` is not as expected. ''' if indices is None: indices = self.indices s = indices.shape # Output of mgrid if (len(s) == 3) and (s[0] == 2): indices = np.concatenate(indices.T) # List of (i, j) pairs elif (len(s) == 2) and (s[1] == 2): pass else: raise ValueError( "Shape of indices is %s, expected (n, 2) or (2, n, m)" % str(indices.shape)) selector = np.ones(len(indices), dtype=np.bool) if drop_zero: nz = np.any(indices != 0, axis=1) selector *= nz peaks = calc_coords(self.zero, self.a, self.b, indices) if frame_shape is not None: fy, fx = frame_shape selector *= within_frame(peaks, r, fy, fx) return peaks[selector]
def calculated_refineds(self): ''' numpy.ndarray : Calculated peak positions based on lattice parameters and indices. ''' return calc_coords(self.zero, self.a, self.b, self.indices)