In [5]:
import matplotlib.pyplot as plt
%matplotlib inline
from utils import *
from spike_train_utils import *
from scipy.signal import chirp
import scipy.stats as stats
from brian2 import *#BrianLogger.suppress_hierarchy('brian2.codegen')
import os
from loadEXTRA import loadISI
from sNMO.error.spikeTrainErrors import emd_pdist_spk, isi_swasserstein_2d, isi_wasserstein_dd, emd_isi
import joblib
import pandas as pd
import network_CADEX as cadex
from joblib import Parallel, delayed
In [6]:
dict_choice = {'slow_gaba_w_shift': {},
              'slow_crh_v2': {},
              'network_ff_w_shift': {},
              'grid_all_fast_v5_w_shift': {}}
def run_net(network_type):
    print(f"Running network for {network_type}")
    
    network_args, synapse_params = cadex.load_params_from_joblib( "output/best_params_" + network_type + ".joblib" )
    print(f"Network type: {network_type}")

    network_events = network_args.pop('network_events_for_viz')
    print(f"Network events: {network_events}") 
    synapse_params['taup'] = 15*second
    synapse_params['taubr'] = 20*second

    network_events = { 100: network_events[30]+";taup = 999999*second;taubr = 999999*second"}  # only keep the events at 30 and 100 seconds 30: network_events[30],
    #network_events = {30: 'eval: P[:500].pr = 0.05; CRH[:500].bd=(CRH.b[:500]/nS *  7)*nS; CRH[:500].tauw = (CRH[:500].tauw/ms *  1.5)*ms'}  # scale by 10 to match the simulation time
    network_args['run_time'] = 200  # set the run time to 600
    netres = cadex.cadex_network(run_time=200, GABA_param_file=cadex.CRH_PARAM_FILE, network_args=network_args, 
                                synapse_params=synapse_params, network_events=network_events)
    return netres['spikes'].spike_trains()

netres_s = Parallel(n_jobs=4)(delayed(run_net)(network_type) for network_type in dict_choice.keys())

# Run with baseline
for i, (network_type, network_info) in enumerate(dict_choice.items()):

    dict_choice[network_type]['netres_baseline'] = netres_s[i]
Running network for slow_crh_v2
Network type: slow_crh_v2
Network events: {30: 'eval: P[:500].pr = 0.1057421875; CRH.bd = CRH_params["b"] * 5.462083333333334; CRH[:500].tauw = (CRH[:500].tauw/ms *  2.013812154696132)*ms'}
Using default CRH params
loaded GABA params from file
taue found, splitting into tauer and taued
setting tauw to 78.42909974 ms; for CRH, which is 34.9753203 ms
setting a to 1.13192403 nS; for CRH, which is 0.50931871 nS
setting b to 1.20590762 nS; for CRH, which is 0.70787273 nS
setting C to 24.37259305 pF; for CRH, which is 12.35263386 pF
setting taum to 25.19464094 ms; for CRH, which is 13.09132677 ms
setting gL to 0.99754744 nS; for CRH, which is 0.94357387 nS
setting DeltaT to 10.43940611 mV; for CRH, which is 13.18607994 mV
setting DeltaA to -5.42709084 mV; for CRH, which is -3.95513921 mV
setting pr to 1.0; for CRH, which is 1.0
setting Va to -96.74838934 mV; for CRH, which is -71.24968551 mV
setting EL to -70.71267431 mV; for CRH, which is -68.38802621 mV
setting Ea to -58.649696 mV; for CRH, which is -87.07411404 mV
setting VT to -49.30489061 mV; for CRH, which is -42.3062799 mV
setting VR to -39.80579876 mV; for CRH, which is -36.5748809 mV
setting Vcut to 2.89213995 mV; for CRH, which is 0. V
setting bd to 0. S; for CRH, which is 0. S
setting tauw to 78.42909974 ms; for GABA, which is 34.9753203 ms
setting a to 1.13192403 nS; for GABA, which is 0.50931871 nS
setting b to 1.20590762 nS; for GABA, which is 0.70787273 nS
setting C to 24.37259305 pF; for GABA, which is 12.35263386 pF
setting taum to 25.19464094 ms; for GABA, which is 13.09132677 ms
setting gL to 0.99754744 nS; for GABA, which is 0.94357387 nS
setting DeltaT to 10.43940611 mV; for GABA, which is 13.18607994 mV
setting DeltaA to -5.42709084 mV; for GABA, which is -3.95513921 mV
setting pr to 1.0; for GABA, which is 1.0
setting Va to -96.74838934 mV; for GABA, which is -71.24968551 mV
setting EL to -70.71267431 mV; for GABA, which is -68.38802621 mV
setting Ea to -58.649696 mV; for GABA, which is -87.07411404 mV
Running network for slow_gaba_w_shift
setting VT to -49.30489061 mV; for GABA, which is -42.3062799 mV
setting VR to -39.80579876 mV; for GABA, which is -36.5748809 mV
Network type: slow_gaba_w_shift
Network events: {30: 'eval: P[:500].pr = 0.02595703125; CRH.bd = CRH_params["b"] * 14.557916666666667; CRH[:500].tauw = (CRH[:500].tauw/ms *  1.5)*ms'}
Using default CRH params
setting Vcut to 2.89213995 mV; for GABA, which is 0. V
setting bd to 0. S; for GABA, which is 0. S
loaded GABA params from fileusing random connectivity

