sweep_design.relation
Module Contents
Classes
A representation of dependency y from x (y = f(x)). |
Attributes
Description first Relation. |
|
Description second Relation. |
- sweep_design.relation.R
Description first Relation.
- sweep_design.relation.R2
Description second Relation.
- class sweep_design.relation.Relation(x: Union[sweep_design.core.RelationProtocol, sweep_design.axis.ArrayAxis, sweep_design.help_types.ArrayLike], y: sweep_design.help_types.ArrayLike = None)[source]
Bases:
sweep_design.core.RelationProtocolA representation of dependency y from x (y = f(x)).
The class describe the dependency between x, y. x is ArrayAxis instance showing the start of sequence, the end of sequence and the sample space between elements. They consist of real or complex numbers. The array length calculated from ArrayAxis 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).
How those operations will be calculated determined by the methods described in the Config class. Methods can be overridden if necessary (sweep-design.config).
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
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, ArrayAxis]) – The Relation class, or a class derived from the Relation class, or instance of ArrayAxis or an ArrayLike object containing numbers(real or complex). if x is ArrayLike then it will be converted to ArrayAxis instance use method get_array_axis_from_array_method from 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 np.ndarray. Defaults to None.
- Raises
BadInputError – Raise this exception if we don’t have enough data.
NotEqualError – Raise this exception if we try create instance use
- property x: sweep_design.axis.ArrayAxis
ArrayAxis of relation.
- Returns
array axis of relation.
- Return type
- property y: numpy.ndarray
Result of relation of y(x)
- Returns
array of numbers represent relation of y(x)
- Return type
np.ndarray
- property start: sweep_design.help_types.RealNumber
Start of array axis x.
- Returns
start number of array axis x.
- Return type
RealNumber
- property end: sweep_design.help_types.RealNumber
End of array axis x.
- Returns
end number of array axis x.
- Return type
RealNumber
- property sample: sweep_design.help_types.RealNumber
Sample for array axis x.
- Returns
sample of array axis x.
- Return type
RealNumber
- property array: numpy.ndarray
Get array representation of array axis x.
- Returns
array of numpy.
- Return type
np.ndarray
- property actual_sample: sweep_design.help_types.Number
Get actual sample or array axis x.
- Returns
number of actual sample array x.
- Return type
Number
- property size: int
size of array axis x.
- Returns
integer number of array size x.
- Return type
int
- get_data() Tuple[numpy.ndarray, numpy.ndarray][source]
Return the data of the object.
- Raises
NotEqualError – After manipulating on x ArrayAxis, 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[np.ndarray, np.ndarray]
- max() sweep_design.help_types.Number[source]
Get maximum of Relation.
- Returns
maximum of y array.
- Return type
Number
- min() sweep_design.help_types.Number[source]
Get minimum of Relation.
- Returns
minimum of y array.
- Return type
Number
- get_norm() sweep_design.help_types.RealNumber[source]
Get signal rate.
Calculated in terms of signal energy.
- Returns
signal rate
- Return type
Number
- select_data(start: sweep_design.help_types.Number = None, end: sweep_design.help_types.Number = 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, sweep_design.axis.ArrayAxis, sweep_design.help_types.ArrayLike]) R[source]
Interpolates and extrapolates an existing relation using new array x of the represented ArrayAxis instance.
- Parameters
self (R) – instance of Relation
new_x (ArrayAxis) – new x array axis
- Returns
new instance of Relation
- Return type
R
- shift(x_shift: sweep_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
- 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
- Raises
TypeFuncError – raise exception
if we try correlate with unexpected types. –
- Returns
new instance of Relation
- Return type
R
- static _operation(a: Relation, b: Union[Relation, sweep_design.help_types.Number], name_operation: sweep_design.core.MathOperation) Tuple[sweep_design.axis.ArrayAxis, numpy.ndarray][source]
- __getitem__(select_data: Union[sweep_design.help_types.Number, slice]) Union[Tuple[sweep_design.help_types.Number, sweep_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]