signal_design.relation

Module Contents

Classes

Relation

A representation of dependency y from x (y = f(x)).

Attributes

R

Description first Relation.

R2

Description second Relation.

signal_design.relation.R

Description first Relation.

signal_design.relation.R2

Description second Relation.

class signal_design.relation.Relation(x: Union[signal_design.core.RelationProtocol, signal_design.axis.Axis, signal_design.help_types.ArrayLike], y: Union[signal_design.help_types.ArrayLike, None] = None)[source]

Bases: signal_design.core.RelationProtocol

A representation of dependency y from x (y = f(x)).

The class describe the dependency between x, y. x is Axis instance showing the start of sequence, size of sequence and the sample space between elements. They consist of real. The size of Axis must be equal length of y sequence.

For the instance of Relation class, define the basic mathematical operations: addition (+), subtraction(-), multiplication(*), division(/), exponentiation (**) and their unary representation (+=, -=, *=, /=). The result of the operation is a new instance of the Relation class.

Determined correlation and convolution between two instances (methods: correlate and convolve).

WARNING!!! When inheriting the Relation class, it is important to write correctly constructor. It must match the constructor of the Relation class. Because some methods return a type(self)(…). For example, addition method (def __add__(self: R, other: Union[‘Relation’, Num]) -> R). Or predefine these methods in the inherited class.

Raises:
  • TypeError – Raise this exception if wrong parameters setting to Axis.

  • ValueError – Raise this exception if wrong parameters setting to Axis.

  • BadInputError – Raise this exception if we don’t have enough data.

  • NotEqualError – Raise this exception if we try create instance use different length of sequence numbers for x and y.

  • TypeFuncError – Raise an exception, when execute some function with unexpected type of value.

Returns:

Type of Relation.

Return type:

_type_

Initialization of instance of Relation.

Parameters:
  • x (Union[RelationProtocol, ArrayLike, Axis]) – The Relation class, or a class derived from the Relation class, or instance of Axis or an ArrayLike object containing numbers(real or complex). if x is ArrayLike then it will be converted to Axis instance use method get_array_axis_from_array_method from config.Config.class

  • y (ArrayLike, optional) – None or array_like object containing real or complex numbers. If it is not None then it will be converted to numpy.ndarray. Defaults to None.

Raises:
  • TypeError – Raise this exception if wrong parameters setting to Axis.

  • ValueError – Raise this exception if wrong parameters setting to Axis.

  • BadInputError – Raise this exception if we don’t have enough data.

  • NotEqualError – Raise this exception if we try create instance use

property x: signal_design.axis.Axis

Axis of relation.

Returns:

array axis of relation.

Return type:

Axis

property y: numpy.ndarray

Result of relation of y(x)

Returns:

array of numbers represent relation of y(x)

Return type:

numpy.ndarray

property start: signal_design.help_types.RealNumber

Start of array axis x.

Returns:

start number of array axis x.

Return type:

RealNumber

property sample: signal_design.help_types.RealNumber

Sample for array axis x.

Returns:

sample of array axis x.

Return type:

RealNumber

property size: int

size of array axis x.

Returns:

integer number of array size x.

Return type:

int

property end: signal_design.help_types.RealNumber

End of array axis x.

Returns:

end number of array axis x.

Return type:

RealNumber

property array: numpy.ndarray

Get array representation of array axis x.

Returns:

array of numpy.

Return type:

numpy.ndarray

get_data() Tuple[numpy.ndarray, numpy.ndarray][source]

Return the data of the object.

Raises:

NotEqualError – After manipulating on x Axis, the size of the extracted arrays is checked. If they are different then raise that error.

Returns:

tuple of two number sequence

Return type:

Tuple[numpy.ndarray, numpy.ndarray]

max() signal_design.help_types.Number[source]

Get maximum of Relation.

Returns:

maximum of y array.

Return type:

Number

min() signal_design.help_types.Number[source]

Get minimum of Relation.

Returns:

