def hologram(self): '''Return hologram of sphere Returns ------- hologram : numpy.ndarray Computed hologram. ''' gpufield = self.alpha * self.field(return_gpu=True) gpufield[0, :] += 1. gpufield = gpufield * gpufield.conj() return np.sum(gpufield.real.get(), axis=0) if __name__ == '__main__': import matplotlib.pyplot as plt from Instrument import coordinates import time shape = [201, 251] # shape = [1024, 1280] h = CudaLMHologram(coordinates=coordinates(shape)) h.particle.r_p = [125, 75, 100] h.instrument.wavelength = 0.447 start = time.time() img = h.hologram().reshape(shape) print(time.time() - start) plt.imshow(img, cmap='gray') plt.show()
if return_gpu is False: hologram = hologram.get() elif self.using_numba: field = self.field() hologram = self.holo fh.fasthologram(field, self.alpha, hologram.size, hologram) else: field = self.alpha * self.field() field[0, :] += 1. hologram = np.sum(np.real(field * np.conj(field)), axis=0) return hologram if __name__ == '__main__': import matplotlib.pyplot as plt from Instrument import coordinates from time import time shape = [201, 201] h = LMHologram(coordinates=coordinates(shape)) h.particle.r_p = [125, 75, 100] h.particle.a_p = 0.9 h.particle.n_p = 1.45 h.instrument.wavelength = 0.447 h.hologram() start = time() hol = h.hologram() print("Time to calculate {}".format(time() - start)) plt.imshow(hol.reshape(shape), cmap='gray') plt.show()
for key in self._keys: params.add(key, getattr(particle, key)) self._minimizer.params = params return self._minimizer.minimize() if __name__ == '__main__': from Instrument import coordinates import numpy as np from lmfit import report_fit import matplotlib.pyplot as plt a = Feature() # Use model to generate synthetic data shape = [201, 201] a.model.coordinates = coordinates(shape) p = a.model.particle p.r_p = [100, 100, 100] p.a_p = 0.75 p.n_p = 1.45 h = a.model.hologram() h += np.random.normal(0., 0.05, h.size) a.data = h # add errors to parameters p.r_p += np.random.normal(0., 1, 3) p.a_p += np.random.normal(0., 0.01, 1) p.n_p += np.random.normal(0., 0.01, 1) # ... and now fit result = a.optimize() report_fit(result) # plot residuals