Using default EI_model
Using default IE_model
taue found, splitting into tauer and taued
setting tauw to 78.42909974 ms; for CRH, which is 34.9753203 ms
setting a to 1.13192403 nS; for CRH, which is 0.50931871 nS
setting b to 1.20590762 nS; for CRH, which is 0.70787273 nS
setting C to 24.37259305 pF; for CRH, which is 12.35263386 pF
setting taum to 25.19464094 ms; for CRH, which is 13.09132677 ms
setting gL to 0.99754744 nS; for CRH, which is 0.94357387 nS
setting DeltaT to 10.43940611 mV; for CRH, which is 13.18607994 mV
setting DeltaA to -5.42709084 mV; for CRH, which is -3.95513921 mV
setting pr to 1.0; for CRH, which is 1.0
setting Va to -96.74838934 mV; for CRH, which is -71.24968551 mV
setting EL to -70.71267431 mV; for CRH, which is -68.38802621 mV
setting Ea to -58.649696 mV; for CRH, which is -87.07411404 mV
setting VT to -49.30489061 mV; for CRH, which is -42.3062799 mV
Running network for network_ff_w_shift
setting VR to -39.80579876 mV; for CRH, which is -36.5748809 mV
Network type: network_ff_w_shift
Network events: {30: 'eval: P[:500].pr = 0.173466796875; CRH.bd = CRH_params["b"] * 9.545208333333331; CRH[:500].tauw = (CRH[:500].tauw/ms *  2.347989988095601)*ms'}
setting Vcut to 2.89213995 mV; for CRH, which is 0. V
Using default CRH params
setting bd to 0. S; for CRH, which is 0. S
loaded GABA params from file
taue found, splitting into tauer and taued
setting tauw to 78.42909974 ms; for GABA, which is 34.9753203 ms
setting a to 1.13192403 nS; for GABA, which is 0.50931871 nS
setting b to 1.20590762 nS; for GABA, which is 0.70787273 nS
setting C to 24.37259305 pF; for GABA, which is 12.35263386 pF
setting taum to 25.19464094 ms; for GABA, which is 13.09132677 ms
setting gL to 0.99754744 nS; for GABA, which is 0.94357387 nS
setting DeltaT to 10.43940611 mV; for GABA, which is 13.18607994 mV
setting DeltaA to -5.42709084 mV; for GABA, which is -3.95513921 mV
setting pr to 1.0; for GABA, which is 1.0
setting Va to -96.74838934 mV; for GABA, which is -71.24968551 mV
setting EL to -70.71267431 mV; for GABA, which is -68.38802621 mV
setting Ea to -58.649696 mV; for GABA, which is -87.07411404 mV
setting VT to -49.30489061 mV; for GABA, which is -42.3062799 mV
setting VR to -39.80579876 mV; for GABA, which is -36.5748809 mV
setting Vcut to 2.89213995 mV; for GABA, which is 0. V
setting bd to 0. S; for GABA, which is 0. S
using random connectivity
Found EI_model in params
Found IE_model in params
setting tauw to 78.42909974 ms; for CRH, which is 34.9753203 ms
setting a to 1.13192403 nS; for CRH, which is 0.50931871 nS
setting b to 1.20590762 nS; for CRH, which is 0.70787273 nS
setting C to 24.37259305 pF; for CRH, which is 12.35263386 pF
setting taum to 25.19464094 ms; for CRH, which is 13.09132677 ms
setting gL to 0.99754744 nS; for CRH, which is 0.94357387 nS
Running network for grid_all_fast_v5_w_shift
setting DeltaT to 10.43940611 mV; for CRH, which is 13.18607994 mV
Network type: grid_all_fast_v5_w_shift
Network events: {30: 'eval: P[:500].pr = 0.108154296875; CRH.bd = CRH_params["b"] * 9.144375; CRH[:500].tauw = (CRH[:500].tauw/ms *  1.0109734135099662)*ms'}
setting DeltaA to -5.42709084 mV; for CRH, which is -3.95513921 mV
Using default CRH params
setting pr to 1.0; for CRH, which is 1.0
setting Va to -96.74838934 mV; for CRH, which is -71.24968551 mV
setting EL to -70.71267431 mV; for CRH, which is -68.38802621 mV
loaded GABA params from file
taue found, splitting into tauer and taued
setting Ea to -58.649696 mV; for CRH, which is -87.07411404 mV
setting VT to -49.30489061 mV; for CRH, which is -42.3062799 mV
setting VR to -39.80579876 mV; for CRH, which is -36.5748809 mV
setting Vcut to 2.89213995 mV; for CRH, which is 0. V
setting bd to 0. S; for CRH, which is 0. S
setting tauw to 78.42909974 ms; for GABA, which is 34.9753203 ms
setting a to 1.13192403 nS; for GABA, which is 0.50931871 nS
setting b to 1.20590762 nS; for GABA, which is 0.70787273 nS
setting C to 24.37259305 pF; for GABA, which is 12.35263386 pF
setting taum to 25.19464094 ms; for GABA, which is 13.09132677 ms
setting gL to 0.99754744 nS; for GABA, which is 0.94357387 nS
setting DeltaT to 10.43940611 mV; for GABA, which is 13.18607994 mV
setting DeltaA to -5.42709084 mV; for GABA, which is -3.95513921 mV
setting pr to 1.0; for GABA, which is 1.0
setting Va to -96.74838934 mV; for GABA, which is -71.24968551 mV
setting EL to -70.71267431 mV; for GABA, which is -68.38802621 mV
setting Ea to -58.649696 mV; for GABA, which is -87.07411404 mV
setting VT to -49.30489061 mV; for GABA, which is -42.3062799 mV
setting VR to -39.80579876 mV; for GABA, which is -36.5748809 mV
setting Vcut to 2.89213995 mV; for GABA, which is 0. V
setting bd to 0. S; for GABA, which is 0. S
using random connectivitysetting tauw to 78.42909974 ms; for CRH, which is 34.9753203 ms

