Skip to content

hertzforge.core.channel_table

channel_table

Channel table: per-channel test metadata (sensor, DOF, engineering units), and, when a test needs them, the settings a controller runs each channel at.

The table has one fixed set of columns, each with a type and a rule for what it accepts, and a source's other columns are dropped. Because every column says what it holds, a direction can be offered as a drop-down, a unit can be limited by the channel's type, and an expiration is read as a date.

A file and an edit are checked differently:

  • A file is read leniently. A value that cannot be read takes the column's default (blank for most columns) and the import goes on, because refusing the import would leave the user nothing to correct, and this table is where they correct it. validate.dofs does the same for DOFs.
  • An edit is refused. When a person types a value the column cannot hold, set_cell raises with the reason and writes nothing.

Classes:

Name Description
Spec

What one column holds, and what it accepts.

Environment

One control loop of a run: the channels the controller read as

ChannelTable

Per-channel metadata, in one fixed set of typed columns.

Functions:

Name Description
record_quantity

A channel's quantity in the word a record's dimension uses. A record

title_of

The header shown for a column, in the window and in the report.

COLUMNS_KIND

What kind of value a column holds, its Spec.kind.

CHOICES_FOR

The values a column is limited to, empty when it is not limited.

canonical_name

A source's column name as this schema spells it.

Classes

Spec

Bases: NamedTuple

What one column holds, and what it accepts.

kind is how a value is read ('int', 'index', 'float', 'choice', 'flag', 'date', 'unit' or 'text'), default fills a missing or unreadable cell, choices limits a 'choice' column, minimum bounds a numeric one, and unique makes the column a key.

Environment dataclass

Environment(controls: list[int] = list(), drives: list[int] = list(), response_transformation: ndarray | None = None, reference_transformation: ndarray | None = None, kind: str = '')

One control loop of a run: the channels the controller read as its control channels, the ones it drove, and the transformations it put over them, if any.

