def speed_test3(imshape=(128,128,128), gshape=(4,4,4)): im = np.zeros(imshape) hs = np.ones(gshape+imshape) out, plan = convolve_spatial3(im, hs, return_plan=True) t = time() out = convolve_spatial3(im, hs, plan=plan) t = time()-t print "imshape: %s \tgshape: %s \ttime = %.2gs"%(imshape, gshape, t) return t
def speed_test3(imshape=(128, 128, 128), gshape=(4, 4, 4)): im = np.zeros(imshape) hs = np.ones(gshape + imshape) out, plan = convolve_spatial3(im, hs, return_plan=True) t = time() out = convolve_spatial3(im, hs, plan=plan) t = time() - t print("imshape: %s \tgshape: %s \ttime = %.2gs" % (imshape, gshape, t)) return t
def test_conv3(): im = np.zeros((128, 64, 32)) Gx = 8 Gy = 4 Gz = 2 hs = psf_grid_linear3(Gx, Gy, Gz, 10) out = convolve_spatial3(im, hs) return im, out, hs
def test_conv3(): im = np.zeros((128,64,32)) Gx = 8 Gy = 4 Gz = 2 hs = psf_grid_linear3(Gx,Gy,Gz,10) out = convolve_spatial3(im, hs) return im,out, hs
def test_conv3_psfs(): im = np.zeros((128, 128, 128)) im[::16, ::16, ::16] = 1. Gx = 16 Gy = 16 Gz = 16 hs = psf_grid_motion3(Gx, Gy, Gz, 20) out = convolve_spatial3(im, hs) return im, out, hs
def test_conv3_psfs(): im = np.zeros((128,64,32)) im[::16,::16,::16] = 1. Gx = 16 Gy = 16 Gz = 16 hs = psf_grid_motion3(Gx,Gy,Gz,20) out = convolve_spatial3(im, hs) return im,out, hs
def test_single_z(): Ng = 32 Nx = 512 Nh = 3 im = np.zeros((16, Nx, Nx)) im[4:-4, 4::16, 4::16] = 1. hs = np.zeros((16, Nx, Nx)) for i in range(Ng): for j in range(Ng): si = slice(i * (Nx // Ng) - Nh + (Nx // Ng) // 2, i * (Nx // Ng) + Nh + 1 + (Nx // Ng) // 2) sj = slice(j * (Nx // Ng) - Nh + (Nx // Ng) // 2, j * (Nx // Ng) + Nh + 1 + (Nx // Ng) // 2) hs[:, sj, si] = np.ones((16, 2 * Nh + 1, 2 * Nh + 1)) hs[:, Nx // Ng // 2::Nx // Ng, Nx // Ng // 2::Nx // Ng] = 1. out = convolve_spatial3(im, hs, grid_dim=(1, Ng, Ng), pad_factor=2) return im, out, hs
def simulate_image_z(self, cz=0, signal=None, psf_grid_dim=(8, 8), zslice=16, conv_sub_blocks=(1, 1), conv_pad_factor=2, conv_mode="wrap", mode="product", with_sheet=True, **bpm_kwargs): """ mode = ["product","illum"] """ if not mode in ["product", "illum"]: raise KeyError("unknown mode: %s" % mode) if signal is None: signal = self.signal if signal is None: raise ValueError("no signal defined (signal)!") # illumination psfs = self.psf_grid_z(cz=cz, grid_dim=psf_grid_dim, zslice=zslice, **bpm_kwargs) offset_z = int(np.round(cz / self._bpm_detect.units[-1])) assert offset_z + zslice < self.Nz and self.Nz // 2 + offset_z - zslice >= 0 s = slice(self.Nz // 2 + offset_z - zslice, self.Nz // 2 + offset_z + zslice) signal = 1. * signal[s].copy() if with_sheet: print("illuminating at z= %s mu with psf mode %s" % (cz, mode)) u = self.propagate_illum(cz=cz, **bpm_kwargs) if mode == "psf_product": psfs = psfs * u[s] else: signal = signal * u[s] print("spatially varying convolution: %s %s" % (signal.shape, psfs.shape)) #convolve conv = convolve_spatial3(signal.copy(), psfs.copy(), grid_dim=(1, ) + psf_grid_dim, sub_blocks=(1, ) + conv_sub_blocks, pad_factor=conv_pad_factor, mode=conv_mode, verbose=True) #return u, self.signal[s].copy(), signal, psfs, conv return conv
def test_conv3_reflect(): im = np.zeros((128, 64, 32)) Gx, Gy, Gz = 8, 4, 2 hs = psf_grid_linear3(Gx, Gy, Gz, 10) out = convolve_spatial3(im, hs, mode='reflect') return im, out, hs
def simulate_image_z(self, cz = 0, signal = None, psf_grid_dim = (8,8), zslice = 16, conv_sub_blocks = (1,1), conv_pad_factor = 2, conv_mode = "wrap", mode = "product", with_sheet = True, **bpm_kwargs): """ mode = ["product","illum"] """ if not mode in ["product","illum"]: raise KeyError("unknown mode: %s"%mode) if signal is None: signal = self.signal if signal is None: raise ValueError("no signal defined (signal)!") # illumination psfs = self.psf_grid_z(cz = cz, grid_dim=psf_grid_dim, zslice=zslice, **bpm_kwargs) offset_z = int(np.round(cz/self._bpm_detect.units[-1])) assert offset_z+zslice<self.Nz and self.Nz//2+offset_z-zslice>=0 s = slice(self.Nz//2+offset_z-zslice,self.Nz//2+offset_z+zslice) signal = 1.*signal[s].copy() if with_sheet: print("illuminating at z= %s mu with psf mode %s" % (cz, mode)) u = self.propagate_illum(cz = cz,**bpm_kwargs) if mode =="psf_product": psfs = psfs*u[s] else: signal = signal*u[s] print("spatially varying convolution: %s %s"%(signal.shape,psfs.shape)) #convolve conv = convolve_spatial3(signal.copy(), psfs.copy(), grid_dim = (1,)+psf_grid_dim, sub_blocks=(1,)+conv_sub_blocks, pad_factor=conv_pad_factor, mode = conv_mode, verbose = True) #return u, self.signal[s].copy(), signal, psfs, conv return conv