visualdynamics.io.stated_units¶
stated_units
¶
Declaring the units a source states, one record at a time.
A reader whose source writes a unit beside each channel (a SEP 005
dict's unit_str, a column header's "(g)") declares it on the record,
so the values are converted to SI the way define_units converts them.
Two things can stop that, and each reader decides what follows: the
unit is not one this package reads, or it reads as something no channel
measures. "Gs" is the case that brought the second up: pint reads it as
gigaseconds, a time, and a record declared in it would hold an
acceleration channel as a duration a billion seconds long. A unit that
reads as a time, a frequency or a mass is refused here, because a
channel of a time history measures none of them.
A claimed quantity can be checked against the unit at the same time: a column stated to be an acceleration and headed "(lbf)" is a contradiction, and the reader is told so rather than either claim being preferred.
Functions:
| Name | Description |
|---|---|
unit_problem |
Why |
declare_stated_units |
Declare each record's stated unit where it can be declared. |
Functions:¶
unit_problem
¶
Why unit cannot be declared on a channel, or None when it can.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
str
|
The unit as the source wrote it. |
required |
quantity
|
str
|
The stored dimension tag the channel is claimed to measure ('acceleration'); the unit must then be one of its units. |
None
|
Returns:
| Type | Description |
|---|---|
str or None
|
The reason in words, written to follow the quoted unit ("'counts' is ..."), or None. |
Source code in src/visualdynamics/io/stated_units.py
declare_stated_units
¶
declare_stated_units(data: Any, units: Sequence[str | None], quantities: Sequence[str | None] | None = None) -> list[tuple[int, str, str]]
Declare each record's stated unit where it can be declared.
units holds one entry per record (None or '' for a record whose
source stated nothing); quantities, when given, the dimension tag
each record is claimed to measure, which its unit must agree with.
A unit that passes unit_problem is declared with define_units,
converting that record to SI. One that does not leaves the record's
values as they are, and is returned with the reason.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
The records, declared in place. |
required |
units
|
sequence of str or None
|
The unit each record's source stated. |
required |
quantities
|
sequence of str or None
|
The quantity each record is claimed to measure. |
None
|
Returns:
| Type | Description |
|---|---|
list of (int, str, str)
|
(record, unit, reason) for each unit that was not declared. |