visualdynamics.core.transformation¶
transformation
¶
A transformation between control channels and degrees of freedom, as an object of its own: a matrix with named inputs and outputs and the units its entries carry.
A six-DOF test controls the motion of a point, and measures it with
accelerometers spread over the article. The matrix that turns the
measured channels into the point's three translations and three
rotations is the most consequential setting in such a test, and it is
usually typed into a controller once and never read again. A
Transformation holds it so it can be read: which channel goes in
where, what comes out, in what unit, how well the inputs resolve the
outputs, and how much of the measured motion the outputs leave
unexplained.
The matrix T maps inputs to outputs, y = T u. Built from geometry it
is the pseudo-inverse of the six rigid-body shapes at the input DOFs,
T = Φ⁺, the same matrix transform.to_modal applies through a rigid
set (transform.matrix_at's response form); typed, it is whatever the
user states, with its inputs and outputs named. A controller run's
matrices arrive on the channel table, one per environment
(channel_table.ChannelTable.transformation), with a column per control
channel headed by its DOF and the rows numbered; named, the rows make
one a typed transformation. Either way it is applied the same way, to a time history or spectrum row by row,
y = T u, and to a cross-spectral density or a specification as the
quadratic form G_yy = T G_uu Tᵀ, which needs every cross term between
the inputs: the phase between two channels is what tells a translation
from a rotation. The package stores a cross term as conj(X_a)·X_b
(compute_cpsds), which makes the form conj(T) G_uu Tᵀ; a
transformation is real, so the two are one.
Every input and output is a translation or a rotation. An entry's unit
follows from the two it joins: [T_ij] = length^(r_j − r_i), with r
one for a rotation and zero for a translation, so a translation from
translations is a plain number, a rotation from translations is per
meter, and a translation from a rotation is in meters. Stored values
are SI like every other value in the package. An output rotation comes
out in the input's angular quantity: acceleration in, angular
acceleration out, in rad/s².
The residual is what the outputs cannot carry back. Q = T⁺T is the
orthogonal projector onto the motions the outputs describe, and
P = I − Q onto the rest. For a rigid-body transformation, P u is the
part of the measured motion that is not rigid: a channel's local
flexing, a mode of the article, a loose mount or a channel wired to the
wrong DOF. For a density the measured power splits exactly in two,
trace G = trace(Q G Q) + trace(P G P), because P Q = 0, so the
residual is a fraction of the measured power at every line, and
read_residual says up to what frequency that fraction stays under a
stated threshold: where the rigid-body assumption holds.
The conditioning is the ratio of the largest to the smallest singular
value. Entries in mixed units make that ratio depend on the length
unit, so it is computed with every rotation scaled by a characteristic
length, length_scale: the RMS lever arm of the inputs about the point
for a transformation built from geometry, one of the stated length unit
for a typed one. A pseudo-inverse whose conditioning is past a stated
limit is refused, since an error of one part in a hundred at the inputs
can then reach the outputs a hundred times larger.
A force does not transform by this matrix. A force is work-conjugate
to a motion, so a controller's drives transform by the transpose of the
shapes (transform.matrix_at(form='reference')), and the transform
verbs apply that rule by quantity.
Classes:
| Name | Description |
|---|---|
Transformation |
A matrix from named inputs to named outputs, |
TransformationResidual |
The measured power at a transformation's inputs split in two at |
Functions:
| Name | Description |
|---|---|
read_residual |
Split the measured power at a transformation's inputs into the |
Classes¶
Transformation
dataclass
¶
Transformation(matrix: ndarray, inputs: tuple[str, ...], outputs: tuple[str, ...], input_kinds: tuple[str, ...], output_kinds: tuple[str, ...], description: tuple[str, ...] = (), length_scale: float = 1.0, origin: str = '')
A matrix from named inputs to named outputs, y = T u, with the
kind of each so its entries' units are known.
Made with from_geometry (the rigid-body transformation to a point),
from_shapes (through any rigid set at chosen DOFs) or typed (a
matrix stated by hand). Checked when it is created: the matrix is
real and finite, its shape is the outputs by the inputs, the names
are DOF strings with none repeated, and the length scale is a
positive number of meters.
Attributes:
| Name | Type | Description |
|---|---|---|
matrix |
ndarray
|
|
inputs, outputs |
tuple of str
|
The DOF strings, in the matrix's order. An input's sign is
honored when a record is matched to it: a |
input_kinds, output_kinds |
tuple of str
|
'translation' or 'rotation' for each ( |
description |
tuple of str
|
A line per output saying what it is ('Rigid rotation about Y'), or empty. |
length_scale |
float
|
The length, in meters, the rotations are scaled by for the
conditioning ( |
origin |
str
|
How the transformation was made, in a line. |
Methods:
| Name | Description |
|---|---|
from_shapes |
The transformation from motions at |
from_geometry |
The rigid-body transformation from motions at |
typed |
A transformation stated by hand: a matrix and the names and |
entry_unit |
The unit of one entry, in |
output_dimension |
The dimension output |
matrix_at |
The matrix as |
table |
The matrix as text for a controller: a row per output, a |
describe |
One line: the shape, the conditioning and how it was made. |
inverse |
The pseudo-inverse, outputs back to inputs, |
apply |
Apply the transformation to a record: a time history or a |
read_residual |
What the outputs leave unexplained of a cross-spectral |
Attributes¶
scaled
property
¶
The matrix with every entry a plain number: rotation rows
times length_scale, rotation columns over it. What the
singular values and the conditioning are read from.
condition
property
¶
The largest singular value of scaled over the smallest:
how many times larger a relative error at the inputs can reach
the outputs. Infinite when the matrix is short of full rank.
residual_projector
property
¶
P = I − T⁺T, (inputs, inputs): the part of an input
motion the outputs cannot carry back. Zero for a square,
invertible transformation, which explains everything it is
given and so cannot say anything about the residual.
Methods:¶
from_shapes
classmethod
¶
from_shapes(shapes: ShapeSet, inputs: Sequence[str], *, max_condition: float = MAX_CONDITION) -> Transformation
The transformation from motions at inputs to the coordinates
of a rigid set, T = Φ⁺, the matrix transform.to_modal applies
through the same set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shapes
|
ShapeSet
|
Six unscaled rigid-body shapes ( |
required |
inputs
|
sequence of str
|
The input DOFs, in the order wanted. A DOF the set has no column for is refused by name. |
required |
max_condition
|
float
|
The conditioning past which the pseudo-inverse is refused. |
`MAX_CONDITION`
|
Returns:
| Type | Description |
|---|---|
Transformation
|
Outputs |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the set is not unscaled rigid shapes, an input is not in the set, the inputs resolve fewer than six motions, or the conditioning is past the limit. |
Source code in src/visualdynamics/core/transformation.py
from_geometry
classmethod
¶
from_geometry(geometry: Geometry, point: Sequence[float], inputs: Sequence[str], *, max_condition: float = MAX_CONDITION) -> Transformation
The rigid-body transformation from motions at inputs to the
three translations and three rotations of point.
The six unit rigid-body shapes about the point
(rigid.rigid_body_shapes) at the inputs, pseudo-inverted
(from_shapes). The geometry's length unit must be declared:
the rotation rows are per meter, and coordinates with no unit
would make them per nothing anyone could name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Geometry
|
The nodes the inputs are on, in declared units. |
required |
point
|
sequence of float
|
The point, three coordinates in meters. |
required |
inputs
|
sequence of str
|
The input DOFs, in the order wanted. |
required |
max_condition
|
float
|
The conditioning past which the pseudo-inverse is refused. |
`MAX_CONDITION`
|
Returns:
| Type | Description |
|---|---|
Transformation
|
As |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the geometry's length unit is not declared, or as
|
Source code in src/visualdynamics/core/transformation.py
typed
classmethod
¶
typed(matrix: Any, inputs: Sequence[str], outputs: Sequence[str], *, input_kinds: Sequence[str] | None = None, output_kinds: Sequence[str] | None = None, length_unit: str = 'm', description: Sequence[str] = ()) -> Transformation
A transformation stated by hand: a matrix and the names and kinds of what goes in and what comes out.
The entries are read in length_unit, as a controller's matrix
is usually typed: a rotation row from translations per that
unit, a translation row from a rotation in it. They are stored
in SI. The length scale for the conditioning is one of that
unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
array - like
|
|
required |
inputs
|
sequence of str
|
The DOF strings. A virtual point is a node of its own
( |
required |
outputs
|
sequence of str
|
The DOF strings. A virtual point is a node of its own
( |
required |
input_kinds
|
sequence of str
|
'translation' or 'rotation' for each. Read from each DOF's
direction when left out ( |
None
|
output_kinds
|
sequence of str
|
'translation' or 'rotation' for each. Read from each DOF's
direction when left out ( |
None
|
length_unit
|
str
|
The length the entries are read in. |
'm'
|
description
|
sequence of str
|
A line per output. |
()
|
Returns:
| Type | Description |
|---|---|
Transformation
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When the matrix, the names or the kinds do not agree, an entry is not a finite real number, or the unit is not a length. |
Source code in src/visualdynamics/core/transformation.py
entry_unit
¶
The unit of one entry, in length_unit: '' for a plain
number, '1/m' or 'm'.
Source code in src/visualdynamics/core/transformation.py
output_dimension
¶
The dimension output row takes for an input motion
quantity: the quantity for a translation, its angular quantity
for a rotation.
Source code in src/visualdynamics/core/transformation.py
matrix_at
¶
matrix_at() -> MatrixAt
The matrix as transform.matrix_at gives a shape set's, rows
the outputs and columns the inputs, so its weights draw on a
geometry as arrows (viz.geometry.plot_transformation).
Source code in src/visualdynamics/core/transformation.py
table
¶
The matrix as text for a controller: a row per output, a
column per input, each entry in length_unit with the row's
unit named in the last column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length_unit
|
str
|
The length a rotation row's entries are written per. |
'm'
|
Returns:
| Type | Description |
|---|---|
tuple of (list of str, list of list of str)
|
The column headings and the rows. |
Source code in src/visualdynamics/core/transformation.py
describe
¶
One line: the shape, the conditioning and how it was made.
Source code in src/visualdynamics/core/transformation.py
inverse
¶
inverse(*, max_condition: float = MAX_CONDITION) -> Transformation
The pseudo-inverse, outputs back to inputs, u = T⁺ y.
For a rigid-body transformation this is the expansion: the six
motions of the point carried out to the channels, the rigid
part of what they measure. It is refused when the outputs are
more than the matrix's rank (they could not all be told apart)
or the conditioning is past max_condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_condition
|
float
|
The conditioning past which it is refused. |
`MAX_CONDITION`
|
Returns:
| Type | Description |
|---|---|
Transformation
|
Inputs and outputs exchanged, with the same length scale. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the rank is short or the conditioning is past the limit. |
Source code in src/visualdynamics/core/transformation.py
apply
¶
apply(data: DataArray, records: Sequence[int] | None = None, *, quantity: str | None = None) -> tuple[DataArray, TransformReport]
Apply the transformation to a record: a time history or a spectrum row by row, a cross-spectral density or specification as the quadratic form.
Every input must be present as a record of one motion quantity
in declared units: a translation input as that quantity, a
rotation input as its angular one. Records at other DOFs are
left out and listed (the report's dropped), and records of
another quantity at the inputs left out and counted by quantity
(skipped). A specification's bands carry through when
every input wears the same band, as transform.to_modal
carries them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
A |
required |
records
|
sequence of int
|
Which records to take the inputs from; all when omitted. |
None
|
quantity
|
str
|
The motion to transform ('acceleration', 'velocity' or 'length') when the record holds more than one at the inputs. |
None
|
Returns:
| Type | Description |
|---|---|
tuple of (DataArray, TransformReport)
|
The outputs, of the source's kind, and the report: the inputs used, the records left out, and each input's residual fraction (of its RMS, or of its power for a density). |
Raises:
| Type | Description |
|---|---|
ValueError
|
When an input is missing, in undefined units, of the wrong quantity or kind, or holds a value that is not a finite number, or a density's cross terms are missing. |
TypeError
|
When the data is an FRF or another kind that does not transform by one matrix. |
Source code in src/visualdynamics/core/transformation.py
read_residual
¶
read_residual(density: DataArray, records: Sequence[int] | None = None, *, threshold: float = RESIDUAL_THRESHOLD, quantity: str | None = None) -> TransformationResidual
What the outputs leave unexplained of a cross-spectral
density at the inputs, line by line (read_residual).
Source code in src/visualdynamics/core/transformation.py
TransformationResidual
dataclass
¶
TransformationResidual(transformation: Transformation, frequency: ndarray, channels: list[str], quantity: str, measured: ndarray, explained: ndarray, residual: ndarray, threshold: float = RESIDUAL_THRESHOLD, notes: list[str] = list())
The measured power at a transformation's inputs split in two at every line: the part the outputs carry back, and the residual.
Attributes:
| Name | Type | Description |
|---|---|---|
transformation |
Transformation
|
What was read. |
frequency |
ndarray
|
The lines, Hz. |
channels |
list of str
|
The inputs, in the transformation's order. |
quantity |
str
|
The motion the density is of. |
measured, explained, residual |
ndarray
|
|
threshold |
float
|
The share of the measured power the residual may reach and the
transformation still be said to hold ( |
notes |
list of str
|
Anything the numbers should be read with: dead channels, lines with no measured power. |
Methods:
| Name | Description |
|---|---|
describe |
One line, worded as the status line shows it. |
Attributes¶
fraction
property
¶
The residual's share of the summed measured power at every line, 0 to 1, not a number where nothing was measured.
overall
property
¶
The residual's share of the measured power over the whole band, or not a number when nothing was measured.
channel_fractions
property
¶
Each input's residual over its own power across the band,
not a number for a channel that measured nothing. It can pass
one on a quiet channel, where the projector carries a louder
channel's motion into it (residual).
worst_channel
property
¶
The input whose own residual share is largest, or None when no channel measured anything.
holds_to
property
¶
The highest frequency up to which the residual stays at or
under threshold of the measured power at every line, from the
first line with power. The last line when it never passes the
threshold; None when it is past it at the first line, or nothing
was measured.
Methods:¶
describe
¶
One line, worded as the status line shows it.
Source code in src/visualdynamics/core/transformation.py
Functions:¶
read_residual
¶
read_residual(transformation: Transformation, density: DataArray, records: Sequence[int] | None = None, *, threshold: float = RESIDUAL_THRESHOLD, quantity: str | None = None) -> TransformationResidual
Split the measured power at a transformation's inputs into the part its outputs explain and the residual, at every line.
With Q = T⁺T and P = I − Q, the explained part of the
cross-spectral matrix at the inputs is Q G Q and the residual
P G P; their traces sum to the measured power because P Q = 0,
and each is read on its own diagonal, since channel by channel the
cross terms Q G P + P G Q need not vanish. For a rigid-body
transformation the residual is
the motion that is not rigid, and holds_to says up to what
frequency it stays under threshold of the measured power.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
Its inputs all translations, so their powers can be summed. |
required |
density
|
DataArray
|
A |
required |
records
|
sequence of int
|
Which records to read; all when omitted. |
None
|
threshold
|
float
|
The share of the measured power, above 0 and under 1. |
`RESIDUAL_THRESHOLD`
|
quantity
|
str
|
As for |
None
|
Returns:
| Type | Description |
|---|---|
TransformationResidual
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When an input is a rotation, the threshold is not between 0 and
1, the density has no cross terms, or as |
TypeError
|
When the density is not a |
Source code in src/visualdynamics/core/transformation.py
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 | |