From 87b23ad75ecaf22853bbf431b9ba600014583e6e Mon Sep 17 00:00:00 2001 From: arnaudon Date: Thu, 19 Sep 2024 14:57:41 +0200 Subject: [PATCH] more --- emodel_generalisation/adaptation.py | 14 ++++++++------ emodel_generalisation/cli.py | 7 ++++++- emodel_generalisation/model/bpopt.py | 4 +--- emodel_generalisation/model/evaluation.py | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/emodel_generalisation/adaptation.py b/emodel_generalisation/adaptation.py index ccf488d..58f5f60 100644 --- a/emodel_generalisation/adaptation.py +++ b/emodel_generalisation/adaptation.py @@ -84,7 +84,6 @@ def build_resistance_models( # it seems dask does not quite work on this (to investigate, but multiprocessing is fast enough) df = func(df, access_point, parallel_factory="multiprocessing") - models = {} for emodel in emodels: _df = df[df.emodel == emodel] @@ -93,13 +92,16 @@ def build_resistance_models( if len(rin[rin < 0]) == 0: try: coeffs, extra = Polynomial.fit(np.log10(scaler), np.log10(rin), 3, full=True) - if extra[0] < rcond_min: - models[emodel] = { - "resistance": {"polyfit_params": coeffs.convert().coef.tolist()}, - "shape": exemplar_data[key], - } + if extra[0] > rcond_min: + print(f"resistance fit for {key} of {emodel} is not so good") + models[emodel] = { + "resistance": {"polyfit_params": coeffs.convert().coef.tolist()}, + "shape": exemplar_data[key], + } except (np.linalg.LinAlgError, TypeError): print(f"fail to fit emodel {emodel}") + else: + print(f"resistance fit for {key} of {emodel} has negative rin") return df[df.emodel.isin(models)], models diff --git a/emodel_generalisation/cli.py b/emodel_generalisation/cli.py index e65c5e8..e65167a 100644 --- a/emodel_generalisation/cli.py +++ b/emodel_generalisation/cli.py @@ -755,8 +755,13 @@ def _get_resistance_models(exemplar_df, exemplar_data, scales_params): """We fit the scale/Rin relation for AIS and soma.""" models = {} for emodel in exemplar_df.emodel: + Path(f"local/{emodel}").mkdir(parents=True, exist_ok=True) models[emodel] = build_all_resistance_models( - access_point, [emodel], exemplar_data[emodel], scales_params + access_point, + [emodel], + exemplar_data[emodel], + scales_params, + fig_path=Path(f"local/{emodel}"), ) return models diff --git a/emodel_generalisation/model/bpopt.py b/emodel_generalisation/model/bpopt.py index b5e358d..c2b06c1 100644 --- a/emodel_generalisation/model/bpopt.py +++ b/emodel_generalisation/model/bpopt.py @@ -832,7 +832,7 @@ def __init__( location, target_voltage=None, voltage_precision=0.1, - stimulus_duration=500.0, + stimulus_duration=1000.0, upper_bound=0.2, lower_bound=-0.2, strict_bounds=True, @@ -912,7 +912,6 @@ def get_voltage_base( self, holding_current, cell_model, param_values, sim, isolate, timeout=None ): """Calculate voltage base for a certain holding current""" - self.stimuli[0].amp = holding_current response = BPEMProtocol.run( self, cell_model, param_values, sim=sim, isolate=isolate, timeout=timeout @@ -1102,7 +1101,6 @@ def __init__( "totduration": stimulus_totduration, "holding_current": None, } - self.recording_name = f"{name}.{location.name}.v" stimulus = eCodes["step"](location=location, **stimulus_definition) recordings = [ diff --git a/emodel_generalisation/model/evaluation.py b/emodel_generalisation/model/evaluation.py index ed32b0d..e5a7138 100644 --- a/emodel_generalisation/model/evaluation.py +++ b/emodel_generalisation/model/evaluation.py @@ -451,7 +451,7 @@ def _define_Rin_protocol( def _define_holding_protocol( - efeatures, strict_bounds=False, ais_recording=False, max_depth=7, stimulus_duration=500.0 + efeatures, strict_bounds=False, ais_recording=False, max_depth=7, stimulus_duration=1000.0 ): """Define the search holding current protocol""" target_voltage = None @@ -1013,7 +1013,7 @@ def __init__( self.rin_step_duration = 500.0 self.rin_step_amp = -0.02 self.rin_totduration = self.rin_step_delay + self.rin_step_duration - self.search_holding_duration = 500.0 + self.search_holding_duration = 1000.0 self.search_threshold_step_delay = 500.0 self.search_threshold_step_duration = 2000.0 self.search_threshold_totduration = 3000.0