Ejemplo n.º 1
0
Archivo: cli.py Proyecto: gic888/MIEN
def save(fn=None, format='guess'):
	'''write the current document to a file. If fn is not specified, and the 
	document was concatenated from multiple files, it will save to the first of
	these files (overwriting data)''' 
	if not fn:
		fn=doc.fileinformation.get('filename', 'miendoc.nmpml')
	io.write(doc, fn, format=format)
Ejemplo n.º 2
0
def sum_stack(fn,sw):
	'''Measures relative illumination between frames. Sums the values of each frame, divides by the number of pixels, and removes the mean.'''
	dat, fs = retrieveData(fn[0],sw)
	nframes = dat.shape[3]
	print('processing image stack: %ix%i, %i frames ...' % (dat.shape[0], dat.shape[1], nframes))
	s = zeros(nframes)
	for k in arange(nframes):
		s[k]=sum(dat[:,:,0,k])
	numpix = float32(dat.shape[0]*dat.shape[1])
	s = s/numpix
	s -= s.mean()
	if len(s.shape)==2:
		s=s.reshape(-1,)
	h = nmpdat.newHeader(fs=fs)
	nd = nmpdat.newData(s, h)
	doc = nmp.blankDocument()
	doc.newElement(nd)
	if sw.has_key('dir'):
		a = io.write(doc,sw['dir'] + '/' + sw['sum_file'])
	else:	
		a = io.write(doc,sw['sum_file'])
	if a:
		print "%s successfully written." % sw['sum_file']
	else:	
		print "%s failed to write." % sw['sum_file']
	
	return s, fs
Ejemplo n.º 3
0
def makeDBGroup(lfn):
    """For each file in the list, make a database group containing the metadata for these objects. Also, remove these metadata from the objects contained within the group. Attempt's to guess a database ID ane assign it as the name of the group as well"""

    PATH = "/CercalSystem/"
    for fn in lfn:
        doc = io.read(fn)
        m = db_getmetas(doc, False)
        if "meta_dbid" in m:
            name = m["meta_dbid"]
            del (m["meta_dbid"])
        else:
            try:
                name = "%s_%s_%s" % (m["meta_length"][0].upper(), str(m["meta_class"]), str(m["meta_slide_number"]))
            except:
                name = "DBGroup"
        print "setting group %s in %s" % (name, fn)
        m["Name"] = name
        m["DBrecord"] = PATH
        m["DBurl"] = URL
        group = createElement("Group", m)
        els = doc.elements[:]
        doc.newElement(group)
        for e in els:
            e.move(group)
        del (m["Name"])
        for e in group.getElements():
            for k in m:
                if k in e.attributes:
                    del (e.attributes[k])
            for k in ["Color", "DisplayGroup"]:
                if k in e.attributes:
                    del (e.attributes[k])
        io.write(doc, fn)
Ejemplo n.º 4
0
def convertMetas(lfn):
    """set some values for the metadata tags cercal_distance, class, cercus, and directional_tuning. Use these to set color. Sets cercal_distance to 10 (proximal). Uses the dircolors module to infer class and thus direction and color. This module assumes the data are stored in a file name of origin, using "." as the field separator."""
    for fn in lfn:
        print fn
        doc = io.read(fn)
        els = doc.getElements(["Cell", "Fiducial", "SpatialField"], depth=1)
        for e in els:
            e.setAttrib("meta_cercal_distance", 10)
            aclass = e.attrib("meta_class")
            if aclass == None:
                try:
                    dc._getclass(e)
                    aclass = e.attrib("meta_class")
                except:
                    print "failed to get class for %s" % fn
                    continue
            cerc = e.attrib("meta_cercus").lower()[0]
            try:
                d = dc.DIRECTIONS[aclass]
            except:
                print "no directional tuning for  %s" % (str(aclass),)
                continue
            if cerc == "r":
                d = 360 - d
            e.setAttrib("meta_directional_tuning", d)
            d = d % 360
            ang = d * pi / 180
            c = dc._getAngleColor(ang)
            pycol = dc.convertColor(c, "py")
            if "Color" in e.attributes:
                del (e.attributes["Color"])
            e.setAttrib("color", pycol)
        io.write(doc, fn)
