Helper module

These are helper functions to ease the definition of the high-level API of the PyNEST wrapper.

class nest.lib.hl_api_helper.SuppressedDeprecationWarning(no_dep_funcs)

Bases: object

Context manager turning off deprecation warnings for given methods.

Think thoroughly before use. This context should only be used as a way to make sure examples do not display deprecation warnings, that is, used in functions called from examples, and not as a way to make tedious deprecation warnings dissapear.

nest.lib.hl_api_helper.broadcast(item, length, allowed_types, name='item')

Broadcast item to given length.

Parameters:
  • item (object) – Object to broadcast

  • length (int) – Length to broadcast to

  • allowed_types (list) – List of allowed types

  • name (str, optional) – Name of item

Returns:

The original item broadcasted to sequence form of length

Return type:

object

Raises:

TypeError

nest.lib.hl_api_helper.deprecated(alt_func_name, text=None)

Decorator for deprecated functions.

Shows a warning and calls the original function.

Parameters:
  • alt_func_name (str, optional) – Name of the function to use instead, may be empty string

  • text (str, optional) – Text to display instead of standard text

Returns:

Decorator function

Return type:

function

nest.lib.hl_api_helper.get_parameters(nc, param)

Get parameters from nodes.

Used by NodeCollections get() function.

Parameters:
  • nc (NodeCollection) – nodes to get values from

  • param (string or list of strings) – string or list of string naming model properties.

Returns:

  • int, list – param is a string so the value(s) is returned

  • dict – param is a list of string so a dictionary is returned

nest.lib.hl_api_helper.get_parameters_hierarchical_addressing(nc, params)

Get parameters from nodes, hierarchical case.

Used by NodeCollections get() function.

Parameters:
  • nc (NodeCollection) – nodes to get values from

  • params (tuple) – first value in the tuple should be a string, second can be a string or a list of string. The first value corresponds to the path into the hierarchical structure while the second value corresponds to the name(s) of the desired properties.

Returns:

  • int, list – params[-1] is a string so the value(s) is returned

  • dict – params[-1] is a list of string so a dictionary is returned

nest.lib.hl_api_helper.get_unistring_type()

Returns string type dependent on python version.

Returns:

Depending on Python version

Return type:

str or basestring

nest.lib.hl_api_helper.get_wrapped_text(text, width=80)

Formats a given multiline string to wrap at a given width, while preserving newlines (and removing excessive whitespace).

Parameters:

text (str) – String to format

Returns:

Wrapped string

Return type:

str

nest.lib.hl_api_helper.is_coercible_to_sli_array(seq)

Checks whether a given object is coercible to a SLI array

Parameters:

seq (object) – Object to check

Returns:

True if object is coercible to a SLI array

Return type:

bool

nest.lib.hl_api_helper.is_iterable(seq)

Return True if the given object is an iterable, False otherwise.

Parameters:

seq (object) – Object to check

Returns:

True if object is an iterable

Return type:

bool

nest.lib.hl_api_helper.is_literal(obj)

Check whether obj is a “literal”: a unicode string or SLI literal

Parameters:

obj (object) – Object to check

Returns:

True if obj is a “literal”

Return type:

bool

nest.lib.hl_api_helper.is_sequence_of_connections(seq)

Checks whether low-level API accepts seq as a sequence of connections.

Parameters:

seq (object) – Object to check

Returns:

True if object is an iterable of dictionaries or subscriptables of CONN_LEN

Return type:

bool

nest.lib.hl_api_helper.is_sequence_of_node_ids(seq)

Checks whether the argument is a potentially valid sequence of node IDs (non-negative integers).

Parameters:

seq (object) – Object to check

Returns:

True if object is a potentially valid sequence of node IDs

Return type:

bool

nest.lib.hl_api_helper.is_string(obj)

Check whether obj is a unicode string

Parameters:

obj (object) – Object to check

Returns:

True if obj is a unicode string

Return type:

bool

nest.lib.hl_api_helper.load_help(obj)

Returns documentation of the given object in RST format

Parameters:

obj (string) – Object to display help for

Returns:

The documentation of the object or None if no help is available

Return type:

string

nest.lib.hl_api_helper.model_deprecation_warning(model)

Checks whether the model is to be removed in a future version of NEST. If so, a deprecation warning is issued.

Parameters:

model (str) – Name of model

nest.lib.hl_api_helper.restructure_data(result, keys)

Restructure list of status dictionaries or list of parameter values to dict with lists or single list or int.

Parameters:
  • result (list) – list of status dictionaries or list (of lists) of parameter values.

  • keys (string or list of strings) – name(s) of properties

Return type:

int, list or dict

nest.lib.hl_api_helper.show_deprecation_warning(func_name, alt_func_name=None, text=None)

Shows a deprecation warning for a function.

Parameters:
  • func_name (str) – Name of the deprecated function

  • alt_func_name (str, optional) – Name of the function to use instead. Needed if text=None

  • text (str, optional) – Text to display instead of standard text

nest.lib.hl_api_helper.show_help_with_pager(obj)

Display help text for the given object in the Python pager

If called from within a Jupyter notebook, display help in a modal window instead of in the pager.

Parameters:

obj (object) – Object to display

nest.lib.hl_api_helper.uni_str

alias of str