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