a[sdp+1] = sdp_vals return a def process(doc, filt): ds = doc.getElements("Data", depth=1)[0] dat = ds.getData() dat[:,1] = cal._applyfilter(dat[:,1], filt) dat[:,0] = smooth(dat[:,0]) if __name__ == '__main__': mff=os.path.join(os.path.split(ftt.__file__)[0], 'MicroflownCalib.ncl') fd = io.read(mff) filt = fd.getElements('Data')[0] filt = cal._filterResample(filt.data[:,0], filt.fs(), SIGFS) for dname in sys.argv[1:]: dname = dname.strip("/") if os.path.isfile(os.path.join(dname, 'concat_ex.mdat')): ifn = os.path.join(dname, 'concat_ex.mdat') ofn = dname+"_sin.mdat" doc = io.read(ifn) print("Handling %s" % ifn) process(doc, filt) io.write(doc, ofn) if os.path.isfile(os.path.join(dname, 'concat.mdat')): ifn = os.path.join(dname, 'concat.mdat') ofn = dname+"_all.mdat" doc = io.read(ifn) print("Handling %s" % ifn)
import mien.parsers.fileIO as io import mien.nmpml.data as miendata import mien.parsers.nmpml as nmpml from mien.datafiles.dataset import resample, crop import gicaos.fttools as ftt import gicmext.calibration as cal import gicaos.constructTransferFunctions as ctf SIGFS = 1000 TRIGCHAN = 4 MFCHAN = 2 MFF=os.path.join(os.path.split(ftt.__file__)[0], 'MicroflownCalib.ncl') MFF= io.read(MFF) MFF= MFF.getElements('Data')[0] MFF= cal._filterResample(MFF.data[:,0], MFF.fs(), SIGFS) def smooth(a,fs): #find clicks ad = a[1:]-a[:-1] adm = ad.mean() adv = ad.std() cd = nonzero(abs(ad) > abs(adm) + 4*adv)[0] # FREE PARAMETER HERE # each 1 time point click is associated with 2 entries in cd, k and k+1 # each 2 pt time click is associated with 2 entries in cd, k and k+2 # replace clicks with averages c=0; clicks=0; for k in cd: c=c+1 if (k== cd[0]) or ( (k < cd[-1]) and (k-cd[c-2] > 2) and (cd[c] - k ==1) ) or ( (k == cd[-1]) and (k-cd[c-2] > 2) ):