Channels are named by number (the channel column, the table's join key), so the record survives a row deleted elsewhere in the table. The controller's order is kept, because a transformation's columns are the controls, or the drives, in that order.

Attributes:

Name Type Description
controls list of int

The control channels' numbers, in the controller's order.

drives list of int

The drive channels' numbers, in the controller's order.

response_transformation ndarray or None

(rows, len(controls)): what the controller applied to every frame of its control channels, controlling the rows in their place. None when it controlled the channels themselves.

reference_transformation ndarray or None

(rows, len(drives)): what it applied to its drive signals. None when it drove the channels themselves.

kind str

What kind of test the loop ran ('random', 'sine', 'transient', 'modal' or 'time'), so a report on one kind shows that loop's transformations and not another's from the same run. '' when unknown, as in a table saved before the kind was kept.

Methods:

Name Description
matrix

The 'response' or the 'reference' transformation.

Methods:
matrix
matrix(form: str) -> ndarray | None

The 'response' or the 'reference' transformation.

ChannelTable

ChannelTable(columns: Mapping[str, Any] | DataFrame, environments: Mapping[str, Environment] | None = None)

Per-channel metadata, in one fixed set of typed columns.

Parameters:

Name Type Description Default
columns mapping or DataFrame

The columns, by name, each with one entry per channel. Names are read through canonical_name, columns outside COLUMNS are dropped, missing ones take their default, and the values are read leniently (see the module description). The controller's columns (CONTROLLER) are there when the source has any of them, and absent otherwise. A channel type left blank is filled in from the unit when the unit names one.

required
environments mapping of str to Environment

The run's control loops by name, each checked as set_environment checks it.

None

Raises:

Type Description
ValueError

If a column in CORE is missing, or the columns differ in length.

Attributes:

Name Type Description
frame DataFrame

The table, one row per channel, columns in SCHEMA order, then the CONTROLLER columns on a table that carries them. Every cell is text except channel, which is an integer. node is text too, blank where no node was recorded.

environments dict of str to Environment

The control loops, in the order they were set. Empty for a table that describes no controller run. While a table has any, its Control column is the union of their control channels and is set through them (set_control), not directly.

Methods:

Name Description
rule_errors

What the table breaks of the rules a row is checked by on both

set_cell

Write one cell, or refuse a value the column cannot hold.

units_for

The units to offer for this channel, given its declared type.

add_channels

Add blank channels at the end of the table, numbered on from

chosen

The rows of the channels choice picks, in table order.

choices

The CHANNEL_CHOICES that pick a channel, in that order:

delete_channels

Remove the given rows in place. At least one row must remain.

add_controller_settings

Convert the table to carry the settings a controller runs each

remove_controller_settings

Drop the controller's columns (CONTROLLER), and nothing else:

orientation

One channel's measured direction on a geometry.

derived_cells

The derived columns' cells for one row, as text.

dof_strings

Each channel's degree of freedom, as '101Z+' strings: the node

rename_dof

Give the channel at coordinate old the coordinate new, in

identities

Each row as the (DOF, quantity) channel of history it names.

roles

Each channel's declared role ('reference', 'response' or

controls

Which channels are control channels, as a boolean per row.

controls_for

The control channels a reference over dofs was held at, as

drives

Which channels the environment drove, as a boolean per row.

rows_of

The rows of the given channel numbers, in the given order.

set_environment

Record a control loop, or replace the one of that name.

remove_environment

Forget a control loop. The Control column keeps what it

set_control

Check or clear Control on one channel for one environment.

transformation

A control loop's transformation as a labeled matrix.

transformed_responses

What a control loop's response transformation made of a

types

Each channel's type (what it measures), '' where undeclared.

sensitivities

Each channel's sensitivity in mV per engineering unit, NaN where

daq_ranges

Each channel's DAQ input range in volts, NaN where unstated.

sensor_ranges

Each sensor's full-scale output in volts, NaN where unstated.

clip_ranges

The level each channel clips at, in volts: the smaller of its

save

Write the table to a file of its own, in the .hforge format.

Attributes
num_channels property
num_channels: int

How many channels the table describes, one per row.

column_names property
column_names: list[str]

The table's column names, in order (title_of gives the headers shown).

has_controller_settings property
has_controller_settings: bool

Whether the table carries the controller's columns (CONTROLLER).

Methods:
rule_errors
rule_errors() -> list[str]

What the table breaks of the rules a row is checked by on both sides of the program, beyond what one cell can say (schema/PROTOCOL.md, "Channel Table"): a sensitivity of 0 on an enabled row that is not a drive, and a negative sensitivity on any enabled row (a channel read inverted says so in its polarity column). A table without the controller's columns has every row on and none a drive. Empty when it breaks none.

Returns:

Type Description
list of str

One sentence per finding, naming the channel.

set_cell
set_cell(name: str, row: int, value: object) -> None

Write one cell, or refuse a value the column cannot hold.

A unit that is not of the channel's declared type is refused; change the type first. Changing the type clears a unit of another kind. A model in the sensor catalog (core.sensor_catalog) fills a blank Make with its maker; a make already written is kept. A triaxial accelerometer's model or serial number is written once: the other acceleration rows at its node, its other legs, get its Make, Model and Serial Number where theirs are blank (and their model is blank or the same). A row of another type at that node, a force gauge, is never filled.

Parameters:

Name Type Description Default
name str

The column to write.

required
row int

Which channel.

required
value object

The value, refused if the column cannot hold it.

required

Returns:

Type Description
None

Raises:

Type Description
KeyError

If there is no column name.

ValueError

If the value cannot be read for that column, repeats a channel number, or disagrees with the channel's type.

units_for
units_for(row: int) -> list[str]

The units to offer for this channel, given its declared type.

Parameters:

Name Type Description Default
row int

Which channel.

required

Returns:

Type Description
list of str

The shortlist for the declared type, or every unit in every shortlist when the type is blank.

add_channels
add_channels(count: int = 1) -> list[int]

Add blank channels at the end of the table, numbered on from the highest channel in it (from 1 in an empty table).

Every other cell takes its column's default, so the node, direction and unit are blank until they are typed in.

Parameters:

Name Type Description Default
count int

How many channels to add.

1

Returns:

Type Description
list of int

The new channels' numbers.

Raises:

Type Description
ValueError

If count is less than 1.

chosen
chosen(choice: str = 'all') -> list[int]

The rows of the channels choice picks, in table order.

Parameters:

Name Type Description Default
choice str

One of CHANNEL_CHOICES: 'control' for the channels with Control checked, whatever their role, or a role.

'all'

Returns:

Type Description
list of int

The rows.

Raises:

Type Description
ValueError

If choice is not one of CHANNEL_CHOICES.

choices
choices() -> list[str]

The CHANNEL_CHOICES that pick a channel, in that order: 'all' always, then 'control' when a channel has Control checked, then each role a channel holds.

delete_channels
delete_channels(indices: Sequence[int]) -> None

Remove the given rows in place. At least one row must remain.

Parameters:

Name Type Description Default
indices sequence of int

Which rows to remove.

required

Returns:

Type Description
None

Raises:

Type Description
IndexError

If an index is out of range.

ValueError

If every row would be removed.

add_controller_settings
add_controller_settings() -> None

Convert the table to carry the settings a controller runs each channel at: the CONTROLLER columns, added after the others.

Nothing the table holds changes, and a table that has them already is left as it is. The new columns start from what the table says: every channel on, none a drive; the control channels are already the Control column's and a reference its role of reference, since a channel's role in the loop is read from those; and each input's full scale in its own unit is its clip level in volts over its sensitivity, where both are stated. The rest start blank: unbound, no IEPE, positive polarity, no control group and no abort limits.

Returns:

Type Description
None
remove_controller_settings
remove_controller_settings() -> None

Drop the controller's columns (CONTROLLER), and nothing else: the table describes the measurement alone again. A table without them is left as it is.

Returns:

Type Description
None
orientation
orientation(row: int, geometry: Any) -> tuple[ndarray | None, str | None, float | None]

One channel's measured direction on a geometry.

The row's DOF (node and direction) is read through the coordinate system its node is measured in (Geometry.dof_direction). The result is that direction as a unit vector in the geometry's global system, the signed global axis nearest it ('X+', 'Z-'), and the angle between the two in degrees. These are the values the derived columns show.

Parameters:

Name Type Description Default
row int

The channel's row.

required
geometry Geometry

The geometry the channel is measured on.

required

Returns:

Type Description
tuple

(vector, axis, angle), each None when the geometry is None or cannot place the channel: the node is not on it, the direction is missing, or the node is measured in a coordinate system that turns with position.

derived_cells
derived_cells(row: int, geometry: Any) -> list[str]

The derived columns' cells for one row, as text.

The three components of the direction to three decimals, the nearest axis, and the angle to a tenth of a degree; all empty when the geometry cannot place the channel.

Parameters:

Name Type Description Default
row int

The channel's row.

required
geometry Geometry

The geometry the channel is measured on.

required

Returns:

Type Description
list of str

One cell per DERIVED_COLUMNS entry.

dof_strings
dof_strings() -> list[str]

Each channel's degree of freedom, as '101Z+' strings: the node and direction cells joined, so a missing one is left out.

rename_dof
rename_dof(old: str, new: str, quantity: str | None = None) -> int

Give the channel at coordinate old the coordinate new, in place, by rewriting its node and direction cells.

This is the same correction as DataArray.rename_dof, made in the table that names the channels. Only the channels at old that match quantity are changed, not every channel at the node.

Parameters:

Name Type Description Default
old str

The coordinate as the table has it, '101Z+'.

required
new str

The coordinate to give it: a node number then a direction, normalized as every DOF is. It is refused if either part is missing, although a table row may lack one.

required
quantity str

Which channel at old, by its type, or the quantity its unit names when it has none ('acceleration', 'force' and so on; 'unknown' where neither says). Every channel at the coordinate when omitted.

None

Returns:

Type Description
int

How many channels changed; 0 when new equals old.

Raises:

Type Description
ValueError

If new is not a whole DOF, or no channel matches.

identities
identities(history: Any = None) -> list[Any]

Each row as the (DOF, quantity) channel of history it names.

The row's channel type is the quantity, the same word a time history's ordinate_dim uses. A row with no channel type names the history's channel at its DOF when there is exactly one there. A row that names none of the history's channels is None.

Parameters:

Name Type Description Default
history TimeHistory

The recording the table describes. Without one, each row's own (DOF, type) is returned.

None

Returns:

Type Description
list of (str, str) or None

One entry per row.

roles
roles() -> list[str]

Each channel's declared role ('reference', 'response' or 'monitor'), '' where undeclared.

controls
controls(environment: str | None = None) -> ndarray

Which channels are control channels, as a boolean per row.

Parameters:

Name Type Description Default
environment str

One of environments: that loop's control channels. Left out, the Control column, which is the union of every environment's when the table has any.

None

Returns:

Type Description
ndarray

True where the channel is a control channel, one per row.

Raises:

Type Description
ValueError

If there is no environment of that name.

controls_for
controls_for(dofs: Sequence[Any]) -> ndarray

The control channels a reference over dofs was held at, as a boolean per row.

A reference belongs to the loop that controlled what it is over: a transformed loop's rows ('1', '2', ...), or another loop's control channels. With no environments, or one, that is the Control column (controls). With several, it is the one loop the DOFs name; where none or more than one is named, no channel is flagged, so a reader falls back to the reference's own pairing rather than taking every loop's controls.

Parameters:

Name Type Description Default
dofs sequence

The reference's DOFs, compared as text.

required

Returns:

Type Description
ndarray

True where the channel is a control channel of that loop.

drives
drives(environment: str) -> ndarray

Which channels the environment drove, as a boolean per row.

Parameters:

Name Type Description Default
environment str

One of environments.

required

Returns:

Type Description
ndarray

True where the channel is one of that loop's drives.

Raises:

Type Description
ValueError

If there is no environment of that name.

rows_of
rows_of(numbers: Sequence[int]) -> list[int]

The rows of the given channel numbers, in the given order.

Parameters:

Name Type Description Default
numbers sequence of int

Channel numbers (the channel column).

required

Returns:

Type Description
list of int

Their rows.

Raises:

Type Description
ValueError

If a number is no channel of the table.

set_environment
set_environment(name: str, environment: Environment) -> None

Record a control loop, or replace the one of that name.

Parameters:

Name Type Description Default
name str

The environment's name, as the controller names it.

required
environment Environment

Its channels and matrices. Every channel number must be a channel of the table, listed once; a response transformation must be two-dimensional with one column per control channel, and a reference transformation one per drive.

required

Returns:

Type Description
None

Raises:

Type Description
ValueError

If the name is blank or any of that fails. Nothing is recorded then.

remove_environment
remove_environment(name: str) -> None

Forget a control loop. The Control column keeps what it showed, which a table without environments may then edit.

Parameters:

Name Type Description Default
name str

The environment to forget.

required

Returns:

Type Description
None

Raises:

Type Description
ValueError

If there is no environment of that name.

set_control
set_control(environment: str, row: int, value: object) -> None

Check or clear Control on one channel for one environment.

A channel checked joins the loop's control channels, after the ones it has; cleared, it leaves them. The Control column follows as the union.

Parameters:

Name Type Description Default
environment str

Which loop.

required
row int

Which channel.

required
value object

True or False, in any spelling Control accepts.

required

Returns:

Type Description
None

Raises:

Type Description
ValueError

If there is no such environment, the flag cannot be read, or the environment transforms its control channels: the matrix's columns are those channels, so it is set with them (set_environment), not one at a time.

transformation
transformation(environment: str, form: str = 'response') -> MatrixAt

A control loop's transformation as a labeled matrix.

Parameters:

Name Type Description Default
environment str

Which loop.

required
form str

'response' for the matrix over its control channels, applied to what they measure, or 'reference' for the one over its drives, applied to the drive signals.

'response'

Returns:

Type Description
MatrixAt

The rows numbered from 1, as the controller's records of them are named, and a column per control (or drive) channel headed by its DOF, in the controller's order.

Raises:

Type Description
ValueError

If there is no such environment, or it holds no such transformation.

transformed_responses
transformed_responses(history: Any, environment: str) -> Any

What a control loop's response transformation made of a recording: its rows, as the controller computed them, as a time history of their own.

The controller applies the matrix to every frame of its control channels in their engineering units and controls the rows in their place, so its specification and spectra are over the rows. The rows are computed the same way here, from each control channel's values in its own stated unit, frame by frame when the recording holds one record per frame. A row is in the control channels' unit when they all share one; over a mix of units its values are numbers in no unit, left undeclared rather than labelled with a guess.

Parameters:

Name Type Description Default
history TimeHistory

The recording, with a record of every control channel.

required
environment str

Which loop.

required

Returns:

Type Description
TimeHistory

A record per row and frame, rows numbered from 1 as the controller's own records of them are, each a response, on the recording's clock and with its averaging.

Raises:

Type Description
ValueError

If the loop holds no response transformation, or the recording lacks a control channel or holds a different number of records of two of them.

types
types() -> list[str]

Each channel's type (what it measures), '' where undeclared.

sensitivities
sensitivities() -> ndarray

Each channel's sensitivity in mV per engineering unit, NaN where undeclared.

daq_ranges
daq_ranges() -> ndarray

Each channel's DAQ input range in volts, NaN where unstated.

sensor_ranges
sensor_ranges() -> ndarray

Each sensor's full-scale output in volts, NaN where unstated.

clip_ranges
clip_ranges() -> ndarray

The level each channel clips at, in volts: the smaller of its DAQ range and its sensor range, whichever is stated, NaN where neither is.

save
save(path: str | PathLike) -> None

Write the table to a file of its own, in the .hforge format.

Parameters:

Name Type Description Default
path str or PathLike

Where to write it; .hforge is added when the suffix is not there.

required

Returns:

Type Description
None

Functions:

record_quantity

record_quantity(quantity: str) -> str

A channel's quantity in the word a record's dimension uses. A record never says strain: a microstrain has no dimension, so its ordinate_dim is 'dimensionless', and the two words name one channel.

title_of

title_of(name: str) -> str

The header shown for a column, in the window and in the report.

Parameters:

Name Type Description Default
name str

The column name, such as 'serial_number'.

required

Returns:

Type Description
str

The header, from TITLES or the name title-cased ('Serial Number').

COLUMNS_KIND

COLUMNS_KIND(name: str) -> str

What kind of value a column holds, its Spec.kind.

Parameters:

Name Type Description Default
name str

The column name.

required

Returns:

Type Description
str

The kind, such as 'int', 'choice' or 'text'.

CHOICES_FOR

CHOICES_FOR(name: str) -> tuple[str, ...]

The values a column is limited to, empty when it is not limited.

A flag column such as 'control' returns ('True', 'False'), since a spreadsheet treats it as a choice of two.

Parameters:

Name Type Description Default
name str

The column name.

required

Returns:

Type Description
tuple of str

The allowed values.

canonical_name

canonical_name(name: str) -> str

A source's column name as this schema spells it.

The name is lower-cased, spaces and hyphens become underscores, and a trailing colon and anything from an opening parenthesis on are dropped; then ChannelTable.ALIASES maps the words that differ. Dropping the parenthetical unit reads this table's own headers back ('Sensitivity (mV/Unit)'), and a calibration sheet's ('Sensitivity (mV/g)') into the same column.

Parameters:

Name Type Description Default
name str

The column name as the source wrote it.

required

Returns:

Type Description
str

The schema's name for it, or the tidied name if it has none.