def create_many_particle_state(imsize=None, N=None, phi=None, radius=5.0, polydispersity=0.0, seed=None, **kwargs): """ Creates a random packing of spheres and generates the state. In order to specify the state, either (phi, imsize) or (N, phi) or (N, imsize) must be given. Any more than that and it would be over-specified. Parameters: ----------- imsize : tuple, array_like, or integer the unpadded image size to fill with particles N : integer number of particles phi : float packing fraction radius : float radius of particles to add N : integer Number of particles seed : integer set the seed if desired *args, **kwargs : see create_state """ _seed_or_not(seed) if imsize is not None: imsize = _toarr(imsize) tile = util.Tile(imsize) else: tile = None pos, rad, tile = nbody.create_configuration(N, tile, radius=radius, phi=phi, polydispersity=polydispersity) s = create_state(util.NullImage(shape=tile.shape), pos, rad, **kwargs) if isinstance(s.get('ilm'), ilms.BarnesStreakLegPoly2P1D): ilm = s.get('ilm') ilm.randomize_parameters() s.reset() s.model_to_data(s.sigma) return s
def create_img(): """Creates an image, as a `peri.util.Image`, which is similar to the image in the tutorial""" # 1. particles + coverslip rad = 0.5 * np.random.randn(POS.shape[0]) + 4.5 # 4.5 +- 0.5 px particles part = objs.PlatonicSpheresCollection(POS, rad, zscale=0.89) slab = objs.Slab(zpos=4.92, angles=(-4.7e-3, -7.3e-4)) objects = comp.ComponentCollection([part, slab], category='obj') # 2. psf, ilm p = exactpsf.FixedSSChebLinePSF(kfki=1.07, zslab=-29.3, alpha=1.17, n2n1=0.98, sigkf=-0.33, zscale=0.89, laser_wavelength=0.45) i = ilms.BarnesStreakLegPoly2P1D(npts=(16,10,8,4), zorder=8) b = ilms.LegendrePoly2P1D(order=(7,2,2), category='bkg') off = comp.GlobalScalar(name='offset', value=-2.11) mdl = models.ConfocalImageModel() st = states.ImageState(util.NullImage(shape=[48,64,64]), [objects, p, i, b, off], mdl=mdl, model_as_data=True) b.update(b.params, BKGVALS) i.update(i.params, ILMVALS) im = st.model + np.random.randn(*st.model.shape) * 0.03 return util.Image(im)
def create_two_particle_state(imsize, radius=5.0, delta=1.0, seed=None, axis='x', **kwargs): """ Creates a two particle state Parameters: ----------- imsize : tuple, array_like, or integer the unpadded image size to fill with particles radius : float radius of particles to add delta : float separation between the two particles seed : integer set the seed if desired *args, **kwargs : see create_state """ _seed_or_not(seed) imsize = _toarr(imsize) comp = {'x': 2, 'y': 1, 'z': 0} t = float(radius) + float(delta) / 2 d = np.array([0.0, 0.0, 0.0]) d[comp[axis]] = t pos = np.array([imsize / 2 - d, imsize / 2 + d]).reshape(-1, 3) rad = np.array([radius, radius]) return create_state(util.NullImage(shape=imsize), pos, rad, **kwargs)
def create_single_particle_state(imsize, radius=5.0, seed=None, **kwargs): """ Creates a single particle state Parameters: ----------- imsize : tuple, array_like, or integer the unpadded image size to fill with particles radius : float radius of particles to add seed : integer set the seed if desired *args, **kwargs : see create_state """ _seed_or_not(seed) imsize = _toarr(imsize) pos = imsize.reshape(-1, 3) / 2.0 rad = radius return create_state(util.NullImage(shape=imsize), pos, rad, **kwargs)
def model_to_data(self, sigma=0.0): """ Switch out the data for the model's recreation of the data. """ im = self.model.copy() im += sigma * np.random.randn(*im.shape) self.set_image(util.NullImage(image=im))
import pylab as pl import numpy as np from peri import states, runner, util from peri.comp import psfs, objs, ilms, exactpsf, GlobalScalar from peri.viz import interaction from peri.test import nbody im = util.NullImage(np.zeros((32, ) * 3)) pos, rad, tile = nbody.create_configuration(30, im.tile) def make_image_0(): P = objs.PlatonicSpheresCollection(pos, rad) H = psfs.AnisotropicGaussian() I = ilms.BarnesStreakLegPoly2P1D(npts=(20, 10), local_updates=True) B = GlobalScalar('bkg', 0.0) C = GlobalScalar('offset', 0.0) I.randomize_parameters() return states.ImageState(im, [B, I, H, P, C], pad=16, model_as_data=True) def make_image_1(): P = objs.PlatonicSpheresCollection(pos, rad) H = psfs.AnisotropicGaussian() I = ilms.LegendrePoly3D(order=(5, 3, 3), constval=1.0) B = ilms.Polynomial3D(order=(3, 1, 1), category='bkg', constval=0.01) C = GlobalScalar('offset', 0.0) return states.ImageState(im, [B, I, H, P, C], pad=16, model_as_data=True)
from peri import states, util, models from peri.comp import psfs, objs, ilms, GlobalScalar, ComponentCollection from peri.test import nbody import peri.opt.optimize as opt import peri.opt.addsubtract as addsub im = util.NullImage(shape=(32, ) * 3) pos, rad, tile = nbody.create_configuration(3, im.tile) P = ComponentCollection( [objs.PlatonicSpheresCollection(pos, rad), objs.Slab(2)], category='obj') H = psfs.AnisotropicGaussian() I = ilms.BarnesStreakLegPoly2P1D(npts=(25, 13, 3), zorder=2, local_updates=False) B = ilms.LegendrePoly2P1D(order=(3, 1, 1), category='bkg', constval=0.01) C = GlobalScalar('offset', 0.0) I.randomize_parameters() s = states.ImageState(im, [B, I, H, P, C], pad=16, model_as_data=True)