-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_results.py
4233 lines (4118 loc) · 222 KB
/
plot_results.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__author__ = 'milsteina'
from function_lib import *
import matplotlib.lines as mlines
import matplotlib as mpl
import numpy as np
import scipy.signal as signal
import scipy.stats as stats
mpl.rcParams['svg.fonttype'] = 'none'
mpl.rcParams['font.size'] = 18. # 18.
#mpl.rcParams['font.sans-serif'] = 'Arial'
mpl.rcParams['font.sans-serif'] = 'Calibri'
mpl.rcParams['text.usetex'] = False
"""
mpl.rcParams['axes.labelsize'] = 'larger'
mpl.rcParams['axes.titlesize'] = 'xx-large'
mpl.rcParams['xtick.labelsize'] = 'large'
mpl.rcParams['ytick.labelsize'] = 'large'
mpl.rcParams['legend.fontsize'] = 'x-large'
"""
def plot_AR(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_spine_attenuation_ratio.
Files contain voltage recordings from spine and branch probed with EPSC-shaped current injections to measure spine
to branch EPSP amplitude attenuation ratio, dendritic branch impedance, and spine neck resistance. Plots these
parameters vs distance from dendrite origin, with one column per dendritic sec_type.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_sec_types = ['basal', 'trunk', 'apical', 'tuft']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_sec_types = []
for sim in [sim for sim in f.itervalues() if sim.attrs['stim_loc'] == 'spine']:
rec = sim['rec']['0'] if sim['rec']['0'].attrs['description'] == 'branch' else sim['rec']['1']
sec_type = rec.attrs['type']
if not sec_type in temp_sec_types:
temp_sec_types.append(sec_type)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
sec_types = [sec_type for sec_type in default_sec_types if sec_type in temp_sec_types]+\
[sec_type for sec_type in temp_sec_types if not sec_type in default_sec_types]
distances = {}
AR = {}
dendR = {}
neckR = {}
fig, axes = plt.subplots(3, max(2, len(sec_types)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
for index, rec_filename in enumerate(rec_file_list):
index_dict = {}
for sec_type in sec_types:
distances[sec_type] = []
AR[sec_type] = []
dendR[sec_type] = []
neckR[sec_type] = []
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
amp = f['0'].attrs['amp']
equilibrate = f['0'].attrs['equilibrate']
duration = f['0'].attrs['duration']
# following parallel execution and combine_rec_files, the order of simulation records is shuffled
# here the indices of paired records from spine_stim and branch_stim are collected
for simiter in f:
sim = f[simiter]
stim_loc = sim.attrs['stim_loc']
spine_rec = sim['rec']['0'] if sim['rec']['0'].attrs['description'] == 'spine' else sim['rec']['1']
spine_index = spine_rec.attrs['index']
if not spine_index in index_dict:
index_dict[spine_index] = {}
index_dict[spine_index][stim_loc] = simiter
for indices in index_dict.itervalues():
spine_stim = f[indices['spine']]['rec']
spine_tvec = f[indices['spine']]['time']
branch_stim = f[indices['branch']]['rec']
branch_tvec = f[indices['branch']]['time']
for rec in spine_stim.itervalues():
if rec.attrs['description'] == 'branch':
branch_rec = rec
sec_type = rec.attrs['type']
elif rec.attrs['description'] == 'spine':
spine_rec = rec
distances[sec_type].append(branch_rec.attrs['branch_distance'])
interp_t = np.arange(0., duration, 0.001)
interp_branch_vm = np.interp(interp_t, spine_tvec[:], branch_rec[:])
interp_spine_vm = np.interp(interp_t, spine_tvec[:], spine_rec[:])
left, right = time2index(interp_t, equilibrate-3.0, equilibrate-1.0)
baseline_branch = np.average(interp_branch_vm[left:right])
baseline_spine = np.average(interp_spine_vm[left:right])
left, right = time2index(interp_t, equilibrate, duration)
peak_branch = np.max(interp_branch_vm[left:right]) - baseline_branch
peak_spine = np.max(interp_spine_vm[left:right]) - baseline_spine
this_AR = peak_spine / peak_branch
AR[sec_type].append(this_AR)
branch_rec = branch_stim['0'] if branch_stim['0'].attrs['description'] == 'branch' else branch_stim['1']
interp_t = np.arange(0., duration, 0.001)
interp_branch_vm = np.interp(interp_t, branch_tvec[:], branch_rec[:])
left, right = time2index(interp_t, equilibrate-3.0, equilibrate-1.0)
baseline_branch = np.average(interp_branch_vm[left:right])
left, right = time2index(interp_t, equilibrate, duration)
peak_branch = np.max(interp_branch_vm[left:right]) - baseline_branch
this_dendR = peak_branch / amp
dendR[sec_type].append(this_dendR)
this_neckR = (this_AR - 1) * this_dendR
neckR[sec_type].append(this_neckR)
for i, sec_type in enumerate(sec_types):
axes[0][i].scatter(distances[sec_type], AR[sec_type], label=description_list[index],
color=colors[index])
axes[0][i].set_xlabel('Distance from Dendrite Origin (um)') # , fontsize=20)
axes[0][i].set_title(sec_type) # , fontsize=28)
axes[1][i].scatter(distances[sec_type], dendR[sec_type], label=description_list[index],
color=colors[index])
axes[1][i].set_xlabel('Distance from Dendrite Origin (um)') # , fontsize=20)
axes[1][i].set_title(sec_type) # , fontsize=28)
axes[2][i].scatter(distances[sec_type], neckR[sec_type], label=description_list[index],
color=colors[index])
axes[2][i].set_xlabel('Distance from Dendrite Origin (um)') # , fontsize=20)
axes[2][i].set_title(sec_type) # , fontsize=28)
axes[0][0].set_ylabel('Amplitude Ratio') # , fontsize=20)
axes[1][0].set_ylabel('R_Dend (MOhm)') # , fontsize=20)
axes[2][0].set_ylabel('R_Neck (MOhm)') # , fontsize=20)
if not description_list == [""]:
axes[0][0].legend(loc='best', scatterpoints=1, frameon=False, framealpha=0.5)
fig.subplots_adjust(hspace=0.45, wspace=0.3, left=0.06, right=0.94, top=0.94, bottom=0.06)
if not title is None:
fig.set_size_inches(20.8, 13)
fig.savefig(data_dir+title+' - spine AR.svg', format='svg')
plt.show()
plt.close()
def plot_AR_EPSP_amp(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_spine_attenuation.
Files contain voltage recordings from spine and branch while injecting EPSC-shaped currents into either spine or
branch to measure the amplitude attenuation ratio.
Creates a grid of 16 plots of EPSP amp vs. time, with one row per dendritic sec_type and four columns containing all
stimulation and recording conditions.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_sec_types = ['basal', 'trunk', 'apical', 'tuft']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_sec_types = []
for sim in [sim for sim in f.itervalues() if sim.attrs['stim_loc'] == 'spine']:
rec = sim['rec']['0'] if sim['rec']['0'].attrs['description'] == 'branch' else sim['rec']['1']
sec_type = rec.attrs['type']
if not sec_type in temp_sec_types:
temp_sec_types.append(sec_type)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
sec_types = [sec_type for sec_type in default_sec_types if sec_type in temp_sec_types]+\
[sec_type for sec_type in temp_sec_types if not sec_type in default_sec_types]
distances = {}
spine_amp = {'spine': {}, 'branch': {}}
branch_amp = {'spine': {}, 'branch': {}}
fig, axes = plt.subplots(max(2, len(sec_types)), 4)
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
for index, rec_filename in enumerate(rec_file_list):
index_dict = {}
for sec_type in sec_types:
distances[sec_type] = []
for stim_loc in ['spine', 'branch']:
spine_amp[stim_loc][sec_type] = []
branch_amp[stim_loc][sec_type] = []
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
amp = f['0'].attrs['amp']
equilibrate = f['0'].attrs['equilibrate']
duration = f['0'].attrs['duration']
# following parallel execution and combine_rec_files, the order of simulation records is shuffled
# here the indices of paired records from spine_stim and branch_stim are collected
for simiter in f:
sim = f[simiter]
stim_loc = sim.attrs['stim_loc']
spine_rec = sim['rec']['0'] if sim['rec']['0'].attrs['description'] == 'spine' else sim['rec']['1']
spine_index = spine_rec.attrs['index']
if not spine_index in index_dict:
index_dict[spine_index] = {}
index_dict[spine_index][stim_loc] = simiter
for indices in index_dict.itervalues():
spine_stim = f[indices['spine']]['rec']
for rec in spine_stim.itervalues():
if rec.attrs['description'] == 'branch':
branch_rec = rec
sec_type = rec.attrs['type']
distances[sec_type].append(branch_rec.attrs['branch_distance'])
for stim_loc, stim, tvec in [(stim_loc, f[indices[stim_loc]]['rec'], f[indices[stim_loc]]['time'])
for stim_loc in ['spine', 'branch']]:
for rec in stim.itervalues():
if rec.attrs['description'] == 'branch':
branch_rec = rec
else:
spine_rec = rec
interp_t = np.arange(0., duration, 0.001)
interp_branch_vm = np.interp(interp_t, tvec[:], branch_rec[:])
interp_spine_vm = np.interp(interp_t, tvec[:], spine_rec[:])
left, right = time2index(interp_t, equilibrate-3.0, equilibrate-1.0)
baseline_branch = np.average(interp_branch_vm[left:right])
baseline_spine = np.average(interp_spine_vm[left:right])
left, right = time2index(interp_t, equilibrate, duration)
peak_branch = np.max(interp_branch_vm[left:right]) - baseline_branch
peak_spine = np.max(interp_spine_vm[left:right]) - baseline_spine
spine_amp[stim_loc][sec_type].append(peak_spine)
branch_amp[stim_loc][sec_type].append(peak_branch)
for i, sec_type in enumerate(sec_types):
axes[i][0].scatter(distances[sec_type], branch_amp['branch'][sec_type], label=description_list[index],
color=colors[index])
axes[i][1].scatter(distances[sec_type], spine_amp['branch'][sec_type], label=description_list[index],
color=colors[index])
axes[i][2].scatter(distances[sec_type], branch_amp['spine'][sec_type], label=description_list[index],
color=colors[index])
axes[i][3].scatter(distances[sec_type], spine_amp['spine'][sec_type], label=description_list[index],
color=colors[index])
for i, sec_type in enumerate(sec_types):
for j, label in enumerate(['Stim Branch - Record Branch', 'Stim Branch - Record Spine',
'Stim Spine - Record Branch', 'Stim Spine - Record Spine']):
axes[i][j].set_xlabel('Distance from Dendrite Origin (um)')
axes[i][j].set_ylabel('Input Loc: '+sec_type+'\nEPSP Amplitude (mV)')
axes[i][j].set_title(label)
if not description_list == [""]:
axes[0][0].legend(loc='best', scatterpoints=1, frameon=False, framealpha=0.5)
fig.subplots_adjust(hspace=0.5, wspace=0.3, left=0.05, right=0.98, top=0.95, bottom=0.05)
if not title is None:
fig.set_size_inches(19.2, 12)
fig.savefig(data_dir+title+' - spine AR - EPSP amp.svg', format='svg')
plt.show()
plt.close()
def plot_AR_vm(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_spine_attenuation.
Files contain voltage recordings from spine and branch while injecting EPSC-shaped currents into either spine or
branch to measure the amplitude attenuation ratio.
Creates a grid of 16 plots of vm vs. time, with one row per dendritic sec_type and four columns containing all
stimulation and recording conditions.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_sec_types = ['basal', 'trunk', 'apical', 'tuft']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_sec_types = []
for sim in f.itervalues():
rec = sim['rec']['0'] if sim['rec']['0'].attrs['description'] == 'branch' else sim['rec']['1']
sec_type = rec.attrs['type']
if not sec_type in temp_sec_types:
temp_sec_types.append(sec_type)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
sec_types = [sec_type for sec_type in default_sec_types if sec_type in temp_sec_types]+\
[sec_type for sec_type in temp_sec_types if not sec_type in default_sec_types]
fig, axes = plt.subplots(max(2, len(sec_types)), 4)
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
label_handles = []
for index, rec_filename in enumerate(rec_file_list):
index_dict = {}
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
equilibrate = f['0'].attrs['equilibrate']
duration = f['0'].attrs['duration']
# following parallel execution and combine_rec_files, the order of simulation records is shuffled
# here the indices of paired records from spine_stim and branch_stim are collected
for simiter in f:
sim = f[simiter]
stim_loc = sim.attrs['stim_loc']
spine_rec = sim['rec']['0'] if sim['rec']['0'].attrs['description'] == 'spine' else sim['rec']['1']
spine_index = spine_rec.attrs['index']
if not spine_index in index_dict:
index_dict[spine_index] = {}
index_dict[spine_index][stim_loc] = simiter
for indices in index_dict.itervalues():
spine_stim = f[indices['spine']]['rec']
for rec in spine_stim.itervalues():
if rec.attrs['description'] == 'branch':
sec_type = rec.attrs['type']
for stim_loc, stim, tvec in [(stim_loc, f[indices[stim_loc]]['rec'], f[indices[stim_loc]]['time'])
for stim_loc in ['spine', 'branch']]:
for rec in stim.itervalues():
if rec.attrs['description'] == 'branch':
branch_rec = rec
else:
spine_rec = rec
j = 0 if stim_loc == 'branch' else 2
i = sec_types.index(sec_type)
interp_t = np.arange(0., duration, 0.01)
interp_branch_vm = np.interp(interp_t, tvec[:], branch_rec[:])
interp_spine_vm = np.interp(interp_t, tvec[:], spine_rec[:])
left, right = time2index(interp_t, equilibrate-5.0, duration)
interp_t -= interp_t[left] + 5.
axes[i][j].plot(interp_t[left:right], interp_branch_vm[left:right], color=colors[index])
axes[i][j+1].plot(interp_t[left:right], interp_spine_vm[left:right], color=colors[index])
label_handles.append(mlines.Line2D([], [], color=colors[index], label=description_list[index]))
for i, sec_type in enumerate(sec_types):
for j, label in enumerate(['Stim Branch - Record Branch', 'Stim Branch - Record Spine',
'Stim Spine - Record Branch', 'Stim Spine - Record Spine']):
axes[i][j].set_xlabel('Time (ms)')
axes[i][j].set_ylabel('Input Loc: '+sec_type+'\nVm (mV)')
axes[i][j].set_title(label)
if not description_list == [""]:
axes[0][0].legend(handles=label_handles, framealpha=0.5, frameon=False)
fig.subplots_adjust(hspace=0.5, wspace=0.3, left=0.05, right=0.98, top=0.95, bottom=0.05)
if not title is None:
fig.set_size_inches(19.2, 12)
fig.savefig(data_dir+title+' - spine AR - traces.svg', format='svg')
plt.show()
plt.close()
def plot_Rinp(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_rinp.
Files contain voltage recordings from dendritic compartments probed with hyperpolarizing current injections to
measure 1) peak r_inp, 2) steady-state r_inp, 3) their ratio, and 4) v_rest. Plots these parameters vs distance from
dendrite origin, with one column per sec_type.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_sec_types = ['soma', 'basal', 'trunk', 'apical', 'tuft']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_sec_types = []
for sim in f.itervalues():
rec = sim['rec']['0']
sec_type = rec.attrs['type']
if not sec_type in temp_sec_types:
temp_sec_types.append(sec_type)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
sec_types = [sec_type for sec_type in default_sec_types if sec_type in temp_sec_types]+\
[sec_type for sec_type in temp_sec_types if not sec_type in default_sec_types]
distances = {}
peak = {}
steady = {}
sag = {}
v_rest = {}
fig, axes = plt.subplots(4, max(2, len(sec_types)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
for index, rec_filename in enumerate(rec_file_list):
for sec_type in sec_types:
distances[sec_type] = []
peak[sec_type] = []
steady[sec_type] = []
sag[sec_type] = []
v_rest[sec_type] = []
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
amp = f['0']['stim']['0'].attrs['amp']
start = f['0']['stim']['0'].attrs['delay']
stop = start + f['0']['stim']['0'].attrs['dur']
for sim in f.itervalues():
rec = sim['rec']['0']
sec_type = rec.attrs['type']
distances[sec_type].append(rec.attrs['branch_distance'])
tvec = sim['time']
this_rest, this_peak, this_steady = get_Rinp(tvec[:], rec[:], start, stop, amp)
peak[sec_type].append(this_peak)
steady[sec_type].append(this_steady)
sag[sec_type].append(100*(1-this_steady/this_peak))
v_rest[sec_type].append(this_rest)
for i, sec_type in enumerate(sec_types):
axes[0][i].scatter(distances[sec_type], peak[sec_type], label=description_list[index],
color=colors[index])
axes[0][i].set_xlabel('Distance from Dendrite Origin (um)')
axes[1][i].set_title(sec_type)
axes[1][i].scatter(distances[sec_type], steady[sec_type], label=description_list[index],
color=colors[index])
axes[1][i].set_xlabel('Distance from Dendrite Origin (um)')
axes[2][i].scatter(distances[sec_type], sag[sec_type], label=description_list[index],
color=colors[index])
axes[2][i].set_xlabel('Distance from Dendrite Origin (um)')
axes[3][i].scatter(distances[sec_type], v_rest[sec_type], label=description_list[index],
color=colors[index])
axes[3][i].set_xlabel('Distance from Dendrite Origin (um)')
axes[0][1].set_ylabel('Input Resistance\nPeak (MOhm)')
axes[1][1].set_ylabel('Input Resistance\nSteady-state (MOhm)')
axes[2][1].set_ylabel('% Sag')
axes[3][1].set_ylabel('Resting Vm (mV)')
if not description_list == [""]:
axes[0][0].legend(loc='best', scatterpoints=1, frameon=False, framealpha=0.5)
fig.subplots_adjust(hspace=0.45, wspace=0.45, left=0.05, right=0.95, top=0.95, bottom=0.05)
if not title is None:
fig.set_size_inches(20.8, 13) # 19.2, 12)
fig.savefig(data_dir+title+' - Rinp.svg', format='svg')
plt.show()
plt.close()
def plot_Rinp_vm(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_rinp.
Files contain voltage recordings from dendritic compartments probed with hyperpolarizing current injections.
Plots vm vs. time,with one row per sec_type.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_sec_types = ['soma', 'basal', 'trunk', 'apical', 'tuft']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_sec_types = []
for sim in f.itervalues():
rec = sim['rec']['0']
sec_type = rec.attrs['type']
if not sec_type in temp_sec_types:
temp_sec_types.append(sec_type)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
sec_types = [sec_type for sec_type in default_sec_types if sec_type in temp_sec_types]+\
[sec_type for sec_type in temp_sec_types if not sec_type in default_sec_types]
fig, axes = plt.subplots(1, max(2, len(sec_types)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
label_handles = []
for index, rec_filename in enumerate(rec_file_list):
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
start = f['0']['stim']['0'].attrs['delay']
stop = start + f['0']['stim']['0'].attrs['dur']
for sim in f.itervalues():
rec = sim['rec']['0']
sec_type = rec.attrs['type']
i = sec_types.index(sec_type)
tvec = sim['time']
interp_t = np.arange(0., stop, 0.01)
interp_vm = np.interp(interp_t, tvec[:], rec[:])
left, right = time2index(interp_t, start-5.0, stop)
interp_t -= interp_t[left] + 5.
axes[i].plot(interp_t[left:right], interp_vm[left:right], color=colors[index])
for i, sec_type in enumerate(sec_types):
axes[i].set_xlabel('Time (ms)')
axes[i].set_ylabel('Vm (mV)')
axes[i].set_title(sec_type)
label_handles.append(mlines.Line2D([], [], color=colors[index], label=description_list[index]))
if not description_list == [""]:
axes[0].legend(handles=label_handles, framealpha=0.5, frameon=False)
fig.subplots_adjust(hspace=0.4, wspace=0.3, left=0.05, right=0.98, top=0.95, bottom=0.05)
if not title is None:
fig.set_size_inches(19.2, 12)
fig.savefig(data_dir+title+' - Rinp - traces.svg', format='svg')
plt.show()
plt.close()
def plot_Rinp_av_vm(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_rinp.
Files contain voltage recordings from dendritic compartments probed with hyperpolarizing current injections.
Plots vm vs. time, with one row per sec_type, averaging all responses with the same input and recording location.
This method subgroups trunk and apical sections as proximal or distal.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_sec_types = ['soma', 'basal', 'trunk_prox', 'trunk_dist', 'apical_prox', 'apical_dist', 'tuft']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_sec_types = []
for sim in f.itervalues():
rec = sim['rec']['0']
sec_type = rec.attrs['type']
if not sec_type in temp_sec_types:
if sec_type in ['trunk', 'apical']:
temp_sec_types.append(sec_type+'_prox')
temp_sec_types.append(sec_type+'_dist')
else:
temp_sec_types.append(sec_type)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
sec_types = [sec_type for sec_type in default_sec_types if sec_type in temp_sec_types]+\
[sec_type for sec_type in temp_sec_types if not sec_type in default_sec_types]
rows = max(3, len(sec_types)/4)
fig, axes = plt.subplots(rows, min(4, len(sec_types)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
label_handles = []
for index, rec_filename in enumerate(rec_file_list):
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
start = f['0']['stim']['0'].attrs['delay']
stop = start + 200. # f['0']['stim']['0'].attrs['dur']
average_vm = {}
for sim in f.itervalues():
rec = sim['rec']['0']
sec_type = rec.attrs['type']
if sec_type in ['trunk', 'apical']:
distance = rec.attrs['soma_distance'] if sec_type == 'trunk' else rec.attrs['soma_distance'] - \
rec.attrs['branch_distance']
if distance <= 150.:
sec_type += '_prox'
else:
sec_type += '_dist'
i = sec_types.index(sec_type)
tvec = sim['time']
interp_t = np.arange(0., stop, 0.01)
interp_vm = np.interp(interp_t, tvec[:], rec[:])
left, right = time2index(interp_t, start-3.0, start-1.0)
baseline = np.average(interp_vm[left:right])
left, right = time2index(interp_t, start-5.0, stop)
interp_vm = interp_vm[left:right] - baseline
interp_t -= interp_t[left] + 5.
interp_t = interp_t[left:right]
if sec_type in average_vm:
average_vm[sec_type]['count'] += 1
average_vm[sec_type]['trace'] += interp_vm[:]
else:
average_vm[sec_type] = {'count': 1, 'trace': interp_vm[:]}
for i, sec_type in enumerate(sec_types):
axes[i/4][i%4].plot(interp_t[:], average_vm[sec_type]['trace']/average_vm[sec_type]['count'],
color=colors[index])
axes[i/4][i%4].set_xlabel('Time (ms)') #, fontsize=20)
axes[i/4][0].set_ylabel('Voltage (mV)') #, fontsize=20)
axes[i/4][i%4].set_title(sec_type) #, fontsize=28)
label_handles.append(mlines.Line2D([], [], color=colors[index], label=description_list[index]))
if not description_list == [""]:
axes[0][0].legend(handles=label_handles, framealpha=0.5, frameon=False, fontsize=20)
fig.subplots_adjust(hspace=0.5, wspace=0.4, left=0.05, right=0.95, top=0.95, bottom=0.05)
if not title is None:
fig.set_size_inches(20.8, 13)
fig.savefig(data_dir+title+' - Rinp - average traces.svg', format='svg')
plt.show()
plt.close()
def plot_superimpose_conditions(rec_filename, legend=False):
"""
File contains simulation results from iterating through some changes in parameters or stimulation conditions.
This function produces one plot per recorded vector. Each plot superimposes the recordings from each of the
simulation iterations.
:param rec_filename: str
:param legend: bool
"""
f = h5py.File(data_dir+rec_filename+'.hdf5', 'r')
rec_ids = []
sim_ids = []
for sim in f.itervalues():
if 'description' in sim.attrs and not sim.attrs['description'] in sim_ids:
sim_ids.append(sim.attrs['description'])
for rec in sim['rec'].itervalues():
if 'description' in rec.attrs:
rec_id = rec.attrs['description']
else:
rec_id = rec.attrs['type']+str(rec.attrs['index'])
if not rec_id in (id['id'] for id in rec_ids):
rec_ids.append({'id': rec_id, 'ylabel': rec.attrs['ylabel']+' ('+rec.attrs['units']+')'})
fig, axes = plt.subplots(1, max(2, len(rec_ids)))
for i in range(len(rec_ids)):
axes[i].set_xlabel('Time (ms)')
axes[i].set_ylabel(rec_ids[i]['ylabel'])
axes[i].set_title(rec_ids[i]['id'])
for sim in f.itervalues():
if 'description' in sim.attrs:
sim_id = sim.attrs['description']
else:
sim_id = ''
tvec = sim['time']
for rec in sim['rec'].itervalues():
if ('description' in rec.attrs):
rec_id = rec.attrs['description']
else:
rec_id = rec.attrs['type']+str(rec.attrs['index'])
i = [index for index, id in enumerate(rec_ids) if id['id'] == rec_id][0]
axes[i].plot(tvec[:], rec[:], label=sim_id)
if legend:
for i in range(len(rec_ids)):
axes[i].legend(loc='best', framealpha=0.5, frameon=False)
plt.subplots_adjust(hspace=0.4, wspace=0.3, left=0.05, right=0.95, top=0.95, bottom=0.1)
plt.show()
plt.close()
f.close()
def plot_EPSP_attenuation(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_EPSP_attenuation.
Files contain simultaneous voltage recordings from 4 locations (soma, trunk, branch, spine) during single spine
stimulation. Spines are distributed across 4 dendritic sec_types (basal, trunk, apical, tuft).
Produces one figure containing a grid of 16 plots of EPSP amplitude vs. distance from dendrite origin.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_input_locs = ['basal', 'trunk', 'apical', 'tuft']
default_rec_locs = ['soma', 'trunk', 'branch', 'spine']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_input_locs = []
temp_rec_locs = []
for sim in f.itervalues():
input_loc = sim.attrs['input_loc']
if not input_loc in temp_input_locs:
temp_input_locs.append(input_loc)
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
if not rec_loc in temp_rec_locs:
temp_rec_locs.append(rec_loc)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
input_locs = [input_loc for input_loc in default_input_locs if input_loc in temp_input_locs]+\
[input_loc for input_loc in temp_input_locs if not input_loc in default_input_locs]
rec_locs = [rec_loc for rec_loc in default_rec_locs if rec_loc in temp_rec_locs]+\
[rec_loc for rec_loc in temp_rec_locs if not rec_loc in default_rec_locs]
distances = {}
amps = {}
fig, axes = plt.subplots(max(2, len(input_locs)), max(2, len(rec_locs)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
for index, rec_filename in enumerate(rec_file_list):
for input_loc in input_locs:
distances[input_loc] = []
amps[input_loc] = {}
for rec_loc in rec_locs:
amps[input_loc][rec_loc] = []
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
equilibrate = f['0'].attrs['equilibrate']
duration = f['0'].attrs['duration']
for sim in f.itervalues():
tvec = sim['time']
input_loc = sim.attrs['input_loc']
distances[input_loc].append(sim['rec']['3'].attrs['branch_distance'])
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
interp_t = np.arange(0., duration, 0.001)
interp_vm = np.interp(interp_t, tvec[:], rec[:])
left, right = time2index(interp_t, equilibrate-3.0, equilibrate-1.0)
baseline = np.average(interp_vm[left:right])
start, end = time2index(interp_t, equilibrate, duration)
amps[input_loc][rec_loc].append(np.max(interp_vm[start:end]) - baseline)
for i, input_loc in enumerate(input_locs):
for j, rec_loc in enumerate(rec_locs):
axes[i][j].scatter(distances[input_loc], amps[input_loc][rec_loc], color=colors[index],
label=description_list[index])
axes[i][j].set_xlabel('Distance from Dendrite Origin (um)', fontsize='x-large')
axes[i][0].set_ylabel('Spine Location: '+input_loc+'\nEPSP Amp (mV)', fontsize='xx-large')
for j, rec_loc in enumerate(rec_locs):
axes[0][j].set_title('Recording Loc: '+rec_loc)
if not description_list == [""]:
axes[0][0].legend(loc='best', scatterpoints=1, frameon=False, framealpha=0.5)
plt.subplots_adjust(hspace=0.4, wspace=0.3, left=0.05, right=0.95, top=0.95, bottom=0.05)
if not title is None:
fig.set_size_inches(20.8, 15.6) # 19.2, 12)19.2, 12)
fig.savefig(data_dir+title+' - EPSP attenuation.svg', format='svg')
plt.show()
plt.close()
def plot_EPSP_kinetics(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_EPSP_attenuation.
Files contain simultaneous voltage recordings from 4 locations (soma, trunk, branch, spine) during single spine
stimulation. Spines are distributed across 4 dendritic sec_types (basal, trunk, apical, tuft).
Produces a grid of 16 plots of EPSP kinetics vs. distance from dendrite origin.
Produces one figure each for rise kinetics and decay kinetics.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_input_locs = ['basal', 'trunk', 'apical', 'tuft']
default_rec_locs = ['soma', 'trunk', 'branch', 'spine']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_input_locs = []
temp_rec_locs = []
for sim in f.itervalues():
input_loc = sim.attrs['input_loc']
if not input_loc in temp_input_locs:
temp_input_locs.append(input_loc)
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
if not rec_loc in temp_rec_locs:
temp_rec_locs.append(rec_loc)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
input_locs = [input_loc for input_loc in default_input_locs if input_loc in temp_input_locs]+\
[input_loc for input_loc in temp_input_locs if not input_loc in default_input_locs]
rec_locs = [rec_loc for rec_loc in default_rec_locs if rec_loc in temp_rec_locs]+\
[rec_loc for rec_loc in temp_rec_locs if not rec_loc in default_rec_locs]
distances = {}
rise_taus = {}
decay_taus = {}
fig1, axes1 = plt.subplots(max(2, len(input_locs)), max(2, len(rec_locs)))
fig2, axes2 = plt.subplots(max(2, len(input_locs)), max(2, len(rec_locs)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
for index, rec_filename in enumerate(rec_file_list):
for input_loc in input_locs:
distances[input_loc] = []
rise_taus[input_loc] = {}
decay_taus[input_loc] = {}
for rec_loc in rec_locs:
rise_taus[input_loc][rec_loc] = []
decay_taus[input_loc][rec_loc] = []
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
equilibrate = f['0'].attrs['equilibrate']
duration = f['0'].attrs['duration']
for sim in f.itervalues():
tvec = sim['time']
input_loc = sim.attrs['input_loc']
distances[input_loc].append(sim['rec']['3'].attrs['branch_distance'])
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
left, right = time2index(tvec[:], equilibrate-3.0, equilibrate-1.0)
interp_t = np.arange(0., duration, 0.001)
baseline = np.average(rec[left:right])
interp_vm = np.interp(interp_t, tvec[:], rec[:])
start, end = time2index(interp_t, equilibrate, duration)
interp_t = interp_t[start:end]
interp_vm = interp_vm[start:end] - baseline
amp = np.max(interp_vm)
t_peak = np.where(interp_vm == amp)[0][0]
interp_vm /= amp
interp_t -= interp_t[0]
rise_10 = np.where(interp_vm[0:t_peak] >= 0.1)[0][0]
rise_90 = np.where(interp_vm[0:t_peak] >= 0.9)[0][0]
rise_50 = np.where(interp_vm[0:t_peak] >= 0.5)[0][0]
rise_tau = interp_t[rise_90] - interp_t[rise_10]
#decay_90 = np.where(interp_vm[t_peak:] <= 0.9)[0][0]
#decay_10 = np.where(interp_vm[t_peak:] <= 0.1)[0][0]
decay_50 = np.where(interp_vm[t_peak:] <= 0.5)[0][0]
#decay_tau = interp_t[decay_10] - interp_t[decay_90]
decay_tau = interp_t[decay_50] + interp_t[t_peak] - interp_t[rise_50]
"""
rise_tau = optimize.curve_fit(model_exp_rise, interp_t[1:t_peak], interp_vm[1:t_peak], p0=0.3)[0]
decay_tau = optimize.curve_fit(model_exp_decay, interp_t[t_peak+1:]-interp_t[t_peak],
interp_vm[t_peak+1:], p0=5.)[0]
"""
rise_taus[input_loc][rec_loc].append(rise_tau)
decay_taus[input_loc][rec_loc].append(decay_tau)
for i, input_loc in enumerate(input_locs):
for j, rec_loc in enumerate(rec_locs):
axes1[i][j].scatter(distances[input_loc], rise_taus[input_loc][rec_loc], color=colors[index],
label=description_list[index])
axes1[i][j].set_xlabel('Distance from Dendrite Origin (um)')
axes1[i][j].set_ylabel('Spine Location: '+input_loc+'\nEPSP Rise Tau (ms)')
axes1[i][j].set_title('Recording Loc: '+rec_loc)
axes2[i][j].scatter(distances[input_loc], decay_taus[input_loc][rec_loc], color=colors[index],
label=description_list[index])
axes2[i][j].set_xlabel('Distance from Dendrite Origin (um)')
axes2[i][j].set_ylabel('Spine Location: '+input_loc+'\nEPSP Decay Tau (ms)')
axes2[i][j].set_title('Recording Loc: '+rec_loc)
if not description_list == [""]:
axes1[0][0].legend(loc='best', scatterpoints=1, frameon=False, framealpha=0.5)
axes2[0][0].legend(loc='best', scatterpoints=1, frameon=False, framealpha=0.5)
fig1.subplots_adjust(hspace=0.5, wspace=0.3, left=0.05, right=0.98, top=0.95, bottom=0.05)
fig2.subplots_adjust(hspace=0.5, wspace=0.3, left=0.05, right=0.98, top=0.95, bottom=0.05)
if not title is None:
fig1.set_size_inches(20.8, 15.6) # 19.2, 12)19.2, 12)
fig1.savefig(data_dir+title+' - EPSP attenuation - rise.svg', format='svg')
fig2.set_size_inches(20.8, 15.6) # 19.2, 12)19.2, 12)
fig2.savefig(data_dir+title+' - EPSP attenuation - decay.svg', format='svg')
plt.show()
plt.close()
def plot_EPSP_av_vm(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_EPSP_attenuation.
Files contain simultaneous voltage recordings from 4 locations (soma, trunk, branch, spine) during single spine
stimulation. Spines are distributed across 4 dendritic sec_types (basal, trunk, apical, tuft). This method subgroups
trunk and apical sections as proximal or distal.
Produces one figure containing a grid of 24 plots of EPSP vs. time, averaging all responses with the same input and
recording location.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_input_locs = ['basal', 'trunk_prox', 'trunk_dist', 'apical_prox', 'apical_dist', 'tuft']
default_rec_locs = ['soma', 'trunk', 'branch', 'spine']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_input_locs = []
temp_rec_locs = []
for sim in f.itervalues():
input_loc = sim.attrs['input_loc']
if not input_loc in temp_input_locs:
if input_loc in ['trunk', 'apical']:
temp_input_locs.append(input_loc+'_prox')
temp_input_locs.append(input_loc+'_dist')
else:
temp_input_locs.append(input_loc)
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
if not rec_loc in temp_rec_locs:
temp_rec_locs.append(rec_loc)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
input_locs = [input_loc for input_loc in default_input_locs if input_loc in temp_input_locs]+\
[input_loc for input_loc in temp_input_locs if not input_loc in default_input_locs]
rec_locs = [rec_loc for rec_loc in default_rec_locs if rec_loc in temp_rec_locs]+\
[rec_loc for rec_loc in temp_rec_locs if not rec_loc in default_rec_locs]
fig, axes = plt.subplots(max(2, len(input_locs)), max(2, len(rec_locs)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
for index, rec_filename in enumerate(rec_file_list):
average_vm = {}
for input_loc in input_locs:
average_vm[input_loc] = {}
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
equilibrate = f['0'].attrs['equilibrate']
duration = f['0'].attrs['duration']
for sim in f.itervalues():
tvec = sim['time']
input_loc = sim.attrs['input_loc']
if input_loc in ['trunk', 'apical']:
spine_rec = sim['rec']['3'].attrs
distance = spine_rec['soma_distance'] if input_loc == 'trunk' else spine_rec['soma_distance'] - \
spine_rec['branch_distance']
if distance <= 150.:
input_loc += '_prox'
else:
input_loc += '_dist'
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
interp_t = np.arange(0., duration, 0.001)
interp_vm = np.interp(interp_t, tvec[:], rec[:])
left, right = time2index(interp_t, equilibrate-3.0, equilibrate-1.0)
baseline = np.average(interp_vm[left:right])
left, right = time2index(interp_t, equilibrate-5.0, duration)
interp_vm = interp_vm[left:right] - baseline
interp_t -= interp_t[left] + 5.
interp_t = interp_t[left:right]
if rec_loc in average_vm[input_loc]:
average_vm[input_loc][rec_loc]['count'] += 1
average_vm[input_loc][rec_loc]['trace'] += interp_vm[:]
else:
average_vm[input_loc][rec_loc] = {'count': 1, 'trace': interp_vm[:]}
for i, input_loc in enumerate(input_locs):
for j, rec_loc in enumerate(rec_locs):
axes[i][j].plot(interp_t[:], average_vm[input_loc][rec_loc]['trace'] /
average_vm[input_loc][rec_loc]['count'], color=colors[index], label=description_list[index])
axes[i][j].set_xlabel('Time (ms)', fontsize='x-large')
axes[i][0].set_ylabel('Spine Location:\n'+input_loc+'\nEPSP (mV)', fontsize='xx-large')
for j, rec_loc in enumerate(rec_locs):
axes[0][j].set_title('Recording Loc: '+rec_loc)
if not description_list == [""]:
axes[0][0].legend(loc='best', scatterpoints=1, frameon=False, framealpha=0.5)
plt.subplots_adjust(hspace=0.5, wspace=0.3, left=0.05, right=0.95, top=0.95, bottom=0.05)
if not title is None:
fig.set_size_inches(20.8, 15.6) # 19.2, 12)19.2, 12)
fig.savefig(data_dir+title+' - EPSP average traces.svg', format='svg')
plt.show()
plt.close()
def plot_EPSP_i_attenuation(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_EPSP_i_attenuation.
Files contain simultaneous voltage recordings from 3 locations (soma, trunk, branch) during stimulation of a single
branch with an EPSC-shaped current injection. Stimulated sec_types include (soma, basal, trunk, apical, tuft).
Produces one figure containing a grid of 15 plots of EPSP amplitude vs. distance from soma.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_input_locs = ['soma', 'basal', 'trunk', 'apical', 'tuft']
default_rec_locs = ['soma', 'trunk', 'branch']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_input_locs = []
temp_rec_locs = []
for sim in f.itervalues():
input_loc = sim.attrs['input_loc']
if not input_loc in temp_input_locs:
temp_input_locs.append(input_loc)
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
if not rec_loc in temp_rec_locs:
temp_rec_locs.append(rec_loc)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
input_locs = [input_loc for input_loc in default_input_locs if input_loc in temp_input_locs]+\
[input_loc for input_loc in temp_input_locs if not input_loc in default_input_locs]
rec_locs = [rec_loc for rec_loc in default_rec_locs if rec_loc in temp_rec_locs]+\
[rec_loc for rec_loc in temp_rec_locs if not rec_loc in default_rec_locs]
distances = {}
amps = {}
fig, axes = plt.subplots(max(2, len(input_locs)), max(2, len(rec_locs)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
for index, rec_filename in enumerate(rec_file_list):
for input_loc in input_locs:
distances[input_loc] = []
amps[input_loc] = {}
for rec_loc in rec_locs:
amps[input_loc][rec_loc] = []
with h5py.File(data_dir+rec_filename+'.hdf5', 'r') as f:
equilibrate = f['0'].attrs['equilibrate']
duration = f['0'].attrs['duration']
for sim in f.itervalues():
tvec = sim['time']
input_loc = sim.attrs['input_loc']
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
if rec_loc == 'branch':
distances[input_loc].append(rec.attrs['soma_distance'])
interp_t = np.arange(0., duration, 0.001)
interp_vm = np.interp(interp_t, tvec[:], rec[:])
left, right = time2index(interp_t, equilibrate-3.0, equilibrate-1.0)
baseline = np.average(interp_vm[left:right])
start, end = time2index(interp_t, equilibrate, duration)
amps[input_loc][rec_loc].append(np.max(interp_vm[start:end]) - baseline)
for i, input_loc in enumerate(input_locs):
for j, rec_loc in enumerate(rec_locs):
axes[i][j].scatter(distances[input_loc], amps[input_loc][rec_loc], color=colors[index],
label=description_list[index])
axes[i][j].set_xlabel('Distance from Soma (um)', fontsize='xx-large')
axes[i][0].set_ylabel('Input Loc: '+input_loc+'\nEPSP Amp (mV)', fontsize='xx-large')
for j, rec_loc in enumerate(rec_locs):
axes[0][j].set_title('Recording Loc: '+rec_loc)
if not description_list == [""]:
axes[0][0].legend(loc='best', scatterpoints=1, frameon=False, framealpha=0.5)
fig.subplots_adjust(hspace=0.45, wspace=0.25, left=0.05, right=0.95, top=0.95, bottom=0.05)
if not title is None:
fig.set_size_inches(20.8, 15.6) # 19.2, 12)
fig.savefig(data_dir+title+' - EPSP_i attenuation.svg', format='svg')
plt.show()
plt.close()
def plot_EPSP_i_kinetics(rec_file_list, description_list="", title=None):
"""
Expects each file in list to be generated by parallel_EPSP_i_attenuation.
Files contain simultaneous voltage recordings from 3 locations (soma, trunk, branch) during stimulation of a single
branch with an EPSC-shaped current injection. Stimulated sec_types include (soma, basal, trunk, apical, tuft).
Produces a grid of 15 plots of EPSP kinetics vs. distance from soma.
Produces one figure each for rise kinetics and decay kinetics.
Superimposes results from multiple files in list.
:param rec_file_list: list of str
:param description_list: list of str
:param title: str
"""
if not type(rec_file_list) == list:
rec_file_list = [rec_file_list]
if not type(description_list) == list:
description_list = [description_list]
default_input_locs = ['soma', 'basal', 'trunk', 'apical', 'tuft']
default_rec_locs = ['soma', 'trunk', 'branch']
with h5py.File(data_dir+rec_file_list[0]+'.hdf5', 'r') as f:
temp_input_locs = []
temp_rec_locs = []
for sim in f.itervalues():
input_loc = sim.attrs['input_loc']
if not input_loc in temp_input_locs:
temp_input_locs.append(input_loc)
for rec in sim['rec'].itervalues():
rec_loc = rec.attrs['description']
if not rec_loc in temp_rec_locs:
temp_rec_locs.append(rec_loc)
# enforce the default order of input and recording locations for plotting, but allow for adding or subtracting
# sec_types
input_locs = [input_loc for input_loc in default_input_locs if input_loc in temp_input_locs]+\
[input_loc for input_loc in temp_input_locs if not input_loc in default_input_locs]
rec_locs = [rec_loc for rec_loc in default_rec_locs if rec_loc in temp_rec_locs]+\
[rec_loc for rec_loc in temp_rec_locs if not rec_loc in default_rec_locs]
distances = {}
rise_taus = {}
decay_taus = {}
fig1, axes1 = plt.subplots(max(2, len(input_locs)), max(2, len(rec_locs)))
fig2, axes2 = plt.subplots(max(2, len(input_locs)), max(2, len(rec_locs)))
colors = ['k', 'r', 'c', 'y', 'm', 'g', 'b']
for index, rec_filename in enumerate(rec_file_list):
for input_loc in input_locs:
distances[input_loc] = []
rise_taus[input_loc] = {}
decay_taus[input_loc] = {}