Helpers module

class bsb.helpers.CastableConfigurableClass[source]
class bsb.helpers.ConfigurableClass[source]

A class that can be configured.

cast_config()[source]

Casts/validates values imported onto this object from configuration files to their final form. The casts dictionary should contain the key of the attribute and a function that takes a value as only argument. This dictionary will be used to cast the attributes when cast_config is called.

abstract validate()[source]

Must be implemented by child classes. Raise exceptions when invalid configuration parameters are received.

class bsb.helpers.DistributionConfiguration[source]

Cast a configuration node into a scipy.stats distribution.

fallback

alias of float

validate()[source]

Must be implemented by child classes. Raise exceptions when invalid configuration parameters are received.

class bsb.helpers.EvalConfiguration[source]
validate()[source]

Must be implemented by child classes. Raise exceptions when invalid configuration parameters are received.

class bsb.helpers.FloatEvalConfiguration[source]
fallback

alias of float

class bsb.helpers.ListEvalConfiguration[source]
fallback

alias of list

class bsb.helpers.OptionallyCastable[source]
bsb.helpers.assert_attr_array(section, attr, section_name)[source]

Asserts that an attribute exists on a dictionary or object, and that it is an array.

Parameters
  • section (dict, object) – Dictionary or object that needs to contain the attribute.

  • attr (string) – Attribute name.

  • section_name (string) – Name of the section to print out the location of the missing attribute.

bsb.helpers.assert_attr_in(section, attr, values, section_name)[source]

Assert that the attribute is present in the section dictionary and that its value is included in the given array.

bsb.helpers.continuity_hop(iterator)[source]

Hop over a continuity list in steps of 2, returning the start & count pairs.

bsb.helpers.continuity_list(iterable, step=1)[source]

Return a compacted notation of a list of nearly continuous numbers.

The iterable will be iterated and chains of continuous numbers will be determined. Each chain will then be added to the output format as a starting number and count.

Example: [4,5,6,7,8,9,12] ==> [4,6,12,1]

Parameters
  • iterable (iter) – The collection of elements to be compacted.

  • stepiterable[i] needs to be equal to iterable[i - 1] + step for them to considered continuous.

bsb.helpers.expand_continuity_list(iterable, step=1)[source]

Return the full set of items associated with the continuity list, as formatted by helpers.continuity_list().

bsb.helpers.iterate_continuity_list(iterable, step=1)[source]

Generate the continuity list

bsb.helpers.listify_input(value)[source]

Turn any non-list values into a list containing the value. Sequences will be converted to a list using list(), None will be replaced by an empty list.