hertzforge.io.rattlesnake_specification¶
rattlesnake_specification
¶
Read and write Rattlesnake's random vibration specification file.
The controller's target for a random test is a small file its Random
environment loads before the test (its .nc4 is the recording of a
run, and is only read here). The file holds f, the frequency lines in
Hz; cpsd, the full cross-spectral matrix of the control channels at
each line, (lines, n, n) complex; optionally warning_upper,
warning_lower, abort_upper and abort_lower, (lines, n) real
bands on the autospectra; and optionally coordinate, (n, n, 2) node
and direction pairs the controller uses to put the matrix in its own
channel order. The controller reads it as NumPy .npz or MATLAB
.mat; this module writes and reads the .npz.
The controller reads a whole matrix, and a specification here usually
holds autospectra alone, since that is how most random tests are run.
So a pair the specification does not hold is written as a zero, the way
the controller's own targets have it, and the file records which pairs
were held in held, an (n, n) boolean mask. The controller ignores
held; this reader uses it, so a zero that was never specified does not
read back as a specified zero cross term. A missing Hermitian half is
filled with the conjugate of the half that was held.
The controller holds a cross term as X·conj(Y), and this package stores
it as conj(X)·Y (DataArray.compute_cpsds). The two are elementwise
conjugates, and the file has no field saying which it holds, so this
module conjugates in both directions: the file means what the controller
reads it to mean.
The file has no place for units. Values are written in the unit system asked for, g included: the controller reads the target in the unit of each channel of its own channel table, which for an accelerometer is usually g, so the file holds what the plot shows. Reading takes the unit as a parameter.
The file also has dof, the channel names as Hertzforge writes
them, which the controller ignores and this reader prefers.
coordinate is written only when every channel is a node and a
direction, since a modal coordinate (M3) has neither; the names are
what bring the specification back exactly.
Functions:
| Name | Description |
|---|---|
sniff |
True for an |
handles |
True for a random vibration Specification, the target the |
save |
Write a specification as the controller's target file ( |
load |
Read the controller's target file as a Specification. |
Classes¶
Functions:¶
sniff
¶
True for an .npz holding f and cpsd, opened with pickles
refused, since the file is plain arrays.
handles
¶
True for a random vibration Specification, the target the controller's Random environment loads.
save
¶
save(spec: Specification, path: str | PathLike, unit_system: UnitSystem | None = None) -> None
Write a specification as the controller's target file (.npz).
Values, bands included, are written in unit_system itself, g
included, or as stored when there is none or the units are not
defined; the file records no units. A pair the specification does
not hold is written as a zero, the controller's own placeholder, and
held records which pairs were held.
Raises ValueError when the specification holds no autospectrum, or holds a cross term of a channel that has no autospectrum.
load
¶
load(path: str | PathLike, ordinate_unit: str | None = None) -> Specification
Read the controller's target file as a Specification.
Channels come from dof when the file has it, otherwise from the
diagonal of coordinate. A file with neither, which is what the
controller itself writes, is matched to its channel table by order
alone, so its channels are named in that order, '1', '2' and so on,
as the sine specification reader names them and as a run through a
response transformation records them. A file with held was written by this writer, and
the mask says which cross terms were held: those come back, zeros
included, and the rest are left out. In a file without held, the
cross terms are kept only when at least one off-diagonal value is
finite and not zero, as the .nc4 reader does, because an
off-diagonal that is all NaN or zero is how other writers mark a
specification of autospectra alone. ordinate_unit declares the unit
of the values, which the file cannot state.
Raises ValueError when cpsd is not (lines, n, n) over the
frequency lines, or the channel names do not match its size.