fibermodes.slrc

Scalar, list, range or code object.

This is a convenient object used to encapsulate a parameter that can be either a scalar (float), a list of floats, a range, or a function (code).

class fibermodes.slrc.SLRC(value=0)[source]

Scalar, list, range or code object.

Parameters:value (mixed) – Initial value.

Values are assumed to be always sorted.

If the value is a list or a numpy.ndarray, it uses the value inside the list.

If the value is a dict, it assumes keys start, end, and num to be set, and it creates a range of num values from start to end (included), just like numpy.linspace.

If the value is a str, if assumes this is Python code to be evaluated. This code is evaluated in a restricted environment, where builtins are listed in rglobals. math module is also available. The code is assumed called inside a function definition, and must return a scalar value.

Otherwise, the value is assumed to be a scalar (float or int).

kind

Find what is the kind of value.

When read, the property returns a string identifying the kind of value contained.

When set, the property converts the actual value to a new kind. Conversion is performed as described in the following table. Cases in bold are converted without loss of information. Case in italic is converted with possible loss of information. Other cases are converted with systematic loss of information.

From To Result
scalar scalar No change
scalar list List with one item
scalar range Range with one item
scalar code Return the value
list scalar First item of the list
list list No change
list range Range from first item to last item with same number of elements (but intermediate values could be different)
list code Return value of the first item
range scalar First item of the range
range list List with items of the range
range range No change
range code Return first item of the range
code scalar 0
code list [0]
code range {‘start’: 0, ‘end’: 1, ‘num’: 2}
code code No change
Returns:string. It can be ‘scalar’, ‘list’, ‘range’, or ‘code’.
rglobals = {'math': <module 'math' (built-in)>, '__builtins__': {'int': <class 'int'>, 'filter': <class 'filter'>, 'sorted': <built-in function sorted>, 'any': <built-in function any>, 'all': <built-in function all>, 'frozenset': <class 'frozenset'>, 'map': <class 'map'>, 'dict': <class 'dict'>, 'round': <built-in function round>, 'enumerate': <class 'enumerate'>, 'abs': <built-in function abs>, 'tuple': <class 'tuple'>, 'set': <class 'set'>, 'complex': <class 'complex'>, 'max': <built-in function max>, 'pow': <built-in function pow>, 'str': <class 'str'>, 'list': <class 'list'>, 'zip': <class 'zip'>, 'divmod': <built-in function divmod>, 'len': <built-in function len>, 'float': <class 'float'>, 'next': <built-in function next>, 'sum': <built-in function sum>, 'range': <class 'range'>, 'bool': <class 'bool'>, 'reversed': <class 'reversed'>, 'iter': <built-in function iter>, 'slice': <class 'slice'>, 'min': <built-in function min>}}

Allowed builtins for code. It includes the math module.

value

Return evaluated value of object.

Warning: When set, does not check the assigned value.

Returns:The return value can be a float, a list, or a function. Use the type attribute if you need to know what kind it is.