From 52790fb6dc8be2b26e9cfa427006ae45717772ea Mon Sep 17 00:00:00 2001 From: ilkilic Date: Mon, 15 Jan 2024 15:41:25 +0100 Subject: [PATCH 1/4] refactor 'amp' and 'hypamp' in Step current --- bluepyefe/ecode/step.py | 16 ---------------- bluepyefe/recording.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/bluepyefe/ecode/step.py b/bluepyefe/ecode/step.py index 711a4bc..b57c8e0 100644 --- a/bluepyefe/ecode/step.py +++ b/bluepyefe/ecode/step.py @@ -60,8 +60,6 @@ def __init__( self.ton = None self.toff = None self.tend = None - self.amp = None - self.hypamp = None self.dt = None self.amp_rel = None @@ -123,20 +121,6 @@ def interpret(self, t, current, config_data, reader_data): else: self.toff = None - # amp - if "amp" in config_data and config_data["amp"] is not None: - self.amp = config_data["amp"] - elif "amp" in reader_data and reader_data["amp"] is not None: - self.amp = reader_data["amp"] - else: - self.amp = None - - # hypamp - if "hypamp" in config_data and config_data["hypamp"] is not None: - self.hypamp = config_data["hypamp"] - elif "hypamp" in reader_data and reader_data["hypamp"] is not None: - self.hypamp = reader_data["hypamp"] - # Infer the begin and end of the step current if self.ton is None: if self.hypamp is None: diff --git a/bluepyefe/recording.py b/bluepyefe/recording.py index 1f16c77..51ae21c 100644 --- a/bluepyefe/recording.py +++ b/bluepyefe/recording.py @@ -67,11 +67,13 @@ def __init__(self, config_data, reader_data, protocol_name): self.t = None self.current = None self.voltage = None + self.amp = None + self.hypamp = None self.repetition = None if len(reader_data): - self.t, self.current, self.voltage = self.standardize_trace( + self.t, self.current, self.voltage, self.amp, self.hypamp = self.standardize_trace( config_data, reader_data ) @@ -189,8 +191,12 @@ def standardize_trace(self, config_data, reader_data): # Convert current to nA if "i_unit" in config_data and config_data["i_unit"] is not None: current = to_nA(reader_data["current"], config_data["i_unit"]) + amp = to_nA(reader_data["amp"], config_data["i_unit"]) + hypamp = to_nA(reader_data["hypamp"], config_data["i_unit"]) elif "i_unit" in reader_data and reader_data["i_unit"] is not None: current = to_nA(reader_data["current"], reader_data["i_unit"]) + amp = to_nA(reader_data["amp"], reader_data["i_unit"]) + hypamp = to_nA(reader_data["hypamp"], reader_data["i_unit"]) else: raise Exception( "Current unit not configured for " "file {}".format(self.files) @@ -221,7 +227,7 @@ def standardize_trace(self, config_data, reader_data): if "repetition" in reader_data: self.repetition = reader_data["repetition"] - return t, current, voltage + return t, current, voltage, amp, hypamp def call_efel(self, efeatures, efel_settings=None): """ Calls efel to compute the wanted efeatures """ From 63a63a762067b6b5988b9a22d1466dbddd3b4a3b Mon Sep 17 00:00:00 2001 From: ilkilic Date: Mon, 15 Jan 2024 16:10:30 +0100 Subject: [PATCH 2/4] bug fix --- bluepyefe/recording.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bluepyefe/recording.py b/bluepyefe/recording.py index 51ae21c..4985e77 100644 --- a/bluepyefe/recording.py +++ b/bluepyefe/recording.py @@ -189,14 +189,20 @@ def standardize_trace(self, config_data, reader_data): ) # Convert current to nA + amp = None + hypamp = None if "i_unit" in config_data and config_data["i_unit"] is not None: current = to_nA(reader_data["current"], config_data["i_unit"]) - amp = to_nA(reader_data["amp"], config_data["i_unit"]) - hypamp = to_nA(reader_data["hypamp"], config_data["i_unit"]) + if "amp" in reader_data: + amp = to_nA(reader_data["amp"], config_data["i_unit"]) + if "hypamp" in reader_data: + hypamp = to_nA(reader_data["hypamp"], config_data["i_unit"]) elif "i_unit" in reader_data and reader_data["i_unit"] is not None: current = to_nA(reader_data["current"], reader_data["i_unit"]) - amp = to_nA(reader_data["amp"], reader_data["i_unit"]) - hypamp = to_nA(reader_data["hypamp"], reader_data["i_unit"]) + if "amp" in reader_data: + amp = to_nA(reader_data["amp"], reader_data["i_unit"]) + if "hypamp" in reader_data: + hypamp = to_nA(reader_data["hypamp"], reader_data["i_unit"]) else: raise Exception( "Current unit not configured for " "file {}".format(self.files) From cfe6c681860a19a4cadaf66daff38400d6a95622 Mon Sep 17 00:00:00 2001 From: ilkilic Date: Tue, 16 Jan 2024 13:10:26 +0100 Subject: [PATCH 3/4] check 'amp' and 'hypamp' in reader_data and config_data --- bluepyefe/recording.py | 26 ++++++++++++-------------- tests/test_extractor.py | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/bluepyefe/recording.py b/bluepyefe/recording.py index 4985e77..c1024b5 100644 --- a/bluepyefe/recording.py +++ b/bluepyefe/recording.py @@ -189,20 +189,18 @@ def standardize_trace(self, config_data, reader_data): ) # Convert current to nA - amp = None - hypamp = None - if "i_unit" in config_data and config_data["i_unit"] is not None: - current = to_nA(reader_data["current"], config_data["i_unit"]) - if "amp" in reader_data: - amp = to_nA(reader_data["amp"], config_data["i_unit"]) - if "hypamp" in reader_data: - hypamp = to_nA(reader_data["hypamp"], config_data["i_unit"]) - elif "i_unit" in reader_data and reader_data["i_unit"] is not None: - current = to_nA(reader_data["current"], reader_data["i_unit"]) - if "amp" in reader_data: - amp = to_nA(reader_data["amp"], reader_data["i_unit"]) - if "hypamp" in reader_data: - hypamp = to_nA(reader_data["hypamp"], reader_data["i_unit"]) + # Determine the unit to use + unit = config_data.get("i_unit") or reader_data.get("i_unit") + if unit: + current = to_nA(reader_data.get("current", 0), unit) + + # Set amp - prioritize amp in config_data + amp_source = config_data if "amp" in config_data else reader_data + amp = to_nA(amp_source.get("amp", 0), unit) if "amp" in amp_source else None + + # Set hypamp - prioritize hypamp in config_data + hypamp_source = config_data if "hypamp" in config_data else reader_data + hypamp = to_nA(hypamp_source.get("hypamp", 0), unit) if "hypamp" in hypamp_source else None else: raise Exception( "Current unit not configured for " "file {}".format(self.files) diff --git a/tests/test_extractor.py b/tests/test_extractor.py index d011acf..a4d2574 100644 --- a/tests/test_extractor.py +++ b/tests/test_extractor.py @@ -288,7 +288,7 @@ def test_extract_absolute(self): protocols = json.load(fp) self.assertEqual(len(features), len(protocols)) - + def test_extract_sahp(self): files_metadata, targets = get_sahp_config() From 16763d198f29ade1d57174c30b9e48801cc0dc7a Mon Sep 17 00:00:00 2001 From: ilkilic Date: Tue, 16 Jan 2024 13:35:35 +0100 Subject: [PATCH 4/4] handle unit conversion in set_amplitudes_ecode --- bluepyefe/recording.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bluepyefe/recording.py b/bluepyefe/recording.py index c1024b5..7c4b72d 100644 --- a/bluepyefe/recording.py +++ b/bluepyefe/recording.py @@ -117,12 +117,19 @@ def set_amplitudes_ecode(self, amp_name, config_data, reader_data, value): given current amplitude is provided. If it isn't use the value computed from the current series""" + unit = config_data.get("i_unit") or reader_data.get("i_unit") + + if unit is None: + raise Exception(f"Current unit not configured for file {self.files}") + if amp_name in config_data and config_data[amp_name] is not None: - setattr(self, amp_name, config_data[amp_name]) + amp = to_nA(config_data[amp_name], unit) elif amp_name in reader_data and reader_data[amp_name] is not None: - setattr(self, amp_name, reader_data[amp_name]) + amp = to_nA(reader_data[amp_name], unit) else: - setattr(self, amp_name, value) + amp = value + + setattr(self, amp_name, amp) def index_to_ms(self, name_timing, time_series): """Used by some of the children classes to translate a timing attribute