carbatpy

Top-level package for carbatpy.

Submodules

Attributes

TREND

CB_DEFAULTS

Classes

Fluid

The Fluid class is used to set, get, and print states of a fluid with a given

FluidModel

Fluid model to be used Refprop or TREND

FluidState

The thermodynamic state of a fluid is stored here.

FlowDeviceOld

Unified themodynamic calculations for single flow devices, Old version

HeatExchanger

Static heat exchanger model for counterflow configurations.

Surrogate

Functions

init_fluid(fluid, composition, **keywords)

short way to define a Fluid and a FluidModel

Package Contents

carbatpy.TREND[source]
carbatpy.CB_DEFAULTS[source]
class carbatpy.Fluid(fluidmodel, composition=None, option=1)[source]

The Fluid class is used to set, get, and print states of a fluid with a given

model (e.g. RefProp). The compounds are set in the fluidmodel, while the composition is also set here. The calculated values depend also on carbatpy.CB_DEFAULTS[“Fluid_Defaults”][“Property_Names_Short”].

Generate a Fluid instance

a FluidModel instance, the composition and an unused option has to be passed.

Parameters:
  • fluidmodel (FluidModel) – the instance of the property model to be used.

  • composition (list, optional) – mole fractions of all compounds. The default is [1.0].

  • option (TYPE, optional) – unused. The default is 1.

Return type:

None.

fluidmodel
composition
properties = None
state_v = None
option = 1
no_compounds
comp_mass
herr = 0
props
val_dict
set_composition(composition, **kwargs)[source]

Mole fractions are set and mass fractions are calculated.

Sets the self.composition used in the Fluid settings and the self.comp_mass TREND needs the mass fractions for specific (/kg) calculations. Thus calc_mass_fraction() is called.

Parameters:
  • composition (list/numpy.array) – mole fractions must sum up to 1.

  • kwargs (dictionary, optional.) –

    • verbose : boolean, optional. Generate additional printig. The default is False.

Return type:

None.

calc_mass_fraction()[source]

mole to mass fractions for TREND

calc_mole_fraction(comp_mass)[source]

needed for x_liq and y_vap in TREND, therefore mass fraction passed as function argument.

set_state(values, given='TP', wanted=_THERMO_STRING, composition=None, **kwargs)[source]

Sets the state of a fluid and calculates the wanted properties.

Parameters:
  • values (list[2]) – the two state parameter values.

  • given (String, optional) – What are the two values (T,P,H,S,Q,V). The default is “TP”.

  • wanted (String, optional) – Which parameters shall be calculated? The default is _THERMO_STRING.

  • composition (list, optional) – mole fraction of each compound, must sum up to 1. When empty, the last/actual value will be used. The default is [].

  • kwargs (dictionary, optional) –

    dll_selectstr, optional

    is passed to Refprop. The standard value is “2dll” using the faster REFPROP2dll function, not calculating the composition of different phases. The alternative “dll” is slower but does it. Throughout it is expected that compoitions are mole fractions and qualities in mass/mass.

    i_massint (0/1), optional

    should not be used, not tested.

    i_flagint (0/1), optional

    should not be used, not tested.

    verboseBoolean, optional

    leads to additional (printing) output. The default value is False.

    outputString, optional

    what shall be the return value, the “state” as list or an instance of the “FluidState”. default is “state”

Raises:

Exception – DESCRIPTION.

Returns:

DESCRIPTION.

Return type:

TYPE

calc_q_mass(q, liq_x, liq_y)[source]
set_state_v(values, given='TP', wanted=_THERMO_STRING, **kwargs)[source]

set many Fluid states with the values given as array(vector)

Parameters:
  • values (numpy.array((N,2))) – the N value pairs to fix the states.

  • given (String, optional) – what are the input values?(T,P, Q, S,…). The default is “TP”.

  • wanted (String, optional) – with all the outputs wanted. The default is _THERMO_STRING.

  • kwargs (dictionary optional) – This is optional and passed to REFPROP or TREND, depending on the props settings / chosen property model. (see set_state())