Ejemplo n.º 5
0
def procFile(fn, rot, nfn):
	f = open(fn, 'rb')
	h = getInfo(f)
	nframes=h['nframes']
	print "converting %s (%i frames)" % (fn, nframes)
	if nframes<1000:
		frames = arange(nframes)
	else:
		frames = None
	dat = chunkOFrames(fn, frames)
	me = dat.mean(3)[...,0]
	out = []
	for i in range(nframes):
		frame = readFrameN(f, h, i) - me
		if rot!=None:
			frame, junk = imrotate(frame, 1, rot)
		x = frame.sum(1)
		if options['w']>1:
			x=convolve(ones(options['w']), x, mode='same')
		out.append(argmax(x))
		if not i%500:
			print "... frame %i" % i
	out = array(out, float32)
	dat = mdat.newData(out, {'SampleType':'timeseries', 'SamplesPerSecond':1.0/h['timescale']})
	doc = nmpml.blankDocument()
	doc.newElement(dat)
	io.write(doc, nfn)	
Ejemplo n.º 6
0
def batchSort(tf, df):
    if type(tf) == str:
        tf = io.read(tf)
    bn = os.path.split(df)[-1]
    bn, ext = os.path.splitext(bn)
    bn = bn + "-" + ext[1:]
    sfn = bn + "_sorted_spikes.mdat"
    dfstr = df
    df = io.read(df)
    print (tf.getElements("Data", "spikesorter_setup", depth=2))
    setup = tf.getElements("Data", "spikesorter_setup", depth=2)[0]
    temps = tf.getElements("Data", depth=2)
    temps = [t for t in temps if t.name().startswith("spikesort_")]
    temps.sort(sortByOrder)
    dat = df.getElements("Data", depth=1)[0]
    writeShifts(dat, zeros(dat.shape()[1]))
    precondition(dat, setup)
    writeShifts(dat, zeros(dat.data.shape[1]))
    for t in temps:
        spi = detect(dat, t, bn)

    if TOSAVE:
        # newfname=sys.argv[1]
        # newfname, jnk=os.path.splitext(newfname)
        dfstr = os.path.basename(dfstr)
        dfstr, jnk = os.path.splitext(dfstr)
        newfname = "spikes" + dfstr + ".mdat"
        print (newfname)
        io.write(tf, newfname, newdoc=False)

    spikes = dat.getSubData("/spikes")
    io.write(spikes, sfn, newdoc=True, format=".mdat")
Ejemplo n.º 7
0
def defaultMetas(lfn):
    """ sets length:long, class:0, cercus:left, instar:10, slide_number:-1, directional_tuning:0, cercal_distance:10. If any of these attributes already have values, this function will not overwrite them. It is mainly useful to prevent functions that crash if these basic metas are undefined from crashing. If you want to change the defaults, you may pass arguments that are of the form name:value, as well as file names. For example meta_cercus:right fn1 fn2  will operate on files fn1 and fn2, but will set cercus:right as well as the other defaults listed above."""
    defaults = {
        "meta_length": "long",
        "meta_class": 0,
        "meta_cercus": "left",
        "meta_instar": 10,
        "meta_slide_number": -1,
        "meta_directional_tuning": 0,
        "meta_cercal_distance": 10,
    }

    files = []
    for s in lfn:
        if ":" in s:
            n, v = s.split(":")
            defaults[n] = v
        else:
            files.append(s)
    for fn in files:
        doc = io.read(fn)
        for e in doc.getElements(["Cell", "Fiducial", "SpatialField"]):
            for a in defaults:
                if not a in e.attributes:
                    e.setAttrib(a, defaults[a])
                elif a == "meta_directional_tuning":
                    e.setAttrib("meta_directional_tuning", e.attrib("meta_directional_tuning") % 360)
        io.write(doc, fn)
