Python API

pypsbuilder expose several classes which could be used in Python sctipts, interactively or in Jupyter notebooks. Check included jupyter notebook to see how it works.

Here you can find auto-generated documentation of main classes, methods and functions.

psexplorer module

PTPS

Class to postprocess ptbuilder project

TXPS

Class to postprocess txbuilder project

PXPS

Class to postprocess pxbuilder project

class pypsbuilder.psexplorer.PTPS(*args, **kwargs)

Bases: PS

Class to postprocess ptbuilder project

calculate_composition(nx=50, ny=50)

Method to calculate compositional variations on grid.

A compositions are calculated for stable assemblages in regular grid covering pT range of pseudosection. A stable assemblage is identified from constructed divariant fields. Results are stored in grid property as GridData instance. A property all_data_keys is updated.

Before any grid point calculation, ptguesses are updated from nearest invariant point. If calculation fails, nearest solution from univariant line is used to update ptguesses. Finally, if solution is still not found, the method fix_solutions is called and neigbouring grid calculations are used to provide ptguess.

Parameters:
  • nx (int) – Number of grid points along x direction (T)

  • ny (int) – Number of grid points along y direction (p)

fix_solutions()

Method try to find solution for grid points with failed status.

Ptguesses are used from successfully calculated neighboring points until solution is find. Otherwise ststus remains failed.

collect_ptpath(tpath, ppath, N=100, kind='quadratic')

Method to collect THERMOCALC calculations along defined PT path.

PT path is interpolated from provided points using defined method. For each point THERMOCALC seek for solution using ptguess from nearest GridData point.

Parameters:
  • tpath (numpy.array) – 1D array of temperatures for given PT path

  • ppath (numpy.array) – 1D array of pressures for given PT path

  • N (int) – Number of calculation steps. Default 100.

  • kind (str) – Kind of interpolation. See scipy.interpolate.interp1d

Returns:

returns instance of PTpath class storing all calculations

along PT path.

Return type:

PTpath

show_path_data(ptpath, phase, expr=None, label=False, pathwidth=4, allpath=True, skiplabels=0, labelfs=6)

Show values of expression for given phase calculated along PTpath.

It plots colored strip on PT space. Strips arenot drawn accross fields, where ‘phase’ is not present.

Parameters:
  • ptpath (PTpath) – Results obtained by collect_ptpath method.

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

  • pathwidth (int) – Width of colored strip. Default 4.

  • allpath (bool) – Whether to plot full PT path (dashed line).

show_path_modes(ptpath, exclude=[], cmap='tab20')

Show stacked area diagram of phase modes along PT path

Parameters:
  • ptpath (PTpath) – Results obtained by collect_ptpath method.

  • exclude (list) – List of phases to exclude. Included phases area normalized to 100%.

  • cmap (str) – matplotlib colormap. Default ‘tab20’

collect_all_data_keys()

Collect all phases and variables calculated on grid.

Result is stored in all_data_keys property as dictionary of dictionaries.

Example

To get list of all variables calculated for phase ‘g’ or end-member ‘g(alm)’ use:

>>> pt.all_data_keys['g']
['mode', 'x', 'z', 'm', 'f', 'xMgX', 'xFeX', 'xMnX', 'xCaX', 'xAlY',
'xFe3Y', 'H2O', 'SiO2', 'Al2O3', 'CaO', 'MgO', 'FeO', 'K2O', 'Na2O',
'TiO2', 'MnO', 'O', 'factor', 'G', 'H', 'S', 'V', 'rho']
>>> pt.all_data_keys['g(alm)']
['ideal', 'gamma', 'activity', 'prop', 'mu', 'RTlna']
collect_data(key, phase, expr, which=7)

Convinient function to retrieve values of expression for given phase for user-defined combination of results of divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

collect_grid_data(key, phase, expr)

Retrieve values of expression for given phase for all GridData points within divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

collect_inv_data(key, phase, expr)

Retrieve value of variables based expression for given phase for all invariant points surrounding divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

collect_uni_data(key, phase, expr)

Retrieve values of expression for given phase for all univariant lines surrounding divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

common_grid_and_masks(**kwargs)

Initialize common grid and mask for all partial grids

create_masks()

Update grid masks from existing divariant fields

property endmembers

Returns dictionary with phases and their end-members names

gendrawpd(export_areas=True)

Method to write drawpd file

Parameters:

export_areas (bool) – Whether to include constructed areas. Default True.

get_grids(phase, expr=None)

Convinient function to get dictionary of grids.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

get_nearest_grid_data(x, y)

Retrieve nearest results from GridData to point.

Parameters:
  • x (float) – x-coordinate of point

  • y – y-coordiante of point

get_section_id(x, y)

Return index of pseudosection and grid containing point

gidentify(label=False, skiplabels=0, labelfs=6)

Visual version of identify method. PT point is provided by mouse click.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

ginput_path(label=False, skiplabels=0, labelfs=6)

Collect Path data by mouse digitizing.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

glabel(label=False, skiplabels=0, labelfs=6)

Return formatted string of assamblage at PT point provided by mouse click.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

property gridded

True when compositional grid(s) is calculated, otherwise False

identify(x, y)

Return key (frozenset) of divariant field for given temperature and pressure.

Parameters:
  • x (float) – x coord

  • y (float) – y coord

invs_from_unilist(ix, unilist)

Return set of IDs of invariant points associated with unilines. lines.

Parameters:

unilist (iterable) – list of (section_id, uni_id) pairs

Returns:

set of associated invariant points

Return type:

set

isopleths(phase, expr=None, **kwargs)

Method to draw compositional isopleths.

