def addNoiseToMapSolvent(map, varNoise): #********************************* #****** add Noise To Map ********* #********************************* mapData = np.copy(map) mapSize = mapData.shape noiseMap = np.random.randn(mapSize[0], mapSize[1], mapSize[2]) * math.sqrt(varNoise) mask = EMData() mask.set_size(mapSize[0], mapSize[1], mapSize[2]) mask.to_zero() sphere_radius = (np.min(mapSize) / 2.0 - 60) mask.process_inplace("testimage.circlesphere", {"radius": sphere_radius}) maskData = np.copy(EMNumPy.em2numpy(mask)) maskData[maskData > 0] = 10 maskData[maskData <= 0] = 0 maskData[maskData == 0] = 1 maskData[maskData == 10] = 0 noiseMap = noiseMap * maskData mapData = mapData + noiseMap return mapData
def setup_test_data(voldim=30, size=10): from sparx import model_gauss emmap = model_gauss(size, voldim, voldim, voldim) modmap = EMData() modmap.set_size(voldim, voldim, voldim) modmap.process_inplace("testimage.noise.gauss", {"sigma": 1, "seed": 99}) mask = model_square(size, voldim, voldim, voldim) return emmap, modmap, mask
def internal_test_image2(self, nx, ny=1, nz=1): from EMAN2 import EMData, display from fundamentals import cyclic_shift, mirror e = EMData() e.set_size(nx, ny, nz) e.process_inplace("testimage.tomo.objects") e = cyclic_shift(e, nx/2, ny/3, nz/5) e = mirror(e) return e
def prepare_mask_and_maps_for_scaling(args): emmap = get_image(args.em_map) modmap = get_image(args.model_map) if args.mask is None: mask = EMData() xsize, ysize, zsize = emmap.get_xsize(), emmap.get_ysize( ), emmap.get_zsize() mask.set_size(xsize, ysize, zsize) mask.to_zero() if xsize == ysize and xsize == zsize and ysize == zsize: sphere_radius = xsize // 2 mask.process_inplace("testimage.circlesphere", {"radius": sphere_radius}) else: mask += 1 mask = Util.window(mask, xsize - 1, ysize - 1, zsize - 1) mask = Util.pad(mask, xsize, ysize, zsize, 0, 0, 0, '0') elif args.mask is not None: mask = binarize(get_image(args.mask), 0.5) if args.window_size is None: wn = int(math.ceil(round((7 * 3 * args.apix)) / 2.) * 2) elif args.window_size is not None: wn = int(math.ceil(args.window_size / 2.) * 2) window_bleed_and_pad = check_for_window_bleeding(mask, wn) if window_bleed_and_pad: pad_int_emmap = compute_padding_average(emmap, mask) pad_int_modmap = compute_padding_average(modmap, mask) map_shape = [(emmap.get_xsize() + wn), (emmap.get_ysize() + wn), (emmap.get_zsize() + wn)] emmap = Util.pad(emmap, map_shape[0], map_shape[1], map_shape[2], 0, 0, 0, 'pad_int_emmap') modmap = Util.pad(modmap, map_shape[0], map_shape[1], map_shape[2], 0, 0, 0, 'pad_int_modmap') mask = Util.pad(mask, map_shape[0], map_shape[1], map_shape[2], 0, 0, 0, '0') return emmap, modmap, mask, wn, window_bleed_and_pad
def internal_test_image(self, nx, ny=1, nz=1): from EMAN2 import EMData e = EMData() e.set_size(nx, ny, nz) e.process_inplace("testimage.tomo.objects") return e