Skip to content

hertzforge.io.tables

tables

Channel tables and breakpoint tables as files, in four forms.

Two kinds of table are kept here. A channels table is the channel table (core.channel_table.ChannelTable): one table that holds both what the analysis reads (the DOFs, the sensors, their calibration) and the settings a controller runs each channel at, so a test's channel table is the same object its analysis is done with. A breakpoints table is one of the breakpoint tables behind a test's profile, target or limits (its table_kind, such as random_profile), with the units of its x and y columns. Both are read and written in four forms, chosen by the path's suffix:

  • .hforge: a single-object HDF5 file. A channel table is the channel table's own channel_table/ group (io.native); a breakpoint table is a breakpoint_table/ group laid out the same way, a column_order attribute and one dataset per column;
  • .csv: comma-separated text;
  • .tsv and .txt: tab-delimited text;
  • .xlsx: an Excel workbook, the table on its first sheet. A channel table is the workbook io.excel writes and reads.

A channel table's rows are read as every other source of one is: a heading is matched to a column by canonical_name, with the channel table's own aliases, a column the table does not have is left out, and a value that cannot be read takes the column's default. A table read here is for a test, so one without the controller's settings is converted to carry them (ChannelTable.add_controller_settings). What was left out, could not be read or was added is reported in warnings, so a person sees it. A channel table written here is written as it is given: with the controller's columns when they are among its columns, and as the measurement's table alone when they are not.

A breakpoint table is read leniently too: a column is found by its name or a common alias, in any case and spacing, with any unit given in the heading (Frequency (Hz)); comment lines (# or //) and blank rows are skipped, and a column that is not one of the table's is reported and left out. A cell that cannot be read is refused with its row and column.

Writing is strict for both: the columns are the kind's own names, every value of the column's type, and a table that is not well formed is refused before anything is written. The text and workbook forms of a breakpoint table start with comment lines that say which table the file holds (# Hertzforge table: breakpoint_table and its table_kind), so a file of another kind is refused when it is opened.

Classes:

Name Description
TableFileError

A table file that cannot be read or written, said in words.

TableContentError

A table given to be written that is not well formed, said in words.

Column

One column of a kind of breakpoint table.

BreakpointKind

A kind of breakpoint table: its columns, which is the x column, the

Table

A table as read or to be written: its kind, the columns by name, the

Functions:

Name Description
normalize

A heading or a word as a breakpoint table matches it: lower case,

form_of

The form a path is read or written in, by its suffix.

table_kinds

{table_kind: label}: the kinds of breakpoint table there are.

write

Write table to path in the form its suffix names, after checking

channel_table

A ChannelTable of the rows given, each value checked as the column

channel_table_of_rows

A ChannelTable of control channel rows (the protocol's spelling),

channel_rows

A ChannelTable's columns and its rows as JSON values: each column

read

Read the table a file holds, in the form its suffix names.

Classes

TableFileError

Bases: ValueError

A table file that cannot be read or written, said in words.

TableContentError

Bases: ValueError

A table given to be written that is not well formed, said in words.

Column dataclass

Column(name: str, label: str, type: str, default: Any = None, nullable: bool = False, aliases: tuple[str, ...] = (), values: tuple[str, ...] = (), choices: Mapping[str, str] = dict())

One column of a kind of breakpoint table.

type is number, choice or text (a Mixed Mode part's id, name, the part it follows, or its amplitude profile's rows). choices maps each word a file may hold, in normalized form, to the value it stands for; values are the values themselves, which a write must use.

BreakpointKind dataclass

BreakpointKind(label: str, columns: tuple[Column, ...], x: str, x_unit: str, y_unit: str, needs: tuple[str, ...], positional: tuple[str, ...] = ())

A kind of breakpoint table: its columns, which is the x column, the units it is in unless a file says otherwise, the columns of which at least one must be present, and the order a file with no heading row is read in.

Table dataclass

Table(kind: str, columns: list[str], rows: list[list[Any]], table_kind: str | None = None, x_unit: str | None = None, y_unit: str | None = None, warnings: list[str] = list(), channels: list[dict[str, Any]] | None = None, environments: dict[str, Any] | None = None)

A table as read or to be written: its kind, the columns by name, the rows (one value per column, None where a cell holds nothing), and for a breakpoint table its table_kind and units. warnings are what a read left out or assumed.

Functions:

normalize

normalize(text: str) -> str

A heading or a word as a breakpoint table matches it: lower case, with any unit in parentheses or brackets dropped, and spaces, underscores, hyphens and the characters #./^,:² taken out.

form_of

form_of(path: str) -> str

The form a path is read or written in, by its suffix.

table_kinds

table_kinds() -> dict[str, str]

{table_kind: label}: the kinds of breakpoint table there are.

write

write(path: str | PathLike, table: Table) -> str

Write table to path in the form its suffix names, after checking it is well formed; a path with no suffix is given .hforge.

Parameters:

Name Type Description Default
path str or PathLike

Where to write; the file is replaced in one step once written.

required
table Table

The table: its kind, its columns by name, and its rows.

required

Returns:

Type Description
str

The path written, absolute.

channel_table

channel_table(table: Table) -> Any

A ChannelTable of the rows given, each value checked as the column holds it.

The columns are the channel table's own names (ChannelTable.SCHEMA). channel is required; a column not given takes its default in every row. A value is JSON's: a whole number for channel, a whole number or None for a blank-able number (node, control_group), a number or None for a measurement (sensitivity, the ranges, the abort limits), true or false for a flag, and text, '' for blank, for the rest.

Raises TableContentError, naming the row and column, for anything the column cannot hold.

channel_table_of_rows

channel_table_of_rows(rows: Any, environments: Mapping[str, Any] | None = None) -> Any

A ChannelTable of control channel rows (the protocol's spelling), through the one mapping (io.run_convert.channel_table_from_rows), each value checked as channel_table checks a column's: a write is strict.

Raises TableContentError, naming the row and column, for anything the table cannot hold.

channel_rows

channel_rows(table: Any) -> tuple[list[str], list[list[Any]]]

A ChannelTable's columns and its rows as JSON values: each column as channel_table takes it.

read

read(path: str | PathLike, kind: str, table_kind: str | None = None, x_unit: str | None = None, y_unit: str | None = None) -> Table

Read the table a file holds, in the form its suffix names.

Parameters:

Name Type Description Default
path str or PathLike

The file.

required
kind str

channels or breakpoints: the kind of table wanted. A file that holds another is refused.

required
table_kind str

For a breakpoint table, which one is wanted (random_profile and so on); a file that says it holds another is refused. When not given, the file's own is taken.

None
x_unit str

For a breakpoint table, the units it is taken to be in where the file does not say (the units of the table it is opened into); the kind's own when not given.

None
y_unit str

For a breakpoint table, the units it is taken to be in where the file does not say (the units of the table it is opened into); the kind's own when not given.

None

Returns:

Type Description
Table

The columns found, by name, and the rows, with what was left out or assumed in warnings. A channel table comes back with every column of the channel table, as it holds them.