minimum of y array.

Return type:

Number

get_norm() signal_design.help_types.RealNumber[source]

Get signal rate.

Calculated in terms of signal energy.

Returns:

signal rate

Return type:

Number

select_data(start: Union[signal_design.help_types.Number, None] = None, end: Union[signal_design.help_types.Number, None] = None) R[source]

Select data using x-axis

Parameters:
  • self (R) – instance of Relation

  • start (Number, optional) – new start of relation x. Defaults to None.

  • end (Number, optional) – new end of relation x. Defaults to None.

Returns:

new instance of Relation.

Return type:

R

exp() R[source]

Get exponent of Relation.

Parameters:

self (R) – instance of Relation

Returns:

Relation where new y is exponent of old y.

Return type:

R

diff() R[source]

Differentiation of ‘Relation’.

Parameters:

self (R) – instance of Relation

Returns:

result of differentiation.

Return type:

R

integrate() R[source]

Integration of Relation.

Parameters:

self (R) – instance of Relation

Returns:

result of cumulative integration.

Return type:

R

interpolate_extrapolate(new_x: Union[R, signal_design.axis.Axis, signal_design.help_types.ArrayLike]) R[source]

Interpolates and extrapolates an existing relation using new array x of the represented Axis instance.

Parameters:
  • self (R) – instance of Relation

  • new_x (Axis) – new x array axis

Returns:

new instance of Relation

Return type:

R

shift(x_shift: signal_design.help_types.RealNumber = 0) R[source]

Shifting of relation on the x-axis.

Parameters:
  • self (R) – instance of Relation

  • x_shift (Number, optional) – Number of displacement on the x-axis.

  • 0. (Defaults to) –

Returns:

new instance of Relation

Return type:

R

static equalize(r1: R, r2: R2) Tuple[R, R2][source]

Bringing two Relation objects with different x-axes to one common one.

When converting, interpolation and extrapolation are used.

Parameters:
  • r1 (R) – first instance of Relation

  • r2 (R2) – second instance of Relation

Returns:

tuple of new Relation instances with common axis.

Return type:

Tuple[R, R2]

classmethod correlate(r1: Relation, r2: Relation) R[source]

Correlation of two Relations.

Parameters:
  • cls (Type[R]) – class of Relation

  • r1 (Relation) – first Relation.

  • r2 (Relation) – second Relation.

Raises:

TypeFuncError – raise exception if we try correlate with unexpected types.

Returns:

new instance of Relation

Return type:

R

classmethod convolve(r1: Relation, r2: Relation) R[source]

Convolution of two Relations.

Parameters:
  • cls (Type[R]) – class of Relation

  • r1 (Relation) – first Relation.

  • r2 (Relation) – second Relation.

Raises:

TypeFuncError – raise exception if we try correlate with unexpected types.

Returns:

new instance of Relation

Return type:

R

static math_operation(a: Relation, b: Union[Relation, signal_design.help_types.Number], name_operation: signal_design.core.MathOperation) Tuple[signal_design.axis.Axis, numpy.ndarray][source]
__add__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__radd__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__sub__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__rsub__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__mul__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__rmul__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__truediv__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__rtruediv__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__pow__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__rpow__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__iadd__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__isub__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__imul__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__idiv__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__ipow__(other: Union[Relation, signal_design.help_types.Number]) R[source]
__len__() int[source]
__getitem__(select_data: Union[signal_design.help_types.Number, slice]) Union[Tuple[signal_design.help_types.Number, signal_design.help_types.Number], R][source]

Select data from Relation

if item is Number then function return tuple of two numbers. The first number is number near to select data. Second number is number represent of relation to selected data.

if select data is slice then function return Relation that equal Relation if we call select_data function of instance.

Parameters:
  • self (R) – instance of Relation

  • item (Union[float, slice]) – selected data is number or slice

Returns:

two number or instance of relation.

Return type:

Union[Tuple[Num, Num], R]

__str__() str[source]

Return str(self).