當前位置: 首頁>>代碼示例>>Python>>正文


Python EMAN.fileCount方法代碼示例

本文整理匯總了Python中EMAN.fileCount方法的典型用法代碼示例。如果您正苦於以下問題:Python EMAN.fileCount方法的具體用法?Python EMAN.fileCount怎麽用?Python EMAN.fileCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在EMAN的用法示例。


在下文中一共展示了EMAN.fileCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def main():
	(options, input_lstfiles) = parse_command_line()
	ptcls = readLstFiles(input_lstfiles, nBest = options.nBest)
	
	if options.ortLstFile:
		ptcls_list = []
		for p in ptcls:
			ptcls_list += ptcls[p].items()
		ptcls_list.sort()

		fp = open(options.ortLstFile, 'w')
		fp.write("#LST\n")
		for p in ptcls_list:
			fp.write("%d\t%s\teuler=%g,%g,%g\tcenter=%g,%g\n" % (p.imageIndex, p.imageFile, p.euler[0], p.euler[1], p.euler[2], p.center[0], p.center[1]))
		fp.close()
		cmd = "images2lst.py %s %s" % (options.ortLstFile, options.ortLstFile)
		os.system(cmd)
	
	if options.saveClsLst:
		nProj = EMAN.fileCount(options.projFile)[0]
		clses = [ 1 ]* nProj
		for i in range(len(clses)): clses[i] = []

		for p in ptcls:
			solutions = ptcls[p].items()
			for pi in solutions: 
				clses[pi.refid].append(pi)
		import math
		#digits = int(math.log10(nProj)+1)
		digits = 4
		for cls in range(len(clses)):
			ptcls_list = clses[cls]
			ptcls_list.sort()

			clsfn = "%d" % (cls)
			clsfn = "%s%s.lst" % (options.clsFileTag, clsfn.zfill(digits))
			fp = open(clsfn,'w')
			fp.write("#LST\n")
			fp.write("%d\t%s\n" % (cls, options.projFile))
			for p in ptcls_list:
				fp.write("%d\t%s\t%s\n" % (p.imageIndex, p.imageFile, p.clsinfo))
			fp.close()
			
			if options.eotest:
				clsfn = "%d" % (cls)
				clsfn_even = "%s%s.even.lst" % (options.clsFileTag, clsfn.zfill(digits))
				clsfn_odd = "%s%s.odd.lst" % (options.clsFileTag, clsfn.zfill(digits))
				fp_even = open(clsfn_even,'w')
				fp_even.write("#LST\n")
				fp_even.write("%d\t%s\n" % (cls, options.projFile))
				fp_odd = open(clsfn_odd,'w')
				fp_odd.write("#LST\n")
				fp_odd.write("%d\t%s\n" % (cls, options.projFile))
				for p in ptcls_list:
					if p.imageIndex%2:
						fp_odd.write("%d\t%s\t%s\n" % (p.imageIndex, p.imageFile, p.clsinfo))
					else:
						fp_even.write("%d\t%s\t%s\n" % (p.imageIndex, p.imageFile, p.clsinfo))
				fp_even.close()
				fp_odd.close()
開發者ID:,項目名稱:,代碼行數:62,代碼來源:

示例2: random_sample

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def random_sample(num_maps, sf, particles):
	#subset_num = int (len(particles)*fraction)
	num_part = int(len(particles))
	num_proj = EMAN.fileCount("proj.img")[0]
	
	for i in range(num_maps):
		#print "Model %d" % (i)
		#random.shuffle(particles)
		directory = "model_%d" % (i)
		os.mkdir(directory)
		os.chdir(directory)
		for files in ["start.hed","proj.hed"]:
		#up_dir_file = "../"+file
			cmd="lstcat.py "+files+" ../"+files
			os.system(cmd)
			os.link(files, files[:-3]+"img")
		os.link("../"+sf,sf)
		for c in range(num_proj):
			clsfile="cls%04d.lst" % (c)
			fp = file(clsfile,"w")
			fp.write("#LST\n%d\tproj.hed\n" % (c) )
			fp.close()
		#for j in range(subset_num):
		for j in range(num_part):
			#p = int(particles[j][0])	
			#c = int(particles[j][1])
			partt=random.choice(particles)
			p = partt[0]
			c = int(partt[1])
			#print "Index %d/%d/%d\tParticle %d -> Class %d" % (j, subset_num, len(particles), p, c)
			clsfile="cls%04d.lst" % (c)
			fp = open(clsfile,"a")
			fp.write(p)
			fp.close()
		os.chdir("..")