Isopleths are drawn as contours for values evaluated from provided expression. Individual divariant fields are contoured separately, so final plot allows sharp changes accross univariant lines. Within divariant field the selected interpolation is used.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • N (int) – Max number of contours. Default 10.

  • step (int) – Step between contour levels. If defined, N is ignored. Default None.

  • cdf (bool) – When True contour levels are percentile based. Default False.

  • alpha (float) – Alpha value for filled contours. Default 1

  • levels (list) – User-defined contour levels. If defined, N and step is ignored.

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points. Default 7 (all data)

  • colorbar (bool) – Whether to show colorbar. Default True

  • method – Interpolation method. Default is ‘rbf’, other option is ‘quadratic’, which uses least-square fit to quadratic surface or ‘spline’ for bivariate spline interpolation.

  • rbf_func – Default ‘thin_plate’. See scipy.interpolation.Rbf

  • smooth (int) – Values greater than zero increase the smoothness of the approximation. 0 is for interpolation (default), the function will always go through the nodal points.

  • epsilon (int) – Adjustable constant for gaussian or multiquadrics functions - defaults to approximate average distance between nodes (which is a good start).

  • degree (int) – Degrees of the bivariate spline. Default is 3.

  • refine (int) – Degree of grid refinement. Default 1

  • filter_outliers (bool) – Whether to filter outliers. Defaut False.

  • filled (bool) – Whether to contours should be filled. Defaut True.

  • filled_over (bool) – Whether to overlay contourline over filled contours. Defaut False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used for contours. Default ‘viridis’.

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • labelkeys (frozenset or list) – Keys of divariant fields where contours should be labeled.

  • nosplit (bool) – Controls whether the contour underlying labels are removed or not. Defaut True

  • gradient (bool) – Whether the first derivate of values should be used. Default False.

  • dt (bool) – Whether the gradient should be calculated along temperature or pressure. Default True.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

isopleths_vector(phase, expr=None, **kwargs)

Method to draw vectorized compositional isopleths.

Isopleths are drawn as lines for values evaluated from provided expression. Individual divariant fields are contoured separately, so final plot allows sharp changes accross univariant lines. Within divariant field the selected interpolation is used.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • N (int) – Max number of contours. Default 10.

  • step (int) – Step between contour levels. If defined, N is ignored. Default None.

  • cdf (bool) – When True contour levels are percentile based. Default False.

  • levels (list) – User-defined contour levels. If defined, N and step is ignored.

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points. Default 7 (all data)

  • colorbar (bool) – Whether to show colorbar. Default True

  • method – Interpolation method. Default is ‘rbf’, other option is ‘quadratic’, which uses least-square fit to quadratic surface.

  • rbf_func – Default ‘thin_plate’. See scipy.interpolation.Rbf

  • smooth (int) – Values greater than zero increase the smoothness of the approximation. 0 is for interpolation (default), the function will always go through the nodal points.

  • epsilon (int) – Adjustable constant for gaussian or multiquadrics functions - defaults to approximate average distance between nodes (which is a good start).

  • degree (int) – Degrees of the bivariate spline. Default is 3.

  • refine (int) – Degree of grid refinement. Default 1

  • filter_outliers (bool) – Whether to filter outliers. Defaut False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • overlay (bool) – Whether to show assemblage fields. Default True

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used isopleths coloring. Default ‘viridis’.

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • lw (float) – Linewidth of isopleths. Default 1.0

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • color – matplotlib color for isopleths. If None cmap is used. Default None.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

property keys

Returns set of all existing multivariant fields. Fields are identified by frozenset of present phases called key.

merge_data(phase, expr, which=7)

Returns merged data obtained by collect_data method for all divariant fields.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

property name

Get project directory name.

overlap_isopleths(*args, **kwargs)

Function to overlaped isopleths ranges.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • levels (tuple) – tuple of min an max values for isopleth band

  • alpha (float) – Alpha value for filled contours. Default 1

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

Example

>>> pt.overlap_isopleths(
        'g', 'xMgX', (0.07, 0.13),
        'g', 'xFeX', (0.51, 0.65),
        'g', 'xCaX', (0.06, 0.15),
        'g', 'xMnX', (0.16, 0.27),
    )
property phases

Returns set of all phases present in pseudosection

remove_grid_data(key, phase, expr)

Remove calculated data from grid and mark as failed

Note: Click on all data to be discarded by mouse and finish be Enter

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

save()

Save gridded copositions and constructed divariant fields into psbuilder project file.

Note that once project is edited with psbuilder, calculated compositions are removed and need to be recalculated using PTPS.calculate_composition method.

save_tab(comps, tabfile=None)

Export gridded values to Perple_X tab format. Could be used in pywerami.

Note: Gridded values are interpolated from raw results

Parameters:
  • comps (list) –

    List of (phase, expr) tuples. phase (str): Phase or end-member named expr (str): Expression to evaluate. It could use any

    variable existing for given phase. Check all_data_keys property for possible variables.

  • tabfile (str) – filename for tabfile. Default pseudosection name.tab

search_composition(*args, interpolation=None, label=False, skiplabels=0, labelfs=6, geterror=False, getpt=False, fig=None, fig_kw={}, isopleths=False, which=7, smooth=0, alpha=0.5, lw=2)

Function to plot root squared error of calculated and estimated values.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • val (float) – searched value

  • interpolation (str) – matplotlib imshow interpolation method. Default None.

  • label (bool) – Whether to label divariant fields. Default False.

  • geterror (bool) – When True, calculated RMSE array is returned. Otherwise error is plotted. Deafult False

  • getpt (bool) – When True return tuple of (p, T, err) where error is minimal. Default False

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • isopleths (bool) – When True, searched isopleths are shown. Default False

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

Example

>>> pt.search_composition(
        'g', 'xMgX', 0.076,
        'g', 'xFeX', 0.525,
        'g', 'xCaX', 0.126,
        'g', 'xMnX', 0.268
    )
show(**kwargs)

Method to draw PT pseudosection.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used to divariant fields coloring. Colors are based on variance. Default ‘Purples’.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • alpha (float) – alpha value for colors. Default 0.6

  • connect (bool) – Whether mouse click echo stable assemblage to STDOUT. Default False.

  • show_vertices (bool) – Whether to show vertices of drawn areas. Default False.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

show_data(key, phase, expr=None, which=7)

Convinient function to show values of expression for given phase for user-defined combination of results of divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

show_delta(label=False, pointsec=False, skiplabels=0, labelfs=6)

Shows THERMOCALC execution time for all grid points.

