def ccfs(ref,stack): "compute and center CCFs between ref and each member of stack" ret=[i.calc_ccf(ref) for i in stack] f=old_div(ref["nx"],4) for i in ret: i.process_inplace("xform.phaseorigin.tocenter") ret=[i.get_clip(EMAN2.Region(f,f,f*2,f*2)) for i in ret] return ret
def _build(self, index): '''Build a single image in the file.''' # print "...index:", index header = {} # Read the header img = EMAN2.EMData() img.read_image(self.workfile, 0, True) h = img.get_attr_dict() # Copy basic header information header['nx'] = h['nx'] header['ny'] = h['ny'] header['nz'] = h['nz'] header['slices'] = [] if header['nz'] == 1: # 2D Image img2 = EMAN2.EMData() img2.read_image(self.workfile, index, False) img2.process_inplace("normalize") if self.nimg > 1: # ... stack of 2D images. header['slices'].append( self.build_slice(img2, index=index, fixed=[128, 512, 1024])) else: # regular old 2D image -- also generate power spectrum and tiles. header['slices'].append( self.build_slice(img2, index=index, tile=True, pspec=True, fixed=[128, 512, 1024])) else: # 3D Image -- read region for each Z slice for i in range(header['nz']): region = EMAN2.Region(0, 0, i, header['nx'], header['ny'], 1) img2 = EMAN2.EMData() img2.read_image(self.workfile, 0, False, region) header['slices'].append( self.build_slice(img2, index=index, nz=i, fixed=[128, 512, 1024])) return header
def build_tiles(self, img, nz=1, index=0, tilesize=256): '''Build tiles for a 2D slice.''' # Work with a copy of the EMData img2 = img.copy() # Calculate the number of zoom levels based on the tile size levels = math.ceil( math.log(max(img.get_xsize(), img.get_ysize()) / tilesize) / math.log(2.0)) # Tile header header = img.get_attr_dict() tile_dict = {} # Step through shrink range creating tiles for level in range(int(levels)): scale = 2**level rmin = img2.get_attr("mean") - img2.get_attr("sigma") * 3.0 rmax = img2.get_attr("mean") + img2.get_attr("sigma") * 3.0 for x in range(0, img2.get_xsize(), tilesize): for y in range(0, img2.get_ysize(), tilesize): i = img2.get_clip(EMAN2.Region(x, y, tilesize, tilesize), fill=rmax) i.set_attr("render_min", rmin) i.set_attr("render_max", rmax) i.set_attr("jpeg_quality", 80) # Write output fsp = "tile.index-%d.scale-%d.z-%d.x-%d.y-%d.jpg" % ( index, scale, nz, x / tilesize, y / tilesize) fsp = os.path.join(self.tmpdir, fsp) i.write_image(fsp) tile_dict[(scale, x / tilesize, y / tilesize)] = [ fsp, None, 'jpg', tilesize, tilesize ] # Shrink by 2 for next round. img2.process_inplace("math.meanshrink", {"n": 2}) return tile_dict
invert = True norm = False coords = numpy.asarray([[int(val) for val in line.split()] for line in open(partcoords, 'r')]) #get_trans #get_rotation_transform for i in xrange(len(coords)): print i + 1, len(coords) x, y, z = coords[i] x = round(x * cshrink) y = round(y * cshrink) z = round(z * cshrink) r = EMAN2.Region((2 * x - boxsize) / 2, (2 * y - boxsize) / 2, (2 * z - boxsize) / 2, boxsize, boxsize, boxsize) e = EMAN2.EMData() e.read_image(tomogram, 0, False, r) if invert: e = e * -1 if norm: e.process_inplace('normalize', {}) e['origin_x'] = 0 e['origin_y'] = 0 e['origin_z'] = 0 e.write_image(output, i) # norm, intervt, threshold #ptcl.process_inplace("xform",{"transform":ptcl_parms[0]["xform.align3d"]})
def build_pspec(self, img, tilesize=512, nz=1, index=0): """Build a 2D FFT and 1D rotationally averaged power spectrum of a 2D EMData.""" # Return dictionaries pspec_dict = {} pspec1d_dict = {} # Output files outfile = "pspec.index-%d.z-%d.size-%d.png" % (index, nz, tilesize) outfile = os.path.join(self.tmpdir, outfile) outfile1d = "pspec1d.index-%d.z-%d.size-%d.json" % (index, nz, tilesize) outfile1d = os.path.join(self.tmpdir, outfile1d) # Create a new image to hold the 2D FFT nx, ny = img.get_xsize() / tilesize, img.get_ysize() / tilesize a = EMAN2.EMData() a.set_size(tilesize, tilesize) # Image isn't big enough.. if (ny < 2 or nx < 2): return pspec_dict, pspec1d_dict # Create FFT for y in range(1, ny - 1): for x in range(1, nx - 1): c = img.get_clip( EMAN2.Region(x * tilesize, y * tilesize, tilesize, tilesize)) c.process_inplace("normalize") c.process_inplace("math.realtofft") c.process_inplace("math.squared") a += c # Reset the center value a.set_value_at(tilesize / 2, tilesize / 2, 0, .01) # Adjust brightness a -= a.get_attr("minimum") - a.get_attr("sigma") * .01 a.process_inplace("math.log") a.set_attr("render_min", a.get_attr("minimum") - a.get_attr("sigma") * .1) a.set_attr("render_max", a.get_attr("mean") + a.get_attr("sigma") * 4.0) # Write out the PSpec png a.write_image(outfile) # Add to dictionary pspec_dict[tilesize] = [ outfile, None, 'png', a.get_xsize(), a.get_ysize() ] # Calculate t = (tilesize / 2) - 1 y = a.calc_radial_dist(t, 1, 1, 0) # radial power spectrum (log) f = open(outfile1d, "w") json.dump(y, f) f.close() pspec1d_dict[tilesize] = [outfile1d, None, 'json', t] # Return both the 2D and 1D files return pspec_dict, pspec1d_dict