Ejemplo n.º 8
0
def knit(dname):
	if os.path.isfile(os.path.join(dname, 'concat_ex.mdat')):
		os.unlink(os.path.join(dname, 'concat_ex.mdat'))
	if os.path.isfile(os.path.join(dname, 'concat.mdat')):
		os.unlink(os.path.join(dname, 'concat.mdat'))		
	print("=== processing directory %s ===" % dname)
	dat_all = []
	dat_ex = []
	mf_allch = []
	mdat = [f for f in os.listdir(dname) if f.endswith("_ts.mdat")]
	date = mdat[0][:10]
	if all([f[:10] == date for f in mdat]):
		if os.path.isfile(os.path.join(dname, date+'concat_ex.mdat')):
			os.unlink(os.path.join(dname, date+'concat_ex.mdat'))
		if os.path.isfile(os.path.join(dname, date+'concat.mdat')):
			os.unlink(os.path.join(dname, date+'concat.mdat'))		
	else:
		print "Multiple experiments present -- aborting. Put separate experiments in different folders."
		return None	
	bin = [f for f in os.listdir(dname) if f.endswith(".bin")]
	for f in mdat:
		ff1=os.path.join(dname, f)
		f2 = getMatch(f[:-8], bin)
		if not f2:
			print("can't match %s" % (f,))
			continue
		ff2 = os.path.join(dname, f2)
		print("adding file pair %s, %s" % (f, f2))
		dat1 = io.read(ff1).getElements("Data")[0]
		dat2 = io.read(ff2).getElements("Data")[0]
		dat2 = cropMicroflown(dat2)
		# crpd = dat2.getData()
		# ds = miendata.newData(crpd, {'SampleType':'timeseries', 'SamplesPerSecond':10000})
		# doc = nmpml.blankDocument()
		# doc.newElement(ds)
		# io.write(doc, os.path.join(dname, 'crpd.mdat'))
		resample(dat1, 1000)
		resample(dat2, 1000)
		dat1 = dat1.getData()
		dat2 = dat2.getData()[:,2]
		if dat1.shape[0] < dat2.shape[0]:
			dat2 = dat2[:dat1.shape[0]]
		elif dat1.shape[0] > dat2.shape[0]:
			dat1 = dat1[:dat2.shape[0]]
		dat1 -=  dat1.mean()
		dat2 -= dat2.mean()
		dd = column_stack([dat1, dat2])
		dat_all.append(dd)
		if not any([q in f.lower() for q in EXCLUDE]):
			dat_ex.append(dd)
	dat = row_stack(dat_all)
	ds = miendata.newData(dat, {'SampleType':'timeseries', 'SamplesPerSecond':1000})
	doc = nmpml.blankDocument()
	doc.newElement(ds)
	io.write(doc, os.path.join(dname, date+'concat.mdat'))
	if len(dat_ex) < len(dat_all):
		dat = row_stack(dat_ex)
		ds.datinit(dat)
		io.write(doc, os.path.join(dname, date+'concat_ex.mdat'))
Ejemplo n.º 9
0
def writeFile(f,fname='TestMe',sps=None,start=0):
	ndoc = nmpml.blankDocument()
	if sps:
		tf = mdat.newData(f, {'Name':fname, 'SampleType':'timeseries', 'SamplesPerSecond':sps, "StartTime":start}) 
	else:			
		tf = mdat.newData(f, {'Name':fname, 'SampleType':'function'}) 
	ndoc.newElement(tf)
	io.write(ndoc, fname+".mdat")		
Ejemplo n.º 10
0
def makeSubgroups(lfn):
    """Takes the name of an attribute as the first argument, followed by a list of files. For all group element in the files, if at least two, and less than all, of the children  of that group have the same value for the named attribute, a subgroup is created to contain them."""
    attr = lfn[0]
    for fn in lfn[1:]:
        doc = io.read(fn)
        for e in doc.elements:
            if e.__tag__ == "Group":
                _makeSubGroup(e, attr)
    io.write(doc, fn)
Ejemplo n.º 11
0
def setmeta(lfn):
    """the first argument should be a metadata tag (without the leading meta_), and the second should be a value. Sets this tag to this value in all the listed files. If the value is DEL, removes the tag."""
    md = "meta_" + lfn[0]
    mv = lfn[1]
    for fn in lfn[2:]:
        doc = io.read(fn)
        for e in doc.getElements(["Cell", "Fiducial"]):
            e.setAttrib(md, mv)
        print "set %s in %s" % (md, fn)
        io.write(doc, fn)
