upxo.pxtal.pxtal_ori_map_2d module

Orientation map 2D polycrystal data class for UPXO.

class upxo.pxtal.pxtal_ori_map_2d.polyxtal2d[source]

Bases: object

EPS = 1e-12
mprop

The following need not be set while initiating this polyxtal2d class. They will rather be set during calls to concerned defnitions.

flags
valid_mprops
setup(map_type='ebsd', path_filename_noext=None, apply_kuwahara=False, kuwahara_misori=5)[source]

Load and set up a crystal orientation map from an EBSD dataset.

kuwahara_filter(misori=5)[source]

Kuwahara filter.

buildQuatArray()[source]

Buildquatarray.

find_grains_gb(gb_misori=10, min_grain_size=1, print_msg=True)[source]

Find grain boundaries and build neighbourhood network.

port_essentials(print_msg=True)[source]

Port essential data from the defDAP map to UPXO.

charecterize_mprops()[source]

Compute and store morphological properties for all grains.

set_mprops()[source]

Set or update mprops.

get_data_template_giddict(ncopies)[source]

Return the data template giddict.

set_bounding_boxes()[source]

Set or update bounding boxes.

set_mprop_generator(use_extended_bbox=False)[source]

Set or update mprop generator.

set_mprop_npixels()[source]

Set or update mprop npixels.

set_mprop_area()[source]

Set or update mprop area.

set_mprop_perimeter()[source]

Set or update mprop perimeter.

set_mprop_perimeter_crofton()[source]

Set or update mprop perimeter crofton.

set_mprop_major_axis_length()[source]

Set or update mprop major axis length.

set_mprop_minor_axis_length()[source]

Set or update mprop minor axis length.

set_mprop_ar()[source]

Set or update mprop ar.

set_mprop_eccentricity()[source]

Set or update mprop eccentricity.

set_mprop_area_bbox()[source]

Set or update mprop area bbox.

set_mprop_area_convex()[source]

Set or update mprop area convex.

set_mprop_equivalent_diameter_area()[source]

Set or update mprop equivalent diameter area.

set_mprop_euler_number()[source]

Set or update mprop euler number.

set_mprop_feret_diameter_max()[source]

Set or update mprop feret diameter max.

set_mprop_moments()[source]

Set or update mprop moments.

set_mprop_solidity()[source]

Set or update mprop solidity.

set_mprop_orientation()[source]

Set or update mprop orientation.

set_mprop_inertia_tensor()[source]

Set or update mprop inertia tensor.

set_mprop_inertia_tensor_eigvals()[source]

Set or update mprop inertia tensor eigvals.

set_conversion_loss(refn=None)[source]

Determine the loss due to converting UPXO.MCGS2D to DefDAP map.

Returns:

cl_details – Conversion loss details Keys:

loss: conversion_loss value n_pre: number of grains before conversion n_post: number of grains after conversion

Return type:

dict

set_bjp()[source]

Boundary Junction Points.

plot_bjp()[source]

Plot boundary junction points overlaid on pxtal map.

get_gbpoints_grain(gid, retrieval_method='external', chain_approximation='simple')[source]

Return the grain boundary points for the given grain.

Examples

gid = 1
gstslice.pxtal[1].get_gbpoints_grain(gid,
                                     retrieval_method='tree',
                                     chain_approximation='none')
set_grains()[source]

Populate the grain dictionary from the defDAP grain list.

set_lgi()[source]

Return the pixel-to-grain-ID mapping.

shuffle_lgi_random_gid_wise()[source]

Randomly permute grain IDs in the LGI array.

rearrange_g_after_lgi_shuffle()[source]

Rearrange g after lgi shuffle.

reset_lgi()[source]

Reset the LGI array to its original state.

set_gid(reset_lgi=False)[source]

Set or update the grain ID array from the current LGI.

set_grain_locations()[source]

Set or update grain locations.

set_n()[source]

Set the grain count from the current grain ID array.

find_neigh(update_gid=True, reset_lgi=False)[source]

Find O(1) neighbours for every grain and store in neigh_gid.

find_gbseg1()[source]

Find grain boundary segments between every pair of neighbours.

extract_gb_discrete(retrieval_method='external', chain_approximation='simple')[source]

Extract grain boundaries of every grain.