Returns:

output – all the wanted properties for the N inputs.

Return type:

numpy.array(N, n_wanted)

print_state()[source]

Print the actual state of the Fluid

calc_temp_mean(h_final)[source]

Calculate the thermodynamic mean temperature between the actual state

and the final enthalpy along an isobaric (Delta h /Delta s)

Parameters:

h_final (float) – enthalpy of he final stat.

Returns:

temp_mean – the thermodynamic mean temperature.

Return type:

float

class carbatpy.FluidModel(fluid, composition=[1], **kwargs)[source]

Fluid model to be used Refprop or TREND

Only model, chemical compunds units and for TREND some more values are set here. The mixture composition, state etc. is set in Fluid.

For Class Fluidmodell a fluid (mixture) must be defined, the evaluation takes place with props, units can be set and an instance can be set, the latter is important, if more than one fluid is used. For Refprop: Initiates new instance for each fluid (mixture).

Parameters:
  • fluid (String) – as defined in the props (Model), for RefProp it is “fluid1 * fluid2 * fluid3”.

  • composition (array) – of working fluid (mixture), at this level only used for TREND

  • **kwargs (dict) –

    units, props, rp_inst, eos_ind, mix_ind, trendmodel, props_func (see dataclass FluidModelDefaults). For props=”CUSTOM”, props_func must be a callable with signature:

    func(values, given) -> list[T, P, H, V, S, Q, U, ...]
    

    returning SI values (K, Pa, J/kg, m³/kg, J/kg/K, -, J/kg).

Return type:

None.

fluid
props = 'REFPROP'
units = 21
fluid_to_list()[source]

Converts the fluid names string from Refprop to a list for TREND

Returns:

the fluid names in a list.

Return type:

List of strings

class carbatpy.FluidState(state, what, **kwargs)[source]

The thermodynamic state of a fluid is stored here.

Which properties (T,p,h,v,s,q,…), depends on: carbatpy.CB_DEFAULTS[“Fluid_Defaults”][“Property_Names_Short”]

props
verbose
liq_x
vap_y
total_z
state
state_to_dict()[source]

Convert the state properties to a dictionary name:value.

carbatpy.init_fluid(fluid, composition, **keywords)[source]

short way to define a Fluid and a FluidModel

Parameters:
  • fluid (string) – The species within the fluid.

  • composition (List) – mole fraction for each fluid.

  • **keywords (TYPE) – all keywords needed for the FluidModel, if non-defaults shall be set.

Returns:

actual_fluid – Instance of the actually set Fluid.

Return type:

Fluid

class carbatpy.FlowDeviceOld(fluid, p_out, m_dot, device_type='machine', **kwargs)[source]

Unified themodynamic calculations for single flow devices, Old version

Calculate the output state and state changes for single flow devices

Parameters:
  • fluid (cb.Fluid) – The fluid at is entering state.

  • p_out (float) – Output pressure in Pa.

  • m_dot (float) – mass flow rate in kg/s.

  • device_type (TYPE, optional) – ‘machine’ for compressor/expander, ‘pump’, or ‘throttle’. The default is “machine”.

  • **kwargs

    Optional parameters for setting the configuration and parameters

    • plot infodictionary,optional, default value is {} contains a Figure, an

      Axes, a list of What shall be plotted, a list with the colour/styles and a list with the labels must be passed. in “what”, the two numbers coincide with the fluid THERMO order. The x-shift can be used in cycle calculations, to shift the curves, by the value (it will be added). The names in the dictionary are: “fig”, “ax”, “what”,”col”, “label”, “x-shift”.

    • namestring, optional, the name of this specific device, the default is

      ”compressor”.

    • calc_typestring, optional, which method shall be used (e.g.: “const_eta”,

      ”const_h”), default is “const_eta”.

    • calc_parametersdictionary, optional, if further parameters have to be

      given for the calculation. the default is None.

    • verbose : Boolean, optional, the default is False.