Ejemplo n.º 12
0
def stimwrite(ds, nchans=1, fname='fromds'):
	'''write a stimulus with nchans to file fname. If fname is fromds, use the attribute "fname" of ds (which must have been previously set). fname should not include a file type extension'''
	if fname=='fromds':
		fname=ds.attrib('fname')
	if nchans>1:
		ext='.dcl'
	else:
		ext='.scl'
	fname=fname+ext	
	write(ds, fname, newdoc=True, format=ext)
Ejemplo n.º 13
0
def convert_aff(fname, scale=1.0):
	doc = getAff(fname)
	if not doc:
		return
	if scale!=1.0:
		sd={ 'Scale_x':scale, 'Scale_y':scale, 'Scale_z':scale}
		for e in doc.getElements(depth=1):
			alignObject(e, sd)
	fname = os.path.splitext(fname)[0]+'.nmpml'
	io.write(doc, fname, format='nmpml')
Ejemplo n.º 14
0
def save_wo_leak(ds,name):
	''' 
	Saves data in mien formats without the usual memory leaks of using the mien function directly
	'''
	import mien.parsers.fileIO as IO
	from mien.parsers.nmpml import blankDocument
	doc = blankDocument()
	doc.newElement(ds)
	IO.write(doc, name)
	ds.sever()
	doc.sever()
Ejemplo n.º 15
0
def writeFile(f, sps, fname='CubicFunctions', start=0):
    ndoc = nmpml.blankDocument()
    tf = mdat.newData(
        f, {
            'Name': fname,
            'SampleType': 'timeseries',
            'SamplesPerSecond': sps,
            "StartTime": start
        })
    ndoc.newElement(tf)
    io.write(ndoc, fname + ".mdat")
Ejemplo n.º 16
0
Archivo: nmpml.py Proyecto: gic888/MIEN
def saveData(ds, fname, format='mdat', dpath='/', recurse=True):
	'''Saves the data in ds (or the specified subelemnt if dpath is not /)
to the file fname, using the specified format. This will not alter values in 
ds.

SWITCHVALUES(recurse)=[False, True]'''
	if dpath and dpath!='/':
		ds=ds.getSubData(dpath)
	if not recurse:
		ds=ds.clone(False)
	from mien.parsers.fileIO import write
	write(ds, fname, format=format, newdoc=1)	
Ejemplo n.º 17
0
def save_wo_leak(ds,name):
    '''
    Saves data in mien formats without the usual memory leaks of using the mien function directly
    '''
    [ds] = check_inputs([ds],[['Data','list','ndarray']])
    name = check_fname(name)
    from mien.parsers.fileIO import write
    from mien.parsers.nmpml import blankDocument
    doc = blankDocument()
    doc.newElement(ds)
    write(doc, name)
    ds.sever()
    doc.sever()
Ejemplo n.º 18
0
def gmms2data(lfn):
    for fn in lfn:
        doc = io.read(fn)
        doc2 = blankDocument()
        gmms = doc.getElements("MienBlock", {"Function": "ccbcv.gmm.gmm"})
        for g in gmms:
            atr = g.getInheritedAttributes()
            pars = g.getArguments()
            weights = array(pars["weights"])
            means = reshape(array(pars["means"]), (weights.shape[0], -1))
            covs = reshape(array(pars["covs"]), (means.shape[0], means.shape[1], means.shape[1]))
            doc2.newElement(_gmm2dat(atr, weights, means, covs))
        io.write(doc2, fn + ".mat")
Ejemplo n.º 19
0
def scale134(lfn):
    """scale the elements in the listed files by a factor of 1.34 in x y and z (but not d)"""
    from mien.spatial.alignment import alignObject

    for n in lfn:
        doc = io.read(n)
        nn, ext = os.path.splitext(n)
        nn = nn + "_scaledup" + ext
        factor = 1.34
        scale = {"Scale_x": factor, "Scale_y": factor, "Scale_z": factor}
        els = doc.getElements(["Cell", "Fiducial", "SpatialField"])
        for e in els:
            alignObject(e, scale)
        io.write(doc, nn)
