upxo.repqual.mcgs2d_representativeness_assesser module

Statistical representativeness assessment for 2D MCGS vs a target structure.

Class mc2repr runs distribution tests (e.g. KS, Mann–Whitney, Kruskal–Wallis, Pearson) on morphological properties of target vs sample grain structures. Targets may be EBSD-derived or UPXO MC/Voronoi GS. Results are stored for inspection; there is no single automatic accept/reject score in this module.

Import:

from upxo.repqual.mcgs2d_representativeness_assesser import mc2repr
upxo.repqual.mcgs2d_representativeness_assesser.shared_bin_probabilities(target, sample, bins='auto')[source]

Probabilities of two data sets on the same histogram bins.

The bin edges come from the pooled data (numpy’s bins rule, 'auto' by default), so both sets are counted over the same range. Missing values are dropped. Returns (p_target, p_sample), each summing to 1, or None when either set has no value.

upxo.repqual.mcgs2d_representativeness_assesser.kl_divergence(target, sample, bins='auto')[source]

KL divergence D(target || sample), in nats, on shared bins; 0 for identical distributions.

A bin one set fills and the other leaves empty would make the value infinite, so both probability vectors get a floor of 1e-12 and are renormalised. nan when either set has no value.

upxo.repqual.mcgs2d_representativeness_assesser.js_distance(target, sample, bins='auto')[source]

Jensen-Shannon distance (square root of the divergence, base 2) on shared bins.

0 for identical distributions, 1 for distributions that share no bin. nan when either set has no value.

class upxo.repqual.mcgs2d_representativeness_assesser.mc2repr(target_type=None, target=None, samples=None, par_bounds=None, metrics=None, kde_options=None, stest={'ks_p_threshold': 0.9, 'kw_p_threshold': 0.9, 'mw_p_threshold': 0.9, 'tests': ['correlation', 'kldiv', 'ks', 'jsdiv', 'mannwhitneyu', 'kruskalwallis']}, test_metrics=['mode0_location', 'mode0_count', 'mode1_location', 'mode1_count', 'mean'], parameters=['area'])[source]

Bases: object

Statistical representativeness of 2D sample GS vs a target.

Runs distribution tests (KS, Mann–Whitney, Kruskal–Wallis, correlation, KL/JS divergence, etc.) on morphological properties of a target structure against one or more samples. Targets may be EBSD-derived or UPXO MC/Voronoi GS. Results are stored for inspection — there is no single automatic accept/reject score in this class.

target_type

Target source code:

  • ebsd0 — unprocessed 2D EBSD (DefDAP)

  • ebsd1 — processed DefDAP (e.g. remapped avg. orientation)

  • umc2 / umc3 — UPXO Monte-Carlo 2D / 3D

  • uvt2 — UPXO Voronoi tessellation 2D

  • stats — morphology samples as dict or DataFrame columns

Type:

str

target

Target data: MCGS.gs[tslice], VTGS, DefDAP EBSD, or stats table.

samples

Sample name → grain-structure object, or 'make' to generate from an Excel dashboard (simulate → temporal slices → characterise).

Type:

dict

par_bounds

Per-property bounds, e.g. area/perimeter/aspect ratio → [[peak_loc_%], [peak_density_%], [JS_bounds]].

Type:

dict

metrics

Qualification metrics (e.g. modes_n, modes_loc, skewness).

Type:

list

kde_options

KDE options (bw_method: 'scott', 'silverman', or scalar).

Type:

dict

stest, test_metrics, performance

Configured statistical tests and computed outcomes.

target_type
target
samples
par_bounds
metrics
kde_options
stest
test_metrics
parameters
performance
load_target(target=None, target_type=None)[source]

Load or import target.

load_samples(samples=None)[source]

Load or import samples.

add_sample(sample=None)[source]

Add or insert sample.

set_stests(tests)[source]

Set or update stests.

set_cor_thresh(cor_threshold)[source]

Set or update cor thresh.

set_kldiv_thresh(kldiv_thresh)[source]

Set or update kldiv thresh.

set_ks_thresh(ks_thresh_D, ks_thresh_P)[source]

Set or update ks thresh.

set_jsdiv_thresh(jsdiv_thresh)[source]

Set or update jsdiv thresh.

prop_to_excel(filename='pxtal_properties')[source]

Prop to excel.

build_distribution_dataset()[source]

Build and return distribution dataset.

determine_distr_type()[source]

Determine distr type.

test()[source]

TEST 1: correlation: For two datasets, it is a measure of the linear relationship between them. If correlation is close to 1 then, the distributions are very similar.

TEST 2: kldiv: Kullback-Leibler divergence D(target || sample), in nats, of the two property distributions on shared histogram bins (see kl_divergence). 0 for identical distributions; it grows without bound as the sample puts weight where the target has little.

TEST 3: ks: Kolmogorov-Smirnov test: Determines of the two distribution samples differ significantly. It uses cumulative distributions of the two datasets. Retyurns D-statistic and P-value.

  • D-statistic: maximum absolute difference of the cumulative

distributions (absolute max distance (supremum) b/w the CDFs of the two samples). A smaller D-static value is indicative of similar distributions. * P-value: probability that thwe tywo distributions are similar. If p-value is low (<= 0.05), distributions are different. If p-value is high (> 0.05), we cannot reject the null-hypothesis that the two distributions are the same. * Note: if P <= 0.05: the null hypothesis that the two samples are drawn from tyhe sample sample can be rejected, indicating that the samples are not representative of the target

TEST 4: jsdiv: Jensen-Shannon distance (base 2) of the two property distributions on shared histogram bins (see js_distance). Always between 0 and 1. @ 0: Distributions are identical. @ 1: Distributions are completely different

TEST 5: mannwhitneyu: Mann-Whitney test: Used to determine if two ‘ distribution samples are drawn from a population having the same population. If P-value is less than or equal to 0.05, then different distributiopns. If P-value is > 0.05, then the two disrtirbutions are similar.

TEST 6: kruskalwallis: Kruskal-wallis test. Used to determine if there are statistically significant differences between two distributions.

stat_tests
test_threshold
distr_type