dcc_quantities.dcc_quantity_table ¶
Module containing all table related classes.
It is expected for the default case to read a table from an XML to use the
DccQuantityTable class. This call will return the
corresponding DccFlatTable or
DccLongTable instance.
DccQuantityTable ¶
DccQuantityTable(
idx_quants: dict[str | int, DccQuantityType],
value_quants: list[DccQuantityType],
dimension_len: int | None = None,
identifier: str | None = None,
ref_id: str | None = None,
ref_type: list[str] | None = None,
name: DccLangName = None,
date_time: datetime.datetime | None = None,
description: DccLangDescription | None = None,
used_methods: dict | None = None,
used_software: dict | None = None,
measuring_equipments: dict | None = None,
influence_conditions: dict | None = None,
measurement_meta_data: dict | None = None,
)
Bases: ExplicitSerializerMixin
Generic Table class for Flat- and Long-Tables.
| Parameters: |
|
|---|
units
property
¶
units: set[DsiUnit]
Set of all distinct units (DsiUnit instance) used within the table.
shape
property
¶
shape: tuple[int, ...]
Returns the shape of the table. This property is not available for LongTables, as they don't have a fixed shape.
all_quantities
property
¶
all_quantities: list[DccQuantityType]
List of all quantities composing the table (index quantities as well as value quantities).
index_quantities
property
¶
index_quantities: list[DccQuantityType]
List of only the index quantities within the table.
value_quantities
property
¶
value_quantities: list[DccQuantityType]
List of only the value quantities within the table.
from_dcc_data
classmethod
¶
from_dcc_data(dcc_data: dict) -> DccFlatTable | DccLongTable
Create a DccQuantityTable instance from a dictionary representation.
Automatically detects the table format (attribute or reftype) and type (flat or long) to instantiate the correct subclass.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
get_quantity_ids_by_field ¶
get_quantity_ids_by_field(
field: Literal["name", "ref_type", "unit", "scalable"], key: str
) -> Optional[str | list[str]]
Get the quantity unique ID of a specific field.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Examples:
Assuming a table with a single quantity with the name 'Acceleration', the following code shows how to retrieve its ID, then how to obtain the quantity from the table with the ID.
>>> table: DccQuantityTable
>>> quant_id: str = table.get_quantity_ids_by_field("name", "Acceleration")
>>> acc_quant = table[quant_id]
Assuming the same table has at least two quantities with the D-SI unit '\metre', the following code shows how
to obtain the second quantity with this unit.
>>> table: DccQuantityTable
>>> quant_ids: list[str] = table.get_quantity_ids_by_field("unit", "\\metre")
>>> dist_quant = table[quant_ids[1]]
where ¶
where(condition: Callable, ref_uuid: str) -> np.ndarray[bool]
Conditional search among the quantities of a table.
Provided a condition, the method searches among the quantities whether the condition is met among the values. The condition can be applied either to the whole table or to a subset of quantities (defined by their UUID).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Examples:
The constructor of the used table in the example has been simplified for better reading.
>>> table = DccLongTable(
... idx_quants=[
... DccQuantityType(name='Frequency', data=[10.0, 12.5, 16.0, 20.0, 25.0], unit=r'\hertz', ...)
... ],
... ...,
... )
>>> freq_uuid = table.get_quantity_ids_by_field("name", "Frequency")
>>> table.where(lambda x, _: x >= 20, ref_uuid=freq_uuid)
array([False, False, False, True, True])
See Also
export_as_xml_structure ¶
export_as_xml_structure() -> str
Exports the current table as an XML string compliant with the DCC-schema.
DccLongTable ¶
DccLongTable(*args, **kwargs)
Bases: DccQuantityTable
Serialization of a <dcc:list> with the refType basic_{dim}IndexTable, where dim corresponds to the number
of dimensions that compose the table.
shape
property
¶
shape: None
Returns None and prints a warning, as LongTables don't have a specific shape.
DccFlatTable ¶
DccFlatTable(*args, **kwargs)
Bases: DccQuantityTable
Serialization of a <dcc:list> with the refType basic_{dim}IndexFlatTable, where dim corresponds to the
number of dimensions that compose the table.