Ejemplo n.º 20
0
def allTFs(fnames):
	ndoc = nmpml.blankDocument()
	for fname in fnames:
		doc = io.read(fname)
		ds = doc.getElements("Data", depth=1)[0]
		bn=os.path.splitext(fname)[0]
		tf = tffmax(ds, False)
		if not tf:
			continue
		if fname.startswith("2009") or fname.startswith("2010"):
			tf.data[:,2]+=pi
			tf.data[:,2] = tf.data[:,2] -  ( 2*pi*(tf.data[:,2]>pi))
		tf.setName(bn)
		ndoc.newElement(tf)
	io.write(ndoc, "allTFs.mdat")
Ejemplo n.º 21
0
Archivo: cli.py Proyecto: gic888/MIEN
def runmethod(doc, element):
	'''Find and run a method of one of the objects in the specified 
Document. There are several syntaxes for "element"

The most complete syntax is an nmpml upath, joined by a "." to the name
of a method (e.g. "/NmpmlDocument:MyDoc/Experiment:MyExperiment1.run) If
the path doesn't begin with a "/" but does contain a ":" the toplevel
document element is automatically matched, and the seach begins below
it. This syntax exactly specifies a particular element and method, which
must exist of the command fails immeadiately.

Alternatively, the path may be only an nmpml tag, joined to a method by
a '.' (eg "Experiment.run"). In this case mien will find the first
instance of that tag (using a bredth first search) and call the method

The method name may be ommitted, in which case it is assumed to be
"run", so "-r Experiment" is equivalent to the other examples above, if
called on a document that only defines one Experiment tag
'''
	if '.' in element:
		element, method=element.split('.')
	else:
		method="run"
	
	if ":" in element:
		element=doc.getInstance(element)
	else:
		els=doc.getElements(element, depth=1)
		if len(els)==0:
			print "no top level elements of type %s" % element
			return
		elif len(els)>1:
			print "Warning, found %i toplevel elements of type %s. Using the first one (%s)" % (len(els),element,str(els[0]))
		element=els[0]	
	r=getattr(element, method)
	st=time.time()
	out = r()
	print "Run complete in %.2f seconds" % (time.time()-st)
	if out:
		print "Result - %s" % (repr(out),)
	else:
		print "No Output"
	st=time.time()
	fname=doc.fileinformation.get("filename", 'clidoc.mien')
	fname, ext=os.path.splitext(fname)
	fname=fname+"_batchrun"+ext
	io.write(doc, fname)
	print "Saved model to %s in %.2f seconds" % (fname, time.time()-st)	
Ejemplo n.º 22
0
def setAttrs(lfn):
    """Takes a list of "name:value" pairs and a list of filenames, and assigns all the attributes in the name:value pairs to all the toplevel elements in the files. Any input not containing a ":" is assumed to be a file name"""
    attrs = {}
    files = []
    for e in lfn:
        if ":" in e:
            n, v = e.split(":")
            attrs[n] = v
        else:
            files.append(e)
    for fn in files:
        doc = io.read(fn)
        for e in doc.elements:
            for n in attrs:
                e.setAttrib(n, attrs[n])
        io.write(doc, fn)
Ejemplo n.º 23
0
def constructTFs(fname):
	if fname.endswith("_tf.mdat"):
		return
	print("====%s====" % fname)
	doc = io.read(fname)
	ds = doc.getElements("Data", depth=1)[0]
	bn=os.path.splitext(fname)[0]
	ndoc = nmpml.blankDocument()
	for mn in tfmethods:
		tf = tfmethods[mn](ds)
		if not tf:
			continue
		tf.setName(mn)
		ndoc.newElement(tf)
	ofn = bn + "_tf.mdat"
	io.write(ndoc, ofn)
Ejemplo n.º 24
0
def pts2data(arg):
    """pts2data  fname [fname2 [...]] - extract points from sphere fiducials to a text data file

This function will load the contents of all the named files (provided they are readable by MIEN), 
select all the Fiducial elements that have Style == spheres, extract the point data from these
elements, concatenate the data into a single data element, and print that data to standard output
in text data file format. You can use shell redirection (e.g. "pts2data fname > data.txt") to 
write the points to a file.
"""
    doc = io.readall(arg)
    fid = doc.getElements("Fiducial", {"Style": "spheres"})
    pts = [f.getPoints() for f in fid]
    pts = row_stack(pts)
    d = md.newData(pts, {"SampleType": "generic"})
    f = io.match_extension("txt")[0]
    io.write(d, sys.stdout, format=f, newdoc=True)