Found EI_model in params
Found IE_model in params
setting a to 1.13192403 nS; for CRH, which is 0.50931871 nS
setting b to 1.20590762 nS; for CRH, which is 0.70787273 nS
setting C to 24.37259305 pF; for CRH, which is 12.35263386 pF
setting taum to 25.19464094 ms; for CRH, which is 13.09132677 ms
setting gL to 0.99754744 nS; for CRH, which is 0.94357387 nS
setting DeltaT to 10.43940611 mV; for CRH, which is 13.18607994 mV
setting DeltaA to -5.42709084 mV; for CRH, which is -3.95513921 mV
setting pr to 1.0; for CRH, which is 1.0
setting Va to -96.74838934 mV; for CRH, which is -71.24968551 mV
setting EL to -70.71267431 mV; for CRH, which is -68.38802621 mV
setting Ea to -58.649696 mV; for CRH, which is -87.07411404 mV
setting VT to -49.30489061 mV; for CRH, which is -42.3062799 mV
setting VR to -39.80579876 mV; for CRH, which is -36.5748809 mV
setting Vcut to 2.89213995 mV; for CRH, which is 0. V
setting bd to 0. S; for CRH, which is 0. S
setting tauw to 78.42909974 ms; for GABA, which is 34.9753203 ms
setting a to 1.13192403 nS; for GABA, which is 0.50931871 nS
setting b to 1.20590762 nS; for GABA, which is 0.70787273 nS
setting C to 24.37259305 pF; for GABA, which is 12.35263386 pF
setting taum to 25.19464094 ms; for GABA, which is 13.09132677 ms
setting gL to 0.99754744 nS; for GABA, which is 0.94357387 nS
setting DeltaT to 10.43940611 mV; for GABA, which is 13.18607994 mV
setting DeltaA to -5.42709084 mV; for GABA, which is -3.95513921 mV
setting pr to 1.0; for GABA, which is 1.0
setting Va to -96.74838934 mV; for GABA, which is -71.24968551 mV
setting EL to -70.71267431 mV; for GABA, which is -68.38802621 mV
setting Ea to -58.649696 mV; for GABA, which is -87.07411404 mV
setting VT to -49.30489061 mV; for GABA, which is -42.3062799 mV
setting VR to -39.80579876 mV; for GABA, which is -36.5748809 mV
setting Vcut to 2.89213995 mV; for GABA, which is 0. V
setting bd to 0. S; for GABA, which is 0. S
using random connectivity
Found EI_model in params
Found IE_model in params
Found ECRH_model in params
Found ICRH_model in params
Found ECRH_model in params
Found ICRH_model in params
Found ECRH_model in params
Found ICRH_model in params
Using default ECRH_model
Using default ICRH_model
wexti: 7.8299738882283005
=== Net Sim Start ===
wexti: 0.0
=== Net Sim Start ===
wexti: 0.0
=== Net Sim Start ===
wexti: 0.0
=== Net Sim Start ===
Starting simulation at t=0. s for a duration of 5. s
Starting simulation at t=0. s for a duration of 5. s
Starting simulation at t=0. s for a duration of 5. s
Starting simulation at t=0. s for a duration of 5. s
5. s (100%) simulated in 5s
5. s (100%) simulated in 4s
['none'
 'eval: P[:500].pr = 0.173466796875; CRH.bd = CRH_params["b"] * 9.545208333333331; CRH[:500].tauw = (CRH[:500].tauw/ms *  2.347989988095601)*ms;taup = 999999*second;taubr = 999999*second']