set_geom()[source]

Set or update geom.

find_lgi_subset_neigh(gid, plot=True, plot_kwargs={'recalc_centroids': False}, cmap_name='coolwarm', plot_centroids=True, add_gid_text=True, plot_gbseg=False)[source]

Find the LGI subset covering gid and all its O(1) neighbours.

Examples

gstslice.pxtal[1].find_lgi_subset_neigh(gid)
remove_single_pixel_grains()[source]

Remove single pixel grains.

property single_pixel_grains

Single pixel grains.

property plot_single_pixel_grains

Visualise single pixel grains using Matplotlib or PyVista.

validate_propnames(mpnames, return_type='dict')[source]

Validate an iterable containing propnames. Mostly for internal use.

Parameters:
  • mpnames (dth.dt.ITERABLES) – Property names to be validated.

  • return_type (str) – Type of function return. Valid choices: dict (default), list, tuple.

Returns:

validation – If return_type is other than dictionary and either list or tuple, or numpy array, only tuple will be returned. If return_type is dict, then dict with mpnames keys and their individual validations will be the values. The values will all be bool. If a property is a valid property, then True, else False.

Return type:

dict (default) / tuple

Examples

self.validate_propnames(['area', 'perimeter', 'solidity'])
check_mpnamevals_exists(mpnames, return_type='dict')[source]

Check or validate check mpnamevals exists.

validata_gids(gids)[source]

Validate the gid values.

Parameters:

gids (Iterable of ints.)

Return type:

True if all gids are in self.gid else False

get_mprops(mpnames, set_missing_mprop=False)[source]

Get values of mpnames.

Examples

from upxo.ggrowth.mcgs import mcgs
mcgs = mcgs(study='independent', input_dashboard='input_dashboard.xls')
mcgs.simulate()
mcgs.detect_grains()
mcgs.gs[mcgs.m[-1]].char_morph_2d(bbox=True, bbox_ex=True,
                             area=True, aspect_ratio=True,
                             make_skim_prop=True)

mpnames = ['area', 'aspect_ratio', 'perimeter', 'solidity']
mcgs.gs[mcgs.m[-1]].prop
mprop_values = mcgs.gs[mcgs.m[-1]].get_mprops(mpnames,
                                              set_missing_mprop=True)
get_gids_in_params_bounds(search_gid_source='all', search_gids=None, mpnames=['area', 'aspect_ratio', 'perimeter', 'solidity'], fx_stats=[numpy.mean, numpy.mean, numpy.mean, numpy.mean], pdslh=[[50, 50], [50, 50], [50, 50], [50, 50]], param_priority=[1, 2, 3, 2], plot_mprop=False)[source]

pdslh: Percentages of distance from stat to minimum and stat to maximum.

get_upto_nth_order_neighbors(grain_id, neigh_order, recalculate=False, include_parent=True, output_type='list', plot=False)[source]

Return all neighbours up to the nth order for a given grain.

Parameters:
  • grain_id (int) – Grain ID for which to find neighbours.

  • neigh_order (int) – Order of neighbours to accumulate (1st, 2nd, …).

Returns:

Neighbour grain IDs up to the specified order.

Return type:

list or numpy.ndarray or set

Examples

from upxo.ggrowth.mcgs import mcgs
pxt = mcgs()
pxt.simulate()
pxt.detect_grains()
tslice = 20
gstslice = pxt.gs[tslice]
gstslice.export_ctf(r'D:\export_folder', 'sunil')
fname = r'D:\export_folder\sunil'
gstslice.set_pxtal(instance_no=1, path_filename_noext=fname)
IN, gid, neigh_order = 1, 1, 2
gstslice.pxtal[IN].get_upto_nth_order_neighbors(gid, neigh_order,
                                               recalculate=False,
                                               include_parent=True,
                                               output_type='list',
                                               plot=True)
# NOTE: IN refers to Instance number
get_nth_order_neighbors(grain_id, neigh_order, recalculate=False, include_parent=True, plot=False)[source]

Return exactly the nth-order neighbours for a given grain.

Examples

