param.Number#
- class param.Number(default=0.0, *, bounds=None, softbounds=None, inclusive_bounds=(True, True), step=None, doc=None, label=None, precedence=None, instantiate=False, constant=False, readonly=False, pickle_default_value=True, allow_None=False, per_instance=True, allow_refs=False, nested_refs=False, default_factory=None, metadata=None)[source]#
A numeric
DynamicParameter, with a default value and optional bounds.There are two types of bounds:
boundsandsoftbounds.boundsare 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). Bounds are inclusive by default, but exclusivity can be specified for each bound by setting inclusive_bounds (e.g.inclusive_bounds=(True, False)specifies an exclusive upper bound).Number is also a type of
Dynamicparameter, so its value can be set to a callable to get a dynamically generated number.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 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 ofNonewhen declared) then a value ofNoneis also allowed.A separate method
set_in_bounds()is provided that will silently crop the given value into the legal range, for use in, for instance, a GUI.softboundsare 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__(default=0.0, *, bounds=None, softbounds=None, inclusive_bounds=(True, True), step=None, allow_None=False, doc=None, label=None, precedence=None, instantiate=False, constant=False, readonly=False, pickle_default_value=True, per_instance=True, allow_refs=False, nested_refs=False, default_factory=None, metadata=None)[source]#
Initialize this parameter object and store the bounds.
Non-dynamic default values are checked against the bounds.
Methods
__init__([default, bounds, softbounds, ...])Initialize this parameter object and store the bounds.
crop_to_bounds(val)Return the given value cropped to be within the hard bounds for this parameter.
deserialize(value)Given a serializable Python value, return a value that the parameter can be set to.
get_soft_bounds()schema([safe, subset, mode])Generate a schema for the parameters of the
Parameterizedobject.serialize(value)Given the parameter value, return a Python value suitable for serialization.
set_in_bounds(obj, val)Set to the given value, but cropped to be within the legal bounds.
Attributes
boundssoftboundsinclusive_boundsstepallow_Noneallow_refsconstantdefaultdefault_factorydocinstantiatelabelGet the label for this parameter.
metadatanamenested_refsownerper_instancepickle_default_valueprecedencereadonlyrxThe reactive operations namespace.
time_dependenttime_fnwatchers