feat(utils/opatio): updated hash generation to only look at logKappa

This commit is contained in:
2025-02-17 13:02:18 -05:00
parent df6335d25f
commit dc796be7bf
4 changed files with 1193 additions and 3 deletions

View File

@@ -167,13 +167,13 @@ class OpatIO:
raise TypeError(f"{name} must be a non-empty 1D array or iterable")
@staticmethod
def compute_checksum(data: bytes) -> bytes:
def compute_checksum(data: np.ndarray) -> bytes:
"""
@brief Compute the SHA-256 checksum of the given data.
@param data The data to compute the checksum for.
@return The SHA-256 checksum.
"""
return hashlib.sha256(data).digest()
return hashlib.sha256(data.tobytes()).digest()
def set_version(self, version: int) -> int:
"""
@@ -290,7 +290,7 @@ class OpatIO:
*logT,
*logKappa
)
checksum = self.compute_checksum(tableBytes)
checksum = self.compute_checksum(logKappa)
return (checksum, tableBytes)
def _tableIndex_bytes(self, tableIndex: TableIndex) -> bytes:

View File

@@ -0,0 +1,27 @@
from opatio import OpatIO
import numpy as np
np.random.seed(42)
def generate_synthetic_opacity_table(n_r, n_t):
logR = np.linspace(-8, 2, n_r, dtype=np.float64) # log Density grid
logT = np.linspace(3, 9, n_t, dtype=np.float64) # log Temperature grid
logK = np.random.uniform(-2, 2, size=(n_r, n_t)).astype(np.float64) # Synthetic Opacity
return logR, logT, logK
if __name__ == "__main__":
n_r = 50
n_t = 50
num_tables = 20
XValues = np.linspace(0.1, 0.7, num_tables)
ZValues = np.linspace(0.001, 0.03, num_tables)
opat = OpatIO()
opat.set_comment("Synthetic Opacity Tables")
opat.set_source("utils/opatio/utils/mkTestData.py")
for i in range(num_tables):
logR, logT, logK = generate_synthetic_opacity_table(n_r, n_t)
opat.add_table((XValues[i], ZValues[i]), logR, logT, logK)
opat.save("testData/synthetic_tables.opat")
opat.save_as_ascii("testData/synthetic_tables_OPAT.ascii")

Binary file not shown.

File diff suppressed because it is too large Load Diff