bluepyemodel.tools.utils

Utils

Functions

are_same_protocol(name_a, name_b)

Check if two protocol names or list are equal.

checkpoint_path_exists(checkpoint_path)

Returns True if checkpoint path exists, False if not.

existing_checkpoint_paths(emodel_metadata[, ...])

Returns a list of existing checkpoint paths conforming to metadata.

format_protocol_name_to_list(protocol_name)

Make sure that the name of a protocol is a list [protocol_name, amplitude]

get_amplitude_from_feature_key(feat_key)

Get amplitude from a key of the EModel.feature dict.

get_checkpoint_path(metadata[, seed])

Get checkpoint path.

get_curr_name(feature_name)

Extracts the current name from the feature name or response key.

get_legacy_checkpoint_path(checkpoint_path)

Get legacy checkpoint path from checkpoint path

get_loc_name(feature_name)

Extracts the location name from the feature name or response key.

get_mapped_protocol_name(protocol_name, ...)

Returns the mapped protocol name from protocols_mapping if available; otherwise, returns the original name.

get_protocol_name(feature_name)

Extracts the protocol name from the feature name or response key.

get_seed_from_checkpoint_path(path)

Get seed from checkpoint path name.

make_dir(path_dir)

Creates directory if it does not exist

parse_feature_name_parts(feature_name)

Splits the feature name into its respective parts, handling cases where the protocol name contains a dot.

read_checkpoint(checkpoint_path)

Reads a BluePyOpt checkpoint file

select_rec_for_thumbnail(rec_names[, ...])

Select a recording for thumbnail.

yesno(question)

Ask a Yes/No question

are_same_protocol(name_a, name_b)

Check if two protocol names or list are equal. Eg: is IV_0.0 the same as IV_0 and the same as [“IV”, 0.0].

checkpoint_path_exists(checkpoint_path)

Returns True if checkpoint path exists, False if not.

Parameters:

checkpoint_path (str or Path) – checkpoint path

existing_checkpoint_paths(emodel_metadata, checkpoint_paths=None)

Returns a list of existing checkpoint paths conforming to metadata.

Parameters:
  • emodel_metadata (EModelMetadata) – contains emodel and iteration that should be present in each returned checkpoint path

  • checkpoint_paths (list) – list of existing checkpoint paths to be filtered using metadata. If None, will be created on the spot.

format_protocol_name_to_list(protocol_name)

Make sure that the name of a protocol is a list [protocol_name, amplitude]

get_amplitude_from_feature_key(feat_key)

Get amplitude from a key of the EModel.feature dict.

Parameters:

feat_key (str) – feature key, e.g. IV_40.soma.maximum_voltage_from_voltagebase

get_checkpoint_path(metadata, seed=None)

Get checkpoint path. Use legacy format if any is found, else use latest format.

get_curr_name(feature_name)

Extracts the current name from the feature name or response key.

This function works with both a full feature name string (e.g., “IV_40.0.soma.v.voltage_base”) and a response key (e.g., “IV_40.0.soma.v”). It returns the third part of the input, which is the current name, correctly handling cases where the protocol contains a dot.

Parameters:

feature_name (str) – The full feature name string or response key.

Returns:

The current name part of the feature name.

Return type:

str

Raises:

IndexError – If the current name cannot be determined from the input.

Examples

>>> get_curr_name("IV_40.0.soma.v.voltage_base")
'v'
>>> get_curr_name("IV_40.0.soma.v")
'v'
get_legacy_checkpoint_path(checkpoint_path)

Get legacy checkpoint path from checkpoint path

get_loc_name(feature_name)

Extracts the location name from the feature name or response key.

This function works with both a full feature name string (e.g., “IV_40.0.soma.v.voltage_base”) and a response key (e.g., “IV_40.0.soma.v”). It returns the second part of the input, which is the location name, correctly handling cases where the protocol contains a dot.

Parameters:

feature_name (str) – The full feature name string or response key.

Returns:

The location name part of the feature name.

Return type:

str

Raises:

IndexError – If the location name cannot be determined from the input.

Examples

>>> get_loc_name("IV_40.0.soma.v.voltage_base")
'soma'
>>> get_loc_name("IV_40.0.soma.v")
'soma'
get_mapped_protocol_name(protocol_name, protocols_mapping)

Returns the mapped protocol name from protocols_mapping if available; otherwise, returns the original name.

get_protocol_name(feature_name)

Extracts the protocol name from the feature name or response key.

This function works with both a full feature name string (e.g., “IV_40.0.soma.v.voltage_base”) and a response key (e.g., “IV_40.0.soma.v”). It returns the first part of the input, which is the protocol name, correctly handling cases where the protocol contains a dot.

Parameters:

feature_name (str) – The full feature name string or response key.

Returns:

The protocol name part of the feature name.

Return type:

str

Examples

>>> get_protocol_name("IV_40.0.soma.v.voltage_base")
'IV_40.0'
>>> get_protocol_name("IV_40.0.soma.v")
'IV_40.0'
get_seed_from_checkpoint_path(path)

Get seed from checkpoint path name. default seed is 0 if not found.

make_dir(path_dir)

Creates directory if it does not exist

parse_feature_name_parts(feature_name)

Splits the feature name into its respective parts, handling cases where the protocol name contains a dot.

This function works with both a full feature name string (e.g., “IV_40.0.soma.v.voltage_base”) and a response key (e.g., “IV_40.0.soma.v”). It splits the input into a list of parts, combining the first two parts if the protocol name contains a dot and is followed by a numeric component.

Parameters:

feature_name (str) – The full feature name string or response key to be parsed.

Returns:

A list of strings representing the correctly parsed parts of the feature name.

Return type:

list

Examples

>>> parse_feature_name_parts("IV_40.0.soma.v.voltage_base")
['IV_40.0', 'soma', 'v', 'voltage_base']
>>> parse_feature_name_parts("IV_40.0.soma.v")
['IV_40.0', 'soma', 'v']
read_checkpoint(checkpoint_path)

Reads a BluePyOpt checkpoint file

select_rec_for_thumbnail(rec_names, additional_step_prots=None, thumbnail_rec=None)

Select a recording for thumbnail.

Select the step protocol with lowest positive amplitude, so that delay is visible if present.

Parameters:
  • rec_names (set) – the names of the recordings, following this naming convention: protocol_name_amplitude.location.variable

  • additional_step_prots (list) – step protocol names to look for (other than defaults ones)

  • thumbnail_rec (str) – recording name to use for thumbnail if present

yesno(question)

Ask a Yes/No question