From 16763d198f29ade1d57174c30b9e48801cc0dc7a Mon Sep 17 00:00:00 2001 From: ilkilic Date: Tue, 16 Jan 2024 13:35:35 +0100 Subject: [PATCH] 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