開發者ID:triciatricia,項目名稱:SIMPLE,代碼行數:37,代碼來源:calculateMapVariance.py

示例3: parse_command_line

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def parse_command_line():
	usage="Usage: %prog <image filename> <output filename> [options]"
	parser = OptionParser(usage=usage)
	parser.add_option("--mode",metavar="['defocus', 'snr', 'ctfb', 'ctfamp']",dest="mode",type="choice",choices=['defocus', 'snr', 'ctfb', 'ctfamp'], help="ctf mode to plot. default to \"defocus\"", default="defocus")
	parser.add_option("--sf",dest="sffile",type="string",help="structural factor file name", default="")
	parser.add_option("--first",dest="first",type="int",help="first image to use. default to 0", default=0)
	parser.add_option("--last",dest="last",type="int",help="last image to use. default to last image in the file", default=-1)
	
	(options, args) = parser.parse_args()
	if len(args) != 2:
		parser.print_help()
		sys.exit(-1)
	else:
		image = args[0]
		output = args[1]
	
	if options.mode in ['snr']:
		if not options.sffile:
			print "Error: --sf should be specified"
			sys.exit(1)
		elif not os.path.exists(options.sffile):
			print "Error: sffile %s does not exist" % (options.sffile)
			sys.exit(2)
	imgnum = EMAN.fileCount(image)[0]
	if options.last==-1: options.last=imgnum-1
	if options.first>0 or options.last>0:
		if not (0<=options.first<imgnum):
			print "Error: --first=%d is out of correct range [0, %d]" % (options.first, imgnum-1)
			sys.exit(3)
		if not (options.first<=options.last<imgnum):
			print "Error: --last=%d is out of correct range [%d, %d]" % (options.last, options.first, imgnum-1)
			sys.exit(4)

	return (options, image, output)
開發者ID:,項目名稱:,代碼行數:36,代碼來源:

示例4: numberParticlesInStack

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def numberParticlesInStack(stackname, startnum=0, verbose=True):
        ### new faster methond
        apImagicFile.numberStackFile(stackname, startnum=0)
        return

        # store the particle number in the stack header
        # NOTE!!! CONFORMS TO EMAN CONVENTION, STARTS AT 0!!!
        import EMAN
        t0 = time.time()
        apDisplay.printMsg("saving particle numbers to stack header")
        n=EMAN.fileCount(stackname)[0]
        im=EMAN.EMData()
        i = 0
        back = "\b\b\b\b\b\b\b"
        while i < n:
                j=startnum+i
                im.readImage(stackname,i)
                im.setNImg(j)
                im.writeImage(stackname,i)
                if verbose is True and i%100 == 0:
                        sys.stderr.write(back+back+back+str(j)+" of "+str(n))
                i+=1
        sys.stderr.write("\n")
        apDisplay.printMsg("finished in "+apDisplay.timeString(time.time()-t0))
        return
開發者ID:kraftp,項目名稱:Leginon-Feature-Detection-Modification,代碼行數:27,代碼來源:apEMAN.py

示例5: writeStackParticlesToFile

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def writeStackParticlesToFile(stackname, filename):
        import EMAN
        # write out the particle numbers from imagic header to a file
        # NOTE!!! CONFORMS TO EMAN CONVENTION, STARTS AT 0!!!
        apDisplay.printMsg("saving list of saved particles to:")
        apDisplay.printMsg(filename)
        f = open(filename,'w')
        n=EMAN.fileCount(stackname)[0]
        im=EMAN.EMData()
        for i in range(n):
                im.readImage(stackname,i)
                f.write(str(im.NImg())+"\n")
        f.close()
        return
開發者ID:kraftp,項目名稱:Leginon-Feature-Detection-Modification,代碼行數:16,代碼來源:apEMAN.py

示例6: checkStackNumbering

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def checkStackNumbering(stackname):
        import EMAN
        # check that the numbering is stored in the NImg parameter
        apDisplay.printMsg("checking that original stack is numbered")
        n=EMAN.fileCount(stackname)[0]
        im=EMAN.EMData()
        im.readImage(stackname,n-1)

        # if last particle is not numbered with same value as # of particles,
        # renumber the entire stack
        if n-1 != im.NImg():
                apDisplay.printWarning("Original stack is not numbered! numbering now...")
                # check that the stack exists in a writable directory and is not read-only
                if os.access(stackname, os.W_OK) is True:
                        numberParticlesInStack(stackname, startnum=0, verbose=True)
                else:
                        apDisplay.printWarning("old stack header exists in a READ-only directory and cannot be numbered according to EMAN")
        return
