def conventional_xc(self, square_size, disc_radius, upsample_factor): """Refines the peaks using (phase) cross correlation. Parameters ---------- square_size : int Length (in pixels) of one side of a square the contains the peak to be refined. disc_radius: int Radius (in pixels) of the discs that you seek to refine upsample_factor: int Factor by which to upsample the patterns Returns ------- vector_out: DiffractionVectors DiffractionVectors containing the refined vectors in calibrated units with the same navigation shape as the diffraction patterns. """ def _conventional_xc_map( dp, vectors, sim_disc, upsample_factor, center, calibration ): shifts = np.zeros_like(vectors, dtype=np.float64) for i, vector in enumerate(vectors): expt_disc = get_experimental_square(dp, vector, square_size) shifts[i] = _conventional_xc(expt_disc, sim_disc, upsample_factor) return ((vectors + shifts) - center) * calibration sim_disc = get_simulated_disc(square_size, disc_radius) self.vectors_out = self.dp.map( _conventional_xc_map, vectors=self.vector_pixels, sim_disc=sim_disc, upsample_factor=upsample_factor, center=self.center, calibration=self.calibration, inplace=False, ) self.vectors_out.set_signal_type("diffraction_vectors") self.last_method = "conventional_xc" return self.vectors_out
def conventional_xc(self, square_size, disc_radius, upsample_factor): """Refines the peaks using (phase) cross correlation. Parameters ---------- square_size : int Length (in pixels) of one side of a square the contains the peak to be refined. disc_radius: int Radius (in pixels) of the discs that you seek to refine upsample_factor: int Factor by which to upsample the patterns Returns ------- vector_out: np.array() array containing the refined vectors in calibrated units """ self.vectors_out = np.zeros( (self.dp.data.shape[0], self.dp.data.shape[1], self.vectors_init.shape[0], self.vectors_init.shape[1])) sim_disc = get_simulated_disc(square_size, disc_radius) for i in np.arange(0, len(self.vectors_init)): vect = self.vectors_pixels[i] expt_disc = self.dp.map( get_experimental_square, vector=vect, square_size=square_size, inplace=False) shifts = expt_disc.map( _conventional_xc, sim_disc=sim_disc, upsample_factor=upsample_factor, inplace=False) self.vectors_out[:, :, i, :] = (((vect + shifts.data) - self.center) * self.calibration) self.last_method = "conventional_xc" return self.vectors_out
def test_failure_for_non_even_entry_to_get_simulated_disc(): disc = get_simulated_disc(61, 5)
def test_failure_for_non_even_entry_to_get_simulated_disc(): with pytest.raises(ValueError, match="'square_size' must be an even number"): disc = get_simulated_disc(61, 5)
def test_non_even_errors_get_simulated_disc(): disc = get_simulated_disc(61, 5)
def sim_disc(): return get_simulated_disc(60, 5)