Validator functions

Validators are used in conjunction with the Instrument.control function to allow properties with complex restrictions for valid values. They are described in more detail in the Advanced properties section.

pymeasure.instruments.validators.discreteTruncate(number, discreteSet)

Truncates the number to the closest element in the positive discrete set. Returns False if the number is larger than the maximum value or negative.

pymeasure.instruments.validators.joined_validators(*validators)

Join a list of validators together as a single. Expects a list of validator functions and values.

Parameters:validators – an iterable of other validators
pymeasure.instruments.validators.modular_range(value, values)

Provides a validator function that returns the value if it is in the range. Otherwise it returns the value, modulo the max of the range.

Parameters:
  • value – a value to test
  • values – A set of values that are valid
pymeasure.instruments.validators.modular_range_bidirectional(value, values)

Provides a validator function that returns the value if it is in the range. Otherwise it returns the value, modulo the max of the range. Allows negative values.

Parameters:
  • value – a value to test
  • values – A set of values that are valid
pymeasure.instruments.validators.strict_discrete_range(value, values, step)

Provides a validator function that returns the value if its value is less than the maximum and greater than the minimum of the range and is a multiple of step. Otherwise it raises a ValueError.

Parameters:
  • value – A value to test
  • values – A range of values (range, list, etc.)
  • step – Minimum stepsize (resolution limit)
Raises:

ValueError if the value is out of the range

pymeasure.instruments.validators.strict_discrete_set(value, values)

Provides a validator function that returns the value if it is in the discrete set. Otherwise it raises a ValueError.

Parameters:
  • value – A value to test
  • values – A set of values that are valid
Raises:

ValueError if the value is not in the set

pymeasure.instruments.validators.strict_range(value, values)

Provides a validator function that returns the value if its value is less than the maximum and greater than the minimum of the range. Otherwise it raises a ValueError.

Parameters:
  • value – A value to test
  • values – A range of values (range, list, etc.)
Raises:

ValueError if the value is out of the range

pymeasure.instruments.validators.truncated_discrete_set(value, values)

Provides a validator function that returns the value if it is in the discrete set. Otherwise, it returns the smallest value that is larger than the value.

Parameters:
  • value – A value to test
  • values – A set of values that are valid
pymeasure.instruments.validators.truncated_range(value, values)

Provides a validator function that returns the value if it is in the range. Otherwise it returns the closest range bound.

Parameters:
  • value – A value to test
  • values – A set of values that are valid