Parameters:
  • pointsec (bool) – Whether to show points/sec or secs/point. Default False.

  • label (bool) – Whether to label divariant fields. Default False.

show_grid(phase, expr=None, interpolation=None, label=False, skiplabels=0, labelfs=6)

Convinient function to show values of expression for given phase only from Grid Data.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • interpolation (str) – matplotlib imshow interpolation method. Default None.

  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

show_status(label=False, skiplabels=0, labelfs=6)

Shows status of grid calculations

property variance

Returns dictionary of variances

class pypsbuilder.psexplorer.TXPS(*args, **kwargs)

Bases: PS

Class to postprocess txbuilder project

calculate_composition(nx=50, ny=50)

Method to calculate compositional variations on grid.

A compositions are calculated for stable assemblages in regular grid covering pT range of pseudosection. A stable assemblage is identified from constructed divariant fields. Results are stored in grid property as GridData instance. A property all_data_keys is updated.

Before any grid point calculation, ptguesses are updated from nearest invariant point. If calculation fails, nearest solution from univariant line is used to update ptguesses. Finally, if solution is still not found, the method fix_solutions is called and neigbouring grid calculations are used to provide ptguess.

Parameters:
  • nx (int) – Number of grid points along x direction (T)

  • ny (int) – Number of grid points along y direction (p)

fix_solutions()

Method try to find solution for grid points with failed status.

Ptguesses are used from successfully calculated neighboring points until solution is find. Otherwise ststus remains failed.

collect_all_data_keys()

Collect all phases and variables calculated on grid.

Result is stored in all_data_keys property as dictionary of dictionaries.

Example

To get list of all variables calculated for phase ‘g’ or end-member ‘g(alm)’ use:

>>> pt.all_data_keys['g']
['mode', 'x', 'z', 'm', 'f', 'xMgX', 'xFeX', 'xMnX', 'xCaX', 'xAlY',
'xFe3Y', 'H2O', 'SiO2', 'Al2O3', 'CaO', 'MgO', 'FeO', 'K2O', 'Na2O',
'TiO2', 'MnO', 'O', 'factor', 'G', 'H', 'S', 'V', 'rho']
>>> pt.all_data_keys['g(alm)']
['ideal', 'gamma', 'activity', 'prop', 'mu', 'RTlna']
collect_data(key, phase, expr, which=7)

Convinient function to retrieve values of expression for given phase for user-defined combination of results of divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

collect_grid_data(key, phase, expr)

Retrieve values of expression for given phase for all GridData points within divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

collect_inv_data(key, phase, expr)

Retrieve value of variables based expression for given phase for all invariant points surrounding divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

collect_uni_data(key, phase, expr)

Retrieve values of expression for given phase for all univariant lines surrounding divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

common_grid_and_masks(**kwargs)

Initialize common grid and mask for all partial grids

create_masks()

Update grid masks from existing divariant fields

property endmembers

Returns dictionary with phases and their end-members names

gendrawpd(export_areas=True)

Method to write drawpd file

Parameters:

export_areas (bool) – Whether to include constructed areas. Default True.

get_grids(phase, expr=None)

Convinient function to get dictionary of grids.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

get_nearest_grid_data(x, y)

Retrieve nearest results from GridData to point.

Parameters:
  • x (float) – x-coordinate of point

  • y – y-coordiante of point

get_section_id(x, y)

Return index of pseudosection and grid containing point

gidentify(label=False, skiplabels=0, labelfs=6)

Visual version of identify method. PT point is provided by mouse click.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

ginput_path(label=False, skiplabels=0, labelfs=6)

Collect Path data by mouse digitizing.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

glabel(label=False, skiplabels=0, labelfs=6)

Return formatted string of assamblage at PT point provided by mouse click.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

property gridded

True when compositional grid(s) is calculated, otherwise False

identify(x, y)

Return key (frozenset) of divariant field for given temperature and pressure.

Parameters:
  • x (float) – x coord

  • y (float) – y coord

invs_from_unilist(ix, unilist)

Return set of IDs of invariant points associated with unilines. lines.

Parameters:

unilist (iterable) – list of (section_id, uni_id) pairs

Returns:

set of associated invariant points

Return type:

set

isopleths(phase, expr=None, **kwargs)

Method to draw compositional isopleths.

Isopleths are drawn as contours for values evaluated from provided expression. Individual divariant fields are contoured separately, so final plot allows sharp changes accross univariant lines. Within divariant field the selected interpolation is used.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • N (int) – Max number of contours. Default 10.

  • step (int) – Step between contour levels. If defined, N is ignored. Default None.

  • cdf (bool) – When True contour levels are percentile based. Default False.

  • alpha (float) – Alpha value for filled contours. Default 1

  • levels (list) – User-defined contour levels. If defined, N and step is ignored.

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points. Default 7 (all data)

  • colorbar (bool) – Whether to show colorbar. Default True

  • method – Interpolation method. Default is ‘rbf’, other option is ‘quadratic’, which uses least-square fit to quadratic surface or ‘spline’ for bivariate spline interpolation.

  • rbf_func – Default ‘thin_plate’. See scipy.interpolation.Rbf

  • smooth (int) – Values greater than zero increase the smoothness of the approximation. 0 is for interpolation (default), the function will always go through the nodal points.

  • epsilon (int) – Adjustable constant for gaussian or multiquadrics functions - defaults to approximate average distance between nodes (which is a good start).

  • degree (int) – Degrees of the bivariate spline. Default is 3.

  • refine (int) – Degree of grid refinement. Default 1

  • filter_outliers (bool) – Whether to filter outliers. Defaut False.

  • filled (bool) – Whether to contours should be filled. Defaut True.

  • filled_over (bool) – Whether to overlay contourline over filled contours. Defaut False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used for contours. Default ‘viridis’.

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • labelkeys (frozenset or list) – Keys of divariant fields where contours should be labeled.

  • nosplit (bool) – Controls whether the contour underlying labels are removed or not. Defaut True

  • gradient (bool) – Whether the first derivate of values should be used. Default False.

  • dt (bool) – Whether the gradient should be calculated along temperature or pressure. Default True.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