from upxo.ggrowth.mcgs import mcgs
pxt = mcgs()
pxt.simulate()
pxt.detect_grains()
tslice = 20
gstslice = pxt.gs[tslice]
gstslice.export_ctf(r'D:\export_folder', 'sunil')
fname = r'D:\export_folder\sunil'
gstslice.set_pxtal(instance_no=1, path_filename_noext=fname)
IN, gid, neigh_order = 1, 1, 2
gstslice.pxtal[IN].get_nth_order_neighbors(gid, neigh_order,
                            recalculate=False, include_parent=True,
                            plot=True)
# NOTE: IN refers to Instance number
get_upto_nth_order_neighbors_all_grains(neigh_order, recalculate=False, include_parent=True, output_type='list')[source]

Return all neighbours up to the nth order for every grain.

Parameters:

neigh_order (int) – Order of neighbours to accumulate.

Returns:

Mapping of grain ID to list of neighbour grain IDs.

Return type:

dict

Examples

from upxo.ggrowth.mcgs import mcgs
pxt = mcgs()
pxt.simulate()
pxt.detect_grains()
tslice = 20
gstslice = pxt.gs[tslice]
gstslice.export_ctf(r'D:\export_folder', 'sunil')
fname = r'D:\export_folder\sunil'
gstslice.set_pxtal(instance_no=1, path_filename_noext=fname)
IN, neigh_order = 1, 2
gstslice.pxtal[IN].get_upto_nth_order_neighbors_all_grains(
    neigh_order, recalculate=False,
    include_parent=True, output_type='list')
# NOTE: IN refers to Instance number
get_nth_order_neighbors_all_grains(neigh_order, recalculate=False, include_parent=True)[source]

Return exactly the nth-order neighbours for every grain.

Examples

from upxo.ggrowth.mcgs import mcgs
pxt = mcgs()
pxt.simulate()
pxt.detect_grains()
tslice = 20
gstslice = pxt.gs[tslice]
gstslice.export_ctf(r'D:\export_folder', 'sunil')
fname = r'D:\export_folder\sunil'
gstslice.set_pxtal(instance_no=1, path_filename_noext=fname)
IN, neigh_order = 1, 2
gstslice.pxtal[IN].get_nth_order_neighbors_all_grains(neigh_order,
                                                recalculate=False,
                                                include_parent=True)
# NOTE: IN refers to Instance number
get_upto_nth_order_neighbors_all_grains_prob(neigh_order, recalculate=False, include_parent=False, print_msg=False)[source]

Return probabilistic nth-order neighbours for every grain.

Examples

from upxo.ggrowth.mcgs import mcgs
pxt = mcgs()
pxt.simulate()
pxt.detect_grains()
tslice = 10
def_neigh = pxt.gs[tslice].get_upto_nth_order_neighbors_all_grains_prob

neigh0 = def_neigh(1, recalculate=False, include_parent=True)
neigh1 = def_neigh(1.06, recalculate=False, include_parent=True)
neigh2 = def_neigh(1.5, recalculate=False, include_parent=True)
neigh0[22]
neigh1[2][22]
neigh2[2][22]
check_for_neigh(parent_gid, other_gid)[source]

Check if other_gid is indeed a O(1) neighbour of parent_gid.

Parameters:
  • parent_gid – Grain ID of the parent.

  • other_gid – Grain ID of the other grain being checked for O(1) neighbourhood with parent_gid.

Return type:

True if other_gid is a valid O(1) neighbour of parent_gid, else False.

get_two_rand_o1_neighs()[source]

Calculate at random, two neighbouring O(1) grains.

plot_two_rand_neighs(return_gids=True)[source]

Plot two random neighbouring grains.

Parameters:

return_gids (bool) – Flag to return the random neigh gid numbers. Defaults to True.

Returns:

rand_neigh_gids – random neigh gid numbers. Will be gids if return_gids is True. Else, will be [None, None].

Return type:

list

Examples

# See get_two_rand_o1_neighs() for usage.
rand_gids = gstslice.pxtal[1].plot_two_rand_neighs(return_gids=True)
merge_two_neigh_grains(parent_gid, other_gid, check_for_neigh=True, simple_merge=True)[source]

Merge other_gid grain to the parent_gid grain.

Parameters:
  • parent_gid – Grain ID of the parent.

  • other_gid – Grain ID of the other grain being merged into the parent.

  • check_for_neigh (bool.) – If True, other_gid will be checked if it can be merged to the parent grain. Defaults to True.

