temo.fit package

Submodules

temo.fit.binary_helpers module

class temo.fit.binary_helpers.BinaryVLEIsothermFitter(*, ipure: int, T_K: float, anc, df_isoT: DataFrame, identifiers: list[str], component_json: list[dict], p_required: bool = True, tidy: bool = False)[source]

Bases: object

build_model(gammaT: float) AbstractModel[source]

Construct the teqp.AbstractModel instance based on the specified value of 𝛾_T

cost_function(gammaT: float) float[source]

Evaluate the cost function that is to be minimized.

Here the cost function is based solely on the interpolated values of the bubble-point pressure

trace_isotherm(gammaT: float | None = None, model: AbstractModel | None = None) DataFrame[source]

Given either a model instance or a value of 𝛾_T, trace the isotherm

class temo.fit.binary_helpers.BinaryVLEIsothermInterpolator(trace: DataFrame)[source]

Bases: object

A class to hold some interpolator classes along VLE isothems

temo.fit.cost_contributions module

temo.fit.cost_contributions.calc_errB12(*, model, df, step=1, z0)[source]

B12 should not have dependence on composition, but alas, it usually does

temo.fit.cost_contributions.calc_errSOS(model, df, *, step=1, max_iter=10)[source]

Deviation function from discrete speed of sound data at given temperature and pressure

temo.fit.cost_contributions.calc_errVLE(model, df, *, step=1)[source]

Deviation function from VLE data

temo.fit.cost_contributions.calc_errVLE_x(model, df, *, step=1)[source]

Deviation function from VLE data in the x direction

temo.fit.cost_contributions.calc_err_critisoT(model, df, *, step=1)[source]

Deviation function for critical points, tracing from a pure fluid endpoint. Tracing the isotherms ensures that the isotherms are well-behaved in the critical region. While the isotherm tracing to the critical point is relatively slow, it is really important to ensure well-shaped isotherms in the critical region

Two parts come into the deviation term: 1) The pressure is supposed to be close to the measured critical pressure 2) The isotherm needs to close, so that the liquid and vapor traces have

converged to the same composition given by the critical point. The slope dp/dx at the critical point should be zero, but this is not checked

temo.fit.cost_contributions.calc_errcritPT(model, df, *, step=1)[source]

Deviation function from critical points for which temperature and pressure are specified, and density guess is provided The rho(T,p) solver is executed to solve for the matching density and then the criticality conditions are checked

temo.fit.cost_contributions.calc_errcritPVT(model, df, *, step=1)[source]

Deviation function from critical points for which temperature and density are specified

temo.fit.cost_contributions.calc_errrho(*, model, df, step=1, iterate=False)[source]

Deviation function from PVT data

Returns percentage signed relative deviation in density

It is not actually the relative difference in density, because that would require iterative calculations. Instead, the Maclaurin series expansion around the experimental density is used to obtain a non-iterative estimate of this error. This error metric breaks down whn dp/drho|T is very close to zero.

The iterate keyword argument can be used to turn on the iterative calculations, but they are much slower

temo.fit.cost_contributions.calc_errrho_devp(*, model, df, step=1)[source]

Deviation function from PVT data where the deviation is in pressure

Recommended for critical region where density deviations don’t make sense

temo.fit.cost_contributions.calc_errrhosat(model, df, *, step=1, Q)[source]

Deviation function for saturated liquid and/or vapor densities

temo.fit.cost_contributions.calc_errtracecrit(model, df, *, T0, rhovec0, errscheme, step=1)[source]

Deviation function from tracing critical curve

temo.fit.data_loaders module

temo.fit.data_loaders.load_B12(dataroot, identifier, identifiers, apply_skip=True, output_csv=None, verbosity=1, molar_masses=None, sep=',')[source]
temo.fit.data_loaders.load_CRIT(dataroot, identifier, identifiers, apply_skip=True, output_csv=None, verbosity=1, molar_masses=None, sep=',')[source]

Loader for critical point data

temo.fit.data_loaders.load_PVT(dataroot, *, identifier, identifiers, apply_skip=True, output_csv=None, molar_masses, verbosity=1, sep=',', empty_permitted=True)[source]

Loader for p-v-T data

temo.fit.data_loaders.load_PVT_P(dataroot, *, identifier, identifiers, apply_skip=True, output_csv=None, molar_masses, verbosity=1, sep=',')[source]

Loader for p-v-T data with pressure deviations

temo.fit.data_loaders.load_SOS(dataroot, *, apply_skip=True, identifier, identifiers, output_csv=None, molar_masses, verbosity=1, sep=',')[source]

Loader for speed of sound data

temo.fit.data_loaders.load_VLE(dataroot, identifier, identifiers, apply_skip=True, output_csv=None, verbosity=1, molar_masses=None, sep=',')[source]

Loader for VLE data

temo.fit.data_loaders.only_the_fluids(df, identifier, identifiers)[source]
temo.fit.data_loaders.read_and_subset(path, identifier, identifiers, apply_skip, sep=',')[source]

temo.fit.data_transforms module

temo.fit.mutant_factories module

