Skip to content

Commit 72c6210

Browse files
committed
added paper plots
1 parent f9b5158 commit 72c6210

14 files changed

+1967
-195
lines changed

examples/Frey1998_Tag_Decay.ods

19.4 KB
Binary file not shown.

examples/Simulation_results.ipynb

+137-102
Large diffs are not rendered by default.

examples/Untitled(1).ipynb

+764
Large diffs are not rendered by default.

examples/__init__.py

Whitespace-only changes.

examples/fonseca_and_szabo.ipynb

+5-5
Large diffs are not rendered by default.

examples/paper_plots.ipynb

+897
Large diffs are not rendered by default.

examples/plots.mplstyle

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
axes.labelsize: large
2+
axes.linewidth: 1.5
3+
axes.labelpad: 2.0
4+
axes.spines.right: False
5+
axes.spines.top: False
6+
7+
xtick.major.size: 5
8+
xtick.major.width: 1.5
9+
xtick.labelsize: large
10+
xtick.direction: out
11+
12+
ytick.major.size: 5
13+
ytick.major.width: 1.5
14+
ytick.labelsize: large
15+
ytick.direction: out
16+
17+
legend.frameon: False
18+
legend.fontsize: large
19+
20+
figure.frameon: False
21+

examples/protein_availability.pdf

15.3 KB
Binary file not shown.

examples/required_files/__init__.py

Whitespace-only changes.

examples/required_files/experiment_list.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
from examples.required_files.const import *
55
from virtual_lab.settings import prefs
66
with open("experimental_data.json","r") as file:
7-
exp_data = json.load(file)
7+
STC_data = json.load(file)
88

99
# TODO: this looks terrible, I have to implement a better experimental data management system
1010
data_LTP = {}
11-
names = [name for name in exp_data if "Matsuzaki" in name]
11+
names = [name for name in STC_data if "Matsuzaki" in name]
1212
names.append("renorm_var")
1313
names.append("time_unit")
1414
for name in names:
15-
data_LTP[name] = exp_data[name]
15+
data_LTP[name] = STC_data[name]
1616
data_LTD = {}
17-
names = [name for name in exp_data if "Kasai" in name]
17+
names = [name for name in STC_data if "Kasai" in name]
1818
names.append("renorm_var")
1919
names.append("time_unit")
2020
T = 2*3600
2121

2222

2323
for name in names:
24-
data_LTD[name] = exp_data[name]
24+
data_LTD[name] = STC_data[name]
2525
from virtual_lab.model import Model
2626
def create_experiments(model:Model, **kwargs):
2727
# Set the global time duration for the experiments

examples/required_files/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def set_initial_values(self,stochastic_simulation):
4040
# This is a bit of a cheat, but I'll check if without this it still works.
4141
# TODO: check!
4242
self.nf_0 = np.mean(self.nf)
43+
self.variables.Vpsd = 1
4344
self.variables.V_eff = self.nu*self.nf_0*self.tau_Vd + self.variables.Vpsd
4445
self.variables.Vd = self.eql * self.variables.V_eff
4546
self.variables.Vs = (1-self.eql) * self.variables.V_eff

examples/usr_prefs/user_prefs.json

