Exemplo n.º 1
0
	def __getitem__(self, key):
		l=len(self)
		if type(key)==slice:
			st=key.start
			if st<0:
				st=l+st
				if st<0:
					st=0
			elif st>l-1:
				return zeros((0, self.width), self.dtype)
			sp=	key.stop
			if sp<0:
				sp=l+sp
				if sp<1:
					return zeros((0, self.width), self.dtype)				
			ne=min(sp, l)
			ne=ne-st
			self.file.seek(4+4*self.width*st)
			a=fromstring(self.file.read(self.width*4*ne), self.dtype)
			if self.invert:
				a.byteswap()
			a=reshape(a, (ne, self.width))	
		else:
			if key<0:
				key=l+key
			self.file.seek(4+4*self.width*key)
			s=self.file.read(self.width*4)
			a=fromstring(s, self.dtype)
			if self.invert:
				a.byteswap()
		return a	
Exemplo n.º 2
0
	def handle(self):
		hl=struct.unpack("<l", self.rfile.read(4))[0]
		h=cPickle.loads(self.rfile.read(hl))
		a=fromstring(self.rfile.read(), "<f4")
		a=reshape(a, h['ashape'])
		del(h['ashape'])
		self.server.plot(a,h)
		self.wfile.write("ok")
Exemplo n.º 3
0
	def get_drawing_coords(self):
		'''No Args => array
return a 2Nx3 (or 2Nx4) array containing the start and stop coordinates for each
frustum specified in self.points.'''
		points =self.getPoints()
		s = points.shape
		points = concatenate([points, points],1)
		points = reshape(points, (-1, s[1]))[1:-1]
		return points
Exemplo n.º 4
0
def arrayfromstring(s, prec=None):
	if '(' in s:
		shape, values=s.split(':')
		return reshape(arrayfromstring(values), eval(shape))
	elif ";" in s:
		return vstack([arrayfromstring(l) for l in s.split(';')])
	elif prec or ("." in s):
		return array(map(float, s.split(',')))
	else:
		return array(map(int, s.split(',')))
Exemplo n.º 5
0
def readMD(f, **kwargs):
	dats={}
	cat=f.read(16)
	while len(cat)==16:
		pl, hl, dl = struct.unpack("<IIQ", cat)
		path=f.read(pl)
		head=eval(f.read(hl))
		dat=None
		if dl:
			ct=f.read(1)
			if ct in ['<', '>', '|', "{"]:
				ct=ct+f.read(6)
				dti, nd = struct.unpack("<3sI", ct)
				if dti.startswith("{"):
					dti=dti[1:]
				dti=dtype(dti)
			else:
				print "warning, old mdat. May not be platform portable"
				nd = struct.unpack("<I", f.read(4))[0]
				dti=dtype("<"+ct)				
			sh=struct.unpack("<"+"Q"*nd, f.read(8*nd))
			dat=f.read(dl)
			dat=fromstring(dat, dti)
			dti=dti.str
			if DTS!=dti[0]:
				dtil=dtype(DTS+dti[1:])
				dat=dat.astype(dtil)
			dat=reshape(dat, sh)
		dats[path]=(dat, head)	
		cat=f.read(16)	
	try:
		url="file://%s" % (f.name,)
	except:
		try:
			url=f.geturl()
		except:
			url=None		
	if kwargs.get('return_raw_hash'):
		return dats	
	else:
		return hash2doc(dats, url)		
Exemplo n.º 6
0
def readDens(inf, **kwargs):
	l=inf.readlines()	
	if len(l)==1000002:
		l=array([float(line.split()[3]) for line in l[2:]])	
		l=reshape(l, (100,100,100))
	else:
		v=array([float(line.split()[3]) for line in l[2:]])	
		ind=array([map(int, line.split()[:3]) for line in l[2:]])
		l=zeros((ind[:,0].max()+1, ind[:,1].max()+1, ind[:,2].max()+1), Float32)
		for i in range(v.shape[0]):
			l[ind[i,0],ind[i,1], ind[i,2]]=v[i]
	
	mv = l.max()	
	l/=mv
	o = mien.parsers.nmpml.createElement("SpatialField", {"Origin":ORIGIN.tolist(), "Edge":(EDGE,EDGE,EDGE),
			"Vertical":(0.0,1.0,0.0), "Depth":(0.0,0.0,-1.0), "MaxValue":mv,
			"mindensity":.0001, "maxdensity":.1})
	n = mien.parsers.nmpml.blankDocument()
	n.newElement(o)
	d=o.getData()
	d.datinit(l)
	return n
Exemplo n.º 7
0
	def toarray(self):
		self.file.seek(4)
		a=fromstring(self.file.read(), self.dtype)
		if self.invert:
			a.byteswap()
		return reshape(a, (-1, self.width))