superneuromat.util#

Utility functions for SuperNeuroMAT.

superneuromat.util.getenvbool(key: str, default: bool | None | str | Any = None, force_bool: Literal[False] = False) Any[source]#
superneuromat.util.getenvbool(key: str, default: bool | None | str = None, force_bool: Literal[False] = False) bool | str
superneuromat.util.getenvbool(key: str, default: bool | None = None, force_bool: Literal[True] = True) bool

Get the value of an environment variable and attempt to cast to bool, or return a default.

Parameters:
  • key (str) – The name of the environment variable.

  • default (bool | None, optional) – The default value to return if the environment variable is not set.

  • force_bool (bool, default=False) – If True, raise an error if the environment variable is not a bool.

Returns:

The value of the environment variable, or the default value if the environment variable is not set.

Return type:

bool | str

Raises:

ValueError – If the environment variable is not a bool and force_bool is True, or if you set force_bool=True and a non-bool value for default

superneuromat.util.is_intlike(x)[source]#

Returns True if x is equivalent to an integer.

Raises:

ValueError – If x cannot be coerced to an integer.

superneuromat.util.pretty_spike_train(spike_train: list[list[bool]] | list[ndarray] | ndarray, max_steps: int | None = 11, max_neurons: int | None = 28, use_unicode: bool | Any = True)[source]#

Prints the spike train.

Parameters:
  • spike_train (list[list[bool]] | list[np.ndarray] | np.ndarray) – The spike train to show.

  • max_steps (int | None, optional) – Limits the number of steps which will be included. If limited, only a total of max_steps first and last steps will be included.

  • max_neurons (int | None, optional) – Limits the number of neurons which will be included. If limited, only a total of max_neurons first and last neurons will be included.

  • use_unicode (bool, default=True) – If True, use unicode characters to represent spikes. Otherwise fallback to ascii characters.

superneuromat.util.print_spike_train(spike_train, max_steps=None, max_neurons=None, use_unicode=True)[source]#

Prints the spike train.

Parameters:
  • spike_train (list[list[bool]] | list[np.ndarray] | np.ndarray) – The spike train to print.

  • max_steps (int | None, optional) – Limits the number of steps which will be printed. If limited, only a total of max_steps first and last steps will be printed.

  • max_neurons (int | None, optional) – Limits the number of neurons which will be printed. If limited, only a total of max_neurons first and last neurons will be printed.

  • use_unicode (bool, default=True) – If True, use unicode characters to represent spikes. Otherwise fallback to ascii characters.

Functions

float_err(x[, name, fname, msg])

Cast float and raise a custom error

getenv(key[, default])

Get the value of an environment variable or return a default.

getenvbool()

Get the value of an environment variable and attempt to cast to bool, or return a default.

int_err(x[, name, fname, msg])

Cast int and raise a ValueError if x is not an int or int-like.

is_intlike(x)

Returns True if x is equivalent to an integer.

is_intlike_catch(x)

Returns True if x is equivalent to an integer or False if x is not a number.

pretty_spike_train(spike_train[, max_steps, ...])

Prints the spike train.

print_spike_train(spike_train[, max_steps, ...])

Prints the spike train.