Skip to content

Commit

Permalink
Merge pull request #167 from BlueBrain/standardize-trace-amplitude
Browse files Browse the repository at this point in the history
Refactor 'amp' and 'hypamp' variables in Step for correct unit conversion
  • Loading branch information
ilkilic committed Jan 16, 2024
2 parents 2db0f81 + 16763d1 commit ae362c5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
16 changes: 0 additions & 16 deletions bluepyefe/ecode/step.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
35 changes: 26 additions & 9 deletions bluepyefe/recording.py
Expand Up @@ -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
)

Expand Down Expand Up @@ -115,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
Expand Down Expand Up @@ -187,10 +196,18 @@ 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"])
elif "i_unit" in reader_data and reader_data["i_unit"] is not None:
current = to_nA(reader_data["current"], 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)
Expand Down Expand Up @@ -221,7 +238,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 """
Expand Down
2 changes: 1 addition & 1 deletion tests/test_extractor.py
Expand Up @@ -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()
Expand Down

0 comments on commit ae362c5

Please sign in to comment.