vartest

Variable testing procedures.

Utility procedures to evaluate variables to determine if they pass simple tests. These tests are typically to ensure that a variable is of a particular type and a particular format. These methods raise informative exceptions if they fail.

AUTHORS:

  • THOMAS MCTAVISH (2010-02-05): initial version

EXAMPLES:

Test that a variable is greater than 0.:

x = 2
greater_than(x, 0)

This does not raise an exception. This shows that x may be an int or x may be a float. Try a negative value.:

>>> x = -2
>>> greater_than(x, 0)
The variable tested needs to be > 0.
The variable tested is of <type 'int'> and
has a wrong value of -2.

In this case, the error reported is fairly informative, but note that it can be made more informative by telling us the name of the parameter. The next example tries a different format altogether and passes in the name of the variable so that the user understands which variable is in error.:

>>> some_var='abc'
>>> greater_than(some_var, 0, 'some_var')
some_var needs to be > 0.
some_var is of <type 'str'> and has a wrong value of abc.
neuronpy.util.vartest.greater_than(test_var, val=0.0, name=None)[source]

Tests to see that test_var is a float and is greater than a number.

Parameters:
  • test_var (float or int) – the variable to test
  • name (string; default None) – the name of the parameter to help inform the user which variable is problematic, if it does not pass.
Throws :

exception if the test_var does not meet the requirements and describes the problem.

neuronpy.util.vartest.greater_than_or_equal(test_var, val=0.0, name=None)[source]

Tests to see that test_var is a float and is greater than zero.

Parameters:
  • test_var (float or int) – the variable to test
  • name (string; default None) – the name of the parameter to help inform the user which variable is problematic, if it does not pass.
Throws :

exception if the test_var does not meet the requirements and describes the problem.

neuronpy.util.vartest.inrange(test_var, min=0.0, max=1.0, name=None)[source]

Tests to see that test_var is a float and is greater than or equal to min and less than or equal to max.

Parameters:
  • test_var (float or int) – the variable to test
  • min (float or int) – Minimum value
  • max (float or int) – Maximum value
  • name (string; default None) – the name of the parameter to help inform the user which variable is problematic, if it does not pass.
Throws :

exception if the test_var does not meet the requirements and describes the problem.

neuronpy.util.vartest.is1Dvector(test_var, name=None)[source]

Tests to see that test_var is a 1-dimensional list or numpy array.

Parameters:
  • test_var – the variable to test
  • name (string; default None) – the name of the parameter to help inform the user which variable is problematic, if it does not pass.
Throws :

exception if the test_var does not meet the requirements and describes the problem.

neuronpy.util.vartest.isbool(test_var, name=None)[source]

Tests to see that test_var is an explicit boolean (True or False) value.

Parameters:
  • test_var (bool) – the variable to test
  • name (string; default None) – the name of the parameter to help inform the user which variable is problematic, if it does not pass.
Throws :

exception if the test_var does not meet the requirements and describes the problem.

neuronpy.util.vartest.isint(test_var, name=None)[source]

Tests to see that test_var is an integer.

Parameters:
  • test_var (int) – the variable to test
  • name (string; default None) – the name of the parameter to help inform the user which variable is problematic, if it does not pass.
Throws :

exception if the test_var does not meet the requirements and describes the problem.

Previous topic

timeseries

Next topic

Examples, Demos, and Tutorials

This Page