isopleths_vector(phase, expr=None, **kwargs)

Method to draw vectorized compositional isopleths.

Isopleths are drawn as lines for values evaluated from provided expression. Individual divariant fields are contoured separately, so final plot allows sharp changes accross univariant lines. Within divariant field the selected interpolation is used.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • N (int) – Max number of contours. Default 10.

  • step (int) – Step between contour levels. If defined, N is ignored. Default None.

  • cdf (bool) – When True contour levels are percentile based. Default False.

  • levels (list) – User-defined contour levels. If defined, N and step is ignored.

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points. Default 7 (all data)

  • colorbar (bool) – Whether to show colorbar. Default True

  • method – Interpolation method. Default is ‘rbf’, other option is ‘quadratic’, which uses least-square fit to quadratic surface.

  • rbf_func – Default ‘thin_plate’. See scipy.interpolation.Rbf

  • smooth (int) – Values greater than zero increase the smoothness of the approximation. 0 is for interpolation (default), the function will always go through the nodal points.

  • epsilon (int) – Adjustable constant for gaussian or multiquadrics functions - defaults to approximate average distance between nodes (which is a good start).

  • degree (int) – Degrees of the bivariate spline. Default is 3.

  • refine (int) – Degree of grid refinement. Default 1

  • filter_outliers (bool) – Whether to filter outliers. Defaut False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • overlay (bool) – Whether to show assemblage fields. Default True

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used isopleths coloring. Default ‘viridis’.

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • lw (float) – Linewidth of isopleths. Default 1.0

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • color – matplotlib color for isopleths. If None cmap is used. Default None.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

property keys

Returns set of all existing multivariant fields. Fields are identified by frozenset of present phases called key.

merge_data(phase, expr, which=7)

Returns merged data obtained by collect_data method for all divariant fields.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

property name

Get project directory name.

overlap_isopleths(*args, **kwargs)

Function to overlaped isopleths ranges.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • levels (tuple) – tuple of min an max values for isopleth band

  • alpha (float) – Alpha value for filled contours. Default 1

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

Example

>>> pt.overlap_isopleths(
        'g', 'xMgX', (0.07, 0.13),
        'g', 'xFeX', (0.51, 0.65),
        'g', 'xCaX', (0.06, 0.15),
        'g', 'xMnX', (0.16, 0.27),
    )
property phases

Returns set of all phases present in pseudosection

remove_grid_data(key, phase, expr)

Remove calculated data from grid and mark as failed

Note: Click on all data to be discarded by mouse and finish be Enter

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

save()

Save gridded copositions and constructed divariant fields into psbuilder project file.

Note that once project is edited with psbuilder, calculated compositions are removed and need to be recalculated using PTPS.calculate_composition method.

save_tab(comps, tabfile=None)

Export gridded values to Perple_X tab format. Could be used in pywerami.

Note: Gridded values are interpolated from raw results

Parameters:
  • comps (list) –

    List of (phase, expr) tuples. phase (str): Phase or end-member named expr (str): Expression to evaluate. It could use any

    variable existing for given phase. Check all_data_keys property for possible variables.

  • tabfile (str) – filename for tabfile. Default pseudosection name.tab

search_composition(*args, interpolation=None, label=False, skiplabels=0, labelfs=6, geterror=False, getpt=False, fig=None, fig_kw={}, isopleths=False, which=7, smooth=0, alpha=0.5, lw=2)

Function to plot root squared error of calculated and estimated values.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • val (float) – searched value

  • interpolation (str) – matplotlib imshow interpolation method. Default None.

  • label (bool) – Whether to label divariant fields. Default False.

  • geterror (bool) – When True, calculated RMSE array is returned. Otherwise error is plotted. Deafult False

  • getpt (bool) – When True return tuple of (p, T, err) where error is minimal. Default False

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • isopleths (bool) – When True, searched isopleths are shown. Default False

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

Example

>>> pt.search_composition(
        'g', 'xMgX', 0.076,
        'g', 'xFeX', 0.525,
        'g', 'xCaX', 0.126,
        'g', 'xMnX', 0.268
    )
show(**kwargs)

Method to draw PT pseudosection.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used to divariant fields coloring. Colors are based on variance. Default ‘Purples’.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • alpha (float) – alpha value for colors. Default 0.6

  • connect (bool) – Whether mouse click echo stable assemblage to STDOUT. Default False.

  • show_vertices (bool) – Whether to show vertices of drawn areas. Default False.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

show_data(key, phase, expr=None, which=7)

Convinient function to show values of expression for given phase for user-defined combination of results of divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

show_delta(label=False, pointsec=False, skiplabels=0, labelfs=6)

Shows THERMOCALC execution time for all grid points.

Parameters:
  • pointsec (bool) – Whether to show points/sec or secs/point. Default False.

  • label (bool) – Whether to label divariant fields. Default False.

show_grid(phase, expr=None, interpolation=None, label=False, skiplabels=0, labelfs=6)

Convinient function to show values of expression for given phase only from Grid Data.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • interpolation (str) – matplotlib imshow interpolation method. Default None.

  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

show_status(label=False, skiplabels=0, labelfs=6)

Shows status of grid calculations

property variance

Returns dictionary of variances

class pypsbuilder.psexplorer.PXPS(*args, **kwargs)

Bases: PS

Class to postprocess pxbuilder project

calculate_composition(nx=50, ny=50)

Method to calculate compositional variations on grid.

A compositions are calculated for stable assemblages in regular grid covering pT range of pseudosection. A stable assemblage is identified from constructed divariant fields. Results are stored in grid property as GridData instance. A property all_data_keys is updated.

Before any grid point calculation, ptguesses are updated from nearest invariant point. If calculation fails, nearest solution from univariant line is used to update ptguesses. Finally, if solution is still not found, the method fix_solutions is called and neigbouring grid calculations are used to provide ptguess.

Parameters:
  • nx (int) – Number of grid points along x direction (T)

  • ny (int) – Number of grid points along y direction (p)

fix_solutions()

Method try to find solution for grid points with failed status.

Ptguesses are used from successfully calculated neighboring points until solution is find. Otherwise ststus remains failed.

