ValueAxis#

Linear array of values which are used as variables of numerical functions and parameter dependent matrices

Properties#

start : float Starting value of the axis

step : float Step between consecutive values of the axis

length : int Length of the data array

data : numpy.array of float Values of the axis

Examples

Creation of the ValueAxis object

>>> va = ValueAxis(0.0,100,1.0)

Its standard attributes are the following:

>>> print(va.length)
100
>>> print(va.step)
1.0
>>> print(va.start)
0.0

The attribute data is an array of floats

>>> print(va.data[3:5])
[ 3.  4.]

Attributes min and max are provided for convenience

>>> print(va.min)
0.0
>>> print(va.max)
99.0

You can locate an index of a specific value. The lower neighbor and the difference to it is returned.

>>> i,diff = va.locate(16.3)
>>> print(i)
16
>>> print("{0:.1f}".format(diff))
0.3

The following returns the nearest index on the axis

>>> i = va.nearest(16.3)
>>> print(i)
16
>>> i = va.nearest(16.7)
>>> print(i)
17
>>> i = va.nearest(16.5)
>>> print(i)
17

Mutual compatibility of the two ValueAxis objects can be tested as follows

>>> va1 = ValueAxis(0.0, 2000, 1.0)
>>> va2 = ValueAxis(0.0, 1000, 1.0)
>>> va2.is_subsection_of(va1)
True
>>> va1.is_subsection_of(va2)
False
>>> va1.is_extension_of(va2)
True
>>> va2.is_subsection_of(va1)
True
>>> va2.is_extension_of(va1)
False
>>> va1.is_equal_to(va2)
False
>>> va1.is_equal_to(va1)
True
>>> va3 = ValueAxis(0.0, 2000, 1.0)
>>> va3.is_equal_to(va1)
True

Class Details#

class quantarhei.core.valueaxis.ValueAxis(start: float = 0.0, length: int = 1, step: float = 1.0)[source]#

Bases: Saveable

Linear array of values used as the argument axis of numerical functions.

Parameters:
  • start (float) – First value of the axis.

  • length (int) – Number of points on the axis.

  • step (float) – Spacing between consecutive axis values.

data#

Array of axis values, length length.

Type:

numpy.ndarray

min#

Minimum (first) value on the axis.

Type:

float

max#

Maximum (last) value on the axis.

Type:

float

property step: Any#
property start: Any#
property length: Any#
property min: float#

Returns the minimum value on the axis

property max: float#

Returns the maximum value on the axis

locate(val: float) tuple[int, float][source]#

Return the index of the lower neighbor of val and the distance.

Parameters:

val (float) – A value within the [min, max] range of the axis.

Returns:

  • int – Index of the largest axis point that is <= val.

  • float – Distance from that axis point to val.

Raises:

Exception – If val is outside the axis bounds.

nearest(val: float) int[source]#

Return the index of the nearest axis point to val.

If val is within one step above the upper bound, the index of the last point is returned.

Parameters:

val (float) – A value within (or just above) the [min, max] range of the axis.

Returns:

int – Index of the axis point closest to val.

Raises:

Exception – If val is outside the axis bounds.

is_equal_to(axis: ValueAxis) bool[source]#

Returns True if the axis is equal to this ValueAxis

is_extension_of(axis: ValueAxis) bool[source]#

Returns True if the axis is contained in this ValueAxis

is_subsection_of(axis: ValueAxis) bool[source]#

Returns True if the axis contains this ValueAxis

is_subset_of(axis: ValueAxis) bool[source]#

Returns True if the ValueAxis is a subset of axis

We check if all values of this axis are also values of the submitted axis object.

Examples

>>> ta1 = ValueAxis(0.0, 1000, 1.0)
>>> ta2 = ValueAxis(0.0, 490, 2.0)
>>> ta2.is_subset_of(ta1)
True
>>> ta1 = ValueAxis(0.0, 1000, 1.0)
>>> ta2 = ValueAxis(3.0, 900, 1.0)
>>> ta2.is_subset_of(ta1)
True
>>> ta1 = ValueAxis(0.0, 1000, 1.0)
>>> ta2 = ValueAxis(3.0, 400, 2.0)
>>> ta2.is_subset_of(ta1)
True
>>> ta1 = ValueAxis(0.0, 1000, 1.12345)
>>> ta2 = ValueAxis(3*1.12345, 400, 2*1.12345)
>>> ta2.is_subset_of(ta1)
True
>>> ta1 = ValueAxis(0.0, 1000, 1.12345)
>>> ta2 = ValueAxis(3.0, 400, 2*1.12345)
>>> ta2.is_subset_of(ta1)
False
>>> ta1 = ValueAxis(0.0, 1000, 1.0)
>>> ta2 = ValueAxis(3.0, 500, 2.0)
>>> ta2.is_subset_of(ta1)
False
is_superset_of(axis: ValueAxis) bool[source]#

Returns True if the ValueAxis is a superset of axis

We check if all values of this axis are also values of the submitted axis object.

Examples

>>> ta1 = ValueAxis(0.0, 1000, 1.0)
>>> ta2 = ValueAxis(0.0, 490, 2.0)
>>> ta1.is_superset_of(ta2)
True
>>> ta1 = ValueAxis(0.0, 1000, 1.0)
>>> ta2 = ValueAxis(3.0, 900, 1.0)
>>> ta1.is_superset_of(ta2)
True
>>> ta1 = ValueAxis(0.0, 1000, 1.0)
>>> ta2 = ValueAxis(3.0, 400, 2.0)
>>> ta1.is_superset_of(ta2)
True
>>> ta1 = ValueAxis(0.0, 1000, 1.12345)
>>> ta2 = ValueAxis(3*1.12345, 400, 2*1.12345)
>>> ta1.is_superset_of(ta2)
True
>>> ta1 = ValueAxis(0.0, 1000, 1.12345)
>>> ta2 = ValueAxis(3.0, 400, 2*1.12345)
>>> ta1.is_superset_of(ta2)
False
>>> ta1 = ValueAxis(0.0, 1000, 1.0)
>>> ta2 = ValueAxis(3.0, 500, 2.0)
>>> ta1.is_superset_of(ta2)
False