temo.fit.mutant_factories.chunked_iterable(iterable, size)[source]
temo.fit.mutant_factories.get_mutant_Chebyshev2D(model, params, *, taumin: float, taumax: float, deltamin: float, deltamax: float, Ntau: int, Ndelta: int)[source]

Build a teqp-based Gaussian+exponential mutant from the model parameters params: iterable that contains the parameters in a flat iterable object

temo.fit.mutant_factories.get_mutant_Gaussian(model, params, d=None)[source]

Build a teqp-based Gaussian-bell-shaped mutant from the model parameters

Parameters:
  • model – The base model that is used to form the mutant

  • params (iterable) – iterable that contains the parameters in a flat iterable object

  • d (list, optional) – set of exponents on delta, optional

Term is of the form:

\[\begin{split}\\alpha^{\\rm r} = \\sum_{i} n_i\\tau^{t_i}\\delta^{d_i}\\exp(-\\eta_i(\delta-\\varepsilon_i)^2-\\beta_i(\\tau-\\gamma_i)^2)\end{split}\]

where the params populate the variables. Values of d are user-specified as a list, or follow the automatic logic in this function

temo.fit.mutant_factories.get_mutant_Gaussian_invariant(model, params, d=None)[source]

Build a teqp-based Gaussian-bell-shaped mutant from the model parameters and with an invariant reducing function

Parameters:
  • model – the base model that is used to form the mutant

  • params – iterable that contains the parameters in a flat iterable object

  • d – set of exponents on delta, optional

temo.fit.mutant_factories.get_mutant_doubleexponential(model, params, *, d=None, ld=None)[source]

Build a teqp-based double-exponential mutant from the model parameters

Parameters:
  • model – the base model that is used to form the mutant

  • params – iterable that contains the parameters in a flat iterable object

  • d – set of exponents on delta, optional

  • ld (list, optional) – set of exponents on delta in exponential, optional

temo.fit.mutant_factories.get_mutant_exponential(model, params, d=None, l=None)[source]

Build a teqp-based exponential mutant from the model parameters

Parameters:
  • model – The base model that is used to form the mutant

  • params (iterable) – iterable that contains the parameters in a flat iterable object

  • d (list, optional) – set of exponents on delta, optional

  • l (list, optional) – set of exponents on delta in exponential, optional

Term is of the form:

\[\alpha^{\rm r} = \sum_{i} n_i\tau^{t_i}\delta^{d_i}\exp(-\delta^{l_i})\]

where the params populate the n and t. Values of d and l are user-specified, or follow the automatic logic in this function

temo.fit.mutant_factories.get_mutant_exponentialGaussian(model, params, *, Npoly, Ngaussian, d=None, l=None, Nbg=4, bgindices=None)[source]

Build a teqp-based Gaussian+exponential mutant from the model parameters

Parameters:
  • model – The base model that is used to form the mutant

  • params (iterable) – iterable that contains the parameters in a flat iterable object

  • Npoly (int) – number of polynomial-like terms

  • Ngaussian (int) – number of Gaussian terms

  • d (list, optional) – set of exponents on delta, optional

  • l (list, optional) – set of exponents on delta in exponential, optional

  • Nbg (int, optional) – the number of beta and gamma parameters being fit, usually 4 to indicate that all four are being fit

  • bgindices (sequence, optional) – the indices {0: betaT, 1: gammaT, 2: betaV, 3: gammaV} to be fit

Term is of the form:

\[\begin{split}\\alpha^{\\rm r} = \\alpha^{\\rm r}_{\\rm G} + \\alpha^{\\rm r}_{\\rm P}\end{split}\]

with

\[\begin{split}\\alpha^{\\rm r}_{\\rm G} = \\sum_{i} n_i\\tau^{t_i}\\delta^{d_i}\\exp(-\\eta_i(\delta-\\varepsilon_i)^2-\\beta_i(\\tau-\\gamma_i)^2)\end{split}\]
\[\begin{split}\\alpha^{\\rm r}_{\\rm P} = \\sum_{i} n_i\\tau^{t_i}\\delta^{d_i}\\exp(-\\delta^{l_i})\end{split}\]

where the params populate the n and t. Values of d and l are user-specified, or follow the automatic logic in this function

temo.fit.spawn module

A convenience module for forking multiple processes and capturing stdout, for use in code developed for:

Ian H. Bell and Eric W. Lemmon, “Automatic fitting of binary interaction parameters for multi-fluid Helmholtz-energy-explicit mixture models”, 2016

No dependencies aside from standard libraries included in python

By Ian H. Bell, NIST (ian.bell@nist.gov)

LICENSE: public domain, but please reference paper

class temo.fit.spawn.Guppy(pipe_results, target, *args, **kwargs)[source]

Bases: Process

done()[source]
run()[source]

Method to be run in sub-process; can be overridden in sub-class

class temo.fit.spawn.RedirectText2Pipe(pipe_inlet, file_object=None, prefix='')[source]

Bases: object

An text output redirector

flush()[source]
write(string)[source]
class temo.fit.spawn.Spawner(inputs, Nproc_max=1)[source]

Bases: object

add_process()[source]

If an input is waiting in the queue and a slot has opened up, add the process

run()[source]
temo.fit.spawn.f(x)[source]

Module contents