pycalphad.plot.binary package#

Submodules#

pycalphad.plot.binary.compsets module#

class pycalphad.plot.binary.compsets.BinaryCompset(phase_name, temperature, indep_comp, composition, site_fracs)[source]#

Bases: object

Composition set for representations of a phase equilibria in a two component system with a temperature condition.

Parameters:
  • phase_name (str) – Name of phase

  • temperature (float) – Temperature corresponding the the calculation

  • indep_comp (str) – Name of the independent component

  • composition (float) – Mole fraction of the independent component

  • site_fracs (np.ndarray) – Array of floats corresponding to the site fractions.

Notes

In the future, this representation could be phased out if equilibrium returned composition sets.

SITE_FRAC_ATOL = 0.001#
TEMPERATURE_ATOL = 0.1#
classmethod from_dataset_vertices(ds, indep_comp, indep_comp_idx, num_vertex)[source]#
class pycalphad.plot.binary.compsets.CompsetPair(compsets)[source]#

Bases: object

Pair of binary composition sets that make up an equilibrium

Parameters:

compsets (list of BinaryCompset) –

compsets#

CompSets sorted by composition

Type:

list of BinaryCompset

a#

Composition set in the pair with the lower composition

Type:

BinaryCompset

b#

Composition set in the pair with the higher composition

Type:

BinaryCompset

phases#

List of phase names, sorted by composition

Type:

list of str

unique_phases#

Set of phase names

Type:

set of str

compositions#

Array of compositions, sorted

Type:

np.ndarray

temperature#

Temperature of the 2D compsets

Type:

float

same_phase#

Whether the composition sets are for the same phase

Type:

bool

mean_composition#

Mean composition of the CompSets

Type:

float

max_composition#

Max composition of the CompSets

Type:

float

min_composition#

Min composition of the CompSets

Type:

float

Tdiscrepancy(other)[source]#

Calculate the temperature discrepancy (absolute difference) between this pair of composition sets and another.

Parameters:

other (CompsetPair) –

Return type:

np.float64

pairwise_xdiscrepancy(other)[source]#

Compute the ordered composition discrepancy between this and another pair of CompSet2D objects.

Parameters:

other (CompsetPair) –

Return type:

float

xdiscrepancy(ignore_phase=False)[source]#

Calculate the composition discrepancy (absolute difference) between this composition set and another.

Parameters:

ignore_phase (bool) – If False, unlike phases will give infinite discrepancy. If True, we only care about the composition and the real discrepancy will be returned.

Return type:

np.float64

ydiscrepancy()[source]#

Calculate the discrepancy (absolute differences) between the site fractions of the composition sets as an array of discrepancies.

Return type:

Array of np.float64

Notes

The phases must match for this to be meaningful.

ydiscrepancy_max()[source]#

Calculate the maximum discrepancy (absolute difference) between the site fractions of the composition sets.

Return type:

np.float64

Notes

The phases must match for this to be meaningful.

pycalphad.plot.binary.compsets.find_two_phase_region_compsets(hull, temperature, indep_comp, indep_comp_idx, misc_gap_tol=0.1, minimum_composition=None)[source]#

From a 1D convex hull at constant T and P, return the composition sets for a two phase region or that have the smallest index composition coordinate

Parameters:
  • hull (EquilibriumResult) – Equilibrium-like from pycalphad that has a Phase Data variable.

  • temperature (float) – Temperature that the calculation was performed at

  • indep_comp (str) – Name of the independent component

  • indep_comp_idx (str) – Index of the independent component in the the sorted pure elements

  • misc_gap_tol (float) – If any site fractions are different by at least this amount, the composition sets are considered distinct and in a miscibility gap.

  • minimum_composition (float) – Minimum composition in the convex hull to search for composition sets

Return type:

CompsetPair

pycalphad.plot.binary.compsets.get_compsets(eq_dataset, indep_comp=None, indep_comp_index=None)[source]#

Return a CompSet2D object if a pair of composition sets is found in an equilibrium dataset. Otherwise return None.

Parameters:
  • eq_dataset

  • indep_comp

  • indep_comp_index

Return type:

CompsetPair

pycalphad.plot.binary.map module#