開發者ID:kraftp,項目名稱:Leginon-Feature-Detection-Modification,代碼行數:20,代碼來源:apEMAN.py

示例7: getClassInfo

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def getClassInfo(classes):
        import EMAN
        # read a classes.*.img file, get # of images
        imgnum, imgtype = EMAN.fileCount(classes)
        img = EMAN.EMData()
        img.readImage(classes, 0, 1)

        # for projection images, get eulers
        projeulers=[]
        for i in range(imgnum):
                img.readImage(classes, i, 1)
                e = img.getEuler()
                alt = e.thetaMRC()*180./math.pi
                az = e.phiMRC()*180./math.pi
                phi = e.omegaMRC()*180./math.pi
                eulers=[alt,az,phi]
                if i%2==0:
                        projeulers.append(eulers)
        return projeulers
開發者ID:kraftp,項目名稱:Leginon-Feature-Detection-Modification,代碼行數:21,代碼來源:apEMAN.py

示例8: follow_lst_link

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def follow_lst_link(image, index, lstfiles, imagefiles):
    if not (
        imagefiles.has_key(image) or lstfiles.has_key(image)
    ):  # it has not seen this image before and will find out
        imgnum, imgtype = EMAN.fileCount(image)
        if imgtype == "lst":
            tmplst = []
            fp = open(image, "r")
            lines = fp.readlines()
            fp.close()
            if lines[0].startswith("#LST"):
                line0 = 1
            elif lines[0].startswith("#LSX"):
                line0 = 3

            for l in lines[line0:]:
                tokens = l.split()
                tmplst.append((tokens[1], int(tokens[0])))
            lstfiles[image] = tmplst
        else:
            imagefiles[image] = imgnum

    if imagefiles.has_key(image):  # it has already known this image is a binary format image
        if index >= imagefiles[image]:
            print "Error: image file %s only has %d images, not enough for %d" % (image, imagefiles[image], index)
            sys.exit(-1)
        else:
            return (image, index)
    elif lstfiles.has_key(image):  # it has already known this image is a list format image
        if index >= len(lstfiles[image]):
            print "Error: lst file %s only has images, not enough for %d" % (image, len(lstfiles[image]), index)
            sys.exit(-1)
        else:
            return follow_lst_link(lstfiles[image][index][0], lstfiles[image][index][1], lstfiles, imagefiles)
    else:
        print "Something is wrong, need to debug this program and the image file"
        sys.exit(-1)
開發者ID:,項目名稱:,代碼行數:39,代碼來源:

示例9: len

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
#!/usr/bin/env python
import sys, os
from math import pi
import EMAN

if len(sys.argv) != 3:
	print "%s: convert image orientation and center (in EMAN convention) stored in the image headers into a text file in MRC/IMIRS format/convention" % (sys.argv[0])
	print "Usage: %s <input image file> <output ortcen file>" % (sys.argv[0])
	sys.exit(1)

imagefile = sys.argv[1]
output_ortcen_file = sys.argv[2]

imgnum, imgtype = EMAN.fileCount(imagefile)

img = EMAN.EMData()
img.readImage(imagefile, 0, 1)	# read Header only
imagesize = img.xSize()

imagefile_prefix = os.path.splitext(output_ortcen_file)[0]

outFile = open(output_ortcen_file, "w")
	
e5fto2f = EMAN.Euler(1.0172219678978513677, pi, -pi/2)	# rotation from 2fold to 5fold

for i in range(imgnum):
	print "Working on image %d/%d\r" % (i, imgnum) , 
	img.readImage(imagefile, i, 1)
	e = img.getEuler()
	
	e2 = e * e5fto2f;	# use 2-fold view instead of 5-fold view as orientation origin
開發者ID:,項目名稱:,代碼行數:33,代碼來源:

示例10: len

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
#!/usr/bin/env python

# this will save the particle stack number into the header of a stack.
# use this if you want to run cenalignint, and keep track of the particles.
# NOTE!!! CONFORMS TO EMAN CONVENTION, STARTS AT 0!!!!

import sys
try:
	import EMAN
except ImportError:
	print "EMAN module did not get imported"

if __name__ == "__main__":

	if len(sys.argv) < 2:
		print "usage: renumber.py [filename]"
		sys.exit()

	filename=sys.argv[1]

	n=EMAN.fileCount(filename)[0]
	im=EMAN.EMData()
	for i in range(n):
		im.readImage(filename,i)
		im.setNImg(i)
		im.writeImage(filename,i)
		print i
開發者ID:leschzinerlab,項目名稱:myami-3.2-freeHand,代碼行數:29,代碼來源:numberParticlesInStack.py