Ejemplo n.º 25
0
def process(fn, sw):
	#gc.set_debug()
	print('loading image stack ...')
	f=io.read(fn)
	d=f.getElements('Data')[0]
	dat = d.getData()
	h = d.header()
	print('processing image stack: %ix%i, %i frames ...' % (dat.shape[0], dat.shape[1], dat.shape[3]))
	if sw.get('xmin'):
		xm=sw['xmin']
		dat=dat[xm:,:,:]
	else:
		xm=0
	if sw.get('ymin'):
		ym=sw['ymin']
		dat=dat[:, ym:,:,:]
	else:
		ym=0
	if sw.get('xmax', -1)!=-1:
		xx=sw['xmax']
		xr=xx-sw.get('xmin', 0)
		dat=dat[:xr, :,:,:]
	else:
		xx=dat.shape[0]
	if sw.get('ymax', -1)!=-1:
		yy=sw['ymax']
		yr=yy-sw.get('ymin', 0)
		dat=dat[:, :yr,:,:]
	else:
		yy=dat.shape[1]
	print 'cropped to %ix%i' % (xr,yr)
	h['OriginalDims'] = (dat.shape[0],dat.shape[1])
	h['XDims'] = (xm,xx)
	h['YDims'] = (ym,yy)
	if sw.has_key('subtract_mean'):
		print "calculating mean ..."
		dat=dat.astype(float32)-dat.mean(3)[:,:,:,newaxis]
		dat-=dat.min()
		dat/=dat.max()
		h['SubtractMean']=True
	else:
		h['SubtractMean']=False
	if sw.get('rotate'):
		print "rotating ..."
		dat=imrotate(dat, sw['rotate'])
		h['Rotated'] = sw['rotate']
	else:
		h['Rotated'] = 0
	print('writing image stack ...')
	f=newFile(dat,h)
	if sw.has_key('AOS_dir'):
		fname=sw['AOS_dir']+'/'+sw['AOS_file']
	else:
		fname=sw['AOS_file']
	a1=io.write(f,fname)	
	if a1:
		print "Wrote %s." % fname
	else:
		print "Failed to write %s." % fname
Ejemplo n.º 26
0
def setMetasFromNames_(lfn):
    """construct metadata tags based on structured file names"""
    for fn in lfn:
        doc = io.read(fn)
        atr = meta_from_name(fn)
        for e in doc.getElements():
            for a in atr:
                e.setAttrib(a, atr[a])
            for a in ["meta_cercal_length"]:
                if a in e.attributes:
                    del (e.attributes[a])
            ang = e.attrib("meta_directional_tuning") % 360
            ang = ang * dc.pi / 180
            c = dc._getAngleColor(ang)
            pycol = dc.convertColor(c, "py")
            e.setAttrib("color", pycol)
        io.write(doc, fn)
Ejemplo n.º 27
0
def allTFsRs(fnames):
	ndoc = nmpml.blankDocument()
	for fname in fnames:
		doc = io.read(fname)
		ds = doc.getElements("Data", depth=1)[0]
		bn=os.path.splitext(fname)[0]
		tf = tffmax(ds, False)
		if not tf:
			continue
		tf = tf.getData()
		if fname.startswith("2009") or fname.startswith("2010"):
			tf[:,2]+=pi
			tf[:,2] = tf[:,2] -  ( 2*pi*(tf[:,2]>pi))
		tf = row_stack( [array([[0,0,0]]), tf, array([[250,tf[-1,1],tf[-1,2]]])])
		tf = uniformsample(tf, 1.0)
		tf = mdat.newData(tf, {'Name':bn, 'SampleType':'timeseries', 'SamplesPerSecond':1.0, "StartTime":0})
		ndoc.newElement(tf)
	io.write(ndoc, "allTFsResamp.mdat")		