Return type:

None.

fluid
p_out
m_dot
device_type = 'machine'
plot_info
name
calc_type
calc_parameters
verbose
warning = 0
warning_message = 'All o.k.'
input
output = None
property all
to_dict()[source]
compressor()[source]

compressor or expander output state calculation

so far only for a constant isentropic efficiency, according to the pressure change an expansion or compression is detected and handled.

Parameters:
  • p_out (float) – output pressure.

  • eta_s (float) – isentropic efficiency.

  • fluid (cb.Fluid) – entering fluid, including properties, composition, and model.

  • m_dot (float, optional) – mass flow rate (in kg/s). Default is 1

  • calc_type (string, optional) – how to calculate, so far, only one implemented. The default is “const_eta”.

  • name (string, optional) – name of the device. The default is “compressor”.

  • plot_info (dictionary, optional) – if not empty a Figure, an Axes, a list of What shall be plotted, a list with the colour/styles and a list with the labels must be passed. in “what”, the two numbers coincide with the fluid THERMO order. The x-shift can be used in cycle calculations, to shift the curves, by the value (it will be added). The names in the dictionary are: “fig”, “ax”, “what”,”col”, “label”, “x-shift”. Default is empty.

Returns:

  • state_out (array of float) – compressor output state containing [T,p,h,v,s,q].

  • work_specific (float) – work per kg of fluid, positive for compressor; units:J/kg.

pump()[source]

Calculate the exit state of a pump assuming an incompressible fluid.

Only formulated for constant isentropic efficiency

Parameters:
  • p_out (float) – output pressure.

  • eta_s (float) – isentropic efficiency.

  • fluid (fprop.Fluid) – entering fluid, including properties, composition, and model.

  • m_dot (float, optional) – mass flow rate (in kg/s). Default is 1

  • calc_type (string, optional) – how to calculate, so far, only one implemented. The default is “const_eta”.

  • name (string, optional) – name of the device. The default is “pump”.

  • plot_info (dictionary, optional) – if not empty a Figure, an Axes, a list of What shall be plotted, a list with the colour/styles and a list with the labels must be passed. in “what”, the two numbers coincide with the fluid THERMO order. The x-shift can be used in cycle calculations, to shift the curves, by the value (it will be added). The names in the dictionary are: “fig”, “ax”, “what”,”col”, “label”, “x-shift”. Default is empty.

Returns:

  • state_out (array of float) – compressor output state containing [T,p,h,v,s,q].

  • work_specific (float) – work per kg of fluid, positive for compressor; units:J/kg.

throttle()[source]

throttle output state calculation

so far only for a constant enthalpy

Parameters:
  • p_out (float) – output pressure.

  • fluid (fprop.Fluid) – entering fluid, including properties, composition, and model.

  • m_dot (float, optional) – mass flow rate (in kg/s). Default is 1

  • calc_type (string, optional) – how to calculate, so far, only one implemented. The default is “const_h”.

  • name (string, optional) – name of the device. The default is “throttle”.

  • plot_info (dictionary, optional) – if not empty a Figure, an Axes, a list of What shall be plotted, a list with the colour/styles and a list with the labels must be passed. in “what”, the two numbers coincide with the fluid THERMO order. The x-shift can be used in cycle calculations, to shift the curves, by the value (it will be added). The names in the dictionary are: “fig”, “ax”, “what”,”col”, “label”, “x-shift”. Default is empty.

Returns:

state_out – compressor output state containing [T,p,h,v,s,q].

Return type:

array of float

plot_temp_h_flow()[source]

plotting a T-H-dot diagram for simple flows (compressor, throttle etc.)

