LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
process_data.py
Go to the documentation of this file.
1 import numpy as np
2 import scipy.io as sio
3 import pylab as pl
4 import itertools as it
5 import io
6 def ret_tru(inval):
7  return true
8 def get_next_ind(in_file, sep_ln="&", predicate = ret_tru):
9  lvals = []
10  for line in in_file:
11  line = line.strip()
12  if line == sep_ln:
13  break
14  if predicate(line):
15  lvals.append(line)
16  return lvals
17 
18 
19 
20 def split_list(inl, predicate):
21  curl = []
22  tl = []
23  for v in inl:
24  if(predicate(v)):
25  if len(tl) > 0:
26  curl.append(tl)
27  tl = []
28  else:
29  tl.append(v)
30  return curl
31 
32 
33 
34 dat_file = open("data_out.out")
35 #do processing for each value in the output
36 ltest = get_next_ind(dat_file, "&", lambda x:(x.startswith("Func") or x.startswith("Ablation") or x.startswith("Time") or x.startswith("&&")))
37 while(len(ltest) != 0):
38  ltest = split_list(ltest, lambda x:x == "&&")
39  if(len(ltest) == 0):
40  break
41  fncstack = []
42  timelist = ""
43  abl_val=[]
44 #create numpy arrays
45  for simval in ltest:
46  if len(simval)==1:
47  abl_val = np.fromstring(''.join(it.dropwhile(lambda x : not x.isdigit(), simval[0])), sep=' ')
48  continue
49 
50  timestr = simval[0]
51  fncstr = simval[1]
52  timestr = it.dropwhile(lambda x: not x.isdigit(), timestr)
53  timestr = ''.join(timestr)
54  timelist = timelist + " " + timestr
55  fncstr = it.dropwhile(lambda x: not x.isdigit(), fncstr)
56  fncstr = ''.join(fncstr)
57  fncstack.append(np.fromstring(fncstr, sep=' '))
58 
59  print len(fncstack)
60  neur_mat = np.vstack(fncstack).transpose();
61  time_vec = np.fromstring(timelist, sep=' ')
62 #write to .mat file
63 
64 #create file name
65  fbase = "abl_study_"
66  for abl in abl_val:
67  fbase = fbase + str(int(abl)) + "_"
68  fbase = fbase[:-1]
69  print fbase
70  sio.savemat(fbase, {'abl_vals':np.array(abl_val), 'neur_series':neur_mat, 'time_vec':time_vec})
71  ltest = get_next_ind(dat_file, "&", lambda x:(x.startswith("Ablation") or x.startswith("Func") or x.startswith("Time") or x.startswith("&&")))
72