Skip to content

Commit c5ace61

Browse files
authored
Merge pull request #98 from neurolib-dev/example/1.3-bifurcation-diagram-aln
example-1.3
2 parents 7a8556a + 0aea0de commit c5ace61

File tree

11 files changed

+917
-39
lines changed

11 files changed

+917
-39
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ jobs:
3636
homebrew:
3737
update: true
3838
packages:
39-
- python3
39+
4040
- llvm
4141
- libomp
4242
before_install:
43-
- brew link --overwrite python
4443
- export PATH=/usr/local/opt/llvm/bin:$PATH
4544
- pip3 install virtualenv
46-
- virtualenv -p python3 ~/venv
45+
- virtualenv -p /usr/local/opt/[email protected]/bin/python3 ~/venv
4746
- source ~/venv/bin/activate
4847
# - stage: test
4948
# os: windows

codecov.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ coverage:
77
- "neurolib/utils/devutils.py"
88
- "neurolib/utils/atlases.py"
99
status:
10+
project:
11+
default:
12+
enabled: yes
13+
target: auto
14+
threshold: 5%
1015
patch: off

examples/example-0.5-aln-external-stimulus.ipynb

Lines changed: 242 additions & 3 deletions
Large diffs are not rendered by default.

examples/example-1.3-aln-bifurcation-diagram.ipynb

Lines changed: 614 additions & 0 deletions
Large diffs are not rendered by default.

