pduq.uq_plot module¶

pduq.uq_plot.
get_phase_prob
(eq, phaseregL)¶ Get the probablities for the presence of the desired phase region specified by phaseregL.
 Parameters
eq (xarray object) – Structured equilibirum calculation containing a ‘sample’ dimension correspoinding to different parameter sets
phaseregL (tuple or list of str) – list of considered phases in equilibirum
 Returns
prob – Probabilities of nonzero phase fraction for the phase region of interest in the shape of the conditions for the equilibrium calculation.
 Return type
array
Examples
>>> import pickle >>> import pduq.uq_plot as uq >>> # load the collated equilibrium calculation for a single XTP >>> # point as produced by dbf_calc.eq_calc_samples >>> with open('single_point.pkl', 'rb') as buff: >>> eq = pickle.load(buff) >>> # define a set of phases in equilibrium to evaluate >>> phaseregL = ['FCC_A1', 'LIQUID'] >>> # calculate the probability of the set of phases having a >>> # nonzero phase fraction >>> print(uq.get_phase_prob(eq, phaseregL)) 0.2

pduq.uq_plot.
plot_dist
(eq, coordD, phaseregL, phase, typ, figsize=None)¶ Plot the distribution of a property for all parameter sets where the phases of interest are in equilibrium.
 Parameters
eq (xarray object) – Structured equilibirum calculation containing a ‘sample’ dimension correspoinding to different parameter sets
coorD (dict) – Dictionary with ‘T’ for temperature, ‘X_EL’ for the molar composition of element EL, and ‘component’ for the element to consider for the composition
phaseregL (tuple or list of str) – list of considered phases in equilibirum
phase (str) – Phase of interest. This must be specified, but only impacts the calculation for the NP and X properties
typ (str) – The quantity to plot. Available options are: NP: phase fraction X: molar composition of the selected component GM: molar Gibbs energy of the XTP point MU: chemical potential of the selected component
figsize (tuple or list of int or float, optional) – Plot dimensions in inches
 Returns
compL – 1D array with typ values for all parameter sets where only the phases in phaseregL are in equilibrium
 Return type
numpy array
Examples
>>> import pickle >>> import pduq.uq_plot as uq >>> # load the collated equilibrium calculation for a single XTP >>> # point as produced by dbf_calc.eq_calc_samples >>> with open('single_point.pkl', 'rb') as buff: >>> eq = pickle.load(buff) >>> # identify the XTP point of interest >>> coordD = {'T':1003, 'X_MG':.214, 'component':'MG'} >>> phaseregL = ['FCC_A1', 'LIQUID'] >>> phase = 'FCC_A1' >>> # plot the distribution of phase fractions for the selected >>> # phase in an equilibrium calculation with the phases >>> # considered in phaseregL. >>> uq.plot_dist(eq, coordD, phaseregL, phase, typ='NP')

pduq.uq_plot.
plot_property
(dbf, comps, phaseL, params, T, prop, config=None, datasets=None, xlim=None, xlabel=None, ylabel=None, yscale=None, phase_label_dict=None, unit='kJ/mol.', cdict=None, figsize=None)¶ Plot a property of interest versus temperature with uncertainty bounds for all phases of interest
 Parameters
