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 write_out_final_volume_window_back_if_required(args, wn, window_bleed_and_pad, LocScaleVol): LocScaleVol = set_zero_origin_and_pixel_size(LocScaleVol, args.apix) if window_bleed_and_pad: map_shape = [(LocScaleVol.get_xsize() - wn), (LocScaleVol.get_ysize() - wn), (LocScaleVol.get_zsize() - wn)] LocScaleVol = Util.window(LocScaleVol, map_shape[0], map_shape[1], map_shape[2]) LocScaleVol.write_image(args.outfile) return LocScaleVol
# Eulerian angles: # SPIDER, EMAN, IMAGIC Eulerian_Angles = "SPIDER" # NOTICE: beginning from version 0.70, we will no longer use MPI as a global variable # Instead, the user would add mpi as a parameter for command line, example # mpirun -np 10 sxali2d_c.py ... --mpi # We read the global seed here. If the user wish to repeat the random results twice, # he/she should first set the rand_seed to a fixed number and then run the program twice. from EMAN2 import Util, EMData, EMUtil, Transform from random import seed rand_seed = Util.get_randnum_seed() seed(rand_seed) rand_seed = Util.get_randnum_seed() Util.set_randnum_seed(rand_seed) # BATCH flag should generally be set to False, which indicates that the output should be both displayed on the screen and written to the log file. # However, the user may change it to True (either here or in other programs) so that the output is only written to the log file. BATCH = False # variable for disabling bdb cache use, For running sparx on clusters, set it to True to disable cache, CACHE_DISABLE = False global LOGFILE LOGFILE = "logfile"
def do_volume_mrk02(ref_data): """ data - projections (scattered between cpus) or the volume. If volume, just do the volume processing options - the same for all cpus return - volume the same for all cpus """ from EMAN2 import Util from mpi import mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD from filter import filt_table from reconstruction import recons3d_4nn_MPI, recons3d_4nn_ctf_MPI from utilities import bcast_EMData_to_all, bcast_number_to_all, model_blank from fundamentals import rops_table, fftip, fft import types # Retrieve the function specific input arguments from ref_data data = ref_data[0] Tracker = ref_data[1] iter = ref_data[2] mpi_comm = ref_data[3] # # For DEBUG # print "Type of data %s" % (type(data)) # print "Type of Tracker %s" % (type(Tracker)) # print "Type of iter %s" % (type(iter)) # print "Type of mpi_comm %s" % (type(mpi_comm)) if(mpi_comm == None): mpi_comm = MPI_COMM_WORLD myid = mpi_comm_rank(mpi_comm) nproc = mpi_comm_size(mpi_comm) try: local_filter = Tracker["local_filter"] except: local_filter = False #========================================================================= # volume reconstruction if( type(data) == types.ListType ): if Tracker["constants"]["CTF"]: vol = recons3d_4nn_ctf_MPI(myid, data, Tracker["constants"]["snr"], \ symmetry=Tracker["constants"]["sym"], npad=Tracker["constants"]["npad"], mpi_comm=mpi_comm, smearstep = Tracker["smearstep"]) else: vol = recons3d_4nn_MPI (myid, data,\ symmetry=Tracker["constants"]["sym"], npad=Tracker["constants"]["npad"], mpi_comm=mpi_comm) else: vol = data if myid == 0: from morphology import threshold from filter import filt_tanl, filt_btwl from utilities import model_circle, get_im import types nx = vol.get_xsize() if(Tracker["constants"]["mask3D"] == None): mask3D = model_circle(int(Tracker["constants"]["radius"]*float(nx)/float(Tracker["constants"]["nnxo"])+0.5), nx, nx, nx) elif(Tracker["constants"]["mask3D"] == "auto"): from utilities import adaptive_mask mask3D = adaptive_mask(vol) else: if( type(Tracker["constants"]["mask3D"]) == types.StringType ): mask3D = get_im(Tracker["constants"]["mask3D"]) else: mask3D = (Tracker["constants"]["mask3D"]).copy() nxm = mask3D.get_xsize() if( nx != nxm): from fundamentals import rot_shift3D mask3D = Util.window(rot_shift3D(mask3D,scale=float(nx)/float(nxm)),nx,nx,nx) nxm = mask3D.get_xsize() assert(nx == nxm) stat = Util.infomask(vol, mask3D, False) vol -= stat[0] Util.mul_scalar(vol, 1.0/stat[1]) vol = threshold(vol) Util.mul_img(vol, mask3D) if( Tracker["PWadjustment"] ): from utilities import read_text_file, write_text_file rt = read_text_file( Tracker["PWadjustment"] ) fftip(vol) ro = rops_table(vol) # Here unless I am mistaken it is enough to take the beginning of the reference pw. for i in xrange(1,len(ro)): ro[i] = (rt[i]/ro[i])**Tracker["upscale"] #write_text_file(rops_table(filt_table( vol, ro),1),"foo.txt") if Tracker["constants"]["sausage"]: ny = vol.get_ysize() y = float(ny) from math import exp for i in xrange(len(ro)): ro[i] *= \ (1.0+1.0*exp(-(((i/y/Tracker["constants"]["pixel_size"])-0.10)/0.025)**2)+1.0*exp(-(((i/y/Tracker["constants"]["pixel_size"])-0.215)/0.025)**2)) if local_filter: # skip low-pass filtration vol = fft( filt_table( vol, ro) ) else: if( type(Tracker["lowpass"]) == types.ListType ): vol = fft( filt_table( filt_table(vol, Tracker["lowpass"]), ro) ) else: vol = fft( filt_table( filt_tanl(vol, Tracker["lowpass"], Tracker["falloff"]), ro) ) del ro else: if Tracker["constants"]["sausage"]: ny = vol.get_ysize() y = float(ny) ro = [0.0]*(ny//2+2) from math import exp for i in xrange(len(ro)): ro[i] = \ (1.0+1.0*exp(-(((i/y/Tracker["constants"]["pixel_size"])-0.10)/0.025)**2)+1.0*exp(-(((i/y/Tracker["constants"]["pixel_size"])-0.215)/0.025)**2)) fftip(vol) filt_table(vol, ro) del ro if not local_filter: if( type(Tracker["lowpass"]) == types.ListType ): vol = filt_table(vol, Tracker["lowpass"]) else: vol = filt_tanl(vol, Tracker["lowpass"], Tracker["falloff"]) if Tracker["constants"]["sausage"]: vol = fft(vol) if local_filter: from morphology import binarize if(myid == 0): nx = mask3D.get_xsize() else: nx = 0 nx = bcast_number_to_all(nx, source_node = 0) # only main processor needs the two input volumes if(myid == 0): mask = binarize(mask3D, 0.5) locres = get_im(Tracker["local_filter"]) lx = locres.get_xsize() if(lx != nx): if(lx < nx): from fundamentals import fdecimate, rot_shift3D mask = Util.window(rot_shift3D(mask,scale=float(lx)/float(nx)),lx,lx,lx) vol = fdecimate(vol, lx,lx,lx) else: ERROR("local filter cannot be larger than input volume","user function",1) stat = Util.infomask(vol, mask, False) vol -= stat[0] Util.mul_scalar(vol, 1.0/stat[1]) else: lx = 0 locres = model_blank(1,1,1) vol = model_blank(1,1,1) lx = bcast_number_to_all(lx, source_node = 0) if( myid != 0 ): mask = model_blank(lx,lx,lx) bcast_EMData_to_all(mask, myid, 0, comm=mpi_comm) from filter import filterlocal vol = filterlocal( locres, vol, mask, Tracker["falloff"], myid, 0, nproc) if myid == 0: if(lx < nx): from fundamentals import fpol vol = fpol(vol, nx,nx,nx) vol = threshold(vol) vol = filt_btwl(vol, 0.38, 0.5)# This will have to be corrected. Util.mul_img(vol, mask3D) del mask3D # vol.write_image('toto%03d.hdf'%iter) else: vol = model_blank(nx,nx,nx) else: if myid == 0: #from utilities import write_text_file #write_text_file(rops_table(vol,1),"goo.txt") stat = Util.infomask(vol, mask3D, False) vol -= stat[0] Util.mul_scalar(vol, 1.0/stat[1]) vol = threshold(vol) vol = filt_btwl(vol, 0.38, 0.5)# This will have to be corrected. Util.mul_img(vol, mask3D) del mask3D # vol.write_image('toto%03d.hdf'%iter) # broadcast volume bcast_EMData_to_all(vol, myid, 0, comm=mpi_comm) #========================================================================= return vol
def do_volume_mrk03(ref_data): """ data - projections (scattered between cpus) or the volume. If volume, just do the volume processing options - the same for all cpus return - volume the same for all cpus """ from EMAN2 import Util from mpi import mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD from filter import filt_table from reconstruction import recons3d_4nn_MPI, recons3d_4nnw_MPI # recons3d_4nn_ctf_MPI from utilities import bcast_EMData_to_all, bcast_number_to_all, model_blank from fundamentals import rops_table, fftip, fft import types # Retrieve the function specific input arguments from ref_data data = ref_data[0] Tracker = ref_data[1] iter = ref_data[2] mpi_comm = ref_data[3] # # For DEBUG # print "Type of data %s" % (type(data)) # print "Type of Tracker %s" % (type(Tracker)) # print "Type of iter %s" % (type(iter)) # print "Type of mpi_comm %s" % (type(mpi_comm)) if(mpi_comm == None): mpi_comm = MPI_COMM_WORLD myid = mpi_comm_rank(mpi_comm) nproc = mpi_comm_size(mpi_comm) try: local_filter = Tracker["local_filter"] except: local_filter = False #========================================================================= # volume reconstruction if( type(data) == types.ListType ): if Tracker["constants"]["CTF"]: #vol = recons3d_4nn_ctf_MPI(myid, data, Tracker["constants"]["snr"], \ # symmetry=Tracker["constants"]["sym"], npad=Tracker["constants"]["npad"], mpi_comm=mpi_comm, smearstep = Tracker["smearstep"]) vol = recons3d_4nnw_MPI(myid, data, Tracker["bckgnoise"], Tracker["constants"]["snr"], \ symmetry=Tracker["constants"]["sym"], npad=Tracker["constants"]["npad"], mpi_comm=mpi_comm, smearstep = Tracker["smearstep"]) else: vol = recons3d_4nn_MPI (myid, data,\ symmetry=Tracker["constants"]["sym"], npad=Tracker["constants"]["npad"], mpi_comm=mpi_comm) else: vol = data if myid == 0: from morphology import threshold from filter import filt_tanl, filt_btwl from utilities import model_circle, get_im import types nx = vol.get_xsize() if(Tracker["constants"]["mask3D"] == None): mask3D = model_circle(int(Tracker["constants"]["radius"]*float(nx)/float(Tracker["constants"]["nnxo"])+0.5), nx, nx, nx) elif(Tracker["constants"]["mask3D"] == "auto"): from utilities import adaptive_mask mask3D = adaptive_mask(vol) else: if( type(Tracker["constants"]["mask3D"]) == types.StringType ): mask3D = get_im(Tracker["constants"]["mask3D"]) else: mask3D = (Tracker["constants"]["mask3D"]).copy() nxm = mask3D.get_xsize() if( nx != nxm): from fundamentals import rot_shift3D mask3D = Util.window(rot_shift3D(mask3D,scale=float(nx)/float(nxm)),nx,nx,nx) nxm = mask3D.get_xsize() assert(nx == nxm) stat = Util.infomask(vol, mask3D, False) vol -= stat[0] Util.mul_scalar(vol, 1.0/stat[1]) vol = threshold(vol) Util.mul_img(vol, mask3D) if not local_filter: if( type(Tracker["lowpass"]) == types.ListType ): vol = filt_table(vol, Tracker["lowpass"]) else: vol = filt_tanl(vol, Tracker["lowpass"], Tracker["falloff"]) if local_filter: from morphology import binarize if(myid == 0): nx = mask3D.get_xsize() else: nx = 0 nx = bcast_number_to_all(nx, source_node = 0) # only main processor needs the two input volumes if(myid == 0): mask = binarize(mask3D, 0.5) locres = get_im(Tracker["local_filter"]) lx = locres.get_xsize() if(lx != nx): if(lx < nx): from fundamentals import fdecimate, rot_shift3D mask = Util.window(rot_shift3D(mask,scale=float(lx)/float(nx)),lx,lx,lx) vol = fdecimate(vol, lx,lx,lx) else: ERROR("local filter cannot be larger than input volume","user function",1) stat = Util.infomask(vol, mask, False) vol -= stat[0] Util.mul_scalar(vol, 1.0/stat[1]) else: lx = 0 locres = model_blank(1,1,1) vol = model_blank(1,1,1) lx = bcast_number_to_all(lx, source_node = 0) if( myid != 0 ): mask = model_blank(lx,lx,lx) bcast_EMData_to_all(mask, myid, 0, comm=mpi_comm) from filter import filterlocal vol = filterlocal( locres, vol, mask, Tracker["falloff"], myid, 0, nproc) if myid == 0: if(lx < nx): from fundamentals import fpol vol = fpol(vol, nx,nx,nx) vol = threshold(vol) Util.mul_img(vol, mask3D) del mask3D # vol.write_image('toto%03d.hdf'%iter) else: vol = model_blank(nx,nx,nx) """ else: if myid == 0: #from utilities import write_text_file #write_text_file(rops_table(vol,1),"goo.txt") stat = Util.infomask(vol, mask3D, False) vol -= stat[0] Util.mul_scalar(vol, 1.0/stat[1]) vol = threshold(vol) Util.mul_img(vol, mask3D) del mask3D # vol.write_image('toto%03d.hdf'%iter) """ # broadcast volume bcast_EMData_to_all(vol, myid, 0, comm=mpi_comm) #========================================================================= return vol
# Eulerian angles: # SPIDER, EMAN, IMAGIC Eulerian_Angles = "SPIDER" # NOTICE: beginning from version 0.70, we will no longer use MPI as a global variable # Instead, the user would add mpi as a parameter for command line, example # mpirun -np 10 sxali2d_c.py ... --mpi # We read the global seed here. If the user wish to repeat the random results twice, # he/she should first set the rand_seed to a fixed number and then run the program twice. from EMAN2 import Util, EMData, EMUtil, Transform from random import seed rand_seed = Util.get_randnum_seed() seed(rand_seed) rand_seed = Util.get_randnum_seed() Util.set_randnum_seed(rand_seed) # BATCH flag should generally be set to False, which indicates that the output should be both displayed on the screen and written to the log file. # However, the user may change it to True (either here or in other programs) so that the output is only written to the log file. BATCH = False MPI = False # variable for disabling bdb cache use, For running sparx on clusters, set it to True to disable cache, CACHE_DISABLE = False global LOGFILE
def compute_padding_average(map, mask): volume_stats_outside_mask = Util.infomask(map, mask, False) average_padding_intensity = volume_stats_outside_mask[0] return average_padding_intensity
def __new__(cls,filename,application,force_plot=False,force_2d=False,old=None): file_type = Util.get_filename_ext(filename) em_file_type = EMUtil.get_image_ext_type(file_type) if not file_exists(filename): return None if force_plot and force_2d: # ok this sucks but it suffices for the time being print "Error, the force_plot and force_2d options are mutually exclusive" return None if force_plot: from emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget if em_file_type != IMAGE_UNKNOWN or filename[:4] == "bdb:": n = EMUtil.get_image_count(filename) nx,ny,nz = gimme_image_dimensions3D(filename) if n > 1 and nz == 1: if force_2d: a = EMData() data=a.read_images(filename) else: data = None # This is like a flag - the ImageMXWidget only needs the file name elif nz == 1: data = [EMData(filename,0)] else: data = EMData() data.read_image(filename,0,not force_2d) # This should be 3-D. We read the header-only here data = [data] if data != None and len(data) == 1: data = data[0] if force_2d or isinstance(data,EMData) and data.get_zsize()==1: if isinstance(data,list) or data.get_ysize() != 1: from emimage2d import EMImage2DWidget if isinstance(old,EMImage2DWidget): widget = old else: widget= EMImage2DWidget(application=application) else: from emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget elif isinstance(data,EMData): if isinstance(old,EMScene3D): widget = old else: widget = EMScene3D() # print n,data for ii in xrange(n): data=EMData(filename,ii) datai = EMDataItem3D(data, transform=Transform()) widget.insertNewNode(os.path.basename(filename), datai, parentnode=widget) isosurface = EMIsosurface(datai, transform=Transform()) widget.insertNewNode("Iso", isosurface, parentnode=datai) return widget elif data == None or isinstance(data,list): from emimagemx import EMImageMXWidget if isinstance(old,EMImageMXWidget): widget = old else: widget = EMImageMXWidget(application=application) data = filename else: print filename raise # weirdness, this should never happen widget.set_data(data,filename) return widget else: from emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget
def __new__(cls,filename,application,force_plot=False,force_2d=False,old=None): file_type = Util.get_filename_ext(filename) em_file_type = EMUtil.get_image_ext_type(file_type) if not file_exists(filename): return None if force_plot and force_2d: # ok this sucks but it suffices for the time being print("Error, the force_plot and force_2d options are mutually exclusive") return None if force_plot: from .emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget if em_file_type != IMAGE_UNKNOWN or filename[:4] == "bdb:": n = EMUtil.get_image_count(filename) nx,ny,nz = gimme_image_dimensions3D(filename) if n > 1 and nz == 1: if force_2d: a = EMData() data=a.read_images(filename) else: data = None # This is like a flag - the ImageMXWidget only needs the file name elif nz == 1: data = [EMData(filename,0)] else: data = EMData() data.read_image(filename,0,not force_2d) # This should be 3-D. We read the header-only here data = [data] if data != None and len(data) == 1: data = data[0] if force_2d or isinstance(data,EMData) and data.get_zsize()==1: if isinstance(data,list) or data.get_ysize() != 1: from .emimage2d import EMImage2DWidget if isinstance(old,EMImage2DWidget): widget = old else: widget= EMImage2DWidget(application=application) else: from .emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget elif isinstance(data,EMData): if isinstance(old,EMScene3D): widget = old else: widget = EMScene3D() # print n,data for ii in range(n): data=EMData(filename,ii) datai = EMDataItem3D(data, transform=Transform()) widget.insertNewNode(os.path.basename(filename), datai, parentnode=widget) isosurface = EMIsosurface(datai, transform=Transform()) widget.insertNewNode("Iso", isosurface, parentnode=datai) return widget elif data == None or isinstance(data,list): from .emimagemx import EMImageMXWidget if isinstance(old,EMImageMXWidget): widget = old else: widget = EMImageMXWidget(application=application) data = filename else: print(filename) raise # weirdness, this should never happen widget.set_data(data,filename) return widget else: from .emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget
def do_volume_mrk02(ref_data): """ data - projections (scattered between cpus) or the volume. If volume, just do the volume processing options - the same for all cpus return - volume the same for all cpus """ from EMAN2 import Util from mpi import mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD from filter import filt_table from reconstruction import recons3d_4nn_MPI, recons3d_4nn_ctf_MPI from utilities import bcast_EMData_to_all, bcast_number_to_all, model_blank from fundamentals import rops_table, fftip, fft import types # Retrieve the function specific input arguments from ref_data data = ref_data[0] Tracker = ref_data[1] iter = ref_data[2] mpi_comm = ref_data[3] # # For DEBUG # print "Type of data %s" % (type(data)) # print "Type of Tracker %s" % (type(Tracker)) # print "Type of iter %s" % (type(iter)) # print "Type of mpi_comm %s" % (type(mpi_comm)) if (mpi_comm == None): mpi_comm = MPI_COMM_WORLD myid = mpi_comm_rank(mpi_comm) nproc = mpi_comm_size(mpi_comm) try: local_filter = Tracker["local_filter"] except: local_filter = False #========================================================================= # volume reconstruction if (type(data) == types.ListType): if Tracker["constants"]["CTF"]: vol = recons3d_4nn_ctf_MPI(myid, data, Tracker["constants"]["snr"], \ symmetry=Tracker["constants"]["sym"], npad=Tracker["constants"]["npad"], mpi_comm=mpi_comm, smearstep = Tracker["smearstep"]) else: vol = recons3d_4nn_MPI (myid, data,\ symmetry=Tracker["constants"]["sym"], npad=Tracker["constants"]["npad"], mpi_comm=mpi_comm) else: vol = data if myid == 0: from morphology import threshold from filter import filt_tanl, filt_btwl from utilities import model_circle, get_im import types nx = vol.get_xsize() if (Tracker["constants"]["mask3D"] == None): mask3D = model_circle( int(Tracker["constants"]["radius"] * float(nx) / float(Tracker["constants"]["nnxo"]) + 0.5), nx, nx, nx) elif (Tracker["constants"]["mask3D"] == "auto"): from utilities import adaptive_mask mask3D = adaptive_mask(vol) else: if (type(Tracker["constants"]["mask3D"]) == types.StringType): mask3D = get_im(Tracker["constants"]["mask3D"]) else: mask3D = (Tracker["constants"]["mask3D"]).copy() nxm = mask3D.get_xsize() if (nx != nxm): from fundamentals import rot_shift3D mask3D = Util.window( rot_shift3D(mask3D, scale=float(nx) / float(nxm)), nx, nx, nx) nxm = mask3D.get_xsize() assert (nx == nxm) stat = Util.infomask(vol, mask3D, False) vol -= stat[0] Util.mul_scalar(vol, 1.0 / stat[1]) vol = threshold(vol) Util.mul_img(vol, mask3D) if (Tracker["PWadjustment"]): from utilities import read_text_file, write_text_file rt = read_text_file(Tracker["PWadjustment"]) fftip(vol) ro = rops_table(vol) # Here unless I am mistaken it is enough to take the beginning of the reference pw. for i in xrange(1, len(ro)): ro[i] = (rt[i] / ro[i])**Tracker["upscale"] #write_text_file(rops_table(filt_table( vol, ro),1),"foo.txt") if Tracker["constants"]["sausage"]: ny = vol.get_ysize() y = float(ny) from math import exp for i in xrange(len(ro)): ro[i] *= \ (1.0+1.0*exp(-(((i/y/Tracker["constants"]["pixel_size"])-0.10)/0.025)**2)+1.0*exp(-(((i/y/Tracker["constants"]["pixel_size"])-0.215)/0.025)**2)) if local_filter: # skip low-pass filtration vol = fft(filt_table(vol, ro)) else: if (type(Tracker["lowpass"]) == types.ListType): vol = fft( filt_table(filt_table(vol, Tracker["lowpass"]), ro)) else: vol = fft( filt_table( filt_tanl(vol, Tracker["lowpass"], Tracker["falloff"]), ro)) del ro else: if Tracker["constants"]["sausage"]: ny = vol.get_ysize() y = float(ny) ro = [0.0] * (ny // 2 + 2) from math import exp for i in xrange(len(ro)): ro[i] = \ (1.0+1.0*exp(-(((i/y/Tracker["constants"]["pixel_size"])-0.10)/0.025)**2)+1.0*exp(-(((i/y/Tracker["constants"]["pixel_size"])-0.215)/0.025)**2)) fftip(vol) filt_table(vol, ro) del ro if not local_filter: if (type(Tracker["lowpass"]) == types.ListType): vol = filt_table(vol, Tracker["lowpass"]) else: vol = filt_tanl(vol, Tracker["lowpass"], Tracker["falloff"]) if Tracker["constants"]["sausage"]: vol = fft(vol) if local_filter: from morphology import binarize if (myid == 0): nx = mask3D.get_xsize() else: nx = 0 nx = bcast_number_to_all(nx, source_node=0) # only main processor needs the two input volumes if (myid == 0): mask = binarize(mask3D, 0.5) locres = get_im(Tracker["local_filter"]) lx = locres.get_xsize() if (lx != nx): if (lx < nx): from fundamentals import fdecimate, rot_shift3D mask = Util.window( rot_shift3D(mask, scale=float(lx) / float(nx)), lx, lx, lx) vol = fdecimate(vol, lx, lx, lx) else: ERROR("local filter cannot be larger than input volume", "user function", 1) stat = Util.infomask(vol, mask, False) vol -= stat[0] Util.mul_scalar(vol, 1.0 / stat[1]) else: lx = 0 locres = model_blank(1, 1, 1) vol = model_blank(1, 1, 1) lx = bcast_number_to_all(lx, source_node=0) if (myid != 0): mask = model_blank(lx, lx, lx) bcast_EMData_to_all(mask, myid, 0, comm=mpi_comm) from filter import filterlocal vol = filterlocal(locres, vol, mask, Tracker["falloff"], myid, 0, nproc) if myid == 0: if (lx < nx): from fundamentals import fpol vol = fpol(vol, nx, nx, nx) vol = threshold(vol) vol = filt_btwl(vol, 0.38, 0.5) # This will have to be corrected. Util.mul_img(vol, mask3D) del mask3D # vol.write_image('toto%03d.hdf'%iter) else: vol = model_blank(nx, nx, nx) else: if myid == 0: #from utilities import write_text_file #write_text_file(rops_table(vol,1),"goo.txt") stat = Util.infomask(vol, mask3D, False) vol -= stat[0] Util.mul_scalar(vol, 1.0 / stat[1]) vol = threshold(vol) vol = filt_btwl(vol, 0.38, 0.5) # This will have to be corrected. Util.mul_img(vol, mask3D) del mask3D # vol.write_image('toto%03d.hdf'%iter) # broadcast volume bcast_EMData_to_all(vol, myid, 0, comm=mpi_comm) #========================================================================= return vol