[100 100]
5. s (100%) simulated in 4s
5. s (100%) simulated in 4s
Starting simulation at t=5. s for a duration of 100. s
['none'
 'eval: P[:500].pr = 0.02595703125; CRH.bd = CRH_params["b"] * 14.557916666666667; CRH[:500].tauw = (CRH[:500].tauw/ms *  1.5)*ms;taup = 999999*second;taubr = 999999*second']
[100 100]
Starting simulation at t=5. s for a duration of 100. s
['none'
 'eval: P[:500].pr = 0.1057421875; CRH.bd = CRH_params["b"] * 5.462083333333334; CRH[:500].tauw = (CRH[:500].tauw/ms *  2.013812154696132)*ms;taup = 999999*second;taubr = 999999*second']
[100 100]
['none'
 'eval: P[:500].pr = 0.108154296875; CRH.bd = CRH_params["b"] * 9.144375; CRH[:500].tauw = (CRH[:500].tauw/ms *  1.0109734135099662)*ms;taup = 999999*second;taubr = 999999*second']
[100 100]
Starting simulation at t=5. s for a duration of 100. s
Starting simulation at t=5. s for a duration of 100. s
9.8479 s (9%) simulated in 10s, estimated 1m 32s remaining.
10.0789 s (10%) simulated in 10s, estimated 1m 29s remaining.
9.9754 s (9%) simulated in 10s, estimated 1m 30s remaining.
9.9346 s (9%) simulated in 10s, estimated 1m 31s remaining.
19.8806 s (19%) simulated in 20s, estimated 1m 21s remaining.
20.1977 s (20%) simulated in 20s, estimated 1m 19s remaining.
20.0942 s (20%) simulated in 20s, estimated 1m 20s remaining.
19.9367 s (19%) simulated in 20s, estimated 1m 20s remaining.
29.707 s (29%) simulated in 30s, estimated 1m 11s remaining.
30.2646 s (30%) simulated in 30s, estimated 1m 9s remaining.
30.0238 s (30%) simulated in 30s, estimated 1m 10s remaining.
29.7391 s (29%) simulated in 30s, estimated 1m 11s remaining.
39.729 s (39%) simulated in 40s, estimated 1m 1s remaining.
40.4167 s (40%) simulated in 40s, estimated 59s remaining.
40.1189 s (40%) simulated in 40s, estimated 1m 0s remaining.
39.8623 s (39%) simulated in 40s, estimated 1m 0s remaining.
49.3476 s (49%) simulated in 50s, estimated 51s remaining.
50.3555 s (50%) simulated in 50s, estimated 49s remaining.
49.8357 s (49%) simulated in 50s, estimated 50s remaining.
49.2721 s (49%) simulated in 50s, estimated 51s remaining.
59.3991 s (59%) simulated in 1m 0s, estimated 41s remaining.
60.6106 s (60%) simulated in 1m 0s, estimated 39s remaining.
59.9259 s (59%) simulated in 1m 0s, estimated 40s remaining.
59.3242 s (59%) simulated in 1m 0s, estimated 41s remaining.
69.4145 s (69%) simulated in 1m 10s, estimated 31s remaining.
70.8495 s (70%) simulated in 1m 10s, estimated 29s remaining.
70.0093 s (70%) simulated in 1m 10s, estimated 30s remaining.
69.1266 s (69%) simulated in 1m 10s, estimated 31s remaining.
79.4169 s (79%) simulated in 1m 20s, estimated 21s remaining.
81.0943 s (81%) simulated in 1m 20s, estimated 19s remaining.
79.5986 s (79%) simulated in 1m 20s, estimated 21s remaining.
79.0555 s (79%) simulated in 1m 20s, estimated 21s remaining.
89.4588 s (89%) simulated in 1m 30s, estimated 11s remaining.
91.3888 s (91%) simulated in 1m 30s, estimated 8s remaining.
89.5135 s (89%) simulated in 1m 30s, estimated 11s remaining.
89.1541 s (89%) simulated in 1m 30s, estimated 11s remaining.
100. s (100%) simulated in 1m 39s
Evaluating
Starting simulation at t=105. s for a duration of 100. s
99.4255 s (99%) simulated in 1m 40s, estimated 1s remaining.
99.5138 s (99%) simulated in 1m 40s, estimated < 1s remaining.
99.2574 s (99%) simulated in 1m 40s, estimated 1s remaining.
100. s (100%) simulated in 1m 41s
100. s (100%) simulated in 1m 41s
Evaluating
Evaluating
Starting simulation at t=105. s for a duration of 100. s
Starting simulation at t=105. s for a duration of 100. s
100. s (100%) simulated in 1m 41s
Evaluating
Starting simulation at t=105. s for a duration of 100. s
9.9892 s (9%) simulated in 10s, estimated 1m 30s remaining.
9.9536 s (9%) simulated in 10s, estimated 1m 30s remaining.
9.7657 s (9%) simulated in 10s, estimated 1m 32s remaining.
9.6383 s (9%) simulated in 10s, estimated 1m 34s remaining.
20.0335 s (20%) simulated in 20s, estimated 1m 20s remaining.
19.8965 s (19%) simulated in 20s, estimated 1m 21s remaining.
19.6246 s (19%) simulated in 20s, estimated 1m 22s remaining.
19.3051 s (19%) simulated in 20s, estimated 1m 24s remaining.
30.0361 s (30%) simulated in 30s, estimated 1m 10s remaining.
29.8301 s (29%) simulated in 30s, estimated 1m 11s remaining.
29.4675 s (29%) simulated in 30s, estimated 1m 12s remaining.
28.9258 s (28%) simulated in 30s, estimated 1m 14s remaining.
40.1151 s (40%) simulated in 40s, estimated 1m 0s remaining.
39.7936 s (39%) simulated in 40s, estimated 1m 1s remaining.
39.285 s (39%) simulated in 40s, estimated 1m 2s remaining.
38.6715 s (38%) simulated in 40s, estimated 1m 3s remaining.
50.1847 s (50%) simulated in 50s, estimated 50s remaining.
49.6909 s (49%) simulated in 50s, estimated 51s remaining.
49.1522 s (49%) simulated in 50s, estimated 52s remaining.
48.5917 s (48%) simulated in 50s, estimated 53s remaining.
60.255 s (60%) simulated in 1m 0s, estimated 40s remaining.
59.6754 s (59%) simulated in 1m 0s, estimated 41s remaining.
59.0349 s (59%) simulated in 1m 0s, estimated 42s remaining.
58.5064 s (58%) simulated in 1m 0s, estimated 43s remaining.
70.3248 s (70%) simulated in 1m 10s, estimated 30s remaining.
69.6441 s (69%) simulated in 1m 10s, estimated 31s remaining.
68.8608 s (68%) simulated in 1m 10s, estimated 32s remaining.
67.9698 s (67%) simulated in 1m 10s, estimated 33s remaining.
80.3837 s (80%) simulated in 1m 20s, estimated 20s remaining.
79.638 s (79%) simulated in 1m 20s, estimated 20s remaining.
78.7805 s (78%) simulated in 1m 20s, estimated 22s remaining.
77.4452 s (77%) simulated in 1m 20s, estimated 23s remaining.
90.4426 s (90%) simulated in 1m 30s, estimated 10s remaining.
89.6233 s (89%) simulated in 1m 30s, estimated 10s remaining.
88.607 s (88%) simulated in 1m 30s, estimated 12s remaining.
87.1685 s (87%) simulated in 1m 30s, estimated 13s remaining.
100. s (100%) simulated in 1m 39s
simulation took 4.332372891902923
99.4342 s (99%) simulated in 1m 40s, estimated 1s remaining.
98.452 s (98%) simulated in 1m 40s, estimated 2s remaining.
97.2535 s (97%) simulated in 1m 40s, estimated 3s remaining.
100. s (100%) simulated in 1m 40s
simulation took 4.387000890572866
100. s (100%) simulated in 1m 41s
simulation took 4.405532264709473
100. s (100%) simulated in 1m 42s
simulation took 4.427090080579122
In [7]:
for i, (network_type, network_info) in enumerate(dict_choice.items()):
    fig, ax = plt.subplots(1, 2, figsize=(7, 5))
    print(f"Network type: {network_type}")
    spikes = network_info['netres_baseline']
    spikes_pre = [spikes[x][np.logical_and(spikes[x]/second >= 5, spikes[x]/second < 105)] - 5*second for x in spikes]
    spikes_post = [spikes[x][np.logical_and(spikes[x]/second >= 105, spikes[x]/second < 200)] - 105*second for x in spikes]
    isis = build_isi_from_spike_train(network_info['netres_baseline'], low_cut=5, high_cut=105)
    isi_post = build_isi_from_spike_train(network_info['netres_baseline'], low_cut=105, high_cut=200)
    [ax[0].scatter(spikes_pre[j][:-1], isis[j]) for j in range(25)]
    ax[0].set_xlabel("Time (s)")
    ax[0].set_ylabel("ISI (ms)")
    ax[0].set_yscale('log')
    ax[0].set_ylim(1, 10000)
    ax[0].set_xlim(0, 100)

    [ax[1].scatter(spikes_post[j][:-1], isi_post[j]) for j in range(25)]
    ax[1].set_xlabel("Time (s)")
    ax[1].set_ylabel("ISI (ms)")
    ax[1].set_yscale('log')
    ax[1].set_ylim(1, 10000)
    ax[1].set_xlim(0, 100)

    pre_fr = [len(spikes_pre[j])/100 for j in range(500)]
    pre_fr_std = np.nanstd(pre_fr)
    pre_fr_mean = np.nanmean(pre_fr)
    post_fr = [len(spikes_post[j])/95 for j in range(500)]
    post_fr_std = np.nanstd(post_fr)
    post_fr_mean = np.nanmean(post_fr)
    pre_cv2 = [cv2(isis[j]) for j in range(500) if len(isis[j]) > 1]
    post_cv2 = [cv2(isi_post[j]) for j in range(500) if len(isi_post[j]) > 1]
    

    dict_choice[network_type]['baseline_mean_fr_bursters'] = pre_fr_mean
    dict_choice[network_type]['baseline_std_fr_bursters'] = pre_fr_std
    dict_choice[network_type]['end_mean_fr_bursters'] = post_fr_mean
    dict_choice[network_type]['end_std_fr_bursters'] = post_fr_std
    dict_choice[network_type]['baseline_cv2_bursters'] = np.nanmean(pre_cv2)
    dict_choice[network_type]['end_cv2_bursters'] = np.nanmean(post_cv2)
    dict_choice[network_type]['baseline_cv2_std_bursters'] = np.nanstd(pre_cv2)
    dict_choice[network_type]['end_cv2_std_bursters'] = np.nanstd(post_cv2)
    dict_choice[network_type]['baseline_cv2_n'] = len(pre_cv2)
    dict_choice[network_type]['end_cv2_n'] = len(post_cv2)
    dict_choice[network_type]['pre_fr_raw'] = pre_fr
    dict_choice[network_type]['post_fr_raw'] = post_fr
    dict_choice[network_type]['pre_cv2_raw'] = pre_cv2
    dict_choice[network_type]['post_cv2_raw'] = post_cv2

    binned_fr_, bins = binned_fr_pop(network_info['netres_baseline'], end_time=60, popsize=500, binsize=5)
    #trim those 5 seconds
    binned_fr_ = binned_fr_[bins >= 5]
    bins = bins[bins >= 5] - 5 

    bins, binned_isi = bin_signal(spikes_pre[5][:-1]/second, isis[5], bins=bins, bin_func=None)
    binned_cv2 = []
    for isi in binned_isi:
        if len(isi) > 1:
            binned_cv2.append(cv2(isi))
        else:
            binned_cv2.append(np.nan)
    twinx_ = ax[0].twinx()
    twinx_.plot(bins + 2.5, binned_fr_, color='red', label='Mean FR Bursters')
    #twinx_.plot(bins, binned_cv2, color='green', label='CV2')
    twinx_.set_ylim(0, 16)
    twinx_.set_ylabel("Mean FR (Hz)")
    twinx_.set_xlabel("Time (s)")
    twinx_.set_xlim(0, 100)
    #twinx_.legend(loc='upper right')

    ax[0].set_title(f"Network type: {network_type}")

    #ax[1, i].scatter([0,1], [network_info['baseline_mean_fr_bursters'], network_info['end_mean_fr_bursters']], color='k')
    plt.savefig(f"output/ISI_bursters_baseline{network_type}.svg", bbox_inches='tight')
    plt.show()