Returns:

merge_success – True, if successfully merged, else False.

Return type:

bool

get_grain_pixel_coords(gid)[source]

Return pixel coordinates of the given grain.

set_grain_centroids(coord_source='upxo_lgi')[source]

Compute and store centroids for all grains.

get_grain_centroid(gid, recalculate=True)[source]

Return the centroid of the given grain.

find_largest_grain()[source]

Return the grain ID of the grain with the most pixels.

plot_data_imshow_and_get_axis(data)[source]

Plot data using imshow and return the figure, image and axis.

Examples

fig, im, ax = self.plot_data_imshow_and_get_axis(data)
map_scalar_to_lgi(scalars_dict, default_scalar=-1, plot=True, throw_axis=True, plot_centroid=True, plot_gid_number=True, title='title', centroid_kwargs={'marker': 'o', 'mec': 'black', 'mfc': 'yellow', 'ms': 2.5}, gid_text_kwargs={'fontsize': 10}, title_kwargs={'fontsize': 10}, label_kwargs={'fontsize': 10})[source]

Map to LGI, the gid keyed values in scalars_dict.

Parameters:
  • scalars_dict (dict) – Dictionary with keys being a subset of self.gid. Each key must have a single numeric or bool value.

  • default_scalar (int) – Defaults to -1.

Examples

from upxo.ggrowth.mcgs import mcgs
pxt = mcgs()
pxt.simulate()
pxt.detect_grains()
tslice = 20
pxt.char_morph_2d(tslice)
gstslice = pxt.gs[tslice]
gstslice.export_ctf(r'D:\export_folder', 'sunil')
# ---------------------------
fname = r'D:\export_folder\sunil'
gstslice.set_pxtal(instance_no=1, path_filename_noext=fname)
gstslice.pxtal[1].find_gbseg1()
GIDs, VALIND = gstslice.pxtal[1].get_gids_in_params_bounds(
    search_gid_source='all', search_gids=None,
    mpnames=['area', 'solidity'],
    fx_stats=[np.mean, np.mean],
    pdslh=[[20, 20], [5, 5]],
    param_priority=[1, 2, 3, 2],
    plot_mprop=False)
gstslice.pxtal[1].map_scalar_to_lgi(GIDs['presence'],
                                    default_scalar=-1,
                                    plot=True, throw_axis=True)

gid_mprop_map = mcgs.gs[35].get_gid_mprop_map(
    'aspect_ratio', GIDs['mpmapped']['aspect_ratio'])
MPLGIAX = mcgs.gs[35].map_scalar_to_lgi(gid_mprop_map,
                      default_scalar=-1, plot=True, throw_axis=True)
property get_csym

Get crystal symmetry.

property get_pphid

Get primary phase ID.

property get_scale

Get scale.

property get_shape

Get shape of the map.

property get_xdim

Get xdim.

property get_ydim

Get ydim.

property get_nph

Get number of phases.

property get_glist

Get grain list.

property get_bc

Get band contrast of map.

property get_bs

Get band slope.

property get_boundaries

Get grain boundaries.

property get_boundariesX

Get x-grad identified grain boundary points.

property get_boundariesY

Get y-grad identified grain boundary points.

property get_q

Return the quaternion array from the map.

property get_ea

Return the Euler angle array from the map.

property get_coord

Return the coordinate list of the first grain.

plot_grains()[source]

Plot the grain map.

plot_gb()[source]

Plot the grain boundary map.

plot_phase()[source]

Plot the phase map.

plot_bc()[source]

Plot the band contrast map.

plot_ea()[source]

Plot the Euler angle map.

plotIPFMap(direction)[source]

Plot the IPF map for the given direction.

Examples

pxt.gs[tslice].xomap_plotIPFMap([1, 0, 0])
mask_lgi_with_gids(gids, masker=-10)[source]

Mask the lgi (PXGS.gs[n] specific lgi array: lattice of grain IDs) against user input grain indices, with a default UPXO-reserved place-holder value of -10.

Parameters:
  • gids (int/list) – Either a single grain index number or list of them

  • kwargs

    masker:

    An int value, preferably -10, but compulsorily less than -5.

