Пример #1
0
	def read(self, transport, max_particles = 9000000, ):

		print ( "Reading binary boxes from " + transport.address )
		
		containers = {}
		if self.elemets_description:
			for element in self.elemets_description:
				containers[element] = ParticlesContainer(element, self.elemets_description[element]["atom_d"], self.elemets_description[element]["atom_mass"])
		else:
			containers = ParticlesContainer("Unknown", 1, 1)
		
		if self.elemets_description:
			print ("Created {} containers".format(len(containers)))
		particles_count = max_particles;
		
		raw_particles  = self.data_parser(transport).raw_particles(max_particles)
		
		n = raw_particles["n"]
		t = raw_particles["t"]
		x = raw_particles["x"]
		y = raw_particles["y"]
		z = raw_particles["z"]
		vx = raw_particles["vx"]
		vy = raw_particles["vy"]
		vz = raw_particles["vz"]
		particles_count = raw_particles["count"]

		if self.elemets_description:
			for element in self.elemets_description:
				print "Filtering by type ", element
				containers[element].set_particles(n[t == self.elemets_description[element]["id"]], 
												 x[t == self.elemets_description[element]["id"]],
												 y[t == self.elemets_description[element]["id"]],
												 z[t == self.elemets_description[element]["id"]], 
												 vx[t == self.elemets_description[element]["id"]],
												 vy[t == self.elemets_description[element]["id"]],
												 vz[t == self.elemets_description[element]["id"]])

				print "Finalizing ", element
				containers[element].finalize()
				print ("Readed [{}] {} particles".format(len(containers[element].n),element))
		
		else:
			print "Finalizing"
			containers.set_particles(n, x, y, z, vx, vy, vz)
			containers.finalize()
			print ("Readed [{}] particles".format(len(containers.n)))
			
		print "returning"
		return containers
Пример #2
0
	def read(self, transport, max_particles = 100000, np=5):

		print ( "Reading backup directory " + transport.address )

		files = transport.list()
		
		containers = {}

		if self.elemets_description:
			for element in self.elemets_description:
				containers[element] = ParticlesContainer(element, self.elemets_description[element]["atom_d"], self.elemets_description[element]["atom_mass"])
		else:
			containers = ParticlesContainer("Unknown", 1, 1)
		
		if self.elemets_description:
			print ("Created {} containers".format(len(containers)))
		particles_count = max_particles;

		pool = mp.Pool(processes=np)
	
		results = [pool.apply_async(rd, args=(f, transport, max_particles)) for f in files]
		print "Created ",np," readers"

		ts = time();
		for raw_particles in results:
			raw_particles = raw_particles.get()
			n = raw_particles["n"]
			t = raw_particles["t"]
			x = raw_particles["x"]
			y = raw_particles["y"]
			z = raw_particles["z"]
			vx = raw_particles["vx"]
			vy = raw_particles["vy"]
			vz = raw_particles["vz"]
			particles_count = raw_particles["count"]
			tts = time()
			if self.elemets_description:
				
				for element in self.elemets_description:
			#		print "Filtering by type ", element
		
					containers[element].add_particles(n[t == self.elemets_description[element]["id"]], 
													 x[t == self.elemets_description[element]["id"]],
													 y[t == self.elemets_description[element]["id"]],
													 z[t == self.elemets_description[element]["id"]], 
													 vx[t == self.elemets_description[element]["id"]],
													 vy[t == self.elemets_description[element]["id"]],
													 vz[t == self.elemets_description[element]["id"]])

		
			else:
			#	print "Finalizing"
				containers.add_particles(n, x, y, z, vx, vy, vz)
				
		if self.elemets_description:
			for element in self.elemets_description:	
				print "Finalizing ", element
				containers[element].finalize()
				print ("Readed [{}] {} particles".format(len(containers[element].n),element))
		else:
			print "Finalizing "
			containers.finalize()
			print ("Readed [{}] particles".format(len(containers.n)))


		print "Readed directory, total read time:", time()-ts
		
		return containers