Parameters:
  • _state_in (np.array) – entering state [T,p,h,v,s,…].

  • _state_out (np.array) – exiting state.

  • _m_dot (float) – mass flow rate (kg/s).

  • _plot_info (dictionary) – if not empty a Figure, an Axes, a list of What shall be plotted, a list with the colour/styles and a list with the labels must be passed. in “what”, the two numbers coincide with the fluid THERMO order. The x-shift can be used in cycle calculations, to shift the curves, by the value (it will be added). The names in the dictionary are: “fig”, “ax”, “what”,”col”, “label”, “x-shift”.

Return type:

None.

print_device()[source]
state_w_p()[source]
class carbatpy.HeatExchanger(fluids, inlet_states, mdot, resolution, ht_method, pl_method)[source]

Static heat exchanger model for counterflow configurations.

Supports double-pipe and monoblock geometries. Heat exchanger profiles are computed by integrating coupled enthalpy and pressure ODEs along the tube length using scipy.integrate.solve_ivp.

Two inlet-state conventions are available:

  • One-side IVP (calc_IVP_one_side()): Both inlet states are provided for the same side (inlet–outlet pair). Avoids the internal root-finding step and is the recommended approach.

  • Two-side IVP (calc_IVP()): True counterflow setup — inlet states are given for both fluid inlets (left and right end). Requires an internal root-find to determine the unknown starting conditions.

Geometry Options

  • Double-pipe (geo_double_pipe()): Annular secondary-fluid channel around an inner tube carrying the working fluid.

  • Monoblock (geo_monoblock()): Two parallel tubes embedded in a solid conductive block. Thermal coupling is via the block material, using the VDI Heat Atlas shape factor for two eccentric cylinders.

param fluids:

Two-element list [working_fluid, secondary_fluid]. Each fluid must expose a set_state method compatible with carbatpy.fprop.

type fluids:

list of fluid objects

param inlet_states:

Two-element list [state_in_wf, state_in_sf]. Each state is the standard carbatpy property array (T, p, h, v, s, q, u, …).

type inlet_states:

list of array_like

param mdot:

Two-element list [mdot_wf, mdot_sf]. Mass flow rates in kg/s.

type mdot:

list of float

param resolution:

Number of spatial evaluation points along the heat exchanger length.

type resolution:

int

param ht_method:

Heat transfer correlation for the working fluid passed to heat_transfer.alpha_km. Example: "Deng_et_al-2019".

type ht_method:

str

param pl_method:

Pressure-loss correlation for the working fluid passed to heat_transfer.alpha_km. Example: "Macdonald_et_al-2016".

type pl_method:

str

state_array_wf

Fluid-property states along the heat exchanger for the working fluid.

Type:

ndarray, shape (n, n_props)

state_array_sf

Fluid-property states along the heat exchanger for the secondary fluid.

Type:

ndarray, shape (n, n_props)

x

Axial positions [m] corresponding to the state arrays.

Type:

ndarray

alpha_wf

Local heat transfer coefficients of the working fluid [W/(m²·K)].

Type:

list of float

alpha_sf

Local heat transfer coefficients of the secondary fluid [W/(m²·K)].

Type:

list of float

dpdl_wf

Local pressure-loss gradients of the working fluid [Pa/m].

Type:

list of float

dpdl_sf

Local pressure-loss gradients of the secondary fluid [Pa/m].

Type:

list of float

termination_flag

Name of the termination-event function that stopped the ODE solver, or None if the solver reached the end of the integration interval.

Type:

str or None

termination_position

Axial position [m] at which termination occurred, or None.

Type:

float or None

Examples

Double-pipe condenser solved with the one-side IVP method:

>>> import carbatpy as cb
>>> from class_he import HeatExchanger
>>> fluid1 = cb.init_fluid("Butane * CO2", [0.8, 0.2])
>>> fluid2 = cb.fprop.init_fluid("water", [1])
>>> st1_in = fluid1.set_state([3e6, 1], "PQ")
>>> st2_in = fluid2.set_state([st1_in[0] - 10, 3e5], "TP", cb.fprop._TRANS_STRING)
>>> he = HeatExchanger(
...     fluids=[fluid1, fluid2],
...     inlet_states=[st1_in, st2_in],
...     mdot=[0.01, 0.01],
...     resolution=40,
...     ht_method="Deng_et_al-2019",
...     pl_method="Macdonald_et_al-2016",
... )
>>> he.geo_double_pipe(16e-3, 18e-3, 22e-3, 40e-3, 40, 15.4)
>>> he.calc_IVP_one_side(case="wf_condensed")
>>> he.diagram()

See also

heat_transfer

Heat transfer and pressure-loss correlations used internally by thermal_resistance().

fluids
input_state_wf
input_state_sf
mdot_wf
mdot_sf
resolution
dT_wall = 5
ht_method
pl_method
geo_monoblock(d_wf, d_sf, r, l, lam_block)[source]

Set monoblock heat exchanger geometry.

Two parallel circular tubes are embedded in a solid conductive block. The thermal coupling between them is computed via the VDI Heat Atlas (2013) shape factor for two cylinders in an infinite medium (Table E1-3).

Parameters:
  • d_wf (float) – Inner diameter of the working-fluid tube [m].

  • d_sf (float) – Inner diameter of the secondary-fluid tube [m].

  • r (float) – Centre-to-centre distance between the two tubes [m].

  • l (float) – Length of the block (and tubes) [m].

  • lam_block (float) – Thermal conductivity of the block material [W/(m·K)].

Notes

The conduction shape factor for two cylinders in an infinite medium (VDI Heat Atlas 2013, E1 Table 3) is:

\[S = \frac{2\pi}{\mathrm{arccosh}\! \left(\frac{r^2 - r_{wf}^2 - r_{sf}^2} {2\, r_{wf}\, r_{sf}}\right)}\]

where \(r_{wf} = d_{wf}/2\) and \(r_{sf} = d_{sf}/2\).

geo_double_pipe(di, Di, da, Da, l, lam_tube)[source]

Set double-pipe heat exchanger geometry.

The working fluid flows through the inner tube; the secondary fluid flows counter-currently through the annular gap between inner and outer tube.

Parameters:
  • di (float) – Inner diameter of the inner tube (working-fluid side) [m].

  • Di (float) – Outer diameter of the inner tube [m].

  • da (float) – Inner diameter of the outer tube (secondary-fluid side) [m].

  • Da (float) – Outer diameter of the outer tube [m].

  • l (float) – Length of the pipe section [m].

  • lam_tube (float) – Thermal conductivity of the inner-tube wall material [W/(m·K)].

Notes

The total heat transfer area referenced to the inner tube surface is set to \(A = \pi d_i l\).

The thermal resistance network (per unit length) is:

\[R_{tot} = \underbrace{\frac{1}{\alpha_{sf}\, \pi D_i}}_{R_{sf}} + \underbrace{\frac{\ln(D_i/d_i)}{2\pi\lambda_{tube}}}_{R_{tube}} + \underbrace{\frac{1}{\alpha_{wf}\, \pi d_i}}_{R_{wf}}\]

Examples

>>> he.geo_double_pipe(16e-3, 18e-3, 22e-3, 40e-3, 40, 15.4)
calc_IVP_one_side(verbose=False, wf_outlet=False, case=None, stop_value=0)[source]

Calculate the heat exchanger by integrating the governing ODEs.

Both inlet states must be provided for the same physical side of the heat exchanger (i.e. an inlet–outlet pair, not two true inlets). The wf_outlet flag controls which end of the domain is used as the working-fluid inlet.

This is the recommended calculation method because it avoids the internal root-finding step required by calc_IVP().

