9.2. Clamps

class cherab.core.math.clamp.ClampInput1D

Clamps the x input of a Function1D to the range [xmin, xmax].

Parameters
  • f (object) – A Function1D instance or a callable python object that takes one argument.

  • xmin (float) – the lower bound, default=-INFINITY.

  • xmax (float) – the upper bound, default=+INFINITY.

>>> import numpy as np
>>> from cherab.core.math import ClampInput1D
>>>
>>> clamped_func = ClampInput1D(np.exp, xmin=0)
>>> clamped_func(1)
2.718281828459045
>>> clamped_func(-1)
1.0
class cherab.core.math.clamp.ClampInput2D

Clamps the [x, y] inputs of a Function2D to the ranges [xmin, xmax], [ymin, ymax].

Parameters
  • f (object) – A Function2D instance or a callable python object that takes two arguments.

  • xmin (float) – the x lower bound, default=-INFINITY.

  • xmax (float) – the x upper bound, default=+INFINITY.

  • ymin (float) – the y lower bound, default=-INFINITY.

  • ymax (float) – the y upper bound, default=+INFINITY.

>>> import numpy as np
>>> from cherab.core.math import ClampInput2D
>>>
>>> def my_func(x, y):
>>>     return x**2 + y**2
>>>
>>> my_func(1, 1)
2
>>> clamped_func = ClampInput2D(my_func, xmax=0, ymax=0)
>>> clamped_func(1, 1)
0.0
class cherab.core.math.clamp.ClampInput3D

Clamps the [x, y, z] inputs of a Function3D to the ranges [xmin, xmax], [ymin, ymax], [zmin, zmax].

Parameters
  • f (object) – A Function3D instance or a callable python object that takes three arguments.

  • xmin (float) – the x lower bound, default=-INFINITY.

  • xmax (float) – the x upper bound, default=+INFINITY.

  • ymin (float) – the y lower bound, default=-INFINITY.

  • ymax (float) – the y upper bound, default=+INFINITY.

  • zmin (float) – the z lower bound, default=-INFINITY.

  • zmax (float) – the z upper bound, default=+INFINITY.

>>> import numpy as np
>>> from cherab.core.math import ClampInput3D
>>>
>>> def my_func(x, y, z):
>>>     return x**2 + y**2 + z**2
>>>
>>> my_func(-1, -1, -1)
3
>>> clamped_func = ClampInput3D(my_func, xmin=0, ymin=0, zmin=0)
>>> clamped_func(-1, -1, -1)
0.0
class cherab.core.math.clamp.ClampOutput1D

Clamps the output of a Function1D to the range [min, max].

Parameters
  • f (object) – A Function1D instance or a callable python object that takes one argument.

  • min (float) – the lower bound, default=-INFINITY.

  • max (float) – the upper bound, default=+INFINITY.

>>> import numpy as np
>>> from cherab.core.math import ClampOutput1D
>>>
>>> clamped_func = ClampOutput1D(np.exp, min=0.5, max=3)
>>> clamped_func(-3)
0.5
>>> clamped_func(0)
1.0
>>> clamped_func(3)
3.0
class cherab.core.math.clamp.ClampOutput2D

Clamps the output of a Function2D to the range [min, max].

Parameters
  • f (object) – A Function2D instance or a callable python object that takes two arguments.

  • min (float) – the lower bound, default=-INFINITY.

  • max (float) – the upper bound, default=+INFINITY.

>>> import numpy as np
>>> from cherab.core.math import ClampOutput2D
>>>
>>> clamped_func = ClampOutput2D(np.arctan2, min=-1, max=1)
>>> clamped_func(-1, -1)
-1.0
>>> clamped_func(1, -1)
1.0
class cherab.core.math.clamp.ClampOutput3D

Clamps the output of a Function3D to the range [min, max].

Parameters
  • f (object) – A Function3D instance or a callable python object that takes three arguments.

  • min (float) – the lower bound, default=-INFINITY.

  • max (float) – the upper bound, default=+INFINITY.

>>> import numpy as np
>>> from cherab.core.math import ClampOutput3D
>>>
>>> def my_func(x, y, z):
>>>     return x**2 + y**2 + z**2
>>>
>>> clamped_func = ClampOutput3D(my_func, max=10)
>>>
>>> my_func(1, 2, 3)
14
>>> clamped_func(1, 2, 3)
10