collect_all_data_keys()

Collect all phases and variables calculated on grid.

Result is stored in all_data_keys property as dictionary of dictionaries.

Example

To get list of all variables calculated for phase ‘g’ or end-member ‘g(alm)’ use:

>>> pt.all_data_keys['g']
['mode', 'x', 'z', 'm', 'f', 'xMgX', 'xFeX', 'xMnX', 'xCaX', 'xAlY',
'xFe3Y', 'H2O', 'SiO2', 'Al2O3', 'CaO', 'MgO', 'FeO', 'K2O', 'Na2O',
'TiO2', 'MnO', 'O', 'factor', 'G', 'H', 'S', 'V', 'rho']
>>> pt.all_data_keys['g(alm)']
['ideal', 'gamma', 'activity', 'prop', 'mu', 'RTlna']
collect_data(key, phase, expr, which=7)

Convinient function to retrieve values of expression for given phase for user-defined combination of results of divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

collect_grid_data(key, phase, expr)

Retrieve values of expression for given phase for all GridData points within divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

collect_inv_data(key, phase, expr)

Retrieve value of variables based expression for given phase for all invariant points surrounding divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

collect_uni_data(key, phase, expr)

Retrieve values of expression for given phase for all univariant lines surrounding divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

common_grid_and_masks(**kwargs)

Initialize common grid and mask for all partial grids

create_masks()

Update grid masks from existing divariant fields

property endmembers

Returns dictionary with phases and their end-members names

gendrawpd(export_areas=True)

Method to write drawpd file

Parameters:

export_areas (bool) – Whether to include constructed areas. Default True.

get_grids(phase, expr=None)

Convinient function to get dictionary of grids.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

get_nearest_grid_data(x, y)

Retrieve nearest results from GridData to point.

Parameters:
  • x (float) – x-coordinate of point

  • y – y-coordiante of point

get_section_id(x, y)

Return index of pseudosection and grid containing point

gidentify(label=False, skiplabels=0, labelfs=6)

Visual version of identify method. PT point is provided by mouse click.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

ginput_path(label=False, skiplabels=0, labelfs=6)

Collect Path data by mouse digitizing.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

glabel(label=False, skiplabels=0, labelfs=6)

Return formatted string of assamblage at PT point provided by mouse click.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

property gridded

True when compositional grid(s) is calculated, otherwise False

identify(x, y)

Return key (frozenset) of divariant field for given temperature and pressure.

Parameters:
  • x (float) – x coord

  • y (float) – y coord

invs_from_unilist(ix, unilist)

Return set of IDs of invariant points associated with unilines. lines.

Parameters:

unilist (iterable) – list of (section_id, uni_id) pairs

Returns:

set of associated invariant points

Return type:

set

isopleths(phase, expr=None, **kwargs)

Method to draw compositional isopleths.

Isopleths are drawn as contours for values evaluated from provided expression. Individual divariant fields are contoured separately, so final plot allows sharp changes accross univariant lines. Within divariant field the selected interpolation is used.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • N (int) – Max number of contours. Default 10.

  • step (int) – Step between contour levels. If defined, N is ignored. Default None.

  • cdf (bool) – When True contour levels are percentile based. Default False.

  • alpha (float) – Alpha value for filled contours. Default 1

  • levels (list) – User-defined contour levels. If defined, N and step is ignored.

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points. Default 7 (all data)

  • colorbar (bool) – Whether to show colorbar. Default True

  • method – Interpolation method. Default is ‘rbf’, other option is ‘quadratic’, which uses least-square fit to quadratic surface or ‘spline’ for bivariate spline interpolation.

  • rbf_func – Default ‘thin_plate’. See scipy.interpolation.Rbf

  • smooth (int) – Values greater than zero increase the smoothness of the approximation. 0 is for interpolation (default), the function will always go through the nodal points.

  • epsilon (int) – Adjustable constant for gaussian or multiquadrics functions - defaults to approximate average distance between nodes (which is a good start).

  • degree (int) – Degrees of the bivariate spline. Default is 3.

  • refine (int) – Degree of grid refinement. Default 1

  • filter_outliers (bool) – Whether to filter outliers. Defaut False.

  • filled (bool) – Whether to contours should be filled. Defaut True.

  • filled_over (bool) – Whether to overlay contourline over filled contours. Defaut False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used for contours. Default ‘viridis’.

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • labelkeys (frozenset or list) – Keys of divariant fields where contours should be labeled.

  • nosplit (bool) – Controls whether the contour underlying labels are removed or not. Defaut True

  • gradient (bool) – Whether the first derivate of values should be used. Default False.

  • dt (bool) – Whether the gradient should be calculated along temperature or pressure. Default True.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

isopleths_vector(phase, expr=None, **kwargs)

Method to draw vectorized compositional isopleths.

Isopleths are drawn as lines for values evaluated from provided expression. Individual divariant fields are contoured separately, so final plot allows sharp changes accross univariant lines. Within divariant field the selected interpolation is used.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • N (int) – Max number of contours. Default 10.

  • step (int) – Step between contour levels. If defined, N is ignored. Default None.

  • cdf (bool) – When True contour levels are percentile based. Default False.

  • levels (list) – User-defined contour levels. If defined, N and step is ignored.

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points. Default 7 (all data)

  • colorbar (bool) – Whether to show colorbar. Default True

  • method – Interpolation method. Default is ‘rbf’, other option is ‘quadratic’, which uses least-square fit to quadratic surface.

  • rbf_func – Default ‘thin_plate’. See scipy.interpolation.Rbf

  • smooth (int) – Values greater than zero increase the smoothness of the approximation. 0 is for interpolation (default), the function will always go through the nodal points.

  • epsilon (int) – Adjustable constant for gaussian or multiquadrics functions - defaults to approximate average distance between nodes (which is a good start).

  • degree (int) – Degrees of the bivariate spline. Default is 3.

  • refine (int) – Degree of grid refinement. Default 1

  • filter_outliers (bool) – Whether to filter outliers. Defaut False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • overlay (bool) – Whether to show assemblage fields. Default True

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used isopleths coloring. Default ‘viridis’.

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • lw (float) – Linewidth of isopleths. Default 1.0

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • color – matplotlib color for isopleths. If None cmap is used. Default None.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