Network type: slow_gaba_w_shift
Network type: slow_crh_v2
Network type: network_ff_w_shift
Network type: grid_all_fast_v5_w_shift
In [8]:
dict_choice_no_netres = {k: v for k, v in dict_choice.items() if 'raw' not in k and 'netres' not in k}
#dict_choice_no_netres['network_type'] = dict_choice_no_netres
dict_base = pd.DataFrame.from_dict(dict_choice_no_netres, orient='index')
dict_base.drop(columns=['netres_baseline'], inplace=True, errors='ignore')
#drop the raw data columns
dict_base.drop(columns=[col for col in dict_base.columns if col.endswith('_raw')], inplace=True, errors='ignore')
print(dict_base.head())
#dict_base.to_csv("output/ISI_bursters_baseline.csv")
#get the raw data for the ISI save each as a column
raw_dict = {}
for network_type, network_info in dict_choice.items():
    raw_dict[f"{network_type}_raw_pre_fr"] = network_info['pre_fr_raw']
    raw_dict[f"{network_type}_raw_post_fr"] = network_info['post_fr_raw']
    raw_dict[f"{network_type}_raw_pre_cv2"] = network_info['pre_cv2_raw']
    raw_dict[f"{network_type}_raw_post_cv2"] = network_info['post_cv2_raw']