Parameters:
  • verbose (bool, default=False) – If True, print the solver status message.

  • wf_outlet (bool, default=False) –

    Flow-direction flag.

    • False: working-fluid inlet is at \(x = 0\).

    • True: working-fluid inlet is at \(x = l\) (outlet side).

  • case (str or None, default=None) –

    Optional early-termination criterion. Supported values:

    • 'sf_temperature_min' – stop when secondary-fluid temperature falls below stop_value [K].

    • 'sf_enthalpy_min' – stop when secondary-fluid enthalpy falls below stop_value [J/kg].

    • 'wf_enthalpy_min' – stop when working-fluid enthalpy falls below stop_value [J/kg].

    • 'wf_enthalpy_max' – stop when working-fluid enthalpy exceeds stop_value [J/kg].

    • 'wf_condensed' – stop when working fluid is fully condensed (vapour quality ≤ saturated-liquid enthalpy).

    • 'wf_evaporated' – stop when working fluid is fully evaporated (vapour quality ≥ saturated-vapour enthalpy).

  • stop_value (float, default=0) – Threshold value used by the selected case. Unit depends on the chosen case (K or J/kg).

Returns:

Results are stored in state_array_wf, state_array_sf, x, alpha_wf, alpha_sf, dpdl_wf, dpdl_sf, termination_flag, and termination_position.

Return type:

None

Examples

>>> he.geo_double_pipe(16e-3, 18e-3, 22e-3, 40e-3, 40, 15.4)
>>> he.calc_IVP_one_side(verbose=True, case="wf_condensed")
>>> print(he.termination_flag)
calc_IVP(verbose=False, case=None, stop_value=0)[source]

Calculate the heat exchanger using true counterflow inlet conditions.

Note

Not recommended. Use calc_IVP_one_side() instead, which avoids the internal root-finding step and is more robust.

Inlet states must be the true inlet states for both fluids — one at each end of the heat exchanger. An internal scipy.optimize.root call iterates on the unknown secondary-fluid state at \(x = 0\) until the prescribed secondary-fluid inlet condition at \(x = l\) is matched.

Parameters:
  • verbose (bool, default=False) – If True, print the root-finder result and solver status.

  • case (str or None, default=None) – Optional early-termination criterion (see calc_IVP_one_side() for supported values).

  • stop_value (float, default=0) – Threshold for the selected case.

Returns:

Results are stored in state_array_wf, state_array_sf, x, alpha_wf, alpha_sf, dpdl_wf, and dpdl_sf.

Return type:

None

Raises:

ValueError – If the root-finder does not converge.

thermal_resistance(state_wf_x, state_sf_x)[source]

Calculate the local total thermal resistance and pressure-loss gradients.

Dispatches to the correct resistance model based on self.geo_flag ("double_pipe" or "monoblock"), appends the local heat transfer coefficients and pressure-loss gradients to the instance lists, and updates self.dT_wall.

Parameters:
  • state_wf_x (array_like) – Local carbatpy property array of the working fluid (T, p, h, …).

  • state_sf_x (array_like) – Local carbatpy property array of the secondary fluid (T, p, h, …).

Returns:

  • R_ges (float) – Total thermal resistance per unit length [(m·K)/W].

  • dp_wf (float) – Pressure-loss gradient of the working fluid [Pa/m].

  • dp_sf (float) – Pressure-loss gradient of the secondary fluid [Pa/m].

Notes

Double-pipe resistance network (per unit length):

\[R_{tot} = \frac{1}{\alpha_{sf}\,\pi D_i} + \frac{\ln(D_i/d_i)}{2\pi\lambda_{tube}} + \frac{1}{\alpha_{wf}\,\pi d_i}\]

Monoblock resistance network (per unit length):

\[R_{tot} = \frac{1}{\alpha_{sf}\,\pi d_{sf}} + \frac{1}{\lambda_{block}\, S} + \frac{1}{\alpha_{wf}\,\pi d_{wf}}\]

with the VDI shape factor \(S\) from geo_monoblock().

diagram(ordinate=0, second_yaxis=False, save_dir=None, show_plot=False)[source]

