Пример #1
0
	def get(self, url, sub={}):
		prot, serv, path, par, q, f = parseurl(url)
		if not prot:
			prot='file'
		if prot=='auto':
			v="/"+path.lstrip('/')
			v=str(v)
			if self.store.has_key(v):
				d=self.store[v]
			else:	
				print "no file %s in storage" % v
				return (zeros(0), {})
			if not self.keepstore:
				del(self.store[v])
			return d
		elif prot=='file':
			if os.path.isfile(path):
				if q:
					return self.readHDF(path, q, sub)
				else:	
					return self.readLocalFile(path, sub)
			elif sub.get("Type")=="Auto":	
				print "referenced local file url %s not found" % path
				print "The Data tag specifies the depricated attribute Type:Auto"
				print "this could be do to a bug in the pre-version 1.0 url system. Try to load the file using 'auto://upath'"
			else:	
				print "referenced local file url %s not found" % path
			return (zeros(0), {})
		else:
			print "no support for url type %s yet" % t
			return (zeros(0), {})
Пример #2
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	
Пример #3
0
def add_point(a, p):
	if a.shape[1]>len(p):
		p2 = zeros(a.shape[1], p.dtype.char)
		p2[:len(p)]=p
		p=p2	
	elif a.shape[1]<len(p):
		a2=zeros((a.shape[0]+1, len(p)), a.dtype.char)
		a2[:-1,:a.shape[1]]=a
		a2[-1]=p
		return a2
	return concatenate([a, p[NewAxis, :]])
Пример #4
0
Файл: swc.py Проект: gic888/MIEN
def finishSection(accum, par, cell, points, regions):
	pts=zeros((len(accum),4), float32)
	reg={}
	if len(accum)<2:
		name="s%s" % (accum[0],)	
	else:
		name="s%s_%s" % (accum[0], accum[-1])
	for i, pid in enumerate(accum):
		pts[i]=points[pid]
		rp=regions[pid]
		if not reg.has_key(rp):
			reg[rp]=1
		else:
			reg[rp]+=1
	if len(reg.keys())==1:
		reg=reg.keys()[0]
	else:
		ar=reg.keys()
		ar, rest=ar[0], ar[1:]
		nr=reg[ar]
		for k in rest:
			if reg[k]>nr:
				nr=reg[k]
				ar=k

		print "Neuron-style section %s contains points assigned to several regions (%s). Using %s (which contains the most points)" % (name, str(reg.keys()),ar) 
		reg=ar
	if par:
		try:
			ppt=cell.getSection(par).getPoints()[-1]
		except:
			print [s.name() for s in cell.getElements('Section')]
			print cell._sections
			raise
Пример #5
0
	def nthPoint(self, ind):
		'''Return a set of parameters coresponding to the index i in the 1D parameter space (0<=i<self.size()). The index is interpreted first-parameter-first. i=0 is the state where every parameter is set to the botom of its range. i=1 sets the first parameter to one precision step greater than the minimum. i=self._bins[0] sets the second parameter one step up, etc.'''
		indexes=zeros(self._np)
		for i in range(indexes.shape[0]-1, -1, -1):
			l, ind=divmod(ind, self._strides[i])
			indexes[i]=l
		return self._params.indextoPar(indexes)	
Пример #6
0
def readZip(f, **kwargs):
	from mien.parsers.nmpml import elements as dialect
	f=ZipFile(f, 'r')
	xml=f.read('xml')
	xml=StringIO(xml)
	doc=xm.readTree(xml)
	xml.close()
	doc=xm.assignClasses(doc, dialect)	
	try:
		dat=f.read('data')
	except:
		print "No data archive in zip file"
		return doc
	from mien.parsers.datahash import readMD	
	dat=StringIO(dat)
	dat=readMD(dat, return_raw_hash=True)
	des=doc.getElements('Data')
	for de in des:
		try:
			d, h=dat[de.upath()]
		except:
			print "can't find data for element %s" % (de.upath(),)
			d, h=(zeros(0), {})
		de.datinit(d, h)
	f.close()	
	return doc		
Пример #7
0
	def take(self, ai):
		'''Return an array containing all the rows specified in the index array ai. Ai may specify multiple occurances of the same index. This function is probably slower than numpy.take(self.toarray(), ai), but will use much less memory if ai is short and len(self) is large.'''
		ret=zeros((ai.shape[0],self.width), self.dtype)
		for i in ai:
			self.file.seek(4+4*self.width*i)
			s=self.file.read(self.width*4)
			ret[i,:]=fromstring(s, self.dtype)
		if self.invert:
			ret.byteswap()
		return ret	
Пример #8
0
	def codingtest(self):
		self.prep()
		q=ones(self._np)*-32768
		print q
		print self._params.code16toPar(q)	
		q=ones(self._np)*32767
		print q
		print self._params.code16toPar(q)	
		q=zeros(self._np)
		print q
		print self._params.code16toPar(q)
		print self._params.indextoPar(q)
		q=ones(self._np)*self._params._bins
		q-=1
		print q
		print self._params.indextoPar(q)	
