opatio.card.datacard module¶
- class opatio.card.datacard.CardHeader(numTables: int, indexOffset: int, cardSize: int, comment: str, reserved: bytes = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', magicNumber: str = 'CARD', headerSize: int = 256)[source]¶
Bases:
OPATEntity
Represents the header of a data card.
- ascii() str [source]¶
Get the ASCII representation of the card header.
- Returns:
The ASCII representation.
- Return type:
Examples
>>> header = CardHeader(numTables=1, indexOffset=256, cardSize=512, comment="Example") >>> print(header.ascii()) ========== Card Header ========== >> Magic Number: CARD >> Number of Tables: 1 >> Header Size: 256 >> Index Offset: 256 >> Card Size: 512 >> Comment: Example
- copy()[source]¶
Create a copy of the card header.
- Returns:
A copy of the card header.
- Return type:
Examples
>>> header = CardHeader(numTables=1, indexOffset=256, cardSize=512, comment="Example") >>> header_copy = header.copy() >>> header_copy == header True
- reserved: bytes = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'¶
- set_comment(comment: str)[source]¶
Set the comment of the data card.
- Parameters:
comment (str) – The comment to set.
- Raises:
ValueError – If the comment string exceeds 128 characters.
Examples
>>> header = CardHeader(numTables=0, indexOffset=0, cardSize=0, comment="") >>> header.set_comment("This is a comment.")
- class opatio.card.datacard.CardIndexEntry(tag: str, byteStart: int, byteEnd: int, numColumns: int, numRows: int, columnName: str, rowName: str, size: int = 1, reserved: bytes = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')[source]¶
Bases:
OPATEntity
Represents an entry in the index of a data card.
- ascii() str [source]¶
Get the ASCII representation of the card index.
- Returns:
The ASCII representation.
- Return type:
Examples
>>> index = CardIndexEntry(tag="Example", byteStart=0, byteEnd=64, numColumns=4, numRows=4, columnName="col", rowName="row", size=1) >>> print(index.ascii()) Example | 0 | 64 | 4 | 4 | col | row | 1
- copy()[source]¶
Create a copy of the card index entry.
- Returns:
A copy of the card index entry.
- Return type:
Examples
>>> index = CardIndexEntry(tag="Example", byteStart=0, byteEnd=64, numColumns=4, numRows=4, columnName="col", rowName="row") >>> index_copy = index.copy() >>> index_copy == index True
- class opatio.card.datacard.DataCard[source]¶
Bases:
OPATEntity
Represents a data card containing a header, index, and tables.
- header¶
Header of the data card.
- Type:
- index¶
Index of the data card, mapping tags to index entries.
- Type:
Dict[str, CardIndexEntry]
- add_table(tag: str, table: OPATTable, columnName: str = 'columnValues', rowName: str = 'rowValues')[source]¶
Add a table to the data card.
- sha256() bytes [source]¶
Compute the SHA-256 hash of the data card, including all tables and their data.
- add_table(tag: str, table: OPATTable, columnName: str = 'columnValues', rowName: str = 'rowValues')[source]¶
Add a table to the data card.
- Parameters:
- Raises:
TypeError – If table is not an OPATTable or tag is not a string.
ValueError – If a table with the same tag already exists.
Examples
>>> card = DataCard() >>> table = OPATTable(columnValues=[1.0, 2.0], rowValues=[3.0, 4.0], data=[[5.0, 6.0], [7.0, 8.0]]) >>> card.add_table(tag="Example", table=table)
- ascii() str [source]¶
Get the ASCII representation of the data card.
- Returns:
The ASCII representation.
- Return type:
Examples
>>> card = DataCard() >>> print(card.ascii())
- copy()[source]¶
Create a copy of the data card.
- Returns:
A copy of the data card.
- Return type:
Examples
>>> card = DataCard() >>> card_copy = card.copy() >>> card_copy == card True
- header: CardHeader¶
- index: Dict[str, CardIndexEntry]¶
- keys() List[str] [source]¶
Get the list of table tags in the data card.
- Returns:
A list of tags corresponding to the tables in the data card.
- Return type:
List[str]
Examples
>>> card = DataCard() >>> table1 = OPATTable(columnValues=[1.0, 2.0], rowValues=[3.0, 4.0], data=[[5.0, 6.0], [7.0, 8.0]]) >>> table2 = OPATTable(columnValues=[1.5, 2.5], rowValues=[3.5, 4.5], data=[[9.0, 10.0], [11.0, 12.0]]) >>> card.add_table(tag="Table1", table=table1) >>> card.add_table(tag="Table2", table=table2) >>> print(card.keys()) ['Table1', 'Table2']
- sha256() bytes [source]¶
Compute the SHA-256 hash of the data card.
- Returns:
The SHA-256 hash of the data card.
- Return type:
Examples
>>> card = DataCard() >>> table = OPATTable(columnValues=[1.0, 2.0], rowValues=[3.0, 4.0], data=[[5.0, 6.0], [7.0, 8.0]]) >>> card.add_table(tag="Example", table=table) >>> card.sha256()
- class opatio.card.datacard.OPATTable(columnValues: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], rowValues: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], data: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], _size: int = Ellipsis)[source]¶
Bases:
OPATEntity
Represents the data of a single table in an OPAT file.
- data¶
Data of the table, stored as a 2D or 3D array.
- Type:
npt.ArrayLike
Notes
This class is primarily used internally by opatio. Advanced users may create their own tables using this class if needed.
- ascii() str [source]¶
Get the ASCII representation of the OPAT table.
- Returns:
The ASCII representation.
- Return type:
Examples
>>> table = OPATTable(columnValues=[1.0, 2.0], rowValues=[3.0, 4.0], data=[[5.0, 6.0], [7.0, 8.0]]) >>> print(table.ascii())
- columnValues: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]¶
- static compute_col_width(size: int, floatWidth: int) int [source]¶
Compute the total width of a cell for ASCII representation.
- copy()[source]¶
Create a copy of the OPAT table.
- Returns:
A copy of the OPAT table.
- Return type:
Examples
>>> table = OPATTable(columnValues=[1.0, 2.0], rowValues=[3.0, 4.0], data=[[5.0, 6.0], [7.0, 8.0]]) >>> table_copy = table.copy() >>> table_copy == table True
- data: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]¶
- format_centered(value: float, floatWidth: int) str [source]¶
Format a float value centered in a fixed-width field.
- rowValues: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]¶
- sha256() _Hash [source]¶
Compute the SHA-256 checksum of the given data.
- Returns:
The SHA-256 checksum.
- Return type:
- Raises:
ValueError – If the data cannot be cast to a numpy array.
Examples
>>> table = OPATTable(columnValues=[1.0, 2.0], rowValues=[3.0, 4.0], data=[[5.0, 6.0], [7.0, 8.0]]) >>> table.sha256()