def setUp(self): ins = Instrument(magnification=.048, wavelength=.447, n_m=1.335) p1 = Sphere(r_p=[150, 150, 200], a_p=1., n_p=1.45) p2 = Sphere(r_p=[75, 75, 150], a_p=1.25, n_p=1.61) coords = coordinates((201, 201)) self.model = GeneralizedLorenzMie(coords, [p1, p2], ins) self.fast_model = FastGeneralizedLorenzMie(coords, [p1, p2], ins) self.cuda_model = CudaGeneralizedLorenzMie(coords, [p1, p2], ins)
def make_sample(config): '''Returns an array of Sphere objects''' particle = config['particle'] nrange = particle['nspheres'] mpp = config['instrument']['magnification'] if nrange[0] == nrange[1]: nspheres = nrange[0] else: nspheres = np.random.randint(nrange[0], nrange[1]) sample = [] for n in range(nspheres): np.random.seed() sphere = Sphere() for prop in ('a_p', 'n_p', 'k_p', 'z_p'): setattr(sphere, prop, make_value(particle[prop])) ##Making sure separation between particles is large enough## close = True aval = sphere.a_p zval = sphere.z_p while close: close = False xval = make_value(particle['x_p']) yval = make_value(particle['y_p']) for s in sample: xs, ys, zs = s.x_p, s.y_p, s.z_p atest = s.a_p dist = np.sqrt((xs - xval)**2 + (ys - yval)**2 + (zs - zval)**2) threshold = (atest + aval) / mpp if dist < threshold: close = True setattr(sphere, 'x_p', xval) setattr(sphere, 'y_p', yval) sample.append(sphere) return sample
def __init__(self, a_p=None, n_p=None, r_p=None, particle=None, **kwargs): ''' Parameters ---------- a_p : float or numpy.ndarray, optional Starting radius of sphere. Alternatively, can be an array of radii of concentric shells within the sphere n_p : complex or numpy.ndarray, optional Starting refractive index of sphere. Alternatively, can be an array of refractive indexes of the shells. r_p : numpy.ndarray or list, optional coordinates of sphere center: (x_p, y_p, z_p) ''' super(LorenzMie, self).__init__(**kwargs) self.particle = Sphere() if a_p is not None: self.particle.a_p = a_p if n_p is not None: self.particle.n_p = n_p if r_p is not None: self.particle.r_p = r_p
def make_sample(config): '''Returns an array of Sphere objects''' particle = config['particle'] nrange = particle['nspheres'] nspheres = np.random.randint(nrange[0], nrange[1]) sample = [] for n in range(nspheres): sphere = Sphere() for prop in ('a_p', 'n_p', 'k_p', 'x_p', 'y_p', 'z_p'): setattr(sphere, prop, make_value(particle[prop])) sample.append(sphere) return sample
def feature_extent(sphere, config, nfringes=20): '''Radius of holographic feature in pixels''' s = Sphere() s.a_p = sphere.a_p s.n_p = sphere.n_p s.z_p = sphere.z_p h = LMHologram(coordinates=np.arange(300)) h.instrument.properties = config['instrument'] h.particle = sphere # roughly estimate radii of zero crossings b = h.hologram() - 1. ndx = np.where(np.diff(np.sign(b)))[0] + 1 return float(ndx[nfringes])
def setUp(self): self.particle = Sphere() self.fast_particle = FastSphere() self.particle.r_p = (100, 200, 300) self.fast_particle.r_p = (100, 200, 300)
if __name__ == '__main__': from pylorenzmie.theory.Instrument import Instrument from pylorenzmie.theory.Sphere import Sphere import matplotlib.pyplot as plt # Create coordinate grid for image x = np.arange(0, 201) y = np.arange(0, 201) xv, yv = np.meshgrid(x, y) xv = xv.flatten() yv = yv.flatten() zv = np.zeros_like(xv) coordinates = np.stack((xv, yv, zv)) # Place a sphere in the field of view, above the focal plane particle = Sphere() particle.r_p = [125, 75, 100] particle.a_p = 0.5 particle.n_p = 1.45 # Form image with default instrument instrument = Instrument() instrument.magnification = 0.135 instrument.wavelength = 0.447 instrument.n_m = 1.335 k = instrument.wavenumber() # Use Generalized Lorenz-Mie theory to compute field kernel = CudaGeneralizedLorenzMie(coordinates=coordinates, particle=particle, instrument=instrument) field = kernel.field() # Compute hologram from field and show it