43
43
from bluepyemodel .emodel_pipeline .plotting_utils import get_experimental_FI_curve_for_plotting
44
44
from bluepyemodel .emodel_pipeline .plotting_utils import get_impedance
45
45
from bluepyemodel .emodel_pipeline .plotting_utils import get_ordered_currentscape_keys
46
+ from bluepyemodel .emodel_pipeline .plotting_utils import get_original_protocol_name
46
47
from bluepyemodel .emodel_pipeline .plotting_utils import get_recording_names
47
48
from bluepyemodel .emodel_pipeline .plotting_utils import get_simulated_FI_curve_for_plotting
48
49
from bluepyemodel .emodel_pipeline .plotting_utils import get_sinespec_evaluator
49
50
from bluepyemodel .emodel_pipeline .plotting_utils import get_title
50
51
from bluepyemodel .emodel_pipeline .plotting_utils import get_traces_names_and_float_responses
51
52
from bluepyemodel .emodel_pipeline .plotting_utils import get_traces_ylabel
52
53
from bluepyemodel .emodel_pipeline .plotting_utils import get_voltage_currents_from_files
54
+ from bluepyemodel .emodel_pipeline .plotting_utils import plot_fi_curves
53
55
from bluepyemodel .emodel_pipeline .plotting_utils import rel_to_abs_amplitude
56
+ from bluepyemodel .emodel_pipeline .plotting_utils import save_fig
57
+ from bluepyemodel .emodel_pipeline .plotting_utils import update_evaluator
54
58
from bluepyemodel .evaluation .evaluation import compute_responses
55
59
from bluepyemodel .evaluation .evaluation import get_evaluator_from_access_point
56
60
from bluepyemodel .evaluation .evaluator import PRE_PROTOCOLS
85
89
}
86
90
87
91
88
- def save_fig (figures_dir , figure_name , dpi = 100 ):
89
- """Save a matplotlib figure"""
90
- p = Path (figures_dir ) / figure_name
91
- plt .savefig (str (p ), dpi = dpi , bbox_inches = "tight" )
92
- plt .close ("all" )
93
- plt .clf ()
94
-
95
-
96
92
def optimisation (
97
93
optimiser ,
98
94
emodel ,
@@ -1205,8 +1201,11 @@ def run_and_plot_EPSP(
1205
1201
def plot_IV_curves (
1206
1202
evaluator ,
1207
1203
emodels ,
1204
+ access_point ,
1208
1205
figures_dir ,
1209
1206
efel_settings ,
1207
+ mapper ,
1208
+ seeds ,
1210
1209
prot_name = "iv" ,
1211
1210
custom_bluepyefe_cells_pklpath = None ,
1212
1211
write_fig = True ,
@@ -1218,23 +1217,40 @@ def plot_IV_curves(
1218
1217
Args:
1219
1218
evaluator (CellEvaluator): cell evaluator
1220
1219
emodels (list): list of EModels
1220
+ access_point (DataAccessPoint): data access point
1221
1221
figures_dir (str or Path): output directory for the figure to be saved on
1222
1222
efel_settings (dict): eFEL settings in the form {setting_name: setting_value}.
1223
+ mapper (map): used to parallelize the evaluation of the individual in the population.
1224
+ seeds (list): if not None, filter emodels to keep only the ones with these seeds.
1223
1225
prot_name (str): Only recordings from this protocol will be used.
1224
1226
custom_bluepyefe_cells_pklpath (str): file path to the cells.pkl output of BluePyEfe.
1225
1227
If None, will use usual file path used in BluePyEfe,
1226
1228
so this is to be set only to use a file at an unexpected path.
1227
1229
write_fig (bool): whether to save the figure
1228
1230
n_bin (int): number of bins to use
1229
1231
"""
1230
- # pylint: disable=too-many-nested-blocks, possibly-used-before-assignment
1232
+ # pylint: disable=too-many-nested-blocks, possibly-used-before-assignment, disable=too-many-locals, disable=too-many-statements
1231
1233
# note: should maybe also check location and recorded variable
1232
1234
make_dir (figures_dir )
1233
1235
if efel_settings is None :
1234
1236
efel_settings = bluepyefe .tools .DEFAULT_EFEL_SETTINGS .copy ()
1235
1237
1238
+ lower_bound = - 100
1239
+ upper_bound = 100
1240
+
1241
+ # Generate amplitude points
1242
+ sim_amp_points = list (map (int , numpy .linspace (lower_bound , upper_bound , n_bin + 1 )))
1236
1243
# add missing features (if any) to evaluator
1237
- updated_evaluator = fill_in_IV_curve_evaluator (evaluator , efel_settings , prot_name )
1244
+ updated_evaluator = fill_in_IV_curve_evaluator (
1245
+ evaluator , efel_settings , prot_name , sim_amp_points
1246
+ )
1247
+
1248
+ emodels = compute_responses (
1249
+ access_point ,
1250
+ updated_evaluator ,
1251
+ map_function = mapper ,
1252
+ seeds = seeds ,
1253
+ )
1238
1254
1239
1255
emodel_name = None
1240
1256
cells = None
@@ -1349,6 +1365,9 @@ def plot_IV_curves(
1349
1365
def plot_FI_curves_comparison (
1350
1366
evaluator ,
1351
1367
emodels ,
1368
+ access_point ,
1369
+ seeds ,
1370
+ mapper ,
1352
1371
figures_dir ,
1353
1372
prot_name ,
1354
1373
custom_bluepyefe_cells_pklpath = None ,
@@ -1362,6 +1381,9 @@ def plot_FI_curves_comparison(
1362
1381
Args:
1363
1382
evaluator (CellEvaluator): cell evaluator
1364
1383
emodels (list): list of EModels
1384
+ access_point (DataAccessPoint): data access point
1385
+ seeds (list): if not None, filter emodels to keep only the ones with these seeds.
1386
+ mapper (map): used to parallelize the evaluation of the individual in the population.
1365
1387
figures_dir (str or Path): output directory for the figure to be saved on
1366
1388
prot_name (str): name of the protocol to use for the FI curve
1367
1389
custom_bluepyefe_cells_pklpath (str): file path to the cells.pkl output of BluePyEfe.
@@ -1373,24 +1395,18 @@ def plot_FI_curves_comparison(
1373
1395
# pylint: disable=too-many-nested-blocks, possibly-used-before-assignment
1374
1396
make_dir (figures_dir )
1375
1397
1376
- emodel_name = None
1377
- cells = None
1398
+ emodel_name , cells = None , None
1399
+ updated_evaluator = copy . deepcopy ( evaluator )
1378
1400
for emodel in emodels :
1379
1401
# do not re-extract data if the emodel is the same as previously
1380
1402
if custom_bluepyefe_cells_pklpath is not None :
1381
1403
if cells is None :
1382
1404
cells = read_extraction_output (custom_bluepyefe_cells_pklpath )
1383
1405
if cells is None :
1384
1406
continue
1407
+
1385
1408
# experimental FI curve
1386
- (
1387
- expt_amp_rel ,
1388
- expt_freq_rel ,
1389
- expt_freq_rel_err ,
1390
- expt_amp ,
1391
- expt_freq_abs ,
1392
- expt_freq_abs_err ,
1393
- ) = get_experimental_FI_curve_for_plotting (cells , prot_name , n_bin = n_bin )
1409
+ expt_data = get_experimental_FI_curve_for_plotting (cells , prot_name , n_bin = n_bin )
1394
1410
elif emodel_name != emodel .emodel_metadata .emodel or cells is None :
1395
1411
# take extraction data from pickle file and rearange it for plotting
1396
1412
cells = read_extraction_output_cells (emodel .emodel_metadata .emodel )
@@ -1399,57 +1415,47 @@ def plot_FI_curves_comparison(
1399
1415
continue
1400
1416
1401
1417
# experimental FI curve
1402
- (
1403
- expt_amp_rel ,
1404
- expt_freq_rel ,
1405
- expt_freq_rel_err ,
1406
- expt_amp ,
1407
- expt_freq_abs ,
1408
- expt_freq_abs_err ,
1409
- ) = get_experimental_FI_curve_for_plotting (cells , prot_name , n_bin = n_bin )
1418
+ expt_data = get_experimental_FI_curve_for_plotting (cells , prot_name , n_bin = n_bin )
1410
1419
1411
1420
emodel_name = emodel .emodel_metadata .emodel
1412
1421
1413
- # simulated FI curve
1414
- simulated_amp_rel , simulated_amp , simulated_freq = get_simulated_FI_curve_for_plotting (
1415
- evaluator , emodel .responses , prot_name
1422
+ expt_data_amp_rel = expt_data [0 ]
1423
+ prot_name_original = get_original_protocol_name (prot_name , evaluator )
1424
+ updated_evaluator = update_evaluator (
1425
+ expt_data_amp_rel , prot_name_original , updated_evaluator
1416
1426
)
1417
1427
1418
- # plotting
1419
- _ , ax = plt .subplots (nrows = 1 , ncols = 2 , figsize = (10 , 3 ))
1420
- ax [0 ].errorbar (
1421
- expt_amp_rel ,
1422
- expt_freq_rel ,
1423
- yerr = expt_freq_rel_err ,
1424
- marker = "o" ,
1425
- color = "grey" ,
1426
- label = "experiment" ,
1427
- )
1428
- ax [0 ].set_xlabel ("Amplitude (% of rheobase)" )
1429
- ax [0 ].set_ylabel ("Mean Frequency (Hz)" )
1430
- ax [0 ].set_title ("FI curve (relative amplitude)" )
1431
- ax [0 ].plot (simulated_amp_rel , simulated_freq , "o" , color = "blue" , label = "model" )
1428
+ updated_evaluator .fitness_protocols ["main_protocol" ].execution_order = (
1429
+ updated_evaluator .fitness_protocols ["main_protocol" ].compute_execution_order ()
1430
+ )
1432
1431
1433
- ax [1 ].errorbar (
1434
- expt_amp ,
1435
- expt_freq_abs ,
1436
- yerr = expt_freq_abs_err ,
1437
- marker = "o" ,
1438
- color = "grey" ,
1439
- label = "experiment" ,
1440
- )
1441
- ax [1 ].set_xlabel ("Amplitude (nA)" )
1442
- ax [1 ].set_ylabel ("Voltage (mV)" )
1443
- ax [1 ].set_title ("IV curve (absolute amplitude)" )
1444
- ax [1 ].plot (simulated_amp , simulated_freq , "o" , color = "blue" , label = "model" )
1432
+ emodels = compute_responses (access_point , updated_evaluator , mapper , seeds )
1433
+ for emodel in emodels :
1434
+ # do not re-extract data if the emodel is the same as previously
1435
+ if custom_bluepyefe_cells_pklpath is not None :
1436
+ if cells is None :
1437
+ cells = read_extraction_output (custom_bluepyefe_cells_pklpath )
1438
+ if cells is None :
1439
+ continue
1445
1440
1446
- ax [0 ].legend ()
1447
- ax [1 ].legend ()
1448
- if write_fig :
1449
- save_fig (
1450
- figures_dir ,
1451
- emodel .emodel_metadata .as_string (emodel .seed ) + "__FI_curve_comparison.pdf" ,
1452
- )
1441
+ # experimental FI curve
1442
+ expt_data = get_experimental_FI_curve_for_plotting (cells , prot_name , n_bin = n_bin )
1443
+ elif emodel_name != emodel .emodel_metadata .emodel or cells is None :
1444
+ # take extraction data from pickle file and rearange it for plotting
1445
+ cells = read_extraction_output_cells (emodel .emodel_metadata .emodel )
1446
+ emodel_name = emodel .emodel_metadata .emodel
1447
+ if cells is None :
1448
+ continue
1449
+
1450
+ # experimental FI curve
1451
+ expt_data = get_experimental_FI_curve_for_plotting (cells , prot_name , n_bin = n_bin )
1452
+
1453
+ emodel_name = emodel .emodel_metadata .emodel
1454
+
1455
+ sim_data = get_simulated_FI_curve_for_plotting (
1456
+ updated_evaluator , emodel .responses , prot_name
1457
+ )
1458
+ plot_fi_curves (expt_data , sim_data , figures_dir , emodel , write_fig )
1453
1459
1454
1460
1455
1461
def phase_plot (
@@ -2046,10 +2052,13 @@ def plot_models(
2046
2052
plot_IV_curves (
2047
2053
cell_evaluator ,
2048
2054
emodels ,
2055
+ access_point ,
2049
2056
figures_dir_IV_curves ,
2050
2057
# maybe we should give efel_settings as an argument of plot_models,
2051
2058
# like the other pipeline_settings
2052
2059
access_point .pipeline_settings .efel_settings ,
2060
+ mapper ,
2061
+ seeds ,
2053
2062
IV_curve_prot_name ,
2054
2063
custom_bluepyefe_cells_pklpath = custom_bluepyefe_cells_pklpath ,
2055
2064
)
@@ -2059,6 +2068,9 @@ def plot_models(
2059
2068
plot_FI_curves_comparison (
2060
2069
cell_evaluator ,
2061
2070
emodels ,
2071
+ access_point ,
2072
+ seeds ,
2073
+ mapper ,
2062
2074
figures_dir_FI_curves ,
2063
2075
FI_curve_prot_name ,
2064
2076
custom_bluepyefe_cells_pklpath = custom_bluepyefe_cells_pklpath ,
0 commit comments