refactor(utils/opatio): saved

This commit is contained in:
2025-02-16 12:54:20 -05:00
parent c68d36fb55
commit 02c2096ac5

View File

@@ -61,6 +61,46 @@ defaultHeader = Header(
)
class OpatIO:
"""
@brief Class for handling OPAT file input/output operations.
This class provides methods to validate, manipulate, and save OPAT files. It includes functionalities to validate character arrays, 1D arrays, and 2D arrays, compute checksums, set header information, add tables, and save the OPAT file in both ASCII and binary formats.
Attributes:
header (Header): The header of the OPAT file.
tables (List[Tuple[Tuple[float, float], OPATTable]]): A list of tables in the OPAT file.
Methods:
validate_char_array_size(s: str, nmax: int) -> bool:
Validate the size of a character array.
validate_logKappa(logKappa):
Validate the logKappa array.
validate_1D(arr, name: str):
Validate a 1D array.
compute_checksum(data: bytes) -> bytes:
Compute the SHA-256 checksum of the given data.
set_version(version: int) -> int:
Set the version of the OPAT file.
set_source(source: str) -> str:
Set the source information of the OPAT file.
set_comment(comment: str) -> str:
Set the comment of the OPAT file.
add_table(X: float, Z: float, logR: Iterable[float], logT: Iterable[float], logKappa: Iterable[Iterable[float]]):
Add a table to the OPAT file.
_header_bytes() -> bytes:
Convert the header to bytes.
_table_bytes(table: OPATTable) -> Tuple[bytes, bytes]:
Convert a table to bytes.
_tableIndex_bytes(tableIndex: TableIndex) -> bytes:
Convert a table index to bytes.
__repr__() -> str:
Get the string representation of the OpatIO object.
_format_table_as_string(table: OPATTable, X: float, Z: float) -> str:
Format a table as a string.
print_table_indexes(table_indexes: List[TableIndex]) -> str:
Print the table indexes.
save_as_ascii(filename: str) -> str:
Save the OPAT file as an ASCII file.
save(filename: str) -> str:
Save the OPAT file as a binary file.
"""
def __init__(self):
self.header: Header = defaultHeader
self.tables: List[Tuple[Tuple[float, float], OPATTable]] = []