-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
64 lines (51 loc) · 2.1 KB
/
utils.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
from tvb.simulator.lab import *
import numpy as np
import matplotlib.pylab as plt
def plot_connectivity(conn):
# Visualization
fig = plt.figure(figsize=(15, 7))
fig.suptitle('TVB SC', fontsize=20)
# Weights
plt.subplot(121)
plt.imshow(conn.weights, interpolation='nearest', aspect='equal', cmap='jet')
plt.xticks(range(0, conn.number_of_regions), conn.region_labels, fontsize=7, rotation=90)
plt.yticks(range(0, conn.number_of_regions), conn.region_labels, fontsize=7)
cb = plt.colorbar(shrink=0.2)
cb.set_label('Weights', fontsize=14)
# Tracts lengths
plt.subplot(122)
plt.imshow(conn.tract_lengths, interpolation='nearest', aspect='equal', cmap='jet')
plt.xticks(range(0, conn.number_of_regions), conn.region_labels, fontsize=7, rotation=90)
plt.yticks(range(0, conn.number_of_regions), conn.region_labels, fontsize=7)
cb = plt.colorbar(shrink=0.2)
cb.set_label('Tract lenghts', fontsize=14)
fig.tight_layout()
plt.show()
def generate_initial_conditions_array(conn, dt, model):
idelays = np.rint(conn.delays / dt).astype(numpy.int32)
horizon = idelays.max() + 1
nvar = model.nvar
nnodes = conn.number_of_nodes
nmodes = model.number_of_modes
return np.zeros( (horizon, nvar, nnodes, nmodes) )
import anytree, logging, contextlib
@contextlib.contextmanager
def no_log(highest_level=logging.CRITICAL):
"Disable logging within context."
# https://gist.github.com/simon-weber/7853144
previous_level = logging.root.manager.disable
logging.disable(highest_level)
try:
yield
finally:
logging.disable(previous_level)
def region_select_props(atlas, roi_name):
"Select atlas region w/o logging, return centroid & is_cortical."
try:
with no_log():
atlas.select_region(roi_name)
props, = atlas.regionprops(bs.spaces.MNI_152_ICBM_2009C_NONLINEAR_ASYMMETRIC).values()
return props.centroid_mm, props.is_cortical
except (anytree.CountError, AttributeError) as exc:
print(f'skipping {roi_name}: {exc}')
return np.r_[0,0,0], False