def writeTiltSeriesStack(stackdir,stackname,ordered_mrc_files,apix=1):
                stackpath = os.path.join(stackdir, stackname)
                print stackpath
                apixdict = {'x':apix,'y':apix}
                if os.path.exists(stackpath):
                        stheader = mrc.readHeaderFromFile(stackpath)
                        stshape = stheader['shape']
                        imageheader = mrc.readHeaderFromFile(ordered_mrc_files[0])
                        imageshape = imageheader['shape']
                        if stshape[1:] == imageshape and stshape[0] == len(ordered_mrc_files):
                                apDisplay.printMsg("No need to get new stack of the tilt series")
                        else:
                                apImage.writeMrcStack(stackdir,stackname,order3dmrc_files, 1)
                                mrc.updateFilePixelSize(stackpath,apixdict)
                else:
                        apImage.writeMrcStack(stackdir,stackname,ordered_mrc_files, 1)
                        mrc.updateFilePixelSize(stackpath,apixdict)
def writeTiltSeriesStack(stackdir, stackname, ordered_mrc_files, apix=1):
    stackpath = os.path.join(stackdir, stackname)
    print stackpath
    apixdict = {'x': apix, 'y': apix}
    if os.path.exists(stackpath):
        stheader = mrc.readHeaderFromFile(stackpath)
        stshape = stheader['shape']
        imageheader = mrc.readHeaderFromFile(ordered_mrc_files[0])
        imageshape = imageheader['shape']
        if stshape[1:] == imageshape and stshape[0] == len(ordered_mrc_files):
            apDisplay.printMsg("No need to get new stack of the tilt series")
        else:
            apImage.writeMrcStack(stackdir, stackname, order3dmrc_files, 1)
            mrc.updateFilePixelSize(stackpath, apixdict)
    else:
        apImage.writeMrcStack(stackdir, stackname, ordered_mrc_files, 1)
        mrc.updateFilePixelSize(stackpath, apixdict)
Пример #3
0
	def appendParticleListToStackFile(self, partlist, filename):
		"""
		takes any file type and adds a list of particles
		use memory mapping (mmap) to prevent memory overloads
		"""
		if self.particlesWritten < 1 and os.path.exists(filename) and self.params['append'] is False:
			if filename.endswith('.hed') or filename.endswith('.img'):
				root = os.path.splitext(filename)[0]
				headerfile = root+".hed"
				datafile = root+".img"
				os.remove(headerfile)
				os.remove(datafile)
			else:
				os.remove(filename)

		#Determine extension
		if filename.endswith('.mrc'):
			if os.path.exists(filename):
				partarray = numpy.array(partlist)
				mrc.append(partarray, filename)
			else:
				f = open(filename, "wb+")
				partarray = numpy.array(partlist)
				mrc.write(partarray, f)
				f.close()
				apix = self.params['apix']
				pixeldict = {'x': apix, 'y': apix, 'z': apix, }
				mrc.updateFilePixelSize(filename, pixeldict)

		elif filename.endswith('.hed') or filename.endswith('.img'):
			apImagicFile.appendParticleListToStackFile(partlist, filename,
				msg=self.params['debug'])

		elif filename.endswith('.spi'):
			### to be implemented
			apDisplay.printError("SPIDER is not implemented yet")

		elif filename.endswith('.hdf'):
			### to be implemented
			apDisplay.printError("HDF is not implemented yet")

		else:
			apDisplay.printError("unknown stack type")
		self.particlesWritten += len(partlist)
		return True