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.
- find_grains_gb(gb_misori=10, min_grain_size=1, print_msg=True)[source]
Find grain boundaries and build neighbourhood network.
- 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:
- 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')
- find_neigh(update_gid=True, reset_lgi=False)[source]
Find O(1) neighbours for every grain and store in neigh_gid.
- extract_gb_discrete(retrieval_method='external', chain_approximation='simple')[source]
Extract grain boundaries of every grain.
- 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)
- 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:
- 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:
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.
- 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:
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:
- 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:
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.
- 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