Ejemplo n.º 1
0
	def __init_memory(self,options):
		'''
		This function assigns critical attributes
		'''
#		print "init ",options
		from EMAN2PAR import image_range
		shrink = None
		if "shrink" in options and options["shrink"] != None and options["shrink"] > 1:
			shrink = options["shrink"]

		ref_data_name=self.data["references"][1]
		ref_indices = image_range(*self.data["references"][2:])

		if "colmasks" in self.data :
			ref_masks_name=self.data["colmasks"][1]
		else : ref_masks_name=None

		if "mask" in self.data :
			mask=EMData(self.data["mask"][1],self.data["mask"][2])
			if shrink != None : mask.process_inplace("math.fft.resample",{"n":shrink})
		else : mask=None

#		print self.data["references"][2:]
		refs = {}
		for idx in ref_indices:
			datareaderror=True
			for datareadid in range(20):
				try: image = EMData(ref_data_name,idx)
				except:
					print("Failed to read %s. Wait for 5s and try again."%(str(idx)))
					time.sleep(5)
				else:
					datareaderror=False
					break
			if datareaderror:
				print("Cannot read image. Give up.")
				raise Exception("Couldn't read data in init_memory")
				
			if shrink != None:
				image.process_inplace("math.fft.resample",{"n":shrink})

			if ref_masks_name==None :
				refs[idx] = (image,None)
			else :
				mask=EMData(ref_masks_name,idx)
				if shrink != None:
					mask.process_inplace("math.fft.resample",{"n":shrink})
				refs[idx] = (image,mask)

		ptcl_data_name=self.data["particles"][1]
		ptcl_indices = image_range(*self.data["particles"][2:])

		ptcls = {}
		for idx in ptcl_indices:
			datareaderror=True
			for datareadid in range(20):
				try: image = EMData(ptcl_data_name,idx)
				except:
					print("Failed to read %s in %s from range %s. Wait for 5s and try again."%(str(idx),ptcl_data_name,str(ptcl_indices)))
					time.sleep(5)
				else:
					datareaderror=False
					break
			if datareaderror:
				print("Cannot read image. Give up.")
				raise Exception("Couldn't read data in init_memory")
			
			
			if shrink != None:
				image.process_inplace("math.fft.resample",{"n":options["shrink"]})
# removed 8/2/12 stevel. Don't want to apply mask before alignment
#			if mask!=None : image.mult(mask)
			ptcls[idx] = image

		# Note that 'refs' is now a dictionary of tuples: (reference,mask) or (reference,None)
		return refs,ptcls,shrink,mask
Ejemplo n.º 2
0
	def __init_memory(self,options):
		'''
		This function assigns critical attributes
		'''
#		print "init ",options
		from EMAN2PAR import image_range
		shrink = None
		if options.has_key("shrink") and options["shrink"] != None and options["shrink"] > 1:
			shrink = options["shrink"]

		ref_data_name=self.data["references"][1]
		ref_indices = image_range(*self.data["references"][2:])

		if self.data.has_key("colmasks") :
			ref_masks_name=self.data["colmasks"][1]
		else : ref_masks_name=None

		if self.data.has_key("mask") :
			mask=EMData(self.data["mask"][1],self.data["mask"][2])
			if shrink != None : mask.process_inplace("math.meanshrink",{"n":options["shrink"]})
		else : mask=None

#		print self.data["references"][2:]
		refs = {}
		for idx in ref_indices:
			datareaderror=True
			for datareadid in range(20):
				try: image = EMData(ref_data_name,idx)
				except:
					print "Failed to read %s. Wait for 5s and try again."%(str(idx))
					time.sleep(5)
				else:
					datareaderror=False
					break
			if datareaderror:
				print "Cannot read image. Give up."
				raise Exception,"Couldn't read data in init_memory"
				
			if shrink != None:
				image.process_inplace("math.meanshrink",{"n":options["shrink"]})

			if ref_masks_name==None :
				refs[idx] = (image,None)
			else :
				mask=EMData(ref_masks_name,idx)
				if shrink != None:
					mask.process_inplace("math.meanshrink",{"n":options["shrink"]})
				refs[idx] = (image,mask)

		ptcl_data_name=self.data["particles"][1]
		ptcl_indices = image_range(*self.data["particles"][2:])

		ptcls = {}
		for idx in ptcl_indices:
			datareaderror=True
			for datareadid in range(20):
				try: image = EMData(ptcl_data_name,idx)
				except:
					print "Failed to read %s in %s from range %s. Wait for 5s and try again."%(str(idx),ptcl_data_name,str(ptcl_indices))
					time.sleep(5)
				else:
					datareaderror=False
					break
			if datareaderror:
				print "Cannot read image. Give up."
				raise Exception,"Couldn't read data in init_memory"
			
			
			if shrink != None:
				image.process_inplace("math.meanshrink",{"n":options["shrink"]})
# removed 8/2/12 stevel. Don't want to apply mask before alignment
#			if mask!=None : image.mult(mask)
			ptcls[idx] = image

		# Note that 'refs' is now a dictionary of tuples: (reference,mask) or (reference,None)
		return refs,ptcls,shrink,mask