Skip to content

Retrieve 2d-Array From TableMatrixData

Choose a tag to compare

@sinagilassi sinagilassi released this 05 Apr 00:37
· 1671 commits to main since this release

New Features

Introducing the ijs Method: Retrieve data matrix (numpy 2d array) from TableMatrixData with ease.

Example Usage

The following example demonstrates how to use the ijs method to retrieve the "Alpha" property for components comp1 and comp2:

# import packages/modules
import pyThermoDB as ptdb
import os

# COMPONENTS
# comp1
comp1 = "ethanol"
# comp2
comp2 = "butyl-methyl-ether"

# LOAD THERMODB
# ref
thermodb_file = 'thermodb_nrtl_ethanol_butyl-methyl-ether_1.pkl'
thermodb_path = os.path.join(os.getcwd(), thermodb_file)
print(thermodb_path)

# LOAD THERMODB
# load thermodb
nrtl_thermodb = ptdb.load_thermodb(thermodb_path)
print(type(nrtl_thermodb))

# CHECK THERMODB
# check all properties and functions registered
print(nrtl_thermodb.check())

# DATA
# list all data
print(nrtl_thermodb.check_properties())

# load data
nrtl_alpha_data = nrtl_thermodb.check_property('non-randomness-parameters')
print(type(nrtl_alpha_data))

# symbol
print(nrtl_alpha_data.matrix_symbol)

# ij matrix
# format 1
nrtl_data_ = f"alpha_{comp1}_{comp2}"

# format 2
nrtl_data_ = f"alpha | {comp1} | {comp2}"

# load matrix
alpha_ij = nrtl_alpha_data.ijs(nrtl_data_)
print(alpha_ij)

Matrix result:

{'ethanol | ethanol': 0.0, 'ethanol | butyl-methyl-ether': 0.680715, 'butyl-methyl-ether | ethanol': 0.680715, 'butyl-methyl-ether | butyl-methyl-ether': 0.0}