def test_field(self, bohren=False, cartesian=False): p = self.method.particle p.a_p = 1. p.n_p = 1.4 p.r_p = [64, 64, 100] c = coordinates([128, 128]) self.method.coordinates = c field = self.method.field(bohren=bohren, cartesian=cartesian) self.assertEqual(field.shape[1], c.shape[1])
def test_hologram(self): p = self.method.particle p.a_p = 1. p.n_p = 1.4 p.r_p = [64, 64, 100] c = coordinates([128, 128]) self.method.coordinates = c hologram = self.method.hologram() self.assertEqual(hologram.shape[0], c.shape[1])
def setUp(self): data = cv2.imread(TEST_IMAGE, 0).astype(float) data /= np.mean(data) coords = coordinates(data.shape) model = LMHologram(wavelength=0.447, magnification=0.048, n_m=1.34) self.data = data self.coords = coords self.feature = Feature(data=data, coordinates=coords, model=model, percentpix=0.1) model.particle.r_p = [data.shape[0] // 2, data.shape[1] // 2, 330] model.particle.a_p = 1.1 model.particle.n_p = 1.4
def setUp(self): img = cv2.imread(TEST_IMAGE, 0).astype(float) img /= np.mean(img) img = img[::4, ::4] self.shape = img.shape self.data = img.ravel() self.coordinates = 4. * coordinates(self.shape) model = LMHologram(coordinates=self.coordinates) model.instrument.wavelength = 0.447 model.instrument.magnification = 0.048 model.instrument.n_m = 1.34 model.particle.r_p = [self.shape[0] // 2, self.shape[1] // 2, 330] model.particle.a_p = 1.1 model.particle.n_p = 1.4 self.optimizer = Optimizer(model=model)
def test_compare_methods(self): '''check that numpy and cupy pipelines yield consistent results''' shape = [128, 128] c = coordinates(shape) self.method.coordinates = c self.nmethod.coordinates = c p = self.method.particle p.a_p = 1. p.n_p = 1.4 p.r_p = [64, 64, 100] self.nmethod.particle = p field = self.method.field() nfield = self.nmethod.field() inten = np.sum(np.abs(field), axis=0).reshape(shape) ninten = np.sum(np.abs(nfield), axis=0).reshape(shape) self.assertTrue(np.allclose(inten, ninten))
def test_coordinates(self, corner=None): shape = [128, 128] c = coordinates(shape, corner=corner) self.assertEqual(c.shape[1], np.prod(shape))
def test_normal(self): c = coordinates(self.shape, flatten=False) self.assertEqual(c.ndim, 3)
def test_flatten(self): c = coordinates(self.shape) self.assertEqual(c.ndim, 2)
def setUp(self): self.shape = [128, 128] self.coordinates = coordinates(self.shape) self.mask = Mask(self.coordinates)
def test_coordinates(self): c = coordinates(self.shape) self.method.coordinates = c self.assertEqual(self.method.coordinates.shape[1], c.shape[1])
def test_coordinates_2d(self): c = coordinates(self.shape) self.method.coordinates = c self.assertEqual(self.method.coordinates.shape[0], 3) self.assertTrue(np.allclose(self.method.coordinates[0:2, :], c))