property keys

Returns set of all existing multivariant fields. Fields are identified by frozenset of present phases called key.

merge_data(phase, expr, which=7)

Returns merged data obtained by collect_data method for all divariant fields.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

property name

Get project directory name.

overlap_isopleths(*args, **kwargs)

Function to overlaped isopleths ranges.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • levels (tuple) – tuple of min an max values for isopleth band

  • alpha (float) – Alpha value for filled contours. Default 1

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

Example

>>> pt.overlap_isopleths(
        'g', 'xMgX', (0.07, 0.13),
        'g', 'xFeX', (0.51, 0.65),
        'g', 'xCaX', (0.06, 0.15),
        'g', 'xMnX', (0.16, 0.27),
    )
property phases

Returns set of all phases present in pseudosection

remove_grid_data(key, phase, expr)

Remove calculated data from grid and mark as failed

Note: Click on all data to be discarded by mouse and finish be Enter

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

save()

Save gridded copositions and constructed divariant fields into psbuilder project file.

Note that once project is edited with psbuilder, calculated compositions are removed and need to be recalculated using PTPS.calculate_composition method.

save_tab(comps, tabfile=None)

Export gridded values to Perple_X tab format. Could be used in pywerami.

Note: Gridded values are interpolated from raw results

Parameters:
  • comps (list) –

    List of (phase, expr) tuples. phase (str): Phase or end-member named expr (str): Expression to evaluate. It could use any

    variable existing for given phase. Check all_data_keys property for possible variables.

  • tabfile (str) – filename for tabfile. Default pseudosection name.tab

search_composition(*args, interpolation=None, label=False, skiplabels=0, labelfs=6, geterror=False, getpt=False, fig=None, fig_kw={}, isopleths=False, which=7, smooth=0, alpha=0.5, lw=2)

Function to plot root squared error of calculated and estimated values.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • val (float) – searched value

  • interpolation (str) – matplotlib imshow interpolation method. Default None.

  • label (bool) – Whether to label divariant fields. Default False.

  • geterror (bool) – When True, calculated RMSE array is returned. Otherwise error is plotted. Deafult False

  • getpt (bool) – When True return tuple of (p, T, err) where error is minimal. Default False

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • isopleths (bool) – When True, searched isopleths are shown. Default False

  • which (int) – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

Example

>>> pt.search_composition(
        'g', 'xMgX', 0.076,
        'g', 'xFeX', 0.525,
        'g', 'xCaX', 0.126,
        'g', 'xMnX', 0.268
    )
show(**kwargs)

Method to draw PT pseudosection.

Parameters:
  • label (bool) – Whether to label divariant fields. Default False.

  • out (str or list) – Highligt zero-mode lines for given phases.

  • high (frozenset or list) – Highlight divariant fields identified by key(s).

  • cmap (str) – matplotlib colormap used to divariant fields coloring. Colors are based on variance. Default ‘Purples’.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

  • bulk (bool) – Whether to show bulk composition on top of diagram. Default False.

  • alpha (float) – alpha value for colors. Default 0.6

  • connect (bool) – Whether mouse click echo stable assemblage to STDOUT. Default False.

  • show_vertices (bool) – Whether to show vertices of drawn areas. Default False.

  • fig (Figure) – If not None, axes are added to fig and returned. Default None

  • fig_kw – dict passed to subplots method.

  • ax (Axes) – Axes to be used. Default None

  • filename – If not None, figure is saved to file

  • save_kw – dict passed to savefig method.

  • show (bool) – When False, Axes are returned, otherwise plot is shown. Default True

show_data(key, phase, expr=None, which=7)

Convinient function to show values of expression for given phase for user-defined combination of results of divariant field identified by key.

Parameters:
  • key (frozenset) – Key identifying divariant field

  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • which – Bitopt defining from where data are collected. 0 bit - invariant points, 1 bit - uniariant lines and 2 bit - GridData points

show_delta(label=False, pointsec=False, skiplabels=0, labelfs=6)

Shows THERMOCALC execution time for all grid points.

Parameters:
  • pointsec (bool) – Whether to show points/sec or secs/point. Default False.

  • label (bool) – Whether to label divariant fields. Default False.

show_grid(phase, expr=None, interpolation=None, label=False, skiplabels=0, labelfs=6)

Convinient function to show values of expression for given phase only from Grid Data.

Parameters:
  • phase (str) – Phase or end-member named

  • expr (str) – Expression to evaluate. It could use any variable existing for given phase. Check all_data_keys property for possible variables.

  • interpolation (str) – matplotlib imshow interpolation method. Default None.

  • label (bool) – Whether to label divariant fields. Default False.

  • skiplabels (float) – Minimal area fraction of fields to be labelled

  • labelfs (float) – Size of label font. Default 6

show_status(label=False, skiplabels=0, labelfs=6)

Shows status of grid calculations

property variance

Returns dictionary of variances

tcapi module

TC35API

TC34API

class pypsbuilder.tcapi.TC35API(workdir, tcexe, drexe, encoding='mac-roman')

Bases: TCAPI

parse_logfile(**kwargs)

Parser for THERMOCALC 3.50beta output.

It parses the outputs of THERMOCALC after calculation.

Parameters:
  • output (str) – When not None, used as content of logfile. Default None.

  • resic (str) – When not None, used as content of icfile. Default None.

  • get_phases (bool) – When true returns also tuple (phases, out, calcs). Default False

Returns:

Result of parsing. ‘ok’, ‘nir’ (nothing in range) or ‘bombed’. results (TCResultSet): Results of TC calculation. output (str): Full nonparsed THERMOCALC output.

Return type:

status (str)

Example

Parse output after univariant line calculation in P-T pseudosection:

>>> tc = TCAPI('pat/to/dir')
>>> status, result, output = tc.parse_logfile()
update_scriptfile(**kwargs)

Method to update scriptfile.

This method is used to programatically edit scriptfile.

Kwargs:

calcs: List of lines defining fully hands-off calculations. Default None. get_old_calcs: When True method returns existing calcs lines

before possible modification. Default False.

guesses: List of lines defining ptguesses. If None guesses

are not modified. Default None.

get_old_guesses: When True method returns existing ptguess lines

before possible modification. Default False.

bulk: List of lines defining bulk composition. Default None. xsteps: Number of compositional steps between two bulks.

Default 20.

calc_t(phases, out, **kwargs)

Method to run THERMOCALC to find univariant line using Calc T at P strategy.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of single zero mode phase

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_p(phases, out, **kwargs)

Method to run THERMOCALC to find univariant line using Calc P at T strategy.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of single zero mode phase

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_pt(phases, out, **kwargs)

Method to run THERMOCALC to find invariant point.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of two zero mode phases

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_tx(phases, out, **kwargs)

Method to run THERMOCALC for T-X pseudosection calculations.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of zero mode phases

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • xvals (tuple) – range for X variable

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_px(phases, out, **kwargs)

Method to run THERMOCALC for p-X pseudosection calculations.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of zero mode phases

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • xvals (tuple) – range for X variable

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_assemblage(phases, p, t, onebulk=None)

Method to run THERMOCALC to calculate compositions of stable assemblage.

Parameters:
  • phases (set) – Set of present phases

  • p (float) – Temperature for calculation

  • t (float) – Pressure for calculation

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

dogmin(phases, p, t, variance, doglevel=1, onebulk=None)

Run THERMOCALC dogmin session.

Parameters:

variance (int) – Maximum variance to be considered

Returns:

THERMOCALC standard output

Return type:

str

calc_variance(phases)

Get variance of assemblage.

Parameters:

phases (set) – Set of present phases

Returns:

variance

Return type:

int

property axfile

Path to used a-x file.

Type:

pathlib.Path

property csvfile

Path to csv file.

Type:

pathlib.Path

property dataset

Version identification of thermodynamic dataset in use.

Type:

str

property datasetfile

Path to dataset file.

Type:

pathlib.Path

property drawpdfile

Path to drawpd file.

Type:

pathlib.Path

property drfile

Path to -dr output file.

Type:

pathlib.Path

property icfile

Path to ic file.

Type:

pathlib.Path

property itfile

Path to it file.

Type:

pathlib.Path

property logfile

Path to THERMOCALC log file.

Type:

pathlib.Path

property ofile

Path to project output file.

Type:

pathlib.Path

parse_dogmin()

Dogmin parser.

property prefsfile

Path to THERMOCALC prefs file.

Type:

pathlib.Path

rundr()

Method to run drawpd.

runtc(instr='kill\n\n')

Low-level method to actually run THERMOCALC.

Parameters:

instr (str) – String to be passed to standard input for session.

Returns:

THERMOCALC standard output

Return type:

str

property scriptfile

Path to scriptfile.

Type:

pathlib.Path

property tcnewversion

False for THERMOCALC older than 3.5.

Type:

bool

property tcversion

THERMOCALC version string

Type:

str

class pypsbuilder.tcapi.TC34API(workdir, tcexe, drexe, encoding='mac-roman')

Bases: TCAPI

parse_logfile(**kwargs)

Parser for THERMOCALC 3.4x output.

It parses the outputs of THERMOCALC after calculation.

Parameters:
  • output (str) – When not None, used as content of logfile. Default None.

  • resic (str) – When not None, used as content of icfile. Default None.

  • get_phases (bool) – When true returns also tuple (phases, out, calcs). Default False

Returns:

Result of parsing. ‘ok’, ‘nir’ (nothing in range) or ‘bombed’. results (TCResultSet): Results of TC calculation. output (str): Full nonparsed THERMOCALC output.

Return type:

status (str)

Example

Parse output after univariant line calculation in P-T pseudosection:

>>> tc = TCAPI('pat/to/dir')
>>> status, result, output = tc.parse_logfile()
update_scriptfile(**kwargs)

Method to update scriptfile.

This methodcould be used to read or update ptguess or dogmin settings.

Parameters:
  • guesses (list) – List of lines defining ptguesses. If None guesses are not modified. Default None.

  • get_old_guesses (bool) – When True method returns existing ptguess before possible modification. Default False.

  • dogmin (str) – Argument of dogmin script. Could be ‘no’ or ‘yes’ or ‘yes X’, where X is log level. When None no modification is done. Default None.

  • which (set) – Set of phases used for dogmin.

  • bulk (list) – Bulk composition. Default None.

  • xvals (tuple) – x values for compositions. Default (0, 1)

  • xsteps (int) – Number of compositional steps between two bulks. Default 20.

  • p (float) – Pressure for dogmin calculation

  • T (float) – Temperature for dogmin calculation

property axfile

Path to used a-x file.

Type:

pathlib.Path

property csvfile

Path to csv file.

Type:

pathlib.Path

property dataset

Version identification of thermodynamic dataset in use.

Type:

str

property datasetfile

Path to dataset file.

Type:

pathlib.Path

property drawpdfile

Path to drawpd file.

Type:

pathlib.Path

property drfile

Path to -dr output file.

Type:

pathlib.Path

property icfile

Path to ic file.

Type:

pathlib.Path

property itfile

Path to it file.

Type:

pathlib.Path

property logfile

Path to THERMOCALC log file.

Type:

pathlib.Path

property ofile

Path to project output file.

Type:

pathlib.Path

parse_dogmin()

Dogmin parser.

property prefsfile

Path to THERMOCALC prefs file.

Type:

pathlib.Path

rundr()

Method to run drawpd.

runtc(instr='kill\n\n')

Low-level method to actually run THERMOCALC.

Parameters:

instr (str) – String to be passed to standard input for session.

Returns:

THERMOCALC standard output

Return type:

str

property scriptfile

Path to scriptfile.

Type:

pathlib.Path

property tcnewversion

False for THERMOCALC older than 3.5.

Type:

bool

property tcversion

THERMOCALC version string

Type:

str

calc_t(phases, out, **kwargs)

Method to run THERMOCALC to find univariant line using Calc T at P strategy.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of single zero mode phase

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_p(phases, out, **kwargs)

