Skip to content

Commit

Permalink
Explicit the value used as a default for the standard deviation
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTaDa committed Jan 5, 2023
1 parent b201147 commit 9b07e90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
13 changes: 11 additions & 2 deletions bluepyefe/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def create_feature_protocol_files(
threshold_nvalue_save=1,
write_files=True,
save_files_used=False,
default_std_value=1e-3
):
"""
Save the efeatures and protocols for each protocol/target combo
Expand All @@ -496,6 +497,8 @@ def create_feature_protocol_files(
save_files_used (bool): if True, the name of the recording files used
in the computation of the features will be added to the
efeatures.
default_std_value (float): default value used to replace the standard
deviation if the standard deviation is 0.
Returns:
feat (dict)
Expand Down Expand Up @@ -523,7 +526,7 @@ def create_feature_protocol_files(
)
continue

tmp_feat.append(target.as_legacy_dict(save_files_used))
tmp_feat.append(target.as_dict(save_files_used, default_std_value))

if not tmp_feat:
logger.warning(
Expand Down Expand Up @@ -783,7 +786,8 @@ def extract_efeatures_per_cell(
targets,
protocol_mode,
threshold_nvalue_save,
write_files
write_files,
default_std_value=1e-3
):

for cell_name in files_metadata:
Expand All @@ -808,6 +812,7 @@ def extract_efeatures_per_cell(
output_directory=cell_directory,
threshold_nvalue_save=threshold_nvalue_save,
write_files=write_files,
default_std_value=default_std_value
)


Expand All @@ -830,6 +835,7 @@ def extract_efeatures(
rheobase_settings=None,
auto_targets=None,
pickle_cells=False,
default_std_value=1e-3
):
"""
Extract efeatures.
Expand Down Expand Up @@ -908,6 +914,8 @@ def extract_efeatures(
computation function.
auto_targets (list of AutoTarget): targets with more flexible goals.
pickle_cells (bool): if True, the cells object will be saved as a pickle file.
default_std_value (float): default value used to replace the standard
deviation if the standard deviation is 0.
"""

if not files_metadata:
Expand Down Expand Up @@ -978,6 +986,7 @@ def extract_efeatures(
output_directory=output_directory,
threshold_nvalue_save=threshold_nvalue_save,
write_files=write_files,
default_std_value=default_std_value
)

if pickle_cells:
Expand Down
26 changes: 5 additions & 21 deletions bluepyefe/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
amplitude,
tolerance,
efel_settings=None,

):
"""Constructor.
Expand Down Expand Up @@ -127,24 +128,7 @@ def add_effective_threshold(self):
if self._auto_thresholds:
self.efel_settings["Threshold"] = numpy.median(self._auto_thresholds)

def as_dict(self):
"""Returns the target in the form of a dictionary"""

self.add_effective_threshold()

return {
"efeature_name": self.efeature_name,
"feature": self.efel_feature_name,
"mean": self.mean,
"std": self.std,
"values": self._values,
"protocol_name": self.protocol_name,
"amplitude": self.amplitude,
"tolerance": self.tolerance,
"efel_settings": self.efel_settings
}

def as_legacy_dict(self, save_files_used=False):
def as_dict(self, save_files_used=False, default_std_value=1e-3):
"""Returns the target in the form of a dictionary in a legacy format"""

self.add_effective_threshold()
Expand All @@ -153,11 +137,11 @@ def as_legacy_dict(self, save_files_used=False):
if std == 0.0:
logger.warning(
"Standard deviation for efeatures {} stimulus {} is 0 and"
"will be set to 1e-3".format(
self.efel_feature_name, self.protocol_name
"will be set to {}".format(
self.efel_feature_name, self.protocol_name, default_std_value
)
)
std = 1e-3
std = default_std_value

feature_dict = {
"feature": self.efel_feature_name,
Expand Down
9 changes: 3 additions & 6 deletions tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ def test_dict(self):
self.target.append(1.)
self.target.append(2.)
dict_form = self.target.as_dict()
self.assertEqual(len(dict_form), 9)
self.assertEqual(dict_form['mean'], 1.5)
dict_form_legacy = self.target.as_legacy_dict()
self.assertEqual(len(dict_form_legacy), 5)
self.assertEqual(len(dict_form_legacy['val']), 2)
self.assertEqual(len(dict_form_legacy['efel_settings']), 0)
self.assertEqual(len(dict_form), 5)
self.assertEqual(len(dict_form['val']), 2)
self.assertEqual(len(dict_form['efel_settings']), 0)

def test_str(self):
print(self.target)
Expand Down

0 comments on commit 9b07e90

Please sign in to comment.