Skip to content

hertzforge.io.signalcalc_mat

signalcalc_mat

Time histories from SignalCalc's MATLAB export (.mat, version 7.3).

found = hertzforge.import_file('run.mat')
history, table = found['time_data'], found['channel_table']
part = hertzforge.import_file('run.mat', start=120, stop=130,
                              channels=['A6501- Z', 'Current'])

SignalCalc writes a recorded time history to MATLAB as an HDF5 file (MATLAB's version 7.3) holding, for N channels:

  • INP_1_Data to INP_N_Data, one vector of samples per channel, or TimeData, one matrix of samples by N channels;
  • ChanName and Unit, character matrices with one row per channel, padded with NUL characters;
  • hDelta, the time step in seconds;
  • Sensitivity and InputChanNums, one number per channel, and EUType, a code per channel.

INP_k_Data, or column k of TimeData, holds the channel named in row k of ChanName. It is not the channel whose InputChanNums entry is k: the input numbers follow the analyzer's wiring and need not be in row order, and a shaker's current and voltage monitors read by row are coherent with each other the way a shaker's are, where read by input number they are two accelerometers. The values are in each channel's engineering unit, which Unit names; the sensitivity is kept for reference, not applied.

What is read: one TimeHistory with a record per channel, starting at 0 s, and a ChannelTable with each channel's node, direction, unit, quantity and sensitivity, its comment holding its name as the file gives it and its input number. A name that reads as a node and an axis becomes the record's DOF: optional letters naming the sensor, the node number, an optional hyphen, then the axis with an optional sign, so A6002- X and 6002X are 6002X+ and A6002 Y- is 6002Y-. The hyphen after the node separates it from the axis and is not a sign. Any other name (Current, Drive Limit) is the record's DOF as it stands, which tells the channel from the others and matches no node; the channel table's comment keeps the name either way, for correcting a node or direction read wrong. A name that is not a node and an axis and cannot be a DOF either (one that starts with a digit, or an axis alone) leaves its record's DOF empty, and the import says so. A unit Hertzforge reads is declared, converting the values to SI; one it does not is left undeclared with the file's numbers, and the import says so. EUType is not read: no public description of its codes was found.

start, stop and channels read part of a long export, as for a Rattlesnake run (rattlesnake.load): the window is inclusive at both ends on the file's clock, and only the samples it holds are read from the file: a channel at a time from INP_k_Data, and from TimeData a block of samples across the channels at a time, since its compressed chunks each hold every channel.

Refused, each by name: an hDelta that is not one positive time step, a channel vector that is a matrix or of another length than the rest, a Unit, Sensitivity or InputChanNums whose count differs from the names', an INP_k_Data with no row k and a row with no INP_k_Data, a TimeData with another number of columns than there are names, a file holding both TimeData and INP_k_Data, and two channels with one DOF and one quantity, which nothing could tell apart. A missing sample is kept as NaN and noted, and so is a channel that never varies (core.channel_health).

save writes a time history back in the INP_k_Data layout, which this module reads back; whether SignalCalc's own MATLAB import takes it has not been tested. The format has no start time, so a history that starts later than 0 s reads back starting at 0 s.

Functions:

Name Description
sniff

Whether path is a SignalCalc time history export: an HDF5 .mat

load

A SignalCalc time history export, read as a time history and its

handles

Whether save can write obj: a time history.

save

Write a time history as a SignalCalc time history export, which

Classes

Functions:

sniff

sniff(path: str | PathLike) -> bool

Whether path is a SignalCalc time history export: an HDF5 .mat holding ChanName, Unit, hDelta and TimeData or at least one INP_<n>_Data. Only the names of the file's variables are read.

load

load(path: str | PathLike, start: float | None = None, stop: float | None = None, channels: Iterable[int | str] | None = None, progress: Callable[[int, int], None] | None = None) -> dict[str, Any]

A SignalCalc time history export, read as a time history and its channel table.

Parameters:

Name Type Description Default
path str or PathLike

The .mat file.

required
start float

A window in seconds on the file's clock, which starts at 0; either end open when omitted.

None
stop float

A window in seconds on the file's clock, which starts at 0; either end open when omitted.

None
channels iterable of int or str

Which channels to read, by 0-based row or by name as the record is labeled (its DOF, or its name from ChanName). All of them when omitted.

None
progress callable

Called with (done, total) as the samples are read: samples of every channel picked from INP_k_Data, samples across them from TimeData.

None

Returns:

Type Description
dict

'time_data', the TimeHistory, and 'channel_table', the ChannelTable of every channel in the file.

Raises:

Type Description
ValueError

For anything the module docstring lists as refused.

handles

handles(obj: Any) -> bool

Whether save can write obj: a time history.

save

save(history: Any, path: str | PathLike, unit_system: Any = None, **_kwargs: Any) -> None

Write a time history as a SignalCalc time history export, which load reads back.

One INP_k_Data per record, ChanName from each record's label (its DOF, or its block), Unit naming each record's unit and hDelta the time step. With unit_system each record is written in that system's unit for its quantity (g included, since Unit can say g); without one, as stored, in SI. A record with no units is written as its numbers with an empty unit. Sensitivity, InputChanNums and EUType are not written: a time history does not hold them. The start time is not kept, since the format has no place for one.

Parameters:

Name Type Description Default
history TimeHistory

What to write.

required
path str or PathLike

Where; .mat is added when it does not end in it.

required
unit_system UnitSystem

The units to write in.

None

Returns:

Type Description
None

Raises:

Type Description
ValueError

When the history is not evenly sampled.