neurolib/optimize/exploration/exploration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def loadDfResults(self, filename=None, trajectoryName=None):
381381
:type trajectoryName: str, optional
382382
"""
383383
# chose HDF file to load
384-
filename = self.HDF_FILE or filename
384+
filename = filename or self.HDF_FILE
385385
self.pypetTrajectory = pu.loadPypetTrajectory(filename, trajectoryName)
386386
self.nResults = len(self.pypetTrajectory.f_get_run_names())
387387

neurolib/optimize/exploration/explorationUtils.py

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import numpy as np
24
import pandas as pd
35

@@ -11,7 +13,7 @@
1113
from scipy import stats
1214

1315
from ...utils import functions as func
14-
16+
from ...utils import paths as paths
1517

1618
def plotExplorationResults(
1719
dfResults,
@@ -26,6 +28,7 @@ def plotExplorationResults(
2628
one_figure=False,
2729
contour=None,
2830
alpha_mask=None,
31+
savename=None,
2932
**kwargs,
3033
):
3134
"""
@@ -136,29 +139,37 @@ def plotExplorationResults(
136139
contour_alpha = kwargs["contour_alpha"] if "contour_alpha" in kwargs else 1
137140
contour_kwargs = kwargs["contour_kwargs"] if "contour_kwargs" in kwargs else dict()
138141

139-
# check if this is a dataframe
140-
if isinstance(contour, pd.DataFrame):
141-
contourPlotDf(
142-
contour,
143-
color=contour_color,
144-
ax=ax,
145-
levels=contour_levels,
146-
alpha=contour_alpha,
147-
contour_kwargs=contour_kwargs,
148-
)
149-
# if it's a string, take that value as the contour plot value
150-
elif isinstance(contour, str):
151-
df_contour = df.pivot_table(values=contour, index=par2, columns=par1, dropna=False)
152-
if nan_to_zero:
153-
df_contour = df_contour.fillna(0)
154-
contourPlotDf(
155-
df_contour,
156-
color=contour_color,
157-
ax=ax,
158-
levels=contour_levels,
159-
alpha=contour_alpha,
160-
contour_kwargs=contour_kwargs,
161-
)
142+
def plot_contour(contour, contour_color, contour_levels, contour_alpha, contour_kwargs):
143+
# check if this is a dataframe
144+
if isinstance(contour, pd.DataFrame):
145+
contourPlotDf(
146+
contour,
147+
color=contour_color,
148+
ax=ax,
149+
levels=contour_levels,
150+
alpha=contour_alpha,
151+
contour_kwargs=contour_kwargs,
152+
)
153+
# if it's a string, take that value as the contour plot value
154+
elif isinstance(contour, str):
155+
df_contour = df.pivot_table(values=contour, index=par2, columns=par1, dropna=False)
156+
if nan_to_zero:
157+
df_contour = df_contour.fillna(0)
158+
contourPlotDf(
159+
df_contour,
160+
color=contour_color,
161+
ax=ax,
162+
levels=contour_levels,
163+
alpha=contour_alpha,
164+
contour_kwargs=contour_kwargs,
165+
)
166+
167+
# check if contour is alist of variables, e.g. ["max_output", "domfr"]
168+
if isinstance(contour, list):
169+
for ci in range(len(contour)):
170+
plot_contour(contour[ci], contour_color[ci], contour_levels[ci], contour_alpha[ci], contour_kwargs[ci])
171+
else:
172+
plot_contour(contour, contour_color, contour_levels, contour_alpha, contour_kwargs)
162173

163174
# colorbar
164175
if one_figure == False:
@@ -178,14 +189,21 @@ def plotExplorationResults(
178189
if not isinstance(i, tuple):
179190
i = (i,)
180191
if by != ["_by"]:
181-
ax.set_title(" ".join([f"{bb}={bi}" for bb, bi in zip(by_label, i)]))
192+
title = " ".join([f"{bb}={bi}" for bb, bi in zip(by_label, i)])
193+
ax.set_title(title)
182194
if one_figure == False:
195+
if savename:
196+
save_fname = os.path.join(paths.FIGURES_DIR, f"{title}_{savename}")
197+
plt.savefig(save_fname)
183198
plt.show()
184199
else:
185200
axi += 1
186201

187202
if one_figure == True:
188203
plt.tight_layout()
204+
if savename:
205+
save_fname = os.path.join(paths.FIGURES_DIR, f"{savename}")
206+
plt.savefig(save_fname)
189207
plt.show()
190208

191209

@@ -200,15 +218,18 @@ def contourPlotDf(
200218
clabel=False,
201219
**contour_kwargs,
202220
):
203-
levels = levels or [0, 1.0001]
221+
levels = levels or [0, 1]
204222
Xi, Yi = np.meshgrid(dataframe.columns, dataframe.index)
205223
ax = ax or plt
206224

207225
if contourf:
208226
contours = plt.contourf(Xi, Yi, dataframe, 10, levels=levels, alpha=alpha, cmap="plasma")
209227

228+
# unpack, why necessary??
229+
contour_kwargs = contour_kwargs["contour_kwargs"]
230+
210231
contours = ax.contour(
211-
Xi, Yi, dataframe, colors=color, linestyles="solid", levels=levels, zorder=1, alpha=alpha, **contour_kwargs,
232+
Xi, Yi, dataframe, colors=color, levels=levels, zorder=1, alpha=alpha, **contour_kwargs,
212233
)
213234

214235
clabel = contour_kwargs["clabel"] if "clabel" in contour_kwargs else False

neurolib/utils/pypetUtils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def getTrajectorynamesInFile(filename):
1818
:rtype: list[str]
1919
"""
2020
assert pathlib.Path(filename).exists(), f"{filename} does not exist!"
21-
hdf = h5py.File(filename)
21+
hdf = h5py.File(filename, "r")
2222
all_traj_names = list(hdf.keys())
2323
hdf.close()
2424
return all_traj_names

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setuptools.setup(
1313
name="neurolib",
14-
version="0.5.6",
14+
version="0.5.7",
1515
description="Easy whole-brain neural mass modeling",
1616
long_description=long_description,
1717
long_description_content_type="text/markdown",

tests/multimodel/test_fitzhugh_nagumo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import unittest
6-
6+
import numba
77
import numpy as np
88
import xarray as xr
99
from jitcdde import jitcdde_input

tests/multimodel/test_wilson_cowan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_init(self):
150150
self.assertEqual(wc.default_output, f"q_mean_{EXC}")
151151

152152
def test_run(self):
153-
wc = WilsonCowanNetwork(self.SC, self.DELAYS)
153+
wc = WilsonCowanNetwork(self.SC, self.DELAYS, exc_seed=SEED, inh_seed=SEED)
154154
all_results = []
155155
for backend, noise_func in BACKENDS_TO_TEST.items():
156156
result = wc.run(DURATION, DT, noise_func(ZeroInput(DURATION, DT, wc.num_noise_variables)), backend=backend,)

0 commit comments

Comments
 (0)