hertzforge.io.unv¶
unv
¶
Read and write Universal Files (.unv, .uff, .uf), following the SDRL dataset specifications (https://www.ceas3.uc.edu/sdrluff/; local copies are in docs/uff_spec).
Datasets read:
- 164, units: the length, force and temperature factors. The spec divides file values by these factors to get SI, so a file with a 164 imports with its units defined.
- 15, nodes in the old single-precision form, one line per node.
- 2411, nodes in double precision, a 4I10 record and a 3D25.16 record per node. Each position is converted to global from the coordinate system the node is defined in.
- 2420, coordinate systems.
- 82, tracelines: a node list in which 0 lifts the pen (a move without drawing). Each traceline becomes one element group of two-node line elements, with one run for each stretch between pen-ups.
- 2412, elements. The FE descriptor codes are the element type codes Hertzforge uses; beam descriptors have an extra orientation record before the nodes.
- 55, mode shapes: normal modes (analysis type 2) or complex modes (type 3), not both in one file.
- 58, functions at nodal DOFs: time histories (function type 1), FRFs
(4), coherence (6), PSDs (9), spectra (12), shock response spectra
(24) and multiple coherence (26). The scale to SI comes from the axis
data-type unit exponents and the 164 factors. Without a 164, a record
whose quantity has a unit imports with its unit undefined, unless
ordinate_unitis given, and keeps the quantity's name as a hint. Records are grouped by function type into one data object per type, and records of one type with different abscissas go into separate objects. Other function types are skipped. Time histories whose ID line says 'Response Time Trace' or 'Reference Time Trace' are one measurement's two channels, exported as two records that both carry the measurement's DOF as their response and the reference DOF in the reference field. Each such pair becomes a time history of its own, keyed 'time -- ref ', whose two records are the response channel at the response DOF and the reference channel at the reference DOF, with those roles stated ( TimeHistory.roles). A labeled trace with no partner, or with no reference DOF, refuses the file with the trace named. - 58b, the binary form of 58: the same eleven ASCII header records,
followed by the values as raw floats. Read in either byte order at
single or double precision. Only IEEE 754 floats are read; DEC VMS
and IBM 5/370 floats are refused by name, because reading them as
IEEE would return wrong numbers without an error. A marker line with
no fields after the
58bis read too: the size comes from record 7 and has to end at a delimiter, and the values are taken as little endian IEEE 754, which such a file cannot confirm.
A file with several objects returns a dict keyed 'geometry', 'shapes' and the function names ('time', 'frf', 'coherence', 'psd', 'spectrum', 'srs', 'multiple_coherence'; a second abscissa of one type is keyed 'frf (2)' and so on). A file with one object returns it directly. Other datasets are skipped, since a UNV file is a stream of independent datasets separated by '-1' lines.
save writes geometry, data of every function type above, and mode
shapes; save_binary writes the functions as 58b.
Classes:
| Name | Description |
|---|---|
Binary |
The binary part of a dataset 58b: its bytes, and how to read them. |
Functions:
| Name | Description |
|---|---|
iter_datasets |
Yield (dataset_number, record_lines, payload) for each dataset. |
sniff |
True for a |
trace_pair_references |
The reference DOFs a file's labeled time-trace pairs name, in the |
load |
Read the supported datasets of a universal file (see the module |
handles |
True for a Geometry, any DataArray or a ShapeSet: everything |
handles_binary |
True for data arrays only, because only dataset 58 has a binary |
save |
Write a geometry, a data array or a mode shape set as a universal |
save_binary |
|
Classes¶
Binary
dataclass
¶
The binary part of a dataset 58b: its bytes, and how to read them.
order (1 little endian, 2 big endian) and fp_format (2 is IEEE
754) are the fields of the dataset's own marker line, kept with the
bytes so that the data is always decoded by the byte order and
float format it was written with.
Functions:¶
iter_datasets
¶
iter_datasets(data: str | bytes, unread: list[str] | None = None) -> Iterator[tuple[int | None, list[str], bytes]]
Yield (dataset_number, record_lines, payload) for each dataset.
payload is None for an ordinary ASCII dataset and a Binary for a
binary one (dataset 58b), whose eleven header records are still
ASCII and come back in record_lines like any other. A dataset
whose number line is not an integer is not yielded, and that line
is appended to unread when it is given.
data is read as bytes, a line at a time, rather than split into
lines first, because a binary payload is not text: its float bytes
can contain newlines and the byte pattern of a '-1' delimiter line,
and splitting first would cut a dataset in two there. The payload
is taken by the byte count its marker line declares and is never
scanned.
sniff
¶
True for a .unv, .uff or .uf file whose first text is a -1
line, the separator every dataset opens with.
trace_pair_references
¶
The reference DOFs a file's labeled time-trace pairs name, in the order they first come, or [] for a file with none.
Some exporters write a channel number in the reference node field of
these traces rather than the node the reference was measured at.
load takes reference_node to put it right, and these are what to
show beside the question. Only the header records are read.
load
¶
load(path: str | PathLike, length_unit: str | None = None, ordinate_unit: str | None = None, reference_node: int | None = None) -> Any
Read the supported datasets of a universal file (see the module docstring).
Returns the one object the file holds, or a dict keyed 'geometry',
'shapes' and the function names when it holds several. With a dataset
164 the values are converted to SI by its factors; without one,
length_unit declares the unit of the positions and ordinate_unit
that of the functions, and without those they import unit-less.
reference_node is the node the reference of every labeled time-trace
pair was measured at, for a file whose exporter wrote a channel number
in its place; each trace keeps the direction its header gives, and
without it the file's node stands (trace_pair_references lists what
the file names). Raises ValueError when no supported dataset is found,
for a reference_node that is not a positive whole number, and for a
labeled trace that cannot be paired.
handles
¶
True for a Geometry, any DataArray or a ShapeSet: everything save
writes as ASCII datasets.
handles_binary
¶
True for data arrays only, because only dataset 58 has a binary form.
Datasets 2411, 82, 2412 and 55 have no binary variant, so a geometry or a mode shape set written "binary" would be the same ASCII file the other exporter writes.
save
¶
save(obj: Any, path: str | PathLike, unit_system: UnitSystem | None = None, binary: bool = False) -> None
Write a geometry, a data array or a mode shape set as a universal file.
Geometry is written as 2420 coordinate systems, 2411 nodes, 82 tracelines and 2412 elements; data as one dataset 58 per record; mode shapes as one dataset 55 per mode. Node positions are written in the coordinate system each node is defined in. Shape values stay in each node's own displacement system, which is what dataset 55 means by them, and the coordinate systems written with them define those directions.
When the object's units are defined, the values are written in
unit_system (its coherent form, or SI when none is given) and a
dataset 164 declaring that system goes first, so the file reads back
with its units. When they are not defined, the stored values are
written as they are with no 164, and the file reads back unit-less.
binary writes the functions as dataset 58b instead of 58: the same
eleven ASCII header records, then the values as little-endian IEEE
754 doubles instead of 20.12E text. That is 8 bytes a value instead
of 20 characters, and a float read back is exactly the float written.
Only the functions
change form; geometry, mode shapes and the units dataset have no
binary variant and are written as ASCII.
Raises ValueError for a pyramid element, which dataset 2412 has no descriptor for, and for a shape coordinate that is not a direction dataset 55 can hold.
save_binary
¶
save_binary(obj: Any, path: str | PathLike, unit_system: UnitSystem | None = None) -> None
save with binary=True: the registry's exporter for dataset 58b.
It is a separate exporter because the Export menu is a list of formats, and whether another program reads 58b is a property of the format. Choosing the format by suffix gets the ASCII form, which more programs read.