upxo.repqual.grain_network_repr_assesser module
Created on Fri Jun 7 10:10:42 2024
@author: Dr. Sunil Anandatheertha
- class upxo.repqual.grain_network_repr_assesser.KREPR(**kwargs)[source]
Bases:
objectGrain-network representativeness assessor (2D K-topology / morphometrics).
Compares target and sample grain structures via neighbour networks (NetworkX / UPXO netops), morphological property tables, and distribution distances (Wasserstein, KS, energy distance, optional NetLSD). Used by
repgen2dranking and standalone R-field studies.Import:
from upxo.repqual.grain_network_repr_assesser import KREPR
Parameters / attributes
- upxogs_tgt, upxogs_smp
Single UPXO grain-structure objects when used in one-vs-one mode.
- tgset, sgsetdict
Sets of target / sample grain structures (keys often tslices).
- tkset, sksetdict
Neighbour-network graphs (or adjacency dicts) for target / sample, keyed by neighbour order
ordern.- tnset, snsetdict
UPXO neighbour maps (gid → neighbour gids) by order.
- tmpset, smpsetdict
Morphological property sets for target / sample.
- tid, sidlist
Usable target / sample IDs (subset of set keys); default all keys.
- ordernlist
Neighbour orders to analyse (default
[1]if unset).- mprop2d_flags, mprop3d_flags, sprop2d_flags, sprop3d_flagsdict
Flags controlling which morphological properties are computed.
- mprop2d, mprop3d, sprop2d, sprop3ddict
Computed morphological property stores.
- rkfdict
Network-based R-field data; set before full representativeness runs.
- _cim_: str
Class initiation method, not intended for user use.
Author: Dr. Sunil Anandatheertha
om jayanti man’gaLA kALi bhadrakALi kapAlini | durgA kshamA shivA dhAtri svAhA svadhA namOstute ||
- mp_gspn_map
- dim
- gstype
- tid
- sid
- upxogs_tgt
- upxogs_smp
- tgset
- sgset
- tkset
- skset
- tnset
- snset
- classmethod from_gs(*, upxogs_tgt=None, upxogs_smp=None, tgset=None, sgset=None, ordern=[1], tsid_source='from_gs', ssid_source='from_gs', tid=None, sid=None, _cim_='from_gs', gstype_tgt='mcgs2d', gstype_smp='mcgs3d')[source]
Instantiate network based repr class using UPXO grain structure.
- Parameters:
upxogs_tgt
upxogs_smp
tgset (dict) – Target grain structures. Defaults to None.
sgset (dict) – Sample grain structures. Defaults to None.
ordern (list) – Neighbour order-n to be used. Defaults to [1].
_cim_ (str) – Class initiation method. Defaults to ‘from_gs’. Not intended for user. Leave it alone.
mcgs (from upxo.ggrowth.mcgs import)
mcgs(study='independent' (tgt =)
input_dashboard='input_dashboard.xls')
tgt.simulate()
tgt.detect_grains()
tgt.char_morph_2d(tgt.m)
{i (tgset =)
KREPR (from upxo.repqual.grain_network_repr_assesser import)
KREPR.from_gs(tgset=tgset (kr =)
sgset=tgset
ordern=[1
5])
kr.creation_method
kr.calculate_mprop2d()
kr.set_rkf(js=True – btwcen=False, clscen=False, egnvcen=False)
wd=True – btwcen=False, clscen=False, egnvcen=False)
ksp=True – btwcen=False, clscen=False, egnvcen=False)
ed=True – btwcen=False, clscen=False, egnvcen=False)
nlsd=True – btwcen=False, clscen=False, egnvcen=False)
degcen=False – btwcen=False, clscen=False, egnvcen=False)
:param : btwcen=False, clscen=False, egnvcen=False) :param kr.calculate_rkf(): :param kr.plot_rkf(neigh_orders=[1: xtick_incr=5, ytick_incr=5, lfs=7, tfs=8,
cmap=’nipy_spectral’, cbarticks=np.arange(0, 1.1, 0.1), cbfs=10, cbtitle=’Measure of representativeness R(S|T)’, cbfraction=0.046, cbpad=0.04, cbaspect=30, shrink=0.5, cborientation=’vertical’, flags={‘rkf_js’: False, ‘rkf_wd’: True,
‘rkf_ksp’: True, ‘rkf_ed’: True, ‘rkf_nlsd’: True, ‘rkf_degcen’: False, ‘rkf_btwcen’: False, ‘rkf_clscen’: False, ‘rkf_egnvcen’: False})
- Parameters:
5] –
xtick_incr=5, ytick_incr=5, lfs=7, tfs=8, cmap=’nipy_spectral’, cbarticks=np.arange(0, 1.1, 0.1), cbfs=10, cbtitle=’Measure of representativeness R(S|T)’, cbfraction=0.046, cbpad=0.04, cbaspect=30, shrink=0.5, cborientation=’vertical’, flags={‘rkf_js’: False, ‘rkf_wd’: True,
’rkf_ksp’: True, ‘rkf_ed’: True, ‘rkf_nlsd’: True, ‘rkf_degcen’: False, ‘rkf_btwcen’: False, ‘rkf_clscen’: False, ‘rkf_egnvcen’: False})
power=1 –
xtick_incr=5, ytick_incr=5, lfs=7, tfs=8, cmap=’nipy_spectral’, cbarticks=np.arange(0, 1.1, 0.1), cbfs=10, cbtitle=’Measure of representativeness R(S|T)’, cbfraction=0.046, cbpad=0.04, cbaspect=30, shrink=0.5, cborientation=’vertical’, flags={‘rkf_js’: False, ‘rkf_wd’: True,
’rkf_ksp’: True, ‘rkf_ed’: True, ‘rkf_nlsd’: True, ‘rkf_degcen’: False, ‘rkf_btwcen’: False, ‘rkf_clscen’: False, ‘rkf_egnvcen’: False})
figsize=(7 –
xtick_incr=5, ytick_incr=5, lfs=7, tfs=8, cmap=’nipy_spectral’, cbarticks=np.arange(0, 1.1, 0.1), cbfs=10, cbtitle=’Measure of representativeness R(S|T)’, cbfraction=0.046, cbpad=0.04, cbaspect=30, shrink=0.5, cborientation=’vertical’, flags={‘rkf_js’: False, ‘rkf_wd’: True,
’rkf_ksp’: True, ‘rkf_ed’: True, ‘rkf_nlsd’: True, ‘rkf_degcen’: False, ‘rkf_btwcen’: False, ‘rkf_clscen’: False, ‘rkf_egnvcen’: False})
5) –
xtick_incr=5, ytick_incr=5, lfs=7, tfs=8, cmap=’nipy_spectral’, cbarticks=np.arange(0, 1.1, 0.1), cbfs=10, cbtitle=’Measure of representativeness R(S|T)’, cbfraction=0.046, cbpad=0.04, cbaspect=30, shrink=0.5, cborientation=’vertical’, flags={‘rkf_js’: False, ‘rkf_wd’: True,
’rkf_ksp’: True, ‘rkf_ed’: True, ‘rkf_nlsd’: True, ‘rkf_degcen’: False, ‘rkf_btwcen’: False, ‘rkf_clscen’: False, ‘rkf_egnvcen’: False})
dpi=120 –
xtick_incr=5, ytick_incr=5, lfs=7, tfs=8, cmap=’nipy_spectral’, cbarticks=np.arange(0, 1.1, 0.1), cbfs=10, cbtitle=’Measure of representativeness R(S|T)’, cbfraction=0.046, cbpad=0.04, cbaspect=30, shrink=0.5, cborientation=’vertical’, flags={‘rkf_js’: False, ‘rkf_wd’: True,
’rkf_ksp’: True, ‘rkf_ed’: True, ‘rkf_nlsd’: True, ‘rkf_degcen’: False, ‘rkf_btwcen’: False, ‘rkf_clscen’: False, ‘rkf_egnvcen’: False})
- :paramxtick_incr=5, ytick_incr=5, lfs=7, tfs=8,
cmap=’nipy_spectral’, cbarticks=np.arange(0, 1.1, 0.1), cbfs=10, cbtitle=’Measure of representativeness R(S|T)’, cbfraction=0.046, cbpad=0.04, cbaspect=30, shrink=0.5, cborientation=’vertical’, flags={‘rkf_js’: False, ‘rkf_wd’: True,
‘rkf_ksp’: True, ‘rkf_ed’: True, ‘rkf_nlsd’: True, ‘rkf_degcen’: False, ‘rkf_btwcen’: False, ‘rkf_clscen’: False, ‘rkf_egnvcen’: False})
- Parameters:
measure (data_title = 'R-Field)
5 (n_bins =)
AD – neigh_orders=[1, 5], n_bins=n_bins, data_title=data_title, throw=True, plot_ad=False)
kr.calculate_uncertainty_angdist(rkf_measure='ed' (AX =) – neigh_orders=[1, 5], n_bins=n_bins, data_title=data_title, throw=True, plot_ad=False)
- :paramneigh_orders=[1, 5],
n_bins=n_bins, data_title=data_title, throw=True, plot_ad=False)
- Parameters:
kr.plot_ang_dist(AD – figsize=(5, 5), dpi=150, data_title=data_title, cmap=’nipy_spectral’)
neigh_orders=[1 – figsize=(5, 5), dpi=150, data_title=data_title, cmap=’nipy_spectral’)
5] – figsize=(5, 5), dpi=150, data_title=data_title, cmap=’nipy_spectral’)
n_bins=n_bins – figsize=(5, 5), dpi=150, data_title=data_title, cmap=’nipy_spectral’)
- :paramfigsize=(5, 5), dpi=150, data_title=data_title,
cmap=’nipy_spectral’)
- Parameters:
kr.calculate_mprop2d()
- classmethod from_neigh(*, tnset=None, snset=None, ordern=[1], tsid_source='from_neigh', ssid_source='from_neigh', tid=None, sid=None, _cim_='from_neigh')[source]
# Assuming 20 tslices being available witrh increments of tslice=1, # we will go through the folloing example.
ordern = [1, 3]
from upxo.ggrowth.mcgs import mcgs tgt = mcgs(study=’independent’, input_dashboard=’mcgs2d_100x100_m50_q10_mcalg201.xls’) tgt.simulate() tgt.detect_grains() tslices = np.array(list(tgt.gs.keys()))[1::10] tnset = {no: {tslice: None for tslice in tslices} for no in ordern} for no in ordern:
- for tslice in tslices:
_ = tgt.gs[tslice].get_upto_nth_order_neighbors_all_grains tnn = _(no, include_parent=True, output_type=’nparray’) tnset[no][tslice] = tnn
smp = mcgs(study=’independent’, input_dashboard=’mcgs2d_100x100_m50_q10_mcalg201.xls’) smp.simulate() smp.detect_grains() tslices = np.array(list(smp.gs.keys()))[1::10] snset = {no: {tslice: None for tslice in tslices} for no in ordern} for no in ordern:
- for tslice in tslices:
_ = smp.gs[tslice].get_upto_nth_order_neighbors_all_grains snn = _(no, include_parent=True, output_type=’nparray’) snset[no][tslice] = snn
from upxo.repqual.grain_network_repr_assesser import KREPR kr = KREPR.from_neigh(tnset=tnset, snset=tnset,
tid=list(tnset.keys()), sid=list(snset.keys()), _cim_=’from_neigh’)
kr.snset.keys() kr.snset[3].keys() kr.snset[3][11] kr.snset[3][11][40] # <– O(3) Neigh gids of gid=40 of tslice = 11 kr.ordern kr.tid
- classmethod from_k(*, tkset=None, skset=None, ordern=[1], tsid_source='from_k', ssid_source='from_k', tid=None, sid=None, _cim_='from_k')[source]
# Assuming 20 tslices being available witrh increments of tslice=1, # we will go through the folloing example.
ordern = [1, 3]
from upxo.ggrowth.mcgs import mcgs tgt = mcgs(study=’independent’, input_dashboard=’mcgs2d_100x100_m50_q10_mcalg201.xls’) tgt.simulate() tgt.detect_grains() tslices = np.array(list(tgt.gs.keys()))[1::10] tkset = {no: {tslice: None for tslice in tslices} for no in ordern} for no in ordern:
- for tslice in tslices:
_ = tgt.gs[tslice].get_upto_nth_order_neighbors_all_grains tnn = _(no, include_parent=True, output_type=’nparray’) tnn_k = kmake.create_grain_network_nx(tnn) tkset[no][tslice] = tnn_k
smp = mcgs(study=’independent’, input_dashboard=’mcgs2d_100x100_m50_q10_mcalg201.xls’) smp.simulate() smp.detect_grains() tslices = np.array(list(smp.gs.keys()))[1::10] skset = {no: {tslice: None for tslice in tslices} for no in ordern} for no in ordern:
- for tslice in tslices:
_ = smp.gs[tslice].get_upto_nth_order_neighbors_all_grains snn = _(no, include_parent=True, output_type=’nparray’) snn_k = kmake.create_grain_network_nx(snn) skset[no][tslice] = snn_k
from upxo.repqual.grain_network_repr_assesser import KREPR kr = KREPR.from_k(tkset=tkset, skset=tkset,
tid=list(tkset.keys()), sid=list(skset.keys()), _cim_=’from_k’)
kr.tkset kr.ordern kr.tid
- classmethod from_gsgen(gstype_tgt='mcgs2d', gstype_smp='mcgs3d', is_smp_same_as_tgt=False, characterize_tgt=True, characterize_smp=True, tgt_dashboard='input_dashboard_krepr1.xls', smp_dashboard='input_dashboard_krepr2.xls', ordern=[1], tsid_source='from_neigh', ssid_source='from_neigh', tid=None, sid=None, _cim_='from_gsgen')[source]
Initiate KREPR by generating target and sample grain structure sets.
- Parameters:
gstype (str) – Type of grain structure needed. Could be deprecated later on. Defaults to ‘mcgs’.
is_smp_same_as_tgt (bool) – Defaults to False.
tgt_dashboard (str) – Defaults to ‘input_dashboard.xls’.
smp_dashboard (str) – Defaults to ‘input_dashboard.xls’.
_cim_ (str) – Defaults to ‘from_gsgen’.
Explanations
------------
Example
from upxo.repqual.grain_network_repr_assesser import KREPR kr = KREPR.from_gsgen(gstype=’mcgs’,
is_smp_same_as_tgt = False, tgt_dashboard=’input_dashboard.xls’, smp_dashboard=’input_dashboard.xls’, _cim_=’from_gsgen’)
kr.tgset kr.ordern kr.tid
- property creation_method
Creation method.
- set_ordern(ordern)[source]
Set the n values in O(n).
Parametyers
- ordern: list
O(n) values
- rtype:
None
- set_mprop2d_flags(area_pix=True, area_geo=False, gbl_pix=False, gbl_geo=False, eq_dia=False, ell_a=False, ell_b=False, inclination=False, aspect_ratio=False, roundness=False, circularity=False, solidity=False, formfactor=False, convexity=False, br=False, gbr=False, fractal_dimension=False)[source]
Set flags for operational 2D morphological properties.
- Parameters:
area_pix (Pixel area of the grains. Defaults to True.)
area_geo (Geometric area of the grains. Defaults to False.)
gbl_pix (Pixel gb length of the grains. Defaults to False.)
gbl_geo (Geometric gb length of the grains. Defaults to False.)
eq_dia (Equivalent diameter of the grains. Defaults to False.)
ell_a (Fit ellipse's major axis length of grains. Defaults to False.)
ell_b (Fit ellipse's minor axis length of grains. Defaults to False.)
inclination (Morphological inclination of grains. Defaults to False.)
their (The input arguments for characterisaion module for mcgs 2d and)
are (mapping with the above variables) – npixels: area_pix npixels_gb: gbl_pix area: gbl_pix (preferred as of now) eq_diameter: eq_dia perimeter: gbl_pix perimeter_crofton: not available yet compactness gb_length_px aspect_ratio solidity morph_ori circularity eccentricity feret_diameter major_axis_length minor_axis_length euler_number
structures (Data)
---------------
mprop2d_flags (dict)
- set_mprop3d_flags(volume_vox=False, volume_geo=False, eq_dia=False, gba_vox=False, gba_geo=False, gbl_vox=False, gbl_geo=False, ell_a=False, ell_b=False, ell_c=False, inclination=False, sphericity=False, aspectratio_lw=False, aspectratio_lh=False, aspectratio_wh=False, vol_surfarea_ratio=False, flatness=False, compactness=False, iso_parametric_quotient=False, convextity=False, shape_entropy=False)[source]
Set flags for operational 3D morphological properties.
- Parameters:
volume_vox (Voxellated volume of the grains. Defaults to True.)
volume_geo (Geometric volume of the grains. Defaults to False.)
gba_vox (Voxellated gb surface area of grains. Defaults to False.)
gba_geo (Geometric gb surface area of grains. Defaults to False.)
gbl_vox (Voxellated gb length of grains. Defaults to False.)
gbl_geo (Geometric gb length of grains. Defaults to False.)
eq_dia (Equivalent diameter of the grains. Defaults to False.)
ell_a (Fit ellipsoid's 1st axis length of grains. Defaults to False.)
ell_b (Fit ellipsoid's 2nd axis length of grains. Defaults to False.)
ell_c (Fit ellipsoid's 3rd axis length of grains. Defaults to False.)
inclination (Morphological inclination of grains. Defaults to False.)
structures (Data)
---------------
mprop3d_flags (dict)
- calculate_mprop2d(print_msg_tors=True, print_msg_prnm=True, print_msg_no=True, print_msg_gsid=False, print_msg_gid=False)[source]
Data structure
- kr.mprop2d: dict
- kr.mprop2d[tors]: dict
- kr.mprop2d[tors][prnm]: dict
- kr.mprop2d[tors][prnm][no]: dict
- kr.mprop2d[tors][prnm][no][gsid]: dict
- kr.mprop2d[tors][prnm][no][gsid][gid]: np.array
kr.mprop2d[tors][prnm][no][gsid][gid][i]: float
- Where,
mprop2d: 2d morphology properties tors: either ‘tgt’ or ‘smp’ prnm: property name no: neighbour order gsid: grain structure ID gid: grain ID i: prnm Property value of ith neighbour of gid grain of tors gid
for O(n) = on.
Data access
- kr.mprop2d[‘tgt’][‘area_pix’][O(n)][gsid][GID]. This contains a
list of gids which are O(n) neighbours of GID grain.
Example
gid = 2 kr.mprop2d[‘tgt’][‘area_pix’][1.25][8][gid] The correspionding neighbour data is: kr.tnset[1.25][8][gid]
Note
len(kr.tnset[1.25][8][gid]) = kr.mprop2d[‘tgt’][‘area_pix’][1.25][8][gid].size
mpflags: local copy of morpho prop flag. reqprop: keys in mpflags with True values. tors: target or sample: self.mprop2d keys. prnm: property name in the list of values in reqprop. no: neighbour order in list kr.ordern. gsid: Grain structue ID in self.tid gid: Grain IDs in local neighbour network.
Author: Dr. Sunil Anandatheertha
- estimate_upper_ordern_bycount(tors='tgt', gsid=1, on_start=1.0, on_max=10.0, on_incr=0.5, neigh_count_vf_max=0.8, include_parent=True, kdeplot=True, kdeplot_kwargs={'cmap': 'cividis', 'dpi': 120, 'figsize': (5, 5), 'fill': True, 'fs_legend': 10, 'fs_xlabel': 12, 'fs_xticks': 10, 'fs_ylabel': 12, 'fs_yticks': 10, 'legend_loc': 'best', 'legend_ncols': 2}, statplot=True, statplot_kwargs={'dpi': 120, 'figsize': (5, 5), 'stat': 'mean'}, gsplot=True, gsplot_kwargs={'dpi': 120, 'figsize': (5, 5)})[source]
Estimate O(n) needed to reach neigh_count_vf_max.
- Parameters:
tors (str) – Specify ‘tgt’ for Target and ‘smp’ for Sample. Defaults to ‘tgt’.
gsid (int) – Grain Structure ID. Defaults to 1.
on_start (float) – Minimum O(n) value to start iterations from. on_start >= 1. Defaults to 1.0.
on_max (float) – Maximum O(n) value to end iterating. on_max >= on_start. Defaults to 10.0.
on_incr (float) – del(O(n)) increments to o(n) search space. on_incr >= 0.1. Defaults to 0.5.
neigh_count_vf_max (float) – neigh_count_vf value to stop iterating. 0.11 < neigh_count_vf_max < 0.99, generally, although value may change depending on grain structure. Note: these bounds are not accurate. Defaults to 0.8.
include_parent (bool) – Include gid in the neigh list of gid if True, else exclude. Defaults to True.
plot_kde (bool) – Plot kdes of a list containing total number of neighbours of every gid in the grain structure for each O(n). Defaults to True.
- Returns:
LON (float) – Limiting Order-n
neighn_stats (dict) – keys: on of every iteration. value: dict
- (key, value):
’mean’ neighn.min() ‘min’: neighn.min() ‘max’: neighn.max() ‘std’: neighn.std() ‘var’: neighn.var() ‘iqr’: stats.iqr(neighn): Inter-quartile range ‘sem’: stats.sem(neighn): Standard Error of the Mean
- Where,
neighn = np.array([len(neighs) for neighs in ngh.values()]) ngh: dict: {gid: gid neighbours list}
Ng (int) – Number of grains in the provided grain structure.
Explanations
————
As O(n) increases the number of order-n neighbours (N) for a gid
increases. But, it cannot increase for ever. Its maximum value is
the total number of grains in the grain structure. The ratio of N to
total number of grains (i.e. neigh_count_vf) is then unity. However,
for o(n) < O(n), neigh_count_vf < 1. This function helps determine
o(n) for which neigh_count_vf < neigh_count_vf_max.
The kde if plotted, will show the following trends –
Shift right as o(n) increases during iterations.
Peak drops initially as o(n) increases and as width increases.
Peak increase again as o(n) increases further and width decreases.
- create_gid_network(dataid='tgt', neigh_order=1, gsid=1)[source]
Create the network nx graph from the neighbours dictionary.
- Parameters:
dataid (str. Options: 'tgt' (default), 'smp'.)
neigh_order (int. Order of the raw neighbours data-structure. Defaults) – to 1.
gsid (int. ID of the grain structure. Defaults to 1.)
- Returns:
nxg
- Return type:
network nx graph.
- create_tgt_networks(saa=True, throw=False)[source]
Create networkx graphs for all target gs neighbours database.
- Parameters:
saa (bool.) – Save as attrbute of True. Defults to True.
throw (bool.) – Return value if True. Defaults to False.
structure (Data)
--------------
dict(no1 (dict(gsid1: dict(gid1: [12, 1, 16,..]))),) – no2: dict(gsid2: dict(gid2: [16, 15, 8,..]))),… noi: dict(gsidj: dict(gidk: [2, 86, 95,..]))),… noN: dict(gsidM: dict(gidG: [20, 15, 196,..]))),… )
Where –
noi: an element of ordern list of size N. gsidj: jth grain structure’s ID of a toytal of M grain structes. gidk: kth grain ID of all G grains. noi-gsidj-gidk: kth grain ID in the jth grain structure’s
neighbour network dictionary of the ith O(n) database.
- :paramnoi: an element of ordern list of size N.
gsidj: jth grain structure’s ID of a toytal of M grain structes. gidk: kth grain ID of all G grains. noi-gsidj-gidk: kth grain ID in the jth grain structure’s
neighbour network dictionary of the ith O(n) database.
- create_smp_networks(saa=True, throw=False)[source]
Create networkx graphs for all sample gs neighbours database.
- Parameters:
saa (bool.) – Save as attrbute of True. Defults to True.
throw (bool.) – Return value if True. Defaults to False.
structure (Data)
--------------
dict(no1 (dict(gsid1: dict(gid1: [12, 1, 16,..]))),) – no2: dict(gsid2: dict(gid2: [16, 15, 8,..]))),… noi: dict(gsidj: dict(gidk: [2, 86, 95,..]))),… noN: dict(gsidM: dict(gidG: [20, 15, 196,..]))),… )
Where –
noi: an element of ordern list of size N. gsidj: jth grain structure’s ID of a toytal of M grain structes. gidk: kth grain ID of all G grains. noi-gsidj-gidk: kth grain ID in the jth grain structure’s
neighbour network dictionary of the ith O(n) database.
- :paramnoi: an element of ordern list of size N.
gsidj: jth grain structure’s ID of a toytal of M grain structes. gidk: kth grain ID of all G grains. noi-gsidj-gidk: kth grain ID in the jth grain structure’s
neighbour network dictionary of the ith O(n) database.
- create_tgt_smp_networks(saa=True, throw=False)[source]
Create networkx graphs for all tgt and smp gs neighbours database.
- Parameters:
saa (bool.) – Save as attrbute of True. Defults to True.
throw (bool.) – Return value if True. Defaults to False.
structure (Data)
--------------
dict(no1 (dict(gsid1: dict(gid1: [12, 1, 16,..]))),) – no2: dict(gsid2: dict(gid2: [16, 15, 8,..]))),… noi: dict(gsidj: dict(gidk: [2, 86, 95,..]))),… noN: dict(gsidM: dict(gidG: [20, 15, 196,..]))),… )
Where –
noi: an element of ordern list of size N. gsidj: jth grain structure’s ID of a toytal of M grain structes. gidk: kth grain ID of all G grains. noi-gsidj-gidk: kth grain ID in the jth grain structure’s
neighbour network dictionary of the ith O(n) database.
- :paramnoi: an element of ordern list of size N.
gsidj: jth grain structure’s ID of a toytal of M grain structes. gidk: kth grain ID of all G grains. noi-gsidj-gidk: kth grain ID in the jth grain structure’s
neighbour network dictionary of the ith O(n) database.
- set_rkf(js=False, wd=False, ksp=False, ed=False, nlsd=False, degcen=False, btwcen=False, clscen=False, egnvcen=False)[source]
Set rkf field calculation flags and initiate rkf dict accordingly.
- Parameters:
js (bool) – Jaccard similarity measure of representativeness. Defaults to True
wd (bool) – Wasserstein distance measure of representativeness. Defaults to True
ksp (bool) – K-S test P-value measure of representativeness. Defaults to False
ed (bool) – Energy distance measure of representativeness. Defaults to True
nlsd (bool) – NetLSD similarity measure of representativeness. Defaults to False
degcen (bool) – Betweenness Centrality. How connected each grain is. Defaults to False.
btwcen (bool) – Betweenness Centrality. How important a grain is in connecting others. Defaults to False.
clscen (bool) – Closeness Centrality. How close a grain is to all other grains. Defaults to False.
egnvcen (bool) – Eigenvector Centrality. How influential a grain is within the network. Defaults to False.
structures (Data)
---------------
{n (kr.rkf[RMNAME] =)
Where – MNAME = Repr metric name in (‘js’, ‘wd’, ‘ksp’, ‘ed’, ‘nlsd’) ZEROS = np.zeros((len(kr.sid), len(kr.tid)))
- :paramMNAME = Repr metric name in (‘js’, ‘wd’, ‘ksp’, ‘ed’, ‘nlsd’)
ZEROS = np.zeros((len(kr.sid), len(kr.tid)))
- initiate_rk_dict(js=False, wd=False, ksp=False, ed=False, nlsd=False, degcen=False, btwcen=False, clscen=False, egnvcen=False)[source]
Initiate dictionaries to store representativeness measures.
- Parameters:
js (bool) – Jaccard similarity measure of representativeness. Defaults to True
wd (bool) – Wasserstein distance measure of representativeness. Defaults to True
ksp (bool) – K-S test P-value measure of representativeness. Defaults to False
ed (bool) – Energy distance measure of representativeness. Defaults to True
nlsd (bool) – NetLSD similarity measure of representativeness. Defaults to False
structures (Data)
---------------
{n (kr.rkf[RMNAME] =)
Where – MNAME = Repr metric name in (‘js’, ‘wd’, ‘ksp’, ‘ed’, ‘nlsd’) ZEROS = np.zeros((len(kr.sid), len(kr.tid)))
- :paramMNAME = Repr metric name in (‘js’, ‘wd’, ‘ksp’, ‘ed’, ‘nlsd’)
ZEROS = np.zeros((len(kr.sid), len(kr.tid)))
- calculate_kdeg(ktgt, ksmp)[source]
Calculate the node degrees of target and sample gs O(n) networks.
Paramerters
ktgt: target grain structure O(n) neighbour network graph. ksmp: sample grain structure O(n) neighbour network graph.
- returns:
kd_tgt (node degrees of target gs O(n) neigh network graph.)
kd_smp (node degrees of sample gs O(n) neigh network graph.)
Data structures
—————
ktgt (networkx graph for target gs’s O(n) neighbour netwprk dict data.)
ksmp (networkx graph for sample gs’s O(n) neighbour netwprk dict data.)
kd_tgt (list: nodal degres of ktgt)
kd_smp (list: nodal degres of ksmp)
Exzplanations
————-
This def calls for calculate_kdegrees. Please refer to
upxo.netops.kchar.calculate_kdegrees for complete documentaion.
- calculate_kdeg_equal_binning(ktgt, ksmp)[source]
Calculate the node degrees of T and S gs O(n) k’s and equally bin them.
Paramerters
ktgt: target grain structure O(n) neighbour network graph. ksmp: sample grain structure O(n) neighbour network graph.
- returns:
kd_tgt (node degrees of target gs O(n) neigh network graph.)
kd_smp (node degrees of sample gs O(n) neigh network graph.)
Data structures
—————
ktgt (networkx graph for target gs’s O(n) neighbour netwprk dict data.)
ksmp (networkx graph for sample gs’s O(n) neighbour netwprk dict data.)
kd_tgt (list: nodal degres of ktgt)
kd_smp (list: nodal degres of ksmp)
Exzplanations
————-
This def calls for calculate_kdegrees_equalbinning. Please refer to
upxo.netops.kchar.calculate_kdegrees_equalbinning for complete
documentaion.
Data is binned as per global min and max in degree and the distribtuion
is re-computed using histogram.
- tmpset
- smpset
- ntid
- nsid
- ordern
- rkf_flags
- rkf
- mprop2d_flags
- mprop3d_flags
- mprop2d
- mprop3d
- calculate_rkf_js_pairwise(ktgt, ksmp)[source]
Calculate Jaccard similarity between ktgt and ksmp.
- Parameters:
- Returns:
r (representativeness level.)
Explanations
————
Refer to calculate_rkfield_js for complete documentation.
Location (upxo.netops.kcmp.calculate_rkfield_js)
Data structures
—————
ktgt (networkx graph for target gs’s O(n) neighbour netwprk dict data.)
ksmp (networkx graph for sample gs’s O(n) neighbour netwprk dict data.)
r (int between 0 and 1. Higher the value, greater is) – the representativeness.
- calculate_rkf_wd_pairwise(ktgt, ksmp, equal_bins=False)[source]
Calculate Jaccard similarity between ktgt and ksmp.
- Parameters:
- Returns:
r (representativeness level.)
Explanations
————
Refer to calculate_rkfield_wd for complete documentation.
Location (upxo.netops.kcmp.calculate_rkfield_wd)
Data structures
—————
ktgt (networkx graph for target gs’s O(n) neighbour netwprk dict data.)
ksmp (networkx graph for sample gs’s O(n) neighbour netwprk dict data.)
r (int between 0 and 1. Higher the value, greater is) – the representativeness.
- calculate_rkf_ksp_pairwise(ktgt, ksmp, equal_bins=False)[source]
Calculate Jaccard similarity between ktgt and ksmp.
- Parameters:
- Returns:
r (representativeness level.)
Explanations
————
Refer to calculate_rkfield_ksp for complete documentation.
Location (upxo.netops.kcmp.calculate_rkfield_ksp)
Data structures
—————
ktgt (networkx graph for target gs’s O(n) neighbour netwprk dict data.)
ksmp (networkx graph for sample gs’s O(n) neighbour netwprk dict data.)
r (int between 0 and 1. Higher the value, greater is) – the representativeness.
- calculate_rkf_ed_pairwise(ktgt, ksmp, equal_bins=False)[source]
Calculate Jaccard similarity between ktgt and ksmp.
- Parameters:
- Returns:
r (representativeness level.)
Explanations
————
Refer to calculate_rkfield_ed for complete documentation.
Location (upxo.netops.kcmp.calculate_rkfield_ed)
Data structures
—————
ktgt (networkx graph for target gs’s O(n) neighbour netwprk dict data.)
ksmp (networkx graph for sample gs’s O(n) neighbour netwprk dict data.)
r (int between 0 and 1. Higher the value, greater is) – the representativeness.
- calculate_rkf_nlsd_pairwise(ktgt, ksmp, timescales=numpy.logspace, equal_bins=False)[source]
Calculate Jaccard similarity between ktgt and ksmp.
- Parameters:
- Returns:
r (representativeness level.)
Explanations
————
Refer to calculate_rkfield_nlsd for complete documentation.
Location (upxo.netops.kcmp.calculate_rkfield_nlsd)
Data structures
—————
ktgt (networkx graph for target gs’s O(n) neighbour netwprk dict data.)
ksmp (networkx graph for sample gs’s O(n) neighbour netwprk dict data.)
r (int between 0 and 1. Higher the value, greater is) – the representativeness.
- calculate_rkf_js_on(neigh_order=1)[source]
- Parameters:
notgt (neighbour order of interest for target)
nosmp (neighbour order of interest for sample)
- calculate_rkf_wd_on_generalized(neigh_order_tgt=1, neigh_order_smp=1, equal_bins=False)[source]
Calculate rkf wd on generalized.
- calculate_rkf_ksp_on_generalized(neigh_order_tgt=1, neigh_order_smp=1, equal_bins=False)[source]
Calculate rkf ksp on generalized.
- calculate_rkf_ed_on_generalized(neigh_order_tgt=1, neigh_order_smp=1, equal_bins=False)[source]
Calculate rkf ed on generalized.
- calculate_rkf_nlsd_on(neigh_order=1, timescales=numpy.logspace, equal_bins=False)[source]
Calculate rkf nlsd on.
- calculate_rkf_ed_nlsd_generalized(neigh_order_tgt=1, neigh_order_smp=1, equal_bins=False)[source]
Calculate rkf ed nlsd generalized.
- calculate_rkf_pairwise(neigh_order, idtgt, idsmp, prop='kdegree', printmsg=False)[source]
Calculate rkf pairwise.
- calculate_rkf_pairwise_generalized(neigh_order_tgt, neigh_order_smp, idtgt, idsmp, prop='kdegree', printmsg=False)[source]
Calculate rkf pairwise generalized.
- calculate_rkf(prop='kdegree')[source]
Calculate the network R-Field values for entire tgt and smp database.
Parmeters
- prop: str
- property name. Defaults to ‘kdegree’. Options include:
‘kdegree’
‘area_pixel’
‘volume_voxel’
‘gblength_pixel’
‘gblength_geom2’
‘gblength_voxel’
‘gblength_geom3’
‘gbarea_voxels’
‘gbarea_geom’
‘gbrough_r’
‘ntjp’
Explanations
User specified boolean flags in rkf_flags dictate which R-field metrics would be calculated.
- calculate_uncertainty_angdist(rkf_measure='js', neigh_orders=[1], n_bins=30, data_title='Jaccard sim. measure', throw=False, plot_ad=True)[source]
Calculate uncertainty angdist.
- plot_ang_dist(ANG_DISTANCE, n_bins, neigh_orders=[1], figsize=(5, 5), dpi=150, data_title='DATA TITLE', cmap='nipy_spectral', throw_axis=True)[source]
Visualise ang dist using Matplotlib or PyVista.
- plot_rkf(neigh_orders=[1], power=1, figsize=(7, 5), dpi=120, xtick_incr=2, ytick_incr=2, lfs=7, tfs=8, cmap='nipy_spectral', cbarticks=numpy.arange, cbfs=10, cbtitle='Measure of representativeness R(S|T)', cbfraction=0.046, cbpad=0.04, cbaspect=30, shrink=0.5, cborientation='vertical', flags={'rkf_btwcen': False, 'rkf_clscen': False, 'rkf_degcen': False, 'rkf_ed': False, 'rkf_egnvcen': False, 'rkf_js': False, 'rkf_ksp': False, 'rkf_nlsd': False, 'rkf_wd': False}, xlabel='Target GS ID', ylabel='Sample GS ID')[source]
Example
import numpy as np from upxo.repqual.grain_network_repr_assesser import KREPR import matplotlib.pyplot as plt kr = KREPR.from_gsgen(gstype=’mcgs’,
is_smp_same_as_tgt = False, tgt_dashboard=’input_dashboard.xls’, smp_dashboard=’input_dashboard.xls’, ordern=[1, 3, 5],
tsid_source=’from_gs’, ssid_source=’from_gs’,
tid=None, sid=None, _cim_=’from_gsgen’)
kr.set_rkf(js=True, wd=True, ksp=False, ed=True, nlsd=False) kr.calculate_rkf()
- kr.plot_rkf(neigh_orders=[1, 3, 5], figsize=(7, 5), dpi=50,
xtick_incr=2, ytick_incr=2, lfs=7, tfs=8, cmap=’nipy_spectral’, cbarticks=np.arange(0, 1.1, 0.1), cbfs=10, cbtitle=’Measure of representativeness R(S|T)’, cbfraction=0.046, cbpad=0.04, cbaspect=15, shrink=0.4, cborientation=’vertical’, plot_rkf_js=False)