fix(opatio): fixed global numTables

previously there was a global "default header" object which each OpatIO table used to build off of. The issue was that this did a shallow copy so if there were multiple OpatIO objects instantiated they would all modify the same header object. This has been resolved by moving the default header to a function which generates it fresh for each OpatIO object.
This commit is contained in:
2025-03-22 07:13:34 -04:00
parent a38b6ef980
commit 5a8c50d376

View File

@@ -48,18 +48,23 @@ class OPATTable:
logT: Iterable[float] #< Logarithm of T values
logKappa: Iterable[Iterable[float]] #< Logarithm of Kappa values
defaultHeader = Header(
magic="OPAT",
version=1,
numTables=0,
headerSize=256,
indexOffset=0,
creationDate=datetime.now().strftime("%b %d, %Y"),
sourceInfo="no source provided by user",
comment="default header",
numIndex=2,
reserved=b"\x00" * 24
)
def make_default_header() -> Header:
"""
@brief Create a default header for an OPAT file.
@return The default header.
"""
return Header(
magic="OPAT",
version=1,
numTables=0,
headerSize=256,
indexOffset=0,
creationDate=datetime.now().strftime("%b %d, %Y"),
sourceInfo="no source provided by user",
comment="default header",
numIndex=2,
reserved=b"\x00" * 24
)
class OpatIO:
"""
@@ -103,7 +108,7 @@ class OpatIO:
Save the OPAT file as a binary file.
"""
def __init__(self):
self.header: Header = defaultHeader
self.header: Header = make_default_header()
self.tables: List[Tuple[Tuple[float, float], OPATTable]] = []
@staticmethod