+95-67
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,139 @@
11
{
22
"color_coding": {
3-
"v": [
4-
0.4980392156862745,
5-
0.788235294117647,
6-
0.4980392156862745
7-
],
8-
"u": [
9-
0.7450980392156863,
10-
0.6823529411764706,
11-
0.8313725490196079
12-
],
13-
"a_in": [
14-
0.9921568627450981,
15-
0.7529411764705882,
16-
0.5254901960784314
3+
"Vd": "#df7c20",
4+
"Vs": "#bbce50",
5+
"Vpsd": "#a782c9",
6+
"V_n": [
7+
0.5803921568627451,
8+
0.403921568627451,
9+
0.7411764705882353,
10+
1.0
1711
],
18-
"spikes": "#1f77b4"
19-
},
20-
"var": [
21-
[
22-
1.0,
23-
1.0,
24-
0.6
12+
"V_tot": [
13+
0.12156862745098039,
14+
0.4666666666666667,
15+
0.7058823529411765,
16+
1.0
2517
],
26-
[
27-
0.2196078431372549,
28-
0.4235294117647059,
29-
0.6901960784313725
18+
"Ve": [
19+
0.5490196078431373,
20+
0.33725490196078434,
21+
0.29411764705882354,
22+
1.0
3023
],
31-
[
24+
"stim": [
3225
0.9411764705882353,
3326
0.00784313725490196,
34-
0.4980392156862745
27+
0.4980392156862745,
28+
1.0
3529
],
36-
[
30+
"LFS": [
3731
0.7490196078431373,
3832
0.3568627450980392,
39-
0.09019607843137253
33+
0.09019607843137253,
34+
1.0
4035
],
41-
[
42-
0.4,
43-
0.4,
44-
0.4
36+
"xlinkers": [
37+
0.9921568627450981,
38+
0.7529411764705882,
39+
0.5254901960784314,
40+
1.0
4541
],
46-
[
47-
0.12156862745098039,
48-
0.4666666666666667,
49-
0.7058823529411765
42+
"protein": [
43+
0.7450980392156863,
44+
0.6823529411764706,
45+
0.8313725490196079,
46+
1.0
47+
],
48+
"sLTP_Matsuzaki": "#273914",
49+
"sLTD_Kasai_Noguchi": "#391414",
50+
"Vpsd_ref": "tab:blue",
51+
"V_tot_ref": "tab:orange",
52+
"V_eff": "#ff4d4d",
53+
"crosslink": [
54+
0.4980392156862745,
55+
0.788235294117647,
56+
0.4980392156862745,
57+
1.0
5058
],
51-
[
59+
"Matsuzaki 2004": [
5260
1.0,
5361
0.4980392156862745,
54-
0.054901960784313725
62+
0.054901960784313725,
63+
1.0
5564
],
56-
[
65+
"Kasai Noguchi 2015": [
5766
0.17254901960784313,
5867
0.6274509803921569,
59-
0.17254901960784313
68+
0.17254901960784313,
69+
1.0
6070
],
71+
"y": "tab:blue",
72+
"g": "tab:orange",
73+
"my_event": "brown"
74+
},
75+
"var": [
6176
[
6277
0.8392156862745098,
6378
0.15294117647058825,
64-
0.1568627450980392
65-
],
66-
[
67-
0.5803921568627451,
68-
0.403921568627451,
69-
0.7411764705882353
70-
],
71-
[
72-
0.5490196078431373,
73-
0.33725490196078434,
74-
0.29411764705882354
79+
0.1568627450980392,
80+
1.0
7581
],
7682
[
7783
0.8901960784313725,
7884
0.4666666666666667,
79-
0.7607843137254902
85+
0.7607843137254902,
86+
1.0
8087
],
8188
[
8289
0.4980392156862745,
8390
0.4980392156862745,
84-
0.4980392156862745
91+
0.4980392156862745,
92+
1.0
8593
],
8694
[
8795
0.7372549019607844,
8896
0.7411764705882353,
89-
0.13333333333333333
97+
0.13333333333333333,
98+
1.0
9099
],
91100
[
92101
0.09019607843137255,
93102
0.7450980392156863,
94-
0.8117647058823529
95-
]
103+
0.8117647058823529,
104+
1.0
105+
],
106+
[
107+
[
108+
0.9411764705882353,
109+
0.00784313725490196,
110+
0.4980392156862745,
111+
1.0
112+
]
113+
],
114+
"#256f25",
115+
"#273914",
116+
"#391414"
96117
],
97118
"event": [
98-
"#ff7f0e",
99-
"#2ca02c",
100-
"#d62728",
101-
"#9467bd",
102-
"#8c564b",
103-
"#e377c2",
104-
"#7f7f7f",
105-
"#bcbd22",
106-
"#17becf"
119+
[
120+
0.2196078431372549,
121+
0.4235294117647059,
122+
0.6901960784313725,
123+
1.0
124+
],
125+
[
126+
1.0,
127+
1.0,
128+
0.6,
129+
1.0
130+
]
107131
],
108132
"_ordered_quantities": [
109-
"spikes"
133+
"stim",
134+
"LFS",
135+
"crosslink",
136+
"protein",
137+
"my_event"
110138
]
111139
}

virtual_lab/experiments.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,19 @@ def add(self, experiments, idx = None):
6969
self.experiments.append(experiment)
7070
self._exp_names.append(experiment.name)
7171
else:
72-
if not idx in range(len(self.experiments)):
72+
if not idx in range(-len(self.experiments),len(self.experiments)):
7373
warn(f"Index {idx} is not valid for this class containing"
74-
" {len(self.experiments)} experiments. Will simply append at the end")
75-
self.experiments.insert(idx,experiment)
76-
self._exp_names.append(experiment.name)
74+
" {len(self.experiments)} experiments. Will simply append at the end")
75+
if idx == -1:
76+
self.experiments.append(experiment)
77+
self._exp_names.append(experiment.name)
78+
if idx < -1:
79+
self.experiments.insert(idx+1, experiment)
80+
self._exp_names.insert(idx+1,experiment.name)
81+
else:
82+
self.experiments.insert(idx,experiment)
83+
self._exp_names.insert(idx,experiment.name)
84+
7785

7886
def __iter__(self):
7987
return iter(self.experiments)

virtual_lab/simulation.py

+30-12
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def plot_results(self, results = None, exp_names = None,
402402
exp = result["experiment"]
403403
idx = exp_names.index(result["name"])
404404
interval = time_interval[idx] if time_interval is not None else None
405-
time_axis,timescale,start,stop,_ = self._get_time_quantities(exp,interval,step,time_unit)
405+
time_axis,timescale,start,stop,step = self._get_time_quantities(exp,interval,step,time_unit)
406406
values = self.reduce_data(result,start,stop,step)
407407
if variables is None:
408408
model_variables = self.models[model_name].variables
@@ -745,12 +745,20 @@ def plot_comparison(self, results = None, models = None, exp_names = None, **kwa
745745
for model in models:
746746
results[model] = [self.model_results[model][i].copy() for i in range(len(self.model_results[model]))]
747747
elif results is not None and isinstance(results,list):
748+
tmp = results
748749
results = {}
749-
for result in results:
750-
results[result["model"]] = result
750+
for result in tmp:
751+
try:
752+
results[result['model']]
753+
except:
754+
results[result['model']] = []
755+
results[result["model"]].append(result)
756+
else:
757+
print(results)
751758
result_list = self.sort_results_by_exp(results, exp_names = exp_names)
759+
n_cols = kwargs.pop('n_cols', len(results.keys()))
752760
# Giving exp_names at this point is useless, but I guess it doesn't hurt
753-
self.plot_results(result_list,exp_names,n_cols = len(results.keys()), **kwargs)
761+
self.plot_results(result_list,exp_names,n_cols =n_cols, **kwargs)
754762

755763
def sort_results_by_exp(self,res_dict, exp_names = None):
756764
# Not sure if this is necessary but I guess it's a good precaution
@@ -778,9 +786,11 @@ def plot_selected_points(self,results,variables,selection_idx,
778786
reference_values = None, reference_data = None, multi_plot = 1,
779787
save = True, filename = "img.pdf", **kwargs):
780788
# TODO: add possibility to plot from multiple results (i.e. a list or dictionary of results like above)
781-
# TODO: general thing, implement a figure class which makes it easier to manipulate images without the need to:
782-
# 1. Always call these plotting functions with 100 arguments
783-
# 2. Always re-plot everything and keep adding functionalities which would be shared among all plots you can do with this package.
789+
# TODO: general thing, implement a figure class which makes it easier to manipulate images
790+
# without the need to:
791+
# 1. Always call these plotting functions with 100 arguments
792+
# 2. Always re-plot everything and keep adding functionalities which would be
793+
# shared among all plots you can do with this package.
784794

785795
if not isinstance(results,list):
786796
if isinstance(results,dict):
@@ -790,12 +800,12 @@ def plot_selected_points(self,results,variables,selection_idx,
790800
if multi_plot != 1:
791801
assert len(results) == multi_plot
792802
if reference_data is not None:
793-
assert len(reference_data) == multi_plot
803+
assert len(reference_data) == multi_plot, "Reference data does not cover all the plots requested."
794804
multi_data = reference_data
795805
else:
796806
multi_data = [None for k in range(multi_plot)]
797807
if reference_values is not None:
798-
assert len(reference_values) == multi_plot
808+
assert len(reference_values) == multi_plot, "Reference values do not cover all the plots requested."
799809
multi_values = reference_values
800810
else:
801811
multi_values = [None for k in range(multi_plot)]
@@ -913,15 +923,17 @@ def plot_selected_points(self,results,variables,selection_idx,
913923
plot_cols = kwargs.get('n_cols',min(n_plots,4))*multi_plot
914924
plot_rows = ceil(n_plots/plot_cols)
915925
use_legend = kwargs.get("use_legend", True)
926+
title = kwargs.get("title", None)
916927
separate_legend = kwargs.get('separate_legend', False)
917928
figsize = kwargs.get('figsize',self.prefs.determine_figsize(plot_rows,plot_cols,use_legend,separate_legend))
918-
self.logger.debug("Figsize",figsize)
929+
self.logger.debug(f"Figsize {figsize}")
919930
fontsize = kwargs.get('fontsize',12)
920931
plt.rcParams['font.size'] = fontsize
921932
fig = plt.figure(figsize=figsize)
922933
ax0 = fig.add_subplot(1,multi_plot,1)
923934
if multi_plot == 1:
924-
ax0.set_axis_off()
935+
#ax0.set_axis_off()
936+
pass
925937
else:
926938
ax = fig.add_subplot(1, multi_plot, multi_plot_idx+1,sharey = ax0)
927939
axes = []
@@ -957,7 +969,11 @@ def plot_selected_points(self,results,variables,selection_idx,
957969
plt.plot([time_axis[0],time_axis[-1]],[val,val],label = l,ls = "--",lw = 3)
958970
plt.xlabel(kwargs.get("xlabel","iterations"))
959971
plt.ylabel(kwargs.get('ylabel','ratio of baseline'))
960-
plt.title(titles[idx])
972+
if title:
973+
title_i = title
974+
else:
975+
title_i = titles[idx]
976+
plt.title(title_i)
961977
# yticks = plt.yticks()[0]
962978
#TODO delete!
963979
# if multi_plot_idx != 1:
@@ -978,6 +994,8 @@ def plot_selected_points(self,results,variables,selection_idx,
978994
makedirs(self.prefs.plot_directory[:-1],exist_ok=True)
979995
fig.savefig(self.prefs.plot_directory + filename)
980996
plt.show()
997+
if kwargs.get('return_data') is True:
998+
return points
981999

9821000
def determine_label(self,varname):
9831001
if not hasattr(self.model,"labels") or not varname in self.model.labels:

0 commit comments

Comments
 (0)