Returns:

  • s_masked (np.ndarray(dtype=int)) – lgi masked against gid values

  • Internal calls (@dev)

  • ———————

  • None

get_bbox_bounds_gids(gids, plot=True, cmap_name='viridis', plot_centroids=True, add_gid_text=True, plot_gbseg=False)[source]

Return the bbox bounds gids.

polygonize_voronoi_grid()[source]

Polygonizes grains in self.lgi and returns a shapely MultiPolygon.

Parameters:

grid (A NumPy array representing the integer grid values.)

Returns:

  • rioshapes

  • polygons (list of shapely polygon objects of each grain)

  • multi_polygon (shapely multi-polygon object)

plot_grains_gids(gids, add_points=True, points=None, gclr='color', title='user grains', cmap_name='viridis', plot_centroids=True, add_gid_text=True, plot_gbseg=False, bjp_kwargs={'marker': 'o', 'mec': 'black', 'mfc': 'yellow', 'ms': 2.5}, addpoints_kwargs={'marker': 'x', 'mec': 'black', 'mfc': 'black', 'ms': 5})[source]
Parameters:
  • gids (int/list) – Either a single grain index number or list of them

  • title (TYPE, optional) – DESCRIPTION. The default is “user grains”.

  • gclr

Return type:

None.

Examples

# Acquire gids for aspect_ratio between ranks 80 and 100,
# then visualize those grains.
gid, _, __ = PXGS.gs[8].get_gid_prop_range(
    PROP_NAME='aspect_ratio',
    range_type='rank',
    rank_range=[80, 100])
PXGS.gs[8].plot_grains_gids(gid, cmap_name='CMRmap_r')
plotgs(figsize=(6, 6), dpi=120, custom_lgi=None, cmap='coolwarm', plot_cbar=True, title='Title', plot_centroid=False, plot_gid_number=False, plot_bjp=True, centroid_kwargs={'marker': 'o', 'mec': 'black', 'mfc': 'yellow', 'ms': 2.5}, gid_text_kwargs={'fontsize': 10}, title_kwargs={'fontsize': 10}, label_kwargs={'fontsize': 10})[source]

Plot the grain structure LGI map.

Examples

from upxo.ggrowth.mcgs import mcgs
mcgs = mcgs(study='independent', input_dashboard='input_dashboard.xls')
mcgs.simulate()
mcgs.detect_grains()
mcgs.gs[35].plotgs(figsize=(6, 6), dpi=120, cmap='coolwarm',
                   plot_centroid=True,
                   centroid_kwargs={'marker': 'o', 'mfc': 'yellow',
                                    'mec': 'black', 'ms': 2.5},
                   plot_gid_number=True)
plot_gb_discrete(cmap='coolwarm', bjp_kwargs={'marker': 'o', 'mec': 'black', 'mfc': 'yellow', 'ms': 2.5}, simple_all_preference='simple', add_centroids=True, add_gid_text=True, return_axis=False)[source]

Plot grain boundary contours on the LGI map.

plot_contour_grains_all(simple_all_preference='simple', new_fig=True, ax=None, bjp_kwargs={'marker': 'o', 'mec': 'black', 'mfc': 'yellow', 'ms': 2.5})[source]

Plot contour boundaries for all grains.

plot_contour_grains_gids(gids, simple_all_preference='simple', new_fig=True, ax=None, bjp_kwargs={'marker': 'o', 'mec': 'black', 'mfc': 'yellow', 'ms': 2.5})[source]

Plot contour boundaries for the specified grain IDs.

plot_contour_grain_gid(gid, simple_all_preference='simple', new_fig=True, ax=None, bjp_kwargs={'marker': 'o', 'mec': 'black', 'mfc': 'yellow', 'ms': 2.5})[source]

Plot the contour boundary of a single grain.

plot_grain_centroid(gid, axis, add_gid_text=True)[source]

Plot the centroid of a single grain on the given axis.

map
lgi
gid
n
g
bjp
neigh_gid
quat
ea
closs
gbjp
gbseg1
centroids
gb_discrete
gidshuffled
bbox
bbox_bounds
bbox_ex
bbox_ex_bounds
positions
geom
plot_grain_centroids(gids, axis, add_gid_text=True)[source]

Plot centroids for the given grain IDs on the given axis.