示例11: elif

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
nbasis=20
mask=-1

for i in argv[3:] :
#	s=i.split('=')
	s=string.split(i,'=')
	if (s[0]=="n") : nbasis=int(s[1])
	elif (s[0]=="mask") : mask=int(s[1])
	else:
		print "Unknown argument ",i
		exit(1)

EMAN.LOGbegin(argv)

n=EMAN.fileCount(argv[1])
if (n<2) :
	print("Umm... I'd really be happier if the input file had at least 2 images...")
	sys.exit(1)

nbasis=min(n,nbasis)
print "%d source images to consider\nGenerating %d basis images\n"%(n,nbasis)

basis=[EMAN.EMData()]			# the actual basis vectors
basisn=[0]						# list of the input image number used to generate each basis vector
basis[0].readImage(argv[1],0)
basis[0].realFilter(30)			# 'true' normalization. We'll use this a lot
nx=basis[0].xSize()
da=atan2(1.0,nx/2.0)			# da represents 1 pixel at the edge of the image

orig=EMAN.EMData()
開發者ID:triciatricia,項目名稱:SIMPLE,代碼行數:32,代碼來源:powdcmp.py

示例12: in

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
		if o in ("", "--tree"):
			tree=a
		if o in ("", "--treemem"):
			treemem=a

indices = []
members = {}
if tree:
	for l in open(tree,"r"):
		indices.append(int(l.split()[0]))
		if treemem:
			mem = l.split()[1:]
			members[indices[-1]] = []
			for m in mem: members[indices[-1]].append(int(m))
else:
	indices = range(EMAN.fileCount(sys.argv[1])[0])

img = EMAN.EMData()

pdb = open(sys.argv[2],"w")

for  i in indices:
	img.readImage(sys.argv[1],i,nodata=1)
	
	alt=img.alt()
	az=img.az()
	phi=img.phi()
	x=r*sin(alt)*cos(az)
	y=r*sin(alt)*sin(az)
	z=r*cos(alt)
開發者ID:triciatricia,項目名稱:SIMPLE,代碼行數:32,代碼來源:orientation2pdb.py

示例13: getNumParticlesInStack

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
def getNumParticlesInStack(stackname):
        import EMAN
        numparticles = EMAN.fileCount(stackname)[0]
        return numparticles
開發者ID:kraftp,項目名稱:Leginon-Feature-Detection-Modification,代碼行數:6,代碼來源:apEMAN.py

示例14: len

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
	# create new list file with only good particles
	if params['clean'] is True:
		f=open(fsp,'r')
		lines=f.readlines()
		f.close()
		fsp=fsp.split('.')[0]+'.good.lst'
		f=open(fsp,'w')
		for l in lines:
			d=l.strip().split()
			if len(d) < 3:
				f.write(l)
				continue
			if d[3][-1]=='1':
				f.write(l)
		f.close()
	n=EMAN.fileCount(fsp)[0]
	
	classnamepath = fsp.split('.')[0]+'.dir'
	if not os.path.exists(classnamepath):
		os.mkdir(classnamepath)
	b=EMAN.EMData()
	b.readImage(fsp,0)
	e=b.getEuler()

	a=EMAN.EMData()
	if format == "eman" or format=="imagic":
		outname="aligned.hed"
	else:
		outname="aligned.spi"

	startn = 1
開發者ID:leschzinerlab,項目名稱:myami-3.2-freeHand,代碼行數:33,代碼來源:clstoaligned.py

示例15: len

# 需要導入模塊: import EMAN [as 別名]
# 或者: from EMAN import fileCount [as 別名]
# get eulers from proj.img file

import sys, os
from math import pi
try:
	import EMAN
except ImportError:
	print "EMAN module did not get imported"

if __name__ == "__main__":
	if len(sys.argv) !=3:
		print "Usage: getProjEulers.py <infile> <outfile>\n"
		sys.exit(1)

	projfile = sys.argv[1]
	outfile = sys.argv[2]

	out = open(outfile, "w")

	count,imgtype = EMAN.fileCount(projfile)
	imgs = EMAN.EMData()
	imgs.readImage(projfile,0,1)
	for i in range(count):
		imgs.readImage(projfile,i,1)
		e = imgs.getEuler()
		alt = e.alt()*180./pi
		az = e.az()*180./pi
		phi = e.phi()*180./pi
		out.write("%i\t%f\t%f\t%f\n" % (i,alt,az,phi))
	out.close()
開發者ID:leschzinerlab,項目名稱:myami-3.2-freeHand,代碼行數:32,代碼來源:getProjEulers.py


注:本文中的EMAN.fileCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。