Method to run THERMOCALC to find univariant line using Calc P at T strategy.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of single zero mode phase

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_pt(phases, out, **kwargs)

Method to run THERMOCALC to find invariant point.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of two zero mode phases

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_tx(phases, out, **kwargs)

Method to run THERMOCALC for T-X pseudosection calculations.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of zero mode phases

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_px(phases, out, **kwargs)

Method to run THERMOCALC for P-X pseudosection calculations.

Parameters:
  • phases (set) – Set of present phases

  • out (set) – Set of zero mode phases

  • prange (tuple) – Temperature range for calculation

  • trange (tuple) – Pressure range for calculation

  • steps (int) – Number of steps

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

calc_assemblage(phases, p, t)

Method to run THERMOCALC to calculate compositions of stable assemblage.

Parameters:
  • phases (set) – Set of present phases

  • p (float) – Temperature for calculation

  • t (float) – Pressure for calculation

Returns:

(tcout, ans) standard output and input for THERMOCALC run. Input ans could be used to reproduce calculation.

Return type:

tuple

dogmin(phases, p, t, variance, doglevel=1, onebulk=None)

Run THERMOCALC dogmin session.

Parameters:

variance (int) – Maximum variance to be considered

Returns:

THERMOCALC standard output

Return type:

str

calc_variance(phases)

Get variance of assemblage.

Parameters:

phases (set) – Set of present phases

Returns:

variance

Return type:

int

psclasses module

InvPoint

Class to store invariant point

UniLine

Class to store univariant line

Dogmin

TCResult

TCResultSet

PTsection

P-T pseudosection class

TXsection

T-X pseudosection class

PXsection

P-X pseudosection class

class pypsbuilder.psclasses.InvPoint(**kwargs)

Bases: PseudoBase

Class to store invariant point

id

Invariant point identification

Type:

int

phases

set of present phases

Type:

set

out

set of zero mode phases

Type:

set

cmd

THERMOCALC standard input to calculate this point

Type:

str

variance

variance

Type:

int

x

Array of x coordinates (even if only one, it is stored as array)

Type:

numpy.array

y

Array of x coordinates (even if only one, it is stored as array)

Type:

numpy.array

results

List of results dicts with data and ptgues keys.

Type:

list

output

Full THERMOCALC output

Type:

str

manual

True when inavariant point is user-defined and not calculated

Type:

bool

shape()

Return shapely Point representing invariant point.

all_unilines()

Return four tuples (phases, out) indicating possible four univariant lines passing trough this invariant point

annotation(state=0)

str: String representation of ID with possible zermo mode phase.

datakeys(phase=None)

list: Get list of variables for phase.

Parameters:

phase (str) – name of phase

label(excess={})

str: full label with space delimeted phases - zero mode phase.

ptguess(**kwargs)

list: Get stored ptguesses.

InvPoint has just single ptguess, but for UniLine idx need to be specified. If omitted, the middle point from calculated ones is used.

Parameters:

idx (int) – index which guesses to get.

class pypsbuilder.psclasses.UniLine(**kwargs)

Bases: PseudoBase

Class to store univariant line

id

Invariant point identification

Type:

int

phases

set of present phases

Type:

set

out

set of zero mode phase

Type:

set

cmd

THERMOCALC standard input to calculate this point

Type:

str

variance

variance

Type:

int

_x

Array of x coordinates (all calculated)

Type:

numpy.array

_y

Array of x coordinates (all calculated)

Type:

numpy.array

results

List of results dicts with data and ptgues keys.

Type:

list

output

Full THERMOCALC output

Type:

str

manual

True when inavariant point is user-defined and not calculated

Type:

bool

begin

id of invariant point defining begining of the line. 0 for no begin

Type:

int

end

id of invariant point defining end of the line. 0 for no end

Type:

int

used

slice indicating which point on calculated line are between begin and end

Type:

slice

shape(ratio=None, tolerance=None)

Return shapely LineString representing univariant line.

This method is using trimmed points.

Parameters:
  • ratio – y-coordinate multiplier to scale coordinates. Default None

  • tolerance – tolerance x coordinates. Simplified object will be within

  • None (the tolerance distance of the original geometry. Default)

contains_inv(ip)

Check whether invariant point theoretically belong to univariant line.

Parameters:

ip (InvPoint) – Invariant point

Returns:

True for yes, False for no. Note that metastability is not checked.

Return type:

bool

get_label_point()

Returns coordinate tuple of labeling point for univariant line.

annotation(state=0)

str: String representation of ID with possible zermo mode phase.

datakeys(phase=None)

list: Get list of variables for phase.

Parameters:

phase (str) – name of phase

label(excess={})

str: full label with space delimeted phases - zero mode phase.

ptguess(**kwargs)

list: Get stored ptguesses.

InvPoint has just single ptguess, but for UniLine idx need to be specified. If omitted, the middle point from calculated ones is used.

Parameters:

idx (int) – index which guesses to get.

class pypsbuilder.psclasses.Dogmin(**kwargs)

Bases: object

label(excess={})

str: full label with space delimeted phases.

annotation(show_out=False, excess={})

str: String representation of ID with possible zermo mode phase.

class pypsbuilder.psclasses.TCResult(T, p, variance=0, c=0, data={}, ptguess=[''])

Bases: object

class pypsbuilder.psclasses.TCResultSet(results)

Bases: object

class pypsbuilder.psclasses.PTsection(**kwargs)

Bases: SectionBase

P-T pseudosection class

getidinv(inv=None)

Return id of either new or existing invariant point

getiduni(uni=None)

Return id of either new or existing univariant line

class pypsbuilder.psclasses.TXsection(**kwargs)

Bases: SectionBase

T-X pseudosection class

getidinv(inv=None)

Return id of either new or existing invariant point

getiduni(uni=None)

Return id of either new or existing univariant line

class pypsbuilder.psclasses.PXsection(**kwargs)

Bases: SectionBase

P-X pseudosection class

getidinv(inv=None)

Return id of either new or existing invariant point

getiduni(uni=None)

Return id of either new or existing univariant line