Ejemplo n.º 28
0
def spikeDistanceTest(st, rt):
	m, id1, id2=getAllDist(st, rt)
	print m
	d=makeEquiv(m, id1, id2)
	print d
	de=newData(zeros(0), {'SampleType':'group'})
	for i in range(d.shape[0]):
		rst=rt.getData()
		print rst.shape
		rst=take(rst[:,0], nonzero(rst[:,1]==d[i,1])[0], 0)
		est=st.getData()
		est=take(est[:,0], nonzero(est[:,1]==d[i,0])[0], 0)
		cst=zeros((rst.shape[0]+est.shape[0],2))
		cst[:rst.shape[0],0]=rst
		cst[rst.shape[0]:,0]=est
		cst[rst.shape[0]:,1]=1
		cde=de.createSubData("/unit%i" % (int(d[i,1]),), cst, {'SampleType':'labeledevents', 'SamplesPerSecond':rt.fs()})
	io.write(de, "check_results.mdat", format=".mdat", newdoc=True)
Ejemplo n.º 29
0
	def eval(self, ds):
		ds = ds.clone()
		ds.setName('data')
		io.write(ds, self.data, format='.mat', newdoc=1)
		open(self.semaphore, 'w').write("1\n")
		sv = 1
		while sv == 1:
			time.sleep(.5)
			try:
				sv = int(open(self.semaphore, 'r').read())
			except:
				pass
		doc = io.read(self.data)
		ds=doc.getElements('Data')[0]
		if not ds.data.shape[1]==3:
			print ds.attributes
			ef = ones(ds.data.shape[0])*1.9
			ds.data = column_stack([ds.data[:,0], ef, ef])
		return ds
Ejemplo n.º 30
0
def saveWaves(spi, bn, t, dat):
    fn = bn + "_%s.mdat" % (t.name(),)
    tem = t.getElements("Data", "template", depth=1)[0]
    lead = tem.attrib("Lead")
    length = tem.getData().shape[0]

    # ignore spikes too close to the ends of the data file
    spi = spi[where(spi > lead)]
    spi = spi[where(spi < (dat.shape()[0] - (length - lead)))]
    if spi.shape[0] < 1:
        return

    waves = takewindows(dat.getData(), spi, lead, length)
    head = {"SampleType": "ensemble", "Lead": lead, "Reps": spi.shape[0], "SamplesPerSecond": dat.fs()}
    waves = newData(waves, head)
    h = waves.createSubData("/hidden")
    h.newElement(t.clone(False))
    h.newElement(tem.clone(False))
    io.write(waves, fn, newdoc=True, format=".mdat")
Ejemplo n.º 31
0
def getWNTF(dname):
	dp = getDataPairs(dname)
	for exp in dp:
		dpl = dp[exp]
		print "Analyzing all data (using FT) for experiment %s" % exp
		ds = assemble(dpl, dname)
		dat = ds.getData()
		dat[:,1] = cal._applyfilter(dat[:,1], MFF)
		# dat[:,0] = smooth(dat[:,0]) #This now occurs in assemble BEFORE resampling
		ds.datinit(dat, {"SampleType":"timeseries", "StartTime":0.0, 
			"Labels":["HairPosition","MicroFlownVelocity"], "SamplesPerSecond":SIGFS})
		nfn = '%s_compositData.mdat' % exp
		io.write(ds, nfn, newdoc=True)
		tfds = ctf.tf1ft(ds)
		if not tfds:
			continue
		tfds.data[:,1]+=pi
		tfds.data[:,1] = smoothphase(tfds.data[:,1])
		io.write(tfds, "%s_FTTF.mdat" % exp, newdoc=True)
Ejemplo n.º 32
0
def make_map(dir):
	doc = io.read(os.path.join(dir, 'standard_outline.123.nmpml'))
	invert = { 'Scale_x':-1.0}
	for fn in os.listdir(dir):
		if not fn[0] in ['L', 'M', 'S']:
			continue
		if not fn.endswith('nmpml'):
			continue
		d2=io.read(os.path.join(dir, fn))
		varic = d2.getElements('Fiducial', {"Style":'spheres'})[0]
		for s in ["color", "Color", "Direction"]:
			if s in varic.attributes:
				del(varic.attributes[s])		
		right_varic = varic.clone()
		right_varic.setAttrib('meta_cercus', 'right')
		right_varic.setName(varic.name()+"_right")
		alignObject(right_varic, invert) 
		doc.newElement(varic)
		doc.newElement(right_varic)
	io.write(doc, 'full_map.nmpml', format='nmpml')