Skip to content

hertzforge.io.sdynpy_data

sdynpy_data

Read and write sdynpy data array files (.npz).

The format is a NumPy .npz with two entries:

  • 'function_type': a scalar int, the universal file dataset 58 function type code, which is the vocabulary Hertzforge uses (1 time response, 4 FRF, 6 coherence, 9 PSD, 12 spectrum and so on).
  • 'data': a structured array of records with the fields 'abscissa' (n,), 'ordinate' (n,), 'comment1' to 'comment5', and 'coordinate', the (node, direction) pairs, shape (1,) for data with a response only or (2,) for response and reference. Directions use the signed universal file code, 1 to 6.

sdynpy holds a cross-spectral density as X·conj(Y), and this package stores it as conj(X)·Y (DataArray.compute_cpsds). The two are elementwise conjugates and the file does not say which it holds, so a PSD is conjugated in both directions. No other kind of data is touched.

The files have no units. Units may be declared at import:

  • time and spectrum data: ordinate_unit (for example 'm/s**2', 'g' or 'N');
  • FRFs: response_unit and reference_unit, both needed;
  • PSDs: ordinate_unit, the unit whose square per Hz the PSD is in (for example 'g' for g^2/Hz).

Without them the data is unit-less, holding the file's values, and the units can be defined later with define_units(). Every record must share one abscissa; a file whose records differ is refused.

Functions:

Name Description
sniff

True for an .npz holding data and function_type, the two

load

Read an sdynpy data array file as the DataArray subclass its function

handles

True for any DataArray: every kind is written under its function type

save

Write a data array in the sdynpy .npz layout.

Classes

Functions:

sniff

sniff(path: str | PathLike) -> bool

True for an .npz holding data and function_type, the two entries every sdynpy data array file has.

load

load(path: str | PathLike, ordinate_unit: str | None = None, response_unit: str | None = None, reference_unit: str | None = None) -> DataArray

Read an sdynpy data array file as the DataArray subclass its function type names.

Each record's five comment fields are joined with '; '. Units are declared as the module docstring describes; an FRF needs both response_unit and reference_unit, and with only one it imports unit-less. Raises ValueError when the records do not share one abscissa, or the file holds Python objects.

handles

handles(obj: Any) -> bool

True for any DataArray: every kind is written under its function type code.

save

save(data: DataArray, path: str | PathLike, unit_system: UnitSystem | None = None) -> None

Write a data array in the sdynpy .npz layout.

An FRF that fills every response and reference pair is written as a matrix, responses down the rows and references across, as a controller reading a system's FRFs expects; any other data is one row of records.

Values are written in unit_system, g included, when the units are defined, and as stored otherwise. The format has no place to record which units they are. The ordinate is complex only when the data is, and the comment fields are left blank.