opatio package¶
Subpackages¶
Module contents¶
The top-level package for the opatio library.
This module provides the primary interface for interacting with OPAT (Open Parameterized Array Table) files. It makes the main OPAT class for creating and manipulating OPAT data, and the read_opat function for loading existing OPAT files, directly available under the ‘opatio’ namespace.
OPAT is a structured binary file format developed for storing tabular data, particularly useful in scientific applications where data tables are parameterized by one or more floating point index variables.
OPAT was initially developed by the 4D-STAR collaboration as an efficient way to store and retrieve large datasets of opacity data.
Format Specification¶
The full specification of the OPAT format can be found in the opat-core repository:
Modules¶
- base
Contains the core OPAT class definition and header handling.
- card
Defines structures for data cards, headers, index entries, and tables.
- catalog
Handles catalog entries mapping indices to card locations.
- convert
Provides tools for converting other formats (like OPAL) to OPAT.
- index
Manages the float vector indices used for parameterization.
- load
Contains functions for loading OPAT files.
- misc
Includes miscellaneous utilities and base classes.
License¶
This library is licensed under the GNU General Public License v3.0 (GPLv3). You should have received a copy of the license along with this program. If not, see <http://www.gnu.org/licenses/>.
Examples
>>> import opatio
>>> import numpy as np
>>> # 1. Create a new OPAT object
>>> opat = opatio.OPAT()
>>> # Set metadata (optional)
>>> opat.set_comment("Example OPAT file for demonstration.")
>>> opat.set_source("Generated by example script.")
>>> # Set the number of dimensions for the index vector (e.g., 2D)
>>> opat.set_numIndex(2)
>>> # Define data for a table
>>> index_vector = (1.5, 20.0) # Example parameters (e.g., Temperature, Density)
>>> table_tag = "opacity_data"
>>> logT_values = np.array([3.0, 3.5, 4.0])
>>> logR_values = np.array([-5.0, -4.0])
>>> opacity_values = np.array([
... [0.1, 0.5], # Corresponds to logT=3.0, logR=(-5.0, -4.0)
... [0.2, 0.8], # Corresponds to logT=3.5, logR=(-5.0, -4.0)
... [0.4, 1.2] # Corresponds to logT=4.0, logR=(-5.0, -4.0)
... ])
>>> # Add the table to a data card associated with the index vector
>>> updated_card = opat.add_table(
... indexVector=index_vector,
... tag=table_tag,
... columnValues=logR_values, # Values along columns
... rowValues=logT_values, # Values along rows
... data=opacity_values,
... columnName="logR", # Optional name for column axis
... rowName="logT" # Optional name for row axis
... )
>>> print(f"Card added/updated for index {index_vector}")
>>> # Add more tables or cards as needed...
>>> # opat.add_table((2.0, 30.0), "another_table", ...)
>>> # 4. Save the OPAT data to a binary file
>>> output_filename = "my_opat_data.opat"
>>> try:
... opat.save(output_filename)
... print(f"OPAT data saved to {output_filename}")
... except Exception as e:
... print(f"Error saving file: {e}")
>>> # 5. Load an existing OPAT file
>>> try:
... loaded_opat = opatio.read_opat(output_filename)
... print(f"Successfully loaded {output_filename}")
... # Access header info
... print(f"Comment: {loaded_opat.header.comment}")
... # Access a specific card's table (requires knowing the index vector and tag)
... # card = loaded_opat.cards[opatio.FloatVectorIndex(index_vector, loaded_opat.header.hashPrecision)]
... # table = card[table_tag]
... # print(table.data)
... except FileNotFoundError:
... print(f"File not found: {output_filename}")
... except Exception as e:
... print(f"Error loading file: {e}")
>>> # 6. Use TableLattice for interpolation
>>> from opatio.lattice import TableLattice
>>> lattice = TableLattice(opat)
>>> # Query for interpolated data
>>> query_vector = opatio.FloatVectorIndex((1.75, 25.0)) # Example query vector
>>> interpolated_card = lattice.get(query_vector)
>>> # Access interpolated table
>>> interpolated_table = interpolated_card[table_tag]
>>> print("Interpolated data:")
>>> print(interpolated_table.data)