dict_raw = pd.DataFrame.from_dict(raw_dict, orient='index').T
#dict_raw.to_csv("output/ISI_bursters_raw.csv", index=False)
                          baseline_mean_fr_bursters  baseline_std_fr_bursters  \
slow_gaba_w_shift                           0.84436                  1.949151   
slow_crh_v2                                 1.27606                  2.269043   
network_ff_w_shift                          3.13894                  4.139450   
grid_all_fast_v5_w_shift                    2.06432                  1.910105   

                          end_mean_fr_bursters  end_std_fr_bursters  \
slow_gaba_w_shift                     3.399600             0.752648   
slow_crh_v2                           4.245179             1.729709   
network_ff_w_shift                    7.289158             2.700012   
grid_all_fast_v5_w_shift              5.382211             1.307880   

                          baseline_cv2_bursters  end_cv2_bursters  \
slow_gaba_w_shift                      1.292434          0.445757   
slow_crh_v2                            1.236642          0.792139   
network_ff_w_shift                     1.290946          0.519329   
grid_all_fast_v5_w_shift               1.271867          0.718442   

                          baseline_cv2_std_bursters  end_cv2_std_bursters  \
slow_gaba_w_shift                          0.245249              0.092669   
slow_crh_v2                                0.174768              0.208772   
network_ff_w_shift                         0.098425              0.199695   
grid_all_fast_v5_w_shift                   0.108816              0.159221   

                          baseline_cv2_n  end_cv2_n  
slow_gaba_w_shift                    335        500  
slow_crh_v2                          467        500  
network_ff_w_shift                   497        500  
grid_all_fast_v5_w_shift             500        500