forked from yves-weissenberger/twoptb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
130 lines (87 loc) · 3.09 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from __future__ import division
import re, os, csv, time, sys
import itertools
import numpy as np
import scipy.io as spio
def get_DM(stim_dict,framePeriod,nFrames):
nFramesStim = int(np.floor(float(stim_dict['stim_dur'])/framePeriod))
nStims = int(len(stim_dict['stim_list']))
DM = np.zeros([nStims,nFrames])
for i in range(1,1+nStims):
stim_i_frames = np.where(stim_dict['stimOrder']==i)[0]
for stim_presen in stim_i_frames:
DM[i-1,stim_presen*stim_dict['stim_spacing']:stim_presen*stim_dict['stim_spacing']+nFramesStim] = 1
return DM
def cartesian_product_itertools(tup1, tup2):
return list(product(tup1, tup2))
def load_GRABinfo(matobj):
'''
A recursive function which constructs from matobjects nested dictionaries
'''
dictA = {}
for strg in matobj._fieldnames:
elem = matobj.__dict__[strg]
if isinstance(elem, spio.matlab.mio5_params.mat_struct):
dictA[strg] = _todict(elem)
else:
dictA[strg] = elem
return dictA
def copy_ROIs(hdf):
return None
def _todict(matobj):
'''
A recursive function which constructs from matobjects nested dictionaries
'''
d = {}
for strg in matobj._fieldnames:
elem = matobj.__dict__[strg]
if isinstance(elem, spio.matlab.mio5_params.mat_struct):
d[strg] = _todict(elem)
elif isinstance(elem, np.ndarray):
d[strg] = _tolist(elem)
else:
d[strg] = elem
return d
def _select_area(hdf):
print hdf.filename
print 'Sessions:'
sessions = list((i for i in hdf.iterkeys()))
for idx,f in enumerate(sessions):
print idx, f
session = int(raw_input('Select Session Nr: '))
sessions = list((i for i in hdf.iterkeys()))
dataType = 0
if 'registered_data' in hdf[sessions[session]].iterkeys():
print 'Using registered Data'
dataType = 'registered_data'
else:
print '\n!!!!!!!!!!WARNING!!!!!!!!!!!!\nUsing Raw Data\n!!!!!!!!!!WARNING!!!!!!!!!!!!'
dataType = 'raw_data'
areas = list((i for i in hdf[sessions[int(session)]][dataType].iterkeys()))
for idx,f in enumerate(areas):
print idx, f
areaID = int(raw_input('Select Area Nr: '))
areaFile = hdf[sessions[session]][dataType][areas[areaID]];
return areaFile, sessions[session], areas[areaID]
def progress_bar(idx,Tot,maxN=20):
"""
Simple Progress bar that when called in loop will output something looking like this
[.... ] 52%
Args
__________________________
idx: int | float
current index
Tot: int | float
total number of iterations to be completed
maxN: int | float
maxmimum numer of points to have between the square brackets
"""
if Tot<maxN:
maxN = Tot
n_points = int(idx*np.round(Tot/maxN))
#sys.stdout.write('\r')
pStr = "[%-" + str(Tot) + "s] %d%%"
#sys.stdout.write("\r" + pStr % ('.'*int(n_points), np.round(100*np.divide(idx+1.,float(Tot)))))
sys.stdout.write("\r"+str(idx)+"/"+str(Tot))
sys.stdout.flush()
return None