Skip to content

Commit

Permalink
Tentative performance optimization; possibly increasing memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed Jul 7, 2016
1 parent 6e92251 commit b4e98f0
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 141 deletions.
7 changes: 4 additions & 3 deletions thermo/acentric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
47 changes: 24 additions & 23 deletions thermo/critical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions thermo/dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from __future__ import division
import os
import numpy as np
import pandas as pd


Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions thermo/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 16 additions & 22 deletions thermo/heat_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,34 @@
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')


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



Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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:
Expand Down
30 changes: 12 additions & 18 deletions thermo/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions thermo/permittivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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] ]
Expand Down
Loading

0 comments on commit b4e98f0

Please sign in to comment.