From b4e98f077ecf18dad17e56dc41cac34ef9f80be9 Mon Sep 17 00:00:00 2001 From: Caleb Bell Date: Wed, 6 Jul 2016 22:02:43 -0300 Subject: [PATCH] Tentative performance optimization; possibly increasing memory usage --- thermo/acentric.py | 7 +++--- thermo/critical.py | 47 ++++++++++++++++++++-------------------- thermo/dipole.py | 7 +++--- thermo/elements.py | 2 -- thermo/heat_capacity.py | 38 ++++++++++++++------------------ thermo/interface.py | 30 ++++++++++--------------- thermo/permittivity.py | 5 ++--- thermo/phase_change.py | 13 ++++++----- thermo/reaction.py | 3 ++- thermo/safety.py | 17 ++++++++------- thermo/triple.py | 3 ++- thermo/vapor_pressure.py | 34 ++++++++++++----------------- thermo/viscosity.py | 29 +++++++++++-------------- thermo/volume.py | 25 +++++++++------------ 14 files changed, 119 insertions(+), 141 deletions(-) diff --git a/thermo/acentric.py b/thermo/acentric.py index fbe66759..c60e6303 100644 --- a/thermo/acentric.py +++ b/thermo/acentric.py @@ -22,6 +22,7 @@ from __future__ import division from math import log, log10 +import numpy as np import pandas as pd from thermo.utils import mixing_simple, none_and_length_check from thermo.critical import Tc, Pc @@ -117,11 +118,11 @@ def omega(CASRN='', AvailableMethods=False, Method=None, IgnoreMethods=[LK, DEFI ''' def list_methods(): methods = [] - if CASRN in _crit_PSRKR4.index and pd.notnull(_crit_PSRKR4.at[CASRN, 'omega']): + if CASRN in _crit_PSRKR4.index and not np.isnan(_crit_PSRKR4.at[CASRN, 'omega']): methods.append(PSRK) - if CASRN in _crit_PassutDanner.index and pd.notnull(_crit_PassutDanner.at[CASRN, 'omega']): + if CASRN in _crit_PassutDanner.index and not np.isnan(_crit_PassutDanner.at[CASRN, 'omega']): methods.append(PD) - if CASRN in _crit_Yaws.index and pd.notnull(_crit_Yaws.at[CASRN, 'omega']): + if CASRN in _crit_Yaws.index and not np.isnan(_crit_Yaws.at[CASRN, 'omega']): methods.append(YAWS) Tcrit, Pcrit = Tc(CASRN), Pc(CASRN) if Tcrit and Pcrit: diff --git a/thermo/critical.py b/thermo/critical.py index 4c8080c9..86842cea 100644 --- a/thermo/critical.py +++ b/thermo/critical.py @@ -22,7 +22,8 @@ from __future__ import division import os -from numpy import log +from math import log +import numpy as np from scipy.constants import R import pandas as pd from thermo.utils import mixing_simple, none_and_length_check @@ -215,17 +216,17 @@ def Tc(CASRN='', AvailableMethods=False, Method=None, IgnoreMethods=[SURF]): ''' def list_methods(): methods = [] - if CASRN in _crit_IUPAC.index and pd.notnull(_crit_IUPAC.at[CASRN, 'Tc']): + if CASRN in _crit_IUPAC.index and not np.isnan(_crit_IUPAC.at[CASRN, 'Tc']): methods.append(IUPAC) - if CASRN in _crit_Matthews.index and pd.notnull(_crit_Matthews.at[CASRN, 'Tc']): + if CASRN in _crit_Matthews.index and not np.isnan(_crit_Matthews.at[CASRN, 'Tc']): methods.append(MATTHEWS) - if CASRN in _crit_CRC.index and pd.notnull(_crit_CRC.at[CASRN, 'Tc']): + if CASRN in _crit_CRC.index and not np.isnan(_crit_CRC.at[CASRN, 'Tc']): methods.append(CRC) - if CASRN in _crit_PSRKR4.index and pd.notnull(_crit_PSRKR4.at[CASRN, 'Tc']): + if CASRN in _crit_PSRKR4.index and not np.isnan(_crit_PSRKR4.at[CASRN, 'Tc']): methods.append(PSRK) - if CASRN in _crit_PassutDanner.index and pd.notnull(_crit_PassutDanner.at[CASRN, 'Tc']): + if CASRN in _crit_PassutDanner.index and not np.isnan(_crit_PassutDanner.at[CASRN, 'Tc']): methods.append(PD) - if CASRN in _crit_Yaws.index and pd.notnull(_crit_Yaws.at[CASRN, 'Tc']): + if CASRN in _crit_Yaws.index and not np.isnan(_crit_Yaws.at[CASRN, 'Tc']): methods.append(YAWS) if CASRN: methods.append(SURF) @@ -399,17 +400,17 @@ def Pc(CASRN='', AvailableMethods=False, Method=None, IgnoreMethods=[SURF]): ''' def list_methods(): methods = [] - if CASRN in _crit_IUPAC.index and pd.notnull(_crit_IUPAC.at[CASRN, 'Pc']): + if CASRN in _crit_IUPAC.index and not np.isnan(_crit_IUPAC.at[CASRN, 'Pc']): methods.append(IUPAC) - if CASRN in _crit_Matthews.index and pd.notnull(_crit_Matthews.at[CASRN, 'Pc']): + if CASRN in _crit_Matthews.index and not np.isnan(_crit_Matthews.at[CASRN, 'Pc']): methods.append(MATTHEWS) - if CASRN in _crit_CRC.index and pd.notnull(_crit_CRC.at[CASRN, 'Pc']): + if CASRN in _crit_CRC.index and not np.isnan(_crit_CRC.at[CASRN, 'Pc']): methods.append(CRC) - if CASRN in _crit_PSRKR4.index and pd.notnull(_crit_PSRKR4.at[CASRN, 'Pc']): + if CASRN in _crit_PSRKR4.index and not np.isnan(_crit_PSRKR4.at[CASRN, 'Pc']): methods.append(PSRK) - if CASRN in _crit_PassutDanner.index and pd.notnull(_crit_PassutDanner.at[CASRN, 'Pc']): + if CASRN in _crit_PassutDanner.index and not np.isnan(_crit_PassutDanner.at[CASRN, 'Pc']): methods.append(PD) - if CASRN in _crit_Yaws.index and pd.notnull(_crit_Yaws.at[CASRN, 'Pc']): + if CASRN in _crit_Yaws.index and not np.isnan(_crit_Yaws.at[CASRN, 'Pc']): methods.append(YAWS) if CASRN: methods.append(SURF) @@ -577,15 +578,15 @@ def Vc(CASRN='', AvailableMethods=False, Method=None, IgnoreMethods=[SURF]): ''' def list_methods(): methods = [] - if CASRN in _crit_IUPAC.index and pd.notnull(_crit_IUPAC.at[CASRN, 'Vc']): + if CASRN in _crit_IUPAC.index and not np.isnan(_crit_IUPAC.at[CASRN, 'Vc']): methods.append(IUPAC) - if CASRN in _crit_Matthews.index and pd.notnull(_crit_Matthews.at[CASRN, 'Vc']): + if CASRN in _crit_Matthews.index and not np.isnan(_crit_Matthews.at[CASRN, 'Vc']): methods.append(MATTHEWS) - if CASRN in _crit_CRC.index and pd.notnull(_crit_CRC.at[CASRN, 'Vc']): + if CASRN in _crit_CRC.index and not np.isnan(_crit_CRC.at[CASRN, 'Vc']): methods.append(CRC) - if CASRN in _crit_PSRKR4.index and pd.notnull(_crit_PSRKR4.at[CASRN, 'Vc']): + if CASRN in _crit_PSRKR4.index and not np.isnan(_crit_PSRKR4.at[CASRN, 'Vc']): methods.append(PSRK) - if CASRN in _crit_Yaws.index and pd.notnull(_crit_Yaws.at[CASRN, 'Vc']): + if CASRN in _crit_Yaws.index and not np.isnan(_crit_Yaws.at[CASRN, 'Vc']): methods.append(YAWS) if CASRN: methods.append(SURF) @@ -749,15 +750,15 @@ def Zc(CASRN='', AvailableMethods=False, Method=None, IgnoreMethods=[COMBINED]): ''' def list_methods(): methods = [] - if CASRN in _crit_IUPAC.index and pd.notnull(_crit_IUPAC.at[CASRN, 'Zc']): + if CASRN in _crit_IUPAC.index and not np.isnan(_crit_IUPAC.at[CASRN, 'Zc']): methods.append(IUPAC) - if CASRN in _crit_Matthews.index and pd.notnull(_crit_Matthews.at[CASRN, 'Zc']): + if CASRN in _crit_Matthews.index and not np.isnan(_crit_Matthews.at[CASRN, 'Zc']): methods.append(MATTHEWS) - if CASRN in _crit_CRC.index and pd.notnull(_crit_CRC.at[CASRN, 'Zc']): + if CASRN in _crit_CRC.index and not np.isnan(_crit_CRC.at[CASRN, 'Zc']): methods.append(CRC) - if CASRN in _crit_PSRKR4.index and pd.notnull(_crit_PSRKR4.at[CASRN, 'Zc']): + if CASRN in _crit_PSRKR4.index and not np.isnan(_crit_PSRKR4.at[CASRN, 'Zc']): methods.append(PSRK) - if CASRN in _crit_Yaws.index and pd.notnull(_crit_Yaws.at[CASRN, 'Zc']): + if CASRN in _crit_Yaws.index and not np.isnan(_crit_Yaws.at[CASRN, 'Zc']): methods.append(YAWS) if Tc(CASRN) and Vc(CASRN) and Pc(CASRN): methods.append(COMBINED) diff --git a/thermo/dipole.py b/thermo/dipole.py index e18a7b2b..f95289b6 100644 --- a/thermo/dipole.py +++ b/thermo/dipole.py @@ -22,6 +22,7 @@ from __future__ import division import os +import numpy as np import pandas as pd @@ -105,11 +106,11 @@ def dipole(CASRN='', AvailableMethods=False, Method=None): ''' def list_methods(): methods = [] - if CASRN in _dipole_CCDB.index and pd.notnull(_dipole_CCDB.at[CASRN, 'Dipole']): + if CASRN in _dipole_CCDB.index and not np.isnan(_dipole_CCDB.at[CASRN, 'Dipole']): methods.append(CCCBDB) - if CASRN in _dipole_Muller.index and pd.notnull(_dipole_Muller.at[CASRN, 'Dipole']): + if CASRN in _dipole_Muller.index and not np.isnan(_dipole_Muller.at[CASRN, 'Dipole']): methods.append(MULLER) - if CASRN in _dipole_Poling.index and pd.notnull(_dipole_Poling.at[CASRN, 'Dipole']): + if CASRN in _dipole_Poling.index and not np.isnan(_dipole_Poling.at[CASRN, 'Dipole']): methods.append(POLING) methods.append(NONE) return methods diff --git a/thermo/elements.py b/thermo/elements.py index 298a3a71..3054272a 100644 --- a/thermo/elements.py +++ b/thermo/elements.py @@ -261,8 +261,6 @@ def molecular_weight(atoms): for i in atoms: if i in elements: MW += elements[i].MW*atoms[i] -# if i in elements.index: -# MW += elements.at[i, "atomic mass"]*atoms[i] else: raise Exception('Molecule includes unknown atoms') return MW diff --git a/thermo/heat_capacity.py b/thermo/heat_capacity.py index 024e60ff..2de1b746 100644 --- a/thermo/heat_capacity.py +++ b/thermo/heat_capacity.py @@ -23,18 +23,20 @@ from __future__ import division import os from math import log, exp +import numpy as np +import pandas as pd + from scipy.constants import R, calorie from scipy.integrate import quad + from thermo.utils import (to_num, property_molar_to_mass, none_and_length_check, mixing_simple, property_mass_to_molar) from thermo.miscdata import _VDISaturationDict, VDI_tabular_data from thermo.electrochem import (Laliberte_heat_capacity, _Laliberte_Heat_Capacity_ParametersDict) - from thermo.utils import TDependentProperty from thermo.coolprop import * -import pandas as pd folder = os.path.join(os.path.dirname(__file__), 'Heat Capacity') @@ -42,17 +44,13 @@ Poling_data = pd.read_csv(os.path.join(folder, 'PolingDatabank.csv'), sep='\t', index_col=0) - - -# '''Read in a dict of 1961 heat capacity of gases complicated fits from: -# Kabo, G. J., and G. N. Roganov. Thermodynamics of Organic Compounds in the -# Gas State, Volume II: V. 2. College Station, Tex: CRC Press, 1994. -# ''' +_Poling_data_values = Poling_data.values TRC_gas_data = pd.read_csv(os.path.join(folder, 'TRC Thermodynamics of Organic Compounds in the Gas State.csv'), sep='\t', index_col=0) +_TRC_gas_data_values = TRC_gas_data.values @@ -378,23 +376,19 @@ def load_all_methods(self): Tmins, Tmaxs = [], [] if self.CASRN in TRC_gas_data.index: methods.append(TRCIG) - _, Tmin, Tmax, a0, a1, a2, a3, a4, a5, a6, a7, _, _, _ = TRC_gas_data.loc[self.CASRN] - self.TRCIG_Tmin = float(Tmin) - self.TRCIG_Tmax = float(Tmax) - self.TRCIG_coefs = [float(i) for i in [a0, a1, a2, a3, a4, a5, a6, a7]] + _, self.TRCIG_Tmin, self.TRCIG_Tmax, a0, a1, a2, a3, a4, a5, a6, a7, _, _, _ = _TRC_gas_data_values[TRC_gas_data.index.get_loc(self.CASRN)].tolist() + self.TRCIG_coefs = [a0, a1, a2, a3, a4, a5, a6, a7] Tmins.append(self.TRCIG_Tmin); Tmaxs.append(self.TRCIG_Tmax) - if self.CASRN in Poling_data.index and pd.notnull(Poling_data.at[self.CASRN, 'a0']): - _, Tmin, Tmax, a0, a1, a2, a3, a4, Cpg, Cpl = Poling_data.loc[self.CASRN] + if self.CASRN in Poling_data.index and not np.isnan(Poling_data.at[self.CASRN, 'a0']): + _, self.POLING_Tmin, self.POLING_Tmax, a0, a1, a2, a3, a4, Cpg, Cpl = _Poling_data_values[Poling_data.index.get_loc(self.CASRN)].tolist() methods.append(POLING) - self.POLING_Tmin = float(Tmin) - self.POLING_Tmax = float(Tmax) - self.POLING_coefs = [float(i) for i in [a0, a1, a2, a3, a4]] + self.POLING_coefs = [a0, a1, a2, a3, a4] Tmins.append(self.POLING_Tmin); Tmaxs.append(self.POLING_Tmax) - if self.CASRN in Poling_data.index and pd.notnull(Poling_data.at[self.CASRN, 'Cpg']): + if self.CASRN in Poling_data.index and not np.isnan(Poling_data.at[self.CASRN, 'Cpg']): methods.append(POLING_CONST) self.POLING_T = 298.15 self.POLING_constant = float(Poling_data.at[self.CASRN, 'Cpg']) - if self.CASRN in CRC_standard_data.index and pd.notnull(CRC_standard_data.at[self.CASRN, 'Cpg']): + if self.CASRN in CRC_standard_data.index and not np.isnan(CRC_standard_data.at[self.CASRN, 'Cpg']): methods.append(CRCSTD) self.CRCSTD_T = 298.15 self.CRCSTD_constant = float(CRC_standard_data.at[self.CASRN, 'Cpg']) @@ -1051,11 +1045,11 @@ def load_all_methods(self): if self.CASRN in _ZabranskyIsop: methods.append(ZABRANSKY_QUASIPOLYNOMIAL_C) self.ZABRANSKY_QUASIPOLYNOMIAL_C_data = _ZabranskyIsop[self.CASRN] - if self.CASRN in Poling_data.index and pd.notnull(Poling_data.at[self.CASRN, 'Cpl']): + if self.CASRN in Poling_data.index and not np.isnan(Poling_data.at[self.CASRN, 'Cpl']): methods.append(POLING_CONST) self.POLING_T = 298.15 self.POLING_constant = float(Poling_data.at[self.CASRN, 'Cpl']) - if self.CASRN in CRC_standard_data.index and pd.notnull(CRC_standard_data.at[self.CASRN, 'Cpl']): + if self.CASRN in CRC_standard_data.index and not np.isnan(CRC_standard_data.at[self.CASRN, 'Cpl']): methods.append(CRCSTD) self.CRCSTD_T = 298.15 self.CRCSTD_constant = float(CRC_standard_data.at[self.CASRN, 'Cpl']) @@ -1407,7 +1401,7 @@ def load_all_methods(self): self.PERRY151_quadinv = _PerryI[self.CASRN]['c']['Quadinv'] methods.append(PERRY151) Tmins.append(self.PERRY151_Tmin); Tmaxs.append(self.PERRY151_Tmax) - if self.CASRN in CRC_standard_data.index and pd.notnull(CRC_standard_data.at[self.CASRN, 'Cpc']): + if self.CASRN in CRC_standard_data.index and not np.isnan(CRC_standard_data.at[self.CASRN, 'Cpc']): self.CRCSTD_Cp = float(CRC_standard_data.at[self.CASRN, 'Cpc']) methods.append(CRCSTD) if self.MW and self.similarity_variable: diff --git a/thermo/interface.py b/thermo/interface.py index 5b7b6170..2c3f4b69 100644 --- a/thermo/interface.py +++ b/thermo/interface.py @@ -36,17 +36,19 @@ Mulero_Cachadina_data = pd.read_csv(os.path.join(folder, 'MuleroCachadinaParameters.csv'), sep='\t', index_col=0) - +_Mulero_Cachadina_data_values = Mulero_Cachadina_data.values Jasper_Lange_data = pd.read_csv(os.path.join(folder, 'Jasper-Lange.csv'), sep='\t', index_col=0) +_Jasper_Lange_data_values = Jasper_Lange_data.values Somayajulu_data = pd.read_csv(os.path.join(folder, 'Somayajulu.csv'), sep='\t', index_col=0) +_Somayajulu_data_values = Somayajulu_data.values Somayajulu_data_2 = pd.read_csv(os.path.join(folder, 'SomayajuluRevised.csv'), sep='\t', index_col=0) - +_Somayajulu_data_2_values = Somayajulu_data_2.values ### Regressed coefficient-based functions @@ -751,25 +753,19 @@ def load_all_methods(self): Tmins, Tmaxs = [], [] if self.CASRN in Mulero_Cachadina_data.index: methods.append(STREFPROP) - sigma0, n0, sigma1, n1, sigma2, n2, Tc, Tmin, Tmax = map(float, list(Mulero_Cachadina_data.loc[self.CASRN])[1:]) - self.STREFPROP_Tmin = Tmin - self.STREFPROP_Tmax = Tmax + _, sigma0, n0, sigma1, n1, sigma2, n2, Tc, self.STREFPROP_Tmin, self.STREFPROP_Tmax = _Mulero_Cachadina_data_values[Mulero_Cachadina_data.index.get_loc(self.CASRN)].tolist() self.STREFPROP_coeffs = [sigma0, n0, sigma1, n1, sigma2, n2, Tc] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.STREFPROP_Tmin); Tmaxs.append(self.STREFPROP_Tmax) if self.CASRN in Somayajulu_data_2.index: methods.append(SOMAYAJULU2) - Tt, Tc, A, B, C = map(float, list(Somayajulu_data_2.loc[self.CASRN])[1:]) - self.SOMAYAJULU2_Tt = Tt - self.SOMAYAJULU2_Tc = Tc + _, self.SOMAYAJULU2_Tt, self.SOMAYAJULU2_Tc, A, B, C = _Somayajulu_data_2_values[Somayajulu_data_2.index.get_loc(self.CASRN)].tolist() self.SOMAYAJULU2_coeffs = [A, B, C] - Tmins.append(Tt); Tmaxs.append(Tc) + Tmins.append(self.SOMAYAJULU2_Tt); Tmaxs.append(self.SOMAYAJULU2_Tc) if self.CASRN in Somayajulu_data.index: methods.append(SOMAYAJULU) - Tt, Tc, A, B, C = map(float, list(Somayajulu_data.loc[self.CASRN])[1:]) - self.SOMAYAJULU_Tt = Tt - self.SOMAYAJULU_Tc = Tc + _, self.SOMAYAJULU_Tt, self.SOMAYAJULU_Tc, A, B, C = _Somayajulu_data_values[Somayajulu_data.index.get_loc(self.CASRN)].tolist() self.SOMAYAJULU_coeffs = [A, B, C] - Tmins.append(Tt); Tmaxs.append(Tc) + Tmins.append(self.SOMAYAJULU_Tt); Tmaxs.append(self.SOMAYAJULU_Tc) if self.CASRN in _VDISaturationDict: methods.append(VDI_TABULAR) Ts, props = VDI_tabular_data(self.CASRN, 'sigma') @@ -779,11 +775,9 @@ def load_all_methods(self): Tmins.append(self.VDI_Tmin); Tmaxs.append(self.VDI_Tmax) if self.CASRN in Jasper_Lange_data.index: methods.append(JASPER) - a, b, Tmin, Tmax = map(float, list(Jasper_Lange_data.loc[self.CASRN])[1:]) - self.JASPER_Tmin = Tmin - self.JASPER_Tmax = Tmax + _, a, b, self.JASPER_Tmin, self.JASPER_Tmax= _Jasper_Lange_data_values[Jasper_Lange_data.index.get_loc(self.CASRN)].tolist() self.JASPER_coeffs = [a, b] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.JASPER_Tmin); Tmaxs.append(self.JASPER_Tmax) if all((self.Tc, self.Vc, self.omega)): methods.append(MIQUEU) Tmins.append(0.0); Tmaxs.append(self.Tc) diff --git a/thermo/permittivity.py b/thermo/permittivity.py index 54fa28d4..ed072e84 100644 --- a/thermo/permittivity.py +++ b/thermo/permittivity.py @@ -31,6 +31,7 @@ CRC_Permittivity_data = pd.read_csv(os.path.join(folder, 'Permittivity (Dielectric Constant) of Liquids.csv'), sep='\t', index_col=0) +_CRC_Permittivity_data_values = CRC_Permittivity_data.values CRC = 'CRC Handbook polynomials' @@ -143,9 +144,7 @@ def load_all_methods(self): Tmins, Tmaxs = [], [] if self.CASRN in CRC_Permittivity_data.index: methods.append(CRC_CONSTANT) - T, Permittivity, A, B, C, D, Tmin, Tmax = map(float, list(CRC_Permittivity_data.loc[self.CASRN])[1:]) - self.CRC_CONSTANT_T = T - self.CRC_permittivity = Permittivity + _, self.CRC_CONSTANT_T, self.CRC_permittivity, A, B, C, D, Tmin, Tmax = _CRC_Permittivity_data_values[CRC_Permittivity_data.index.get_loc(self.CASRN)].tolist() self.CRC_Tmin = Tmin self.CRC_Tmax = Tmax self.CRC_coeffs = [0 if np.isnan(x) else x for x in [A, B, C, D] ] diff --git a/thermo/phase_change.py b/thermo/phase_change.py index 0e8d8c44..bb6921e5 100644 --- a/thermo/phase_change.py +++ b/thermo/phase_change.py @@ -25,6 +25,7 @@ import os from scipy.constants import R +import numpy as np import pandas as pd from thermo.miscdata import CRC_organic_data, CRC_inorganic_data @@ -115,9 +116,9 @@ def Tb(CASRN='', AvailableMethods=False, Method=None, IgnoreMethods=[PSAT_DEFINI ''' def list_methods(): methods = [] - if CASRN in CRC_inorganic_data.index and pd.notnull(CRC_inorganic_data.at[CASRN, 'Tb']): + if CASRN in CRC_inorganic_data.index and not np.isnan(CRC_inorganic_data.at[CASRN, 'Tb']): methods.append(CRC_INORG) - if CASRN in CRC_organic_data.index and pd.notnull(CRC_organic_data.at[CASRN, 'Tb']): + if CASRN in CRC_organic_data.index and not np.isnan(CRC_organic_data.at[CASRN, 'Tb']): methods.append(CRC_ORG) if CASRN in Yaws_data.index: methods.append(YAWS) @@ -230,9 +231,9 @@ def list_methods(): methods = [] if CASRN in Tm_ON_data.index: methods.append(OPEN_NTBKM) - if CASRN in CRC_inorganic_data.index and pd.notnull(CRC_inorganic_data.at[CASRN, 'Tm']): + if CASRN in CRC_inorganic_data.index and not np.isnan(CRC_inorganic_data.at[CASRN, 'Tm']): methods.append(CRC_INORG) - if CASRN in CRC_organic_data.index and pd.notnull(CRC_organic_data.at[CASRN, 'Tm']): + if CASRN in CRC_organic_data.index and not np.isnan(CRC_organic_data.at[CASRN, 'Tm']): methods.append(CRC_ORG) if IgnoreMethods: for Method in IgnoreMethods: @@ -1078,11 +1079,11 @@ def load_all_methods(self): self.VDI_Tmax = Ts[-1] self.tabular_data[VDI_TABULAR] = (Ts, props) Tmins.append(self.VDI_Tmin); Tmaxs.append(self.VDI_Tmax) - if self.CASRN in CRCHvap_data.index and pd.notnull(CRCHvap_data.at[self.CASRN, 'HvapTb']): + if self.CASRN in CRCHvap_data.index and not np.isnan(CRCHvap_data.at[self.CASRN, 'HvapTb']): methods.append(CRC_HVAP_TB) self.CRC_HVAP_TB_Tb = float(CRCHvap_data.at[self.CASRN, 'Tb']) self.CRC_HVAP_TB_Hvap = float(CRCHvap_data.at[self.CASRN, 'HvapTb']) - if self.CASRN in CRCHvap_data.index and pd.notnull(CRCHvap_data.at[self.CASRN, 'Hvap298']): + if self.CASRN in CRCHvap_data.index and not np.isnan(CRCHvap_data.at[self.CASRN, 'Hvap298']): methods.append(CRC_HVAP_298) self.CRC_HVAP_298 = float(float(CRCHvap_data.at[self.CASRN, 'Hvap298'])) if self.CASRN in GharagheiziHvap_data.index: diff --git a/thermo/reaction.py b/thermo/reaction.py index a5bbe473..fb998d21 100644 --- a/thermo/reaction.py +++ b/thermo/reaction.py @@ -24,6 +24,7 @@ import os from thermo.heat_capacity import TRC_gas_data +import numpy as np import pandas as pd folder = os.path.join(os.path.dirname(__file__), 'Reactions') @@ -249,7 +250,7 @@ def list_methods(): methods = [] if CASRN in ATcT_g.index: methods.append(ATCT_G) - if CASRN in TRC_gas_data.index and pd.notnull(TRC_gas_data.at[CASRN, 'Hf']): + if CASRN in TRC_gas_data.index and not np.isnan(TRC_gas_data.at[CASRN, 'Hf']): methods.append(TRC) methods.append(NONE) return methods diff --git a/thermo/safety.py b/thermo/safety.py index 71654099..a0bf2304 100644 --- a/thermo/safety.py +++ b/thermo/safety.py @@ -23,6 +23,7 @@ from __future__ import division from thermo.identifiers import CASfromAny, MW import os +import numpy as np import pandas as pd from scipy.constants import R @@ -530,9 +531,9 @@ def Tflash(CASRN='', AvailableMethods=False, Method=None): ''' def list_methods(): methods = [] - if CASRN in IEC_2010.index and pd.notnull(IEC_2010.at[CASRN, 'Tflash']): + if CASRN in IEC_2010.index and not np.isnan(IEC_2010.at[CASRN, 'Tflash']): methods.append(IEC) - if CASRN in NFPA_2008.index and pd.notnull(NFPA_2008.at[CASRN, 'Tflash']): + if CASRN in NFPA_2008.index and not np.isnan(NFPA_2008.at[CASRN, 'Tflash']): methods.append(NFPA) methods.append(NONE) return methods @@ -607,9 +608,9 @@ def Tautoignition(CASRN='', AvailableMethods=False, Method=None): ''' def list_methods(): methods = [] - if CASRN in IEC_2010.index and pd.notnull(IEC_2010.at[CASRN, 'Tautoignition']): + if CASRN in IEC_2010.index and not np.isnan(IEC_2010.at[CASRN, 'Tautoignition']): methods.append(IEC) - if CASRN in NFPA_2008.index and pd.notnull(NFPA_2008.at[CASRN, 'Tautoignition']): + if CASRN in NFPA_2008.index and not np.isnan(NFPA_2008.at[CASRN, 'Tautoignition']): methods.append(NFPA) methods.append(NONE) return methods @@ -693,9 +694,9 @@ def LFL(Hc=None, atoms={}, CASRN='', AvailableMethods=False, Method=None): ''' def list_methods(): methods = [] - if CASRN in IEC_2010.index and pd.notnull(IEC_2010.at[CASRN, 'LFL']): + if CASRN in IEC_2010.index and not np.isnan(IEC_2010.at[CASRN, 'LFL']): methods.append(IEC) - if CASRN in NFPA_2008.index and pd.notnull(NFPA_2008.at[CASRN, 'LFL']): + if CASRN in NFPA_2008.index and not np.isnan(NFPA_2008.at[CASRN, 'LFL']): methods.append(NFPA) if Hc: methods.append(SUZUKI) @@ -784,9 +785,9 @@ def UFL(Hc=None, atoms={}, CASRN='', AvailableMethods=False, Method=None): ''' def list_methods(): methods = [] - if CASRN in IEC_2010.index and pd.notnull(IEC_2010.at[CASRN, 'UFL']): + if CASRN in IEC_2010.index and not np.isnan(IEC_2010.at[CASRN, 'UFL']): methods.append(IEC) - if CASRN in NFPA_2008.index and pd.notnull(NFPA_2008.at[CASRN, 'UFL']): + if CASRN in NFPA_2008.index and not np.isnan(NFPA_2008.at[CASRN, 'UFL']): methods.append(NFPA) if Hc: methods.append(SUZUKI) diff --git a/thermo/triple.py b/thermo/triple.py index 45b1a5b0..18f0e178 100644 --- a/thermo/triple.py +++ b/thermo/triple.py @@ -22,6 +22,7 @@ from __future__ import division import os +import numpy as np import pandas as pd from thermo.phase_change import Tm from thermo.vapor_pressure import VaporPressure @@ -167,7 +168,7 @@ def Pt(CASRN, AvailableMethods=False, Method=None): ''' def list_methods(): methods = [] - if CASRN in Staveley_data.index and pd.notnull(Staveley_data.at[CASRN, 'Pt']): + if CASRN in Staveley_data.index and not np.isnan(Staveley_data.at[CASRN, 'Pt']): methods.append(STAVELEY) if Tt(CASRN) and VaporPressure(CASRN=CASRN).T_dependent_property(T=Tt(CASRN)): methods.append(DEFINITION) diff --git a/thermo/vapor_pressure.py b/thermo/vapor_pressure.py index 6ca02025..ad409096 100644 --- a/thermo/vapor_pressure.py +++ b/thermo/vapor_pressure.py @@ -23,6 +23,7 @@ from __future__ import division import os from math import log, exp +import numpy as np import pandas as pd from thermo.miscdata import _VDISaturationDict, VDI_tabular_data from thermo.utils import TDependentProperty @@ -33,16 +34,19 @@ WagnerMcGarry = pd.read_csv(os.path.join(folder, 'Wagner Original McGarry.csv'), sep='\t', index_col=0) +_WagnerMcGarry_values = WagnerMcGarry.values AntoinePoling = pd.read_csv(os.path.join(folder, 'Antoine Collection Poling.csv'), sep='\t', index_col=0) +_AntoinePoling_values = AntoinePoling.values WagnerPoling = pd.read_csv(os.path.join(folder, 'Wagner Collection Poling.csv'), sep='\t', index_col=0) +_WagnerPoling_values = WagnerPoling.values AntoineExtended = pd.read_csv(os.path.join(folder, 'Antoine Extended Collection Poling.csv'), sep='\t', index_col=0) - +_AntoineExtended_values = AntoineExtended.values def Antoine(T, A, B, C, Base=10.0): '''Base 10 assumed; Coefficients type Pascal assumed; Coefficients type Kelvin or Celcius assumed. @@ -339,36 +343,26 @@ def load_all_methods(self): Tmins, Tmaxs = [], [] if self.CASRN in WagnerMcGarry.index: methods.append(WAGNER_MCGARRY) - A, B, C, D, Pc, Tc, Tmin = map(float, list(WagnerMcGarry.loc[self.CASRN])[1:]) - self.WAGNER_MCGARRY_Tmin = Tmin - self.WAGNER_MCGARRY_Tc = Tc - self.WAGNER_MCGARRY_Pc = Pc + _, A, B, C, D, self.WAGNER_MCGARRY_Pc, self.WAGNER_MCGARRY_Tc, self.WAGNER_MCGARRY_Tmin = _WagnerMcGarry_values[WagnerMcGarry.index.get_loc(self.CASRN)].tolist() self.WAGNER_MCGARRY_coefs = [A, B, C, D] - Tmins.append(Tmin); Tmaxs.append(Tc) + Tmins.append(self.WAGNER_MCGARRY_Tmin); Tmaxs.append(self.WAGNER_MCGARRY_Tc) if self.CASRN in WagnerPoling.index: methods.append(WAGNER_POLING) - A, B, C, D, Tc, Pc, Tmin, Tmax = map(float, list(WagnerPoling.loc[self.CASRN])[1:]) + _, A, B, C, D, self.WAGNER_POLING_Tc, self.WAGNER_POLING_Pc, Tmin, self.WAGNER_POLING_Tmax = _WagnerPoling_values[WagnerPoling.index.get_loc(self.CASRN)].tolist() # Some Tmin values are missing; Arbitrary choice of 0.1 lower limit - self.WAGNER_POLING_Tmin = Tmin if pd.notnull(Tmin) else Tmax*0.1 - self.WAGNER_POLING_Tmax = Tmax - self.WAGNER_POLING_Tc = Tc - self.WAGNER_POLING_Pc = Pc + self.WAGNER_POLING_Tmin = Tmin if not np.isnan(Tmin) else self.WAGNER_POLING_Tmax*0.1 self.WAGNER_POLING_coefs = [A, B, C, D] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(Tmin); Tmaxs.append(self.WAGNER_POLING_Tmax) if self.CASRN in AntoineExtended.index: methods.append(ANTOINE_EXTENDED_POLING) - A, B, C, Tc, to, n, E, F, Tmin, Tmax = map(float, list(AntoineExtended.loc[self.CASRN])[1:]) - self.ANTOINE_EXTENDED_POLING_Tmin = Tmin - self.ANTOINE_EXTENDED_POLING_Tmax = Tmax + _, A, B, C, Tc, to, n, E, F, self.ANTOINE_EXTENDED_POLING_Tmin, self.ANTOINE_EXTENDED_POLING_Tmax = _AntoineExtended_values[AntoineExtended.index.get_loc(self.CASRN)].tolist() self.ANTOINE_EXTENDED_POLING_coefs = [Tc, to, A, B, C, n, E, F] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.ANTOINE_EXTENDED_POLING_Tmin); Tmaxs.append(self.ANTOINE_EXTENDED_POLING_Tmax) if self.CASRN in AntoinePoling.index: methods.append(ANTOINE_POLING) - A, B, C, Tmin, Tmax = map(float, list(AntoinePoling.loc[self.CASRN])[1:]) - self.ANTOINE_POLING_Tmin = Tmin - self.ANTOINE_POLING_Tmax = Tmax + _, A, B, C, self.ANTOINE_POLING_Tmin, self.ANTOINE_POLING_Tmax = _AntoinePoling_values[AntoinePoling.index.get_loc(self.CASRN)].tolist() self.ANTOINE_POLING_coefs = [A, B, C] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.ANTOINE_POLING_Tmin); Tmaxs.append(self.ANTOINE_POLING_Tmax) if has_CoolProp and self.CASRN in coolprop_dict: methods.append(COOLPROP) self.CP_f = coolprop_fluids[self.CASRN] diff --git a/thermo/viscosity.py b/thermo/viscosity.py index 6ed2ef17..d4fc9059 100644 --- a/thermo/viscosity.py +++ b/thermo/viscosity.py @@ -35,15 +35,20 @@ Dutt_Prasad = pd.read_csv(os.path.join(folder, 'Dutt Prasad 3 term.csv'), sep='\t', index_col=0) +_Dutt_Prasad_values = Dutt_Prasad.values VN3_data = pd.read_csv(os.path.join(folder, 'Viswanath Natarajan Dynamic 3 term.csv'), sep='\t', index_col=0) +_VN3_data_values = VN3_data.values VN2_data = pd.read_csv(os.path.join(folder, 'Viswanath Natarajan Dynamic 2 term.csv'), sep='\t', index_col=0) +_VN2_data_values = VN2_data.values VN2E_data = pd.read_csv(os.path.join(folder, 'Viswanath Natarajan Dynamic 2 term Exponential.csv'), sep='\t', index_col=0) +_VN2E_data_values = VN2E_data.values + def ViswanathNatarajan2(T, A, B): @@ -480,32 +485,24 @@ def load_all_methods(self): Tmins.append(self.VDI_Tmin); Tmaxs.append(self.VDI_Tmax) if self.CASRN in Dutt_Prasad.index: methods.append(DUTT_PRASAD) - A, B, C, Tmin, Tmax = map(float, Dutt_Prasad.loc[self.CASRN][1:]) - self.DUTT_PRASAD_Tmin = Tmin - self.DUTT_PRASAD_Tmax = Tmax + _, A, B, C, self.DUTT_PRASAD_Tmin, self.DUTT_PRASAD_Tmax = _Dutt_Prasad_values[Dutt_Prasad.index.get_loc(self.CASRN)].tolist() self.DUTT_PRASAD_coeffs = [A, B, C] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.DUTT_PRASAD_Tmin); Tmaxs.append(self.DUTT_PRASAD_Tmax) if self.CASRN in VN3_data.index: methods.append(VISWANATH_NATARAJAN_3) - A, B, C, Tmin, Tmax = map(float, VN3_data.loc[self.CASRN][2:]) - self.VISWANATH_NATARAJAN_3_Tmin = Tmin - self.VISWANATH_NATARAJAN_3_Tmax = Tmax + _, _, A, B, C, self.VISWANATH_NATARAJAN_3_Tmin, self.VISWANATH_NATARAJAN_3_Tmax = _VN3_data_values[VN3_data.index.get_loc(self.CASRN)].tolist() self.VISWANATH_NATARAJAN_3_coeffs = [A, B, C] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.VISWANATH_NATARAJAN_3_Tmin); Tmaxs.append(self.VISWANATH_NATARAJAN_3_Tmax) if self.CASRN in VN2_data.index: methods.append(VISWANATH_NATARAJAN_2) - A, B, Tmin, Tmax = map(float, VN2_data.loc[self.CASRN][2:]) - self.VISWANATH_NATARAJAN_2_Tmin = Tmin - self.VISWANATH_NATARAJAN_2_Tmax = Tmax + _, _, A, B, self.VISWANATH_NATARAJAN_2_Tmin, self.VISWANATH_NATARAJAN_2_Tmax = _VN2_data_values[VN2_data.index.get_loc(self.CASRN)].tolist() self.VISWANATH_NATARAJAN_2_coeffs = [A, B] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.VISWANATH_NATARAJAN_2_Tmin); Tmaxs.append(self.VISWANATH_NATARAJAN_2_Tmax) if self.CASRN in VN2E_data.index: methods.append(VISWANATH_NATARAJAN_2E) - C, D, Tmin, Tmax = map(float, VN2E_data.loc[self.CASRN][2:]) - self.VISWANATH_NATARAJAN_2E_Tmin = Tmin - self.VISWANATH_NATARAJAN_2E_Tmax = Tmax + _, _, C, D, self.VISWANATH_NATARAJAN_2E_Tmin, self.VISWANATH_NATARAJAN_2E_Tmax = _VN2E_data_values[VN2E_data.index.get_loc(self.CASRN)].tolist() self.VISWANATH_NATARAJAN_2E_coeffs = [C, D] - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.VISWANATH_NATARAJAN_2E_Tmin); Tmaxs.append(self.VISWANATH_NATARAJAN_2E_Tmax) if all((self.MW, self.Tc, self.Pc, self.omega)): methods.append(LETSOU_STIEL) Tmins.append(self.Tc/4); Tmaxs.append(self.Tc) # TODO: test model at low T diff --git a/thermo/volume.py b/thermo/volume.py index 198e9224..d53f9104 100644 --- a/thermo/volume.py +++ b/thermo/volume.py @@ -24,6 +24,7 @@ from math import log, exp import os +import numpy as np from scipy.constants import R from scipy.interpolate import interp1d @@ -51,10 +52,11 @@ Perry_l_data = pd.read_csv(os.path.join(folder, 'Perry Parameters 105.csv'), sep='\t', index_col=0) - +_Perry_l_data_values = Perry_l_data.values CRC_inorg_l_data = pd.read_csv(os.path.join(folder, 'CRC Inorganics densties of molten compounds and salts.csv'), sep='\t', index_col=0) +_CRC_inorg_l_data_values = CRC_inorg_l_data.values CRC_inorg_l_const_data = pd.read_csv(os.path.join(folder, 'CRC Liquid Inorganic Constant Densities.csv'), sep='\t', index_col=0) @@ -64,6 +66,7 @@ CRC_virial_data = pd.read_csv(os.path.join(folder, 'CRC Virial polynomials.csv'), sep='\t', index_col=0) +_CRC_virial_data_values = CRC_virial_data.values ### Critical-properties based @@ -930,20 +933,13 @@ def load_all_methods(self): Tmins.append(self.CP_f.Tt); Tmaxs.append(self.CP_f.Tc) if self.CASRN in CRC_inorg_l_data.index: methods.append(CRC_INORG_L) - _, MW, rho, k, Tm, Tmax = CRC_inorg_l_data.loc[self.CASRN] - self.CRC_INORG_L_MW = float(MW) - self.CRC_INORG_L_rho = float(rho) - self.CRC_INORG_L_k = float(k) - self.CRC_INORG_L_Tm = float(Tm) - self.CRC_INORG_L_Tmax = float(Tmax) + _, self.CRC_INORG_L_MW, self.CRC_INORG_L_rho, self.CRC_INORG_L_k, self.CRC_INORG_L_Tm, self.CRC_INORG_L_Tmax = _CRC_inorg_l_data_values[CRC_inorg_l_data.index.get_loc(self.CASRN)].tolist() Tmins.append(self.CRC_INORG_L_Tm); Tmaxs.append(self.CRC_INORG_L_Tmax) if self.CASRN in Perry_l_data.index: methods.append(PERRYDIPPR) - C1, C2, C3, C4, Tmin, Tmax = [float(Perry_l_data.at[self.CASRN, i]) for i in ['C1', 'C2', 'C3', 'C4', 'Tmin', 'Tmax']] + _, C1, C2, C3, C4, self.DIPPR_Tmin, self.DIPPR_Tmax = _Perry_l_data_values[Perry_l_data.index.get_loc(self.CASRN)].tolist() self.DIPPR_coeffs = [C1, C2, C3, C4] - self.DIPPR_Tmin = Tmin - self.DIPPR_Tmax = Tmax - Tmins.append(Tmin); Tmaxs.append(Tmax) + Tmins.append(self.DIPPR_Tmin); Tmaxs.append(self.DIPPR_Tmax) if self.CASRN in _VDISaturationDict: methods.append(VDI_TABULAR) Ts, props = VDI_tabular_data(self.CASRN, 'Volume (l)') @@ -956,7 +952,7 @@ def load_all_methods(self): self.COSTALD_Vchar = float(COSTALD_data.at[self.CASRN, 'Vchar']) self.COSTALD_omega_SRK = float(COSTALD_data.at[self.CASRN, 'omega_SRK']) Tmins.append(0); Tmaxs.append(self.Tc) - if self.Tc and self.Pc and self.CASRN in COSTALD_data.index and pd.notnull(COSTALD_data.at[self.CASRN, 'Z_RA']): + if self.Tc and self.Pc and self.CASRN in COSTALD_data.index and not np.isnan(COSTALD_data.at[self.CASRN, 'Z_RA']): methods.append(RACKETTFIT) self.RACKETT_Z_RA = float(COSTALD_data.at[self.CASRN, 'Z_RA']) Tmins.append(0); Tmaxs.append(self.Tc) @@ -1497,7 +1493,7 @@ def list_methods(): elif Method == 'Rackett Parameters': Zcs = list(Zcs) # Copy to not edit originals for i in range(len(CASRNs)): - if CASRNs[i] in COSTALD_data.index and pd.notnull(COSTALD_data.at[CASRNs[i],'Z_RA']): + if CASRNs[i] in COSTALD_data.index and not np.isnan(COSTALD_data.at[CASRNs[i],'Z_RA']): Zcs[i] = COSTALD_data.at[CASRNs[i],'Z_RA'] _Vm = Rackett_mixture(T, xs, MWs, Tcs, Pcs, Zcs) elif Method == 'Laliberte': @@ -1754,8 +1750,7 @@ def load_all_methods(self): PITZER_CURL]) if self.CASRN in CRC_virial_data.index: methods_P.append(CRC_VIRIAL) - a1, a2, a3, a4, a5 = map(float, CRC_virial_data.loc[self.CASRN][1:]) - self.CRC_VIRIAL_coeffs = [a1, a2, a3, a4, a5] + self.CRC_VIRIAL_coeffs = _CRC_virial_data_values[CRC_virial_data.index.get_loc(self.CASRN)].tolist()[1:] if has_CoolProp and self.CASRN in coolprop_dict: methods_P.append(COOLPROP) self.CP_f = coolprop_fluids[self.CASRN]