Plot fluid-property profiles along the heat exchanger length.

The abscissa is the axial coordinate \(x\) [m]. The ordinate is selected by index, matching the column order of state_array_wf / state_array_sf:

  • 0: Temperature [K]

  • 1: Pressure [Pa]

  • 2: Specific enthalpy [J/kg]

  • 3: Specific volume [m³/kg]

  • 4: Specific entropy [J/(kg·K)]

  • 5: Vapour quality [–]

  • 6: Specific internal energy [J/kg]

  • 7: Dynamic viscosity [Pa·s]

  • 8: Thermal conductivity [W/(m·K)]

  • 9: Prandtl number [–]

  • 10: Kinematic viscosity [m²/s]

  • 11: Molar mass [kg/mol]

  • 12: Speed of sound [m/s]

Parameters:
  • ordinate (int, default=0) – Column index of the property to plot (see list above).

  • second_yaxis (bool, default=False) – If True, working and secondary fluid are plotted on separate y-axes (useful when the two fluids have very different scales).

  • save_dir (str or None, default=None) – Directory path for saving the figure as a PNG file. If None, the figure is only displayed.

  • show_plot (bool, default=False) – If “True”, plots are shown.

Return type:

None

Examples

>>> he.calc_IVP_one_side()
>>> he.diagram()                        # temperature profile
>>> he.diagram(ordinate=1, second_yaxis=True)  # pressure, dual axes
>>> he.diagram(ordinate=2, save_dir=r"C:/results")  # save enthalpy plot
calculate_arrays(save_dir=None)[source]

Export calculation results to CSV files and a termination-event log.

Writes three files to save_dir:

  • wf.csv: Working-fluid state array with columns T, p, h, v, s, q, u, alpha_wf, dpdl_wf, tcx, vis. tcx and vis are the saturated-liquid thermal conductivity and viscosity where the vapour quality is ≥ 0; otherwise 0.

  • sf.csv: Secondary-fluid state array with columns T, p, h, v, s, q, u, eta, tcx, Pr, cp, ws, M, alpha_sf, dpdl_sf.

  • termination_event.txt: Plain-text log of termination_flag and termination_position.

Parameters:

save_dir (str) – Absolute path to an existing directory where the files will be saved.

Returns:

  • df_wf (DataFrame)

  • df_wf (DataFrame)

class carbatpy.Surrogate(title)[source]
title
train_surrogate(DF, features_list, targets_list, split=0.2, random_state=42, hypo='def_hyperparameter.yaml', verbose=False)[source]

train MLP surrogate from dataframe with chosen features and targets, uses minmaxscaler and ‘r2’, ‘neg_root_mean_squared_error’ for scoring, the latter for refitting

Parameters:
  • DF (TYPE) – DESCRIPTION.

  • features_list (TYPE) – DESCRIPTION.

  • targets_list (TYPE) – DESCRIPTION.

  • split (TYPE, optional) – DESCRIPTION. The default is 0.2.

  • random_state (TYPE, optional) – DESCRIPTION. The default is 42.

  • hypo (TYPE, optional) – DESCRIPTION. The default is “def_hyperparameter.yaml”.

Returns:

  • Y_test (TYPE DataFrame) – DESCRIPTION. test targets

  • Y_pred (TYPE) – DESCRIPTION. predicted targets

save(path='default')[source]

save model

Parameters:

path (TYPE, optional) – DESCRIPTION. The default is CARBATPY_RES_DIR

Return type:

None.

load(path)[source]
predict(DF_new_x)[source]

use existing surrogate to predict new data

Parameters:

DF_new_x (TYPE) – DESCRIPTION.

Raises:

ValueError

DESCRIPTION. needs to contain features of model

DESCRIPTION. does not extrapolate

Returns:

  • y (TYPE) – DESCRIPTION. target results

  • DF_y (TYPE) – DESCRIPTION. target results