dbf (Database) – Thermodynamic database containing the relevant parameters
comps (list) – Names of components to consider in the calculation
phaseL (list) – Names of phases to plot properties for
params (numpy array) – Array where the rows contain the parameter sets for the pycalphad equilibrium calculation
T (list, array or xarray object) – Temperature values at which to plot the selected property
prop (str) – property (or attribute in pycalphad terminology) to sample, e.g. GM for molar gibbs energy or H_MIX for the enthalpy of mixing
config (tuple, optional) – Sublattice configuration as a tuple, e.g. (“CU”, (“CU”, “MG”))
datasets (espei.utils.PickleableTinyDB, optional) – Database of datasets to search for data
xlims (list or tuple of float, optional) – List or tuple with two floats corresponding to the minimum and maximum molar composition of comp
xlabel (str, optional) – plot x label
ylabel (str, optional) – plot y label
yscale (int or float, optional) – scaling factor to apply to property (e.g. to plot kJ/mol. instead of J/mol. choose yscale to be 0.001)
phase_label_dict (dict, optional) – Dictionary with keys given by phase names and corresponding strings to use in plotting (e.g. to enable LaTeX labels)
unit (str, optional) – Unit to plot on the yaxis for the property of interest
cdict (dict, optional) – Dictionary with phase names and corresponding colors
figsize (tuple or list of int or float, optional) – Plot dimensions in inches
Examples
>>> import numpy as np >>> import pduq.uq_plot as uq >>> from pycalphad import Database >>> dbf = Database('CUMG_param_gen.tdb') >>> comps = ['MG', 'CU', 'VA'] >>> phaseL = ['CUMG2', 'LIQUID'] >>> params = np.loadtxt('params.npy')[: 1, :] >>> T = 650 >>> prop = 'GM' >>> # Plot the molar gibbs energy of all phases in phaseL >>> # versus molar fraction of MG at 650K. This will have >>> # uncertainty intervals generated by the parameter sets >>> # in params >>> uq.plot_property(dbf, comps, phaseL, params, T, prop)

pduq.uq_plot.
plot_binary
(eq, comp, alpha=None, cdict=None)¶ Plot a binary phase diagram. This purposefully has a minimal number of options so that the returned figure can be customized easily.
 Parameters
eq (xarray object) – Structured equilibirum calculation
comp (str) – Label for species to plot on the xaxis, e.g. MG for magnesium
alpha (float, optional) – Number between 0 and 1 for the line transparency
cdict (dict, optional) – Dictionary with phase names and corresponding colors
 Returns
compL – 1D array with typ values for all parameter sets where only the phases in phaseregL are in equilibrium
 Return type
numpy array
Examples
>>> import pickle >>> import pduq.uq_plot as uq >>> with open('single.pkl', 'rb') as buff: >>> eq = pickle.load(buff) >>> comp = 'MG' >>> # plot a binary phase diagram for a set of >>> # equilibrium calculations, and comp as the >>> # molar fraction on the xaxis >>> uq.plot_binary(eq, comp)

pduq.uq_plot.
plot_contour
(points, c='k', bw=0.3)¶ Plot as set of KDE probability density contours for a set of points, typically corresponding to invariant locations
 Parameters
points (numpy array) – an array of compositions and temperatures representing invariant points or some other phase diagram feature
c (color, optional) – color of the density contours
bw (float, optional) – KDE bandwidth
Examples
>>> import numpy as np >>> from pduq.invariant_calc import invariant_samples >>> from pduq.uq_plot import plot_contour >>> from pycalphad import Database >>> # load dbf file and raw parameter set. >>> dbf = Database('CUMG_param_gen.tdb') >>> params = np.loadtxt('trace.csv', delimiter=',') >>> # find the set of invariant points >>> Tv, phv, bndv = invariant_samples( >>> dbf, params, X=.2, P=101325, Tl=600, Tu=1400, >>> comp='MG') >>> # define the 'points' array >>> points = np.zeros((len(Tv, 2))) >>> points[:, 0] = bndv[:, 1] >>> points[:, 1] = Tv >>> # plot the contour >>> plt.figure() >>> uq.plot_contour(points)

pduq.uq_plot.
plot_phasefracline
(eq, coordD, xlabel=None, phase_label_dict=None, cdict=None, figsize=None)¶ Plot the phase fraction with uncertainty versus composition, temperature or pressure.
 Parameters
eq (xarray object) – Structured equilibirum calculation containing a ‘sample’ dimension correspoinding to different parameter sets
coordD (dict) – Dictionary defining constraints on the coordinates in eq for plotting the phase fraction with varying X, T or P For example, we might pick a fixed X and let T vary as follows: coordD = {‘X_MG’:0.1}
xlabel (str, optional) – Label for the xaxis
phase_label_dict (dict, optional) – Dictionary with keys given by phase names and corresponding strings to use in plotting (e.g. to enable LaTeX labels)
xlims (list or tuple of float, optional) – List or tuple with two floats corresponding to the minimum and maximum molar composition of comp
cdict (dict, optional) – Dictionary with phase names and corresponding colors
figsize (tuple or list of int or float, optional) – Plot dimensions in inches
Examples
>>> import pickle >>> import pduq.uq_plot as uq >>> with open('full.pkl', 'rb') as buff: >>> eq = pickle.load(buff) >>> # if for 'full.pkl' X_MG and T have 100 intervals each >>> # we can fix T and plot the phase fraction versus >>> # X_MG with uncertainty >>> coordD = {'T':1000} >>> # plot phase fraction versus X_MG >>> uq.plot_phasefracline(eq, coordD, xlabel='X_MG')

