Class Number
source code
object --+
|
parameterized.Parameter --+
|
Dynamic --+
|
Number
- Known Subclasses:
-
Number is a numeric parameter. Numbers have a default value and
optional bounds. There are two types of bounds: bounds and
softbounds. bounds are hard bounds: the parameter must
have a value within the specified range. The default bounds are
(None,None), meaning there are actually no hard bounds. One or
both bounds can be set by specifying a value
(e.g. bounds=(None,10) means there is no lower bound, and an upper
bound of 10).
Number is also a type of Dynamic parameter, so its value
can be set to a callable to get a dynamically generated
number (see Dynamic).
When not being dynamically generated, bounds are checked when a
Number is created or set. Using a default value outside the hard
bounds, or one that is not numeric, results in an exception. When
being dynamically generated, bounds are checked when a the value
of a Number is requested. A generated value that is not numeric,
or is outside the hard bounds, results in an exception.
As a special case, if allow_None=True (which is true by default if
the parameter has a default of None when declared) then a value
of None is also allowed.
A separate function set_in_bounds() is provided that will
silently crop the given value into the legal range, for use
in, for instance, a GUI.
softbounds are present to indicate the typical range of
the parameter, but are not enforced. Setting the soft bounds
allows, for instance, a GUI to know what values to display on
sliders for the Number.
- Example of creating a Number::
- AB = Number(default=0.5, bounds=(None,10), softbounds=(0,1), doc='Distance from A to B.')
|
|
__init__(self,
default=0.0,
bounds=None,
softbounds=None,
allow_None=False,
**params)
Initialize this parameter object and store the bounds. |
source code
|
|
|
|
__get__(self,
obj,
objtype)
Same as the superclass's __get__, but if the value was
dynamically generated, check the bounds. |
source code
|
|
|
|
__set__(self,
obj,
val)
Set to the given value, raising an exception if out of bounds. |
source code
|
|
|
|
|
|
|
|
|
|
_check_value(self,
val)
Checks that the value is numeric and that it is within the hard
bounds; if not, an exception is raised. |
source code
|
|
|
|
get_soft_bounds(self)
For each soft bound (upper and lower), if there is a defined bound (not equal to None)
then it is returned, otherwise it defaults to the hard bound. |
source code
|
|
|
Inherited from Dynamic:
time_fn
Inherited from parameterized.Parameter:
__delete__,
__getstate__,
__setstate__
Inherited from object:
__delattr__,
__getattribute__,
__hash__,
__new__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__str__
|
|
|
__classdoc = '\n Number is a numeric parameter. Numbers hav...
str(object) -> string
|
__init__(self,
default=0.0,
bounds=None,
softbounds=None,
allow_None=False,
**params)
(Constructor)
| source code
|
Initialize this parameter object and store the bounds.
Non-dynamic default values are checked against the bounds.
- Overrides:
object.__init__
|
Set to the given value, but cropped to be within the legal bounds.
All objects are accepted, and no exceptions will be raised. See
crop_to_bounds for details on how cropping is done.
|
|
Return the given value cropped to be within the hard bounds
for this parameter.
If a numeric value is passed in, check it is within the hard
bounds. If it is larger than the high bound, return the high
bound. If it's smaller, return the low bound. In either case, the
returned value could be None. If a non-numeric value is passed
in, set to be the default value (which could be None). In no
case is an exception raised; all values are accepted.
|
For each soft bound (upper and lower), if there is a defined bound (not equal to None)
then it is returned, otherwise it defaults to the hard bound. The hard bound could still be None.
|
__classdoc
str(object) -> string
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
- Value:
'''
Number is a numeric parameter. Numbers have a default value and
optional bounds. There are two types of bounds: ``bounds`` and
``softbounds``. ``bounds`` are hard bounds: the parameter must
have a value within the specified range. The default bounds are
(None,None), meaning there are actually no hard bounds. One or
both bounds can be set by specifying a value
(e.g. bounds=(None,10) means there is no lower bound, and an upper
...
|
|