pycalphad.plot.binary.map.map_binary(dbf, comps, phases, conds, eq_kwargs=None, calc_kwargs=None, boundary_sets=None, verbose=False, summary=False)[source]#

Map a binary T-X phase diagram

Parameters:
  • dbf (Database) –

  • comps (list of str) –

  • phases (list of str) – List of phases to consider in mapping

  • conds (dict) – Dictionary of conditions

  • eq_kwargs (dict) – Dictionary of keyword arguments to pass to equilibrium

  • verbose (bool) – Print verbose output for mapping

  • boundary_sets (ZPFBoundarySets) – Existing ZPFBoundarySets

Return type:

ZPFBoundarySets

Notes

Assumes conditions in T and X.

Simple algorithm to map a binary phase diagram in T-X. More or less follows the algorithm described in Figure 2 by Snider et al. [1] with the small algorithmic improvement of constructing a convex hull to find the next potential two phase region.

For each temperature, proceed along increasing composition, skipping two over two phase regions, once calculated. [1] J. Snider, I. Griva, X. Sun, M. Emelianenko, Set based framework for Gibbs energy minimization, Calphad. 48 (2015) 18-26. doi: 10.1016/j.calphad.2014.09.005

pycalphad.plot.binary.plot module#

The plot module handles plotting ZPF boundaries and provides a user-facing function binplot for users to plot binary phase diagrams with a similar API as equilibrium.

pycalphad.plot.binary.plot.binplot(database, components, phases, conditions, plot_kwargs=None, **map_kwargs)[source]#

Calculate the binary isobaric phase diagram.

This function is a convenience wrapper around map_binary() and plot_boundaries()

Parameters:
  • database (Database) – Thermodynamic database containing the relevant parameters.

  • components (list) – Names of components to consider in the calculation.

  • phases (list) – Names of phases to consider in the calculation.

  • conditions (dict) – Maps StateVariables to values and/or iterables of values. For binplot only one changing composition and one potential coordinate each is supported.

  • eq_kwargs (dict, optional) – Keyword arguments to use in equilibrium() within map_binary(). If eq_kwargs is defined in map_kwargs, this argument takes precedence.

  • map_kwargs (dict, optional) – Additional keyword arguments to map_binary().

  • plot_kwargs (dict, optional) – Keyword arguments to plot_boundaries().

Returns:

Matplotlib Axes of the phase diagram

Return type:

Axes

Examples

None yet.

pycalphad.plot.binary.plot.plot_boundaries(zpf_boundary_sets, tielines=True, tieline_color=(0, 1, 0, 1), scatter=True, legend_generator=<function phase_legend>, ax=None, gridlines=False)[source]#

Plot a set of ZPFBoundarySets

Parameters:
  • zpf_boundary_sets (pycalphad.mapping.zpf_boundary_sets.ZPFBoundarySets) –

  • tielines (optional, bool) – Whether the plot the tielines (defaults to True)

  • tieline_color (color) – A valid matplotlib color, such as a named color string, hex RGB string, or a tuple of RGBA components to set the color of the two phase region tielines. The default is an RGBA tuple for green: (0, 1, 0, 1).

  • scatter (optional, bool) – Whether to use scatter plot the phase boundaries (True, the default) or to connect lines in the same two phase region by lines. Note that lines may appear broken when the set of phases change, even if the boundary does not change.

  • legend_generator (Callable) – A function that will be called with the list of phases and will return legend labels and colors for each phase. By default pycalphad.plot.utils.phase_legend is used

  • ax (plt.Axes) – Matplotlib axes to plot to. If none are pasesed, a new figure will be created.

  • gridlines (False) – Whether to plot the grid lines in the plot. Defaults to False.

Return type:

plt.Axes

pycalphad.plot.binary.zpf_boundary_sets module#

class pycalphad.plot.binary.zpf_boundary_sets.TwoPhaseRegion(initial_compsets)[source]#

Bases: object

A group of points that belong to the same phase region.

phases#

Unique phases in this two phase region

Type:

frozenset

compsets#
Type:

list of CompsetPair

add_compsets(compset_pair)[source]#

Add composition sets to this region.

Parameters:

pair (CompsetPair) – Add a CompsetPair to the list of composition sets

Notes

For performance reasons (checking whether the CompsetPair belongs has a complexity of O(N)), users are responsible for determining if the compsets belong in this TwoPhaseRegion.

compsets_belong_in_region(compsets, Xtol=0.05, Ttol=10)[source]#

Return True if the composition sets belong to this TwoPhaseRegion

Parameters:
  • compsets (CompsetPair) –

  • Xtol (float) – Composition discrepancy tolerance

  • Ttol (float) – Temperature discrepancy tolerance

Return type:

bool

Notes

A new CompsetPair object belongs in the this region if, when compared to the most recently added CompsetPair:

  1. All the phases are the same (in the same order)

  2. The composition discrepancies between BinaryCompsets of the same phase are below Xtol

  3. The temperature discrepancy between the CompsetPairs is below Ttol

class pycalphad.plot.binary.zpf_boundary_sets.ZPFBoundarySets(comps, indep_composition_condition)[source]#

Bases: object

Holds CompsetPairs that can be organized into TwoPhaseRegions and plotted together.

components#

List of components

Type:

list of str

indep_comp_cond#

Condition for the independent component

Type:

v.X

all_compsets#
Type:

list of CompsetPair

two_phase_regions#
Type:

list of TwoPhaseRegion

add_compsets(compsets, Xtol=0.05, Ttol=10)[source]#

Add composition sets to current boundary sets

Parameters:

compsets (CompsetPair) –

get_line_plot_boundaries(close_miscibility_gaps=0.05, tieline_color=(0, 1, 0, 1), legend_generator=<function phase_legend>)[source]#

Get the ZPF boundaries to plot from each two phase region.

Parameters:
  • close_miscibility_gaps (float, optional) –

    If a float is passed, add a line segment between compsets at the top

    or bottom of a two phase region if the discrepancy is below a tolerance. If None is passed, do not close the gap.

  • tieline_color (color) – A valid matplotlib color, such as a named color string, hex RGB string, or a tuple of RGBA components to set the color of the two phase region tielines. The default is an RGBA tuple for green: (0, 1, 0, 1).

  • legend_generator (Callable) – A function that will be called with the list of phases and will return legend labels and colors for each phase. By default pycalphad.plot.utils.phase_legend is used

Notes

For now, we will not support connecting regions with lines, so this function returns a tuple of scatter_dict and a tineline_collection.

Examples

>>> boundary_collection, tieline_collection, legend_handles = zpf_boundary_sets.get_line_plot_boundaries()  
>>> ax.add_collection(boundary_collection)  
>>> ax.add_collection(tieline_collection)  
>>> ax.legend(handles=legend_handles)  
Return type:

(line_collections, tieline_collection, legend_handles)

get_phases()[source]#

Get all the phases represented in the two phase regions

get_scatter_plot_boundaries(tieline_color=(0, 1, 0, 1), legend_generator=<function phase_legend>)[source]#

Get the ZPF boundaries to plot from each two phase region.

Parameters:
  • tieline_color (color) – A valid matplotlib color, such as a named color string, hex RGB string, or a tuple of RGBA components to set the color of the two phase region tielines. The default is an RGBA tuple for green: (0, 1, 0, 1).

  • legend_generator (Callable) – A function that will be called with the list of phases and will return legend labels and colors for each phase. By default pycalphad.plot.utils.phase_legend is used

Notes

For now, we will not support connecting regions with lines, so this function returns a tuple of scatter_dict and a tineline_collection.

Examples

>>> scatter_dict, tieline_collection, legend_handles = zpf_boundary_sets.get_scatter_plot_boundaries()  
>>> ax.scatter(**scatter_dict)  
>>> ax.add_collection(tieline_collection)  
>>> ax.legend(handles=legend_handles)  
Return type:

(scatter_dict, tieline_collection, legend_handles)

rebuild_two_phase_regions(Xtol=0.05, Ttol=10)[source]#

Rebuild the two phase regions with new tolerances.

Parameters:
  • Xtol (float) – See TwoPhaseRegion.compsets_belong_in_region

  • Ttol (float) – See TwoPhaseRegion.compsets_belong_in_region

Module contents#