Пример #9
0
	def record(self, c, f):
		'''Writes a chromosome and the fitness value to the arraystore. Not thread safe! (self.lockcall(self.record, (c,f)) is thread safe). f should be a tuple (fit, evalconditions) as returned by general_eval. Return value is the new size of the data store'''
		if self.attrib('EvalConditions'):
			evc = int(self.attrib('EvalConditions'))
			evc=zeros((evc, 1))
			if f[1] and type(f[1])==type(evc):
				c=concatenate([[f[0]], f[1], c])
			else:
				c=concatenate([[f[0]], evc, c])
		else:
			c=concatenate([[f[0]], c])
		if self._storesize!=c.shape[0]:
			raise IOError("Attempt to record a parameter set of the wrong length")
		n=self._store.append(c)
		#print self._store[n-1]
		if self.better(f[0], self._best[0]):
			print "New best %.3f (%s)" % (f[0], str(c))
			self._best=(f[0], n-1)
		return n
Пример #10
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
Пример #11
0
def deserialize(f, **kwargs):
	#st=time.time()
	if not type(f) in [str, unicode]:
		f=f.read()
	l=struct.unpack('<I', f[:4])[0]
	doc=zlib.decompress(f[4:l+4])
	doc=StringIO(doc)
	doc=xm.readTree(doc)
	from mien.parsers.nmpml import elements as dialect
	doc=xm.assignClasses(doc, dialect)	
	f=f[l+4:]
	try:
		if f:
			from mien.parsers.datahash import readMD	
			try:
				f2=StringIO(f)
				f=readMD(f2, return_raw_hash=True)
			except:
				f=zlib.decompress(f)		
				f2=StringIO(f)
				f=readMD(f2, return_raw_hash=True)
			del(f2)
			des=doc.getElements('Data')
			for de in des:
				try:
					d, h=f[de.upath()]
				except:
					print "can't find data for element %s" % (de.upath(),)
					d, h=(zeros(0), {})
				de.datinit(d, h)
	except:
		print "cant load data"
					
	#print time.time()-st;st=time.time()

	return doc		
Пример #12
0
        11.62651 ,  19.49572 ,  35.26103 ,  56.1815  ,  72.74056 ,
        76.81319 ,  76.12871 ,  72.58464 ,  64.29499 ,  48.45283 ,
        27.14701 ,  17.2904  ,  10.02258 ,   5.39836 ,   2.794265,
         0.19017 ,  -1.19344 ,  -2.57705 ,  -3.25246 ,  -3.92787 ,
        -4.19672 ,  -4.46557 ,  -4.535245,  -4.60492 ,  -4.56803 ,
        -4.53114 ,  -4.430325,  -4.32951 ,  -4.208195,  -4.08688 ,
        -3.929505,  -3.77213 ,  -3.633605,  -3.49508 ,  -3.34508 ,
        -3.19508 ,  -3.04836 ,  -2.90164 ,  -2.77705 ,  -2.65246 ,
        -2.535245,  -2.41803 ,  -2.300815,  -2.1836  ,  -2.079505,
        -1.97541 ,  -1.854095,  -1.73278 ,  -1.64262 ,  -1.55246 ,
        -1.47623 ,  -1.4     ,  -1.31967 ,  -1.23934 ,  -1.174585,
        -1.10983 ,  -1.047535,  -0.98524 ,  -0.9336  ,  -0.88196 ,
        -0.83606 ,  -0.79016 ,  -0.74098 ,  -0.6918  ,  -0.654915]), 't': 0.0043}
#used rp= -61.75276999, t1=-41.75, t2=-21.75

BLANKSPIKE ={'tmin': 0.004, 'decay':0, 'attack': 0, 'height': 0, 'width': 0.004, 'depth': 0, 'zc1': 0.004, 'ahprec': 0, 'wave': zeros(80, Float32), 't': 0.0043, 'rp':0}

######### Bode Plots (input and transfer)
#first sample at 1Hz, sampzed every 4 Hz, last sample at 357Hz, first col is amp, second is phase

BODE10_3SOMARin=array([[ 10.        ,  -0.120411  ],
       [  8.76628915,  -0.37065249],
       [  8.61881764,  -0.35894145],
       [  8.60367746,  -0.60747759],
       [  6.75429426,  -0.71382487],
       [  6.7692362 ,  -0.69142732],
       [  5.71806099,  -0.87697651],
       [  4.50451846,  -0.77741426],
       [  4.50725666,  -0.73454663],
       [  4.6735331 ,  -0.76698583],
       [  5.00659179,  -0.71069939],
Пример #13
0
## This program is free software; you can redistribute it and/or modify it under 
## the terms of the GNU General Public License as published by the Free Software 
## Foundation; either version 2 of the License, or (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful, but WITHOUT ANY 
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
## PARTICULAR PURPOSE. See the GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License along with 
## this program; if not, write to the Free Software Foundation, Inc., 59 Temple 
## Place, Suite 330, Boston, MA 02111-1307 USA
## 
import wx

from mien.math.array  import zeros, vstack, ravel, reshape, array, round
ArrayType=type(zeros(1))


def FileBrowse(master, dict, control):
	dlg=wx.FileDialog(master, message="Select file name", style=wx.OPEN)
	dlg.CenterOnParent()
	if dlg.ShowModal() == wx.ID_OK:
		control.SetValue(dlg.GetPath())	
	dlg.Destroy()
	
	
def DirBrowse(master, dict, control):
	dlg=wx.DirDialog(master, message="Select Directory Name", style=wx.DD_NEW_DIR_BUTTON)
	dlg.CenterOnParent()
	if dlg.ShowModal() == wx.ID_OK:
		control.SetValue(dlg.GetPath())