pduq.uq_plot.
plot_phasereg_prob
(eq, phaseregL, title=None, figname=None, coordplt=['X', 'T'], typ='grayscale', figsize=None)¶ Plot the probabilty of nonzero phase fraction for a combination of phases in equilibrium versus composition and temperature.
 Parameters
eq (xarray object) – Structured equilibirum calculation containing a ‘sample’ dimension correspoinding to different parameter sets
phaseregL (tuple or list of str) – list of considered phases in equilibirum
title (str, optional) – title of the plot
figname (str, optional) – name of the figure to differentiate plot windows
coordplt (tuple or list of str, optional) – list containing names of the axes
typ (str, optional) – plot type. This can either be ‘grayscale’ or ‘contour’
figsize (tuple or list of int or float, optional) – Plot dimensions in inches
Examples
>>> import pickle >>> import pduq.uq_plot as uq >>> with open('multiple.pkl', 'rb') as buff: >>> eq = pickle.load(buff) >>> phaseregL = ['FCC_A1', 'LIQUID'] >>> # plot the probability of nonzero phase >>> # fraction versus composition and temperature >>> # for the phase region in phaseregL >>> # based on the equilibrium calculations in eq >>> uq.plot_phasereg_prb(eq, phaseregL)

pduq.uq_plot.
plot_superimposed
(eq, comp, nsp=None, alpha=None, phase_label_dict=None, xlims=None, cdict=None, figsize=None)¶ Plot superimposed binary phase diagrams corresponding to multiple parameter sets
 Parameters
eq (xarray object) – Structured equilibirum calculation containing a ‘sample’ dimension correspoinding to different parameter sets
comp (str) – Label for species to plot on the xaxis, e.g. MG for magnesium
nsp (int, optional) – Number of phase diagrams to superimpose, with the maximum given by the number of samples in eq
alpha (float, optional) – Number between 0 and 1 for the line transparency
phase_label_dict (dict, optional) – Dictionary with keys given by phase names and corresponding strings to use in plotting (e.g. to enable LaTeX labels)
xlims (list or tuple of float, optional) – List or tuple with two floats corresponding to the minimum and maximum molar composition of comp
cdict (dict, optional) – Dictionary with phase names and corresponding colors
figsize (tuple or list of int or float, optional) – Plot dimensions in inches
Examples
>>> import pickle >>> import pduq.uq_plot as uq >>> with open('multiple.pkl', 'rb') as buff: >>> eq = pickle.load(buff) >>> comp = 'MG' >>> # plot the superimposed binary phase diagrams >>> # for all of the parameter sets represented by >>> # the equilibrium calculations in eq, with >>> # the molar fraction of MG on the xaxis >>> uq.plot_superimposed(eq, comp)

pduq.uq_plot.
plot_trace
(trace, plabelL=None, figsize=None, savefig=False)¶ For each parameter in the CALPHAD model, plot all of the MCMC chains vs iteration.
 Parameters
trace (array) – Array of parameters with the shape [nwalkers, nlinksT, npar], where nwalkers is the number of MCMC chains, nlinksT is the number of MCMC iterations, and npar is the number of CALPHAD parameters
plabelL (list, optional) – List of plot labels for the parameters
figsize (tuple or list of int or float, optional) – Plot dimensions in inches
savefig (bool, optional) – If savefig is True, plots will be automatically saved
Examples
>>> import numpy as np >>> import pduq.uq_plot as uq >>> trace = np.loadtxt('trace.csv', delimiter=',') >>> plabel = [r"$^{0}G_{CU \colon MG}^{Laves}$", >>> r"$^{0}L_{CU \colon MG}^{FCC}$", >>> ... >>> r"$^{0}L_{CU \colon MG}^{liquid}$"] >>> uq.plot_trace(trace, plabelL=plabelL, figsize=[5, 3])