upxo.pxtal.geotess module
Geometric tessellation class. This has the following components.
class geotess2d for 2D voronoi tessellation grain structures.
class vtess2d, inheriting from geotess2d
class regtess2d, inheriting from geotess2d
class semiregtess2d, inheriting from geotess2d
class demiregtess2d, inheriting from geotess2d
geotess2d: parent class for generalized geometric tessellation
vtess2d: 2D Voronoi tessellation
- regtess2d: Tessellation of regular polygons. Can make tessellations of
Equilateral triangles
SQuares
REgular hexagons
- semiregtess2d: Semi-regular tessellations. Also known as Archimedan
tessellations. Each vertex in a semiregtess2d has the same arrangement of polygons areound it.. Can make tessellations of
triangles & Squares
Triangles & Squares (but a different pattern)
Hexagons & Triangles
Hexagons & Triangles (but a different pattern)
Hexagons & Triangles & Squares
Octagons & Squares
Dodecagons & Triangles
Dodecagons & Squares & Hexagons
demiregtess2d: Demi-regular tessellations.
Dependencies
numpy matplotlib pandas shapely
- class upxo.pxtal.geotess.geotess2d(*, from_mcgs=False)[source]
Bases:
objectBase 2D geometric / Voronoi-style tessellation grain structure.
Parent type for VTGS-style pipelines: holds seeds, junction/vertex points, grain-boundary edges, grain polygons (
xtals), neighbour maps, and a property table. Prefer specialised constructors on related VT / polyxtal classes when available; many seed and neighbour helpers on this base remain stubs.- bounds
Domain bounds on x and y.
- seeds
Seed multipoint / array for the tessellation.
- grid
Optional underlay x/y grids.
- jp, vp
Junction and vertex points (UPXO point entities).
- gbedges, gbseg
Grain-boundary edges and multi-edge segments.
- xtals
Grain polygons (typically Shapely).
- prop
Morphological / other property table (e.g. DataFrame).
- make_seeds_random(nsp=50, bounds=None)[source]
Build uniform-random seed points within the domain bounds.
- Parameters:
- Returns:
seeds – The generated seed points, also stored in
self.seeds. Returned as anupxo.geoEntities.mulpoint2d.MPoint2dwhen construction from coordinates succeeds, otherwise as a plain(nsp, 2)array of x, y coordinates.- Return type:
- make_seeds_pdisc(char_length=0.1, bounds=None)[source]
Build Poisson-disc seed points using Bridson sampling.
- Parameters:
char_length (float, optional) – Minimum allowed spacing (disc radius) between seed points, in the same length units as
bounds. Default value is 0.1.bounds (list or tuple, optional) – Domain bounds as
[xmin, xmax, ymin, ymax]. If given, replaces and updatesself.bounds. IfNone, uses the existingself.bounds, falling back to[0.0, 1.0, 0.0, 1.0]when unset.
- Returns:
seeds – The generated seed points, also stored in
self.seeds. Returned as anupxo.geoEntities.mulpoint2d.MPoint2dwhen construction from coordinates succeeds, otherwise as a plain(n, 2)array of x, y coordinates.- Return type:
Notes
Delegates to
upxo.statops.sampling.bridson_uniform_density, which samples in awidth x heightwindow before the result is translated by(xmin, ymin)back into the requested bounds.
- find_neighbours()[source]
Find neighbours for all grains in
xtalsusing boundary topology.For every pair of grain polygons, checks whether they touch or intersect and, if so, whether their intersection is a genuine shared boundary (a non-empty line with length
> 1e-9, or aLineString/MultiLineStringintersection geometry) rather than a single touching point. Qualifying pairs are recorded as mutual neighbours.This is an exhaustive O(n^2) pairwise scan over
self.xtals(n grains), each pairwise check itself calling into Shapely’stouches/intersects/intersection. There is no spatial index, so this does not scale well to large grain counts.- Returns:
neigh_gid – Mapping of grain ID to a list of neighbouring grain IDs. Also stored on
self.neigh_gid, replacing any previous content. Keys areself.gidwhen its length matcheslen(self.xtals), otherwiserange(len(self.xtals)).- Return type:
Notes
Mutates
self.neigh_gidin place (it is reset to an empty-list-per-grain dict at the start of the call) in addition to returning it.
- find_first_nearest_neighbours(gid=None)[source]
Return first-nearest (directly touching) neighbour grain IDs.
Computes
self.neigh_gidviafind_neighbours()first if it has not been populated yet (i.e. is falsy/empty); an already populatedself.neigh_gidis reused as-is and not recomputed.- Parameters:
gid (hashable, optional) – Grain ID to query. If
None(default), results for all grains are returned.- Returns:
neighbours – If
gidis given: a list of first-nearest-neighbour grain IDs for that grain ([]ifgidis unknown). IfgidisNone: the fullself.neigh_giddict mapping every grain ID to its list of first-nearest-neighbour IDs.- Return type:
- find_second_nearest_neighbours(gid=None)[source]
Return second-nearest neighbour grain IDs (neighbours of neighbours).
For a given grain, the second-nearest neighbours are the union of first-nearest neighbours of each of its first-nearest neighbours, excluding the grain itself and excluding any grain already counted as a first-nearest neighbour.
Computes
self.neigh_gidviafind_neighbours()first if it has not been populated yet (i.e. is falsy/empty); an already populatedself.neigh_gidis reused as-is and not recomputed.- Parameters:
gid (hashable, optional) – Grain ID to query. If
None(default), results for all grains present inself.neigh_gidare returned.- Returns:
neighbours – If
gidis given: a sorted list of second-nearest-neighbour grain IDs for that grain. IfgidisNone: a dict mapping every grain ID inself.neigh_gidto its sorted list of second-nearest-neighbour IDs.- Return type:
- filter_boundary_grains()[source]
Return grain IDs that touch or intersect the domain boundary.
- Returns:
boundary_grains – Grain IDs whose polygon intersects the boundary of the domain box built from
self.bounds. Empty list ifself.boundsorself.xtalsis unset/empty.- Return type:
- filter_internal_grains()[source]
Return grain IDs that do not touch the domain boundary.
- Returns:
internal_grains – Grain IDs in
self.gid(orrange(len(self.xtals))whenself.giddoesn’t match in length) that are not in the result offilter_boundary_grains().- Return type:
- filter_grains_by_prop(col, op, val)[source]
Filter grains in
self.propby a comparison on one property column.- Parameters:
- Returns:
filtered – Subset of
self.propwhereself.prop[col] op valis True.- Return type:
pandas.DataFrame
- Raises:
ValueError – If
self.propis not a pandas DataFrame, or ifopis not one of the supported operator strings.
- perturb_grain_boundaries(factor=0.05, seed=None)[source]
Perturb grain boundaries with controlled curvature while keeping junctions fixed.
- Parameters:
factor (float, optional) – Magnitude of the boundary perturbation (curvature strength), passed through to
upxo.pxtal.voronoi_tessellation_2d.engine.perturb_interfaces_2d. Default value is 0.05. Larger values produce more strongly curved grain boundaries; junctions (grain-boundary triple points) remain fixed regardless offactor.seed (int, optional) – Random seed for reproducible perturbation. Default value is
None(non-deterministic).
- Returns:
xtals – The updated list of grain polygons, also stored in
self.xtals. Returned unchanged (andself.xtalsis left untouched) ifself.xtalsis empty.- Return type:
- bounds
- seeds
- grid
- gridpoints
- jp
- vp
- gbedges
- gbseg
- xtals
- gid
- neigh_gid
- prop
- info
- class upxo.pxtal.geotess.geoxtal2d[source]
Bases:
objectSingle 2D geometric grain (crystal) within a tessellation.
Placeholder for future work. Planned companion to
geotess2dfor per-grain geometry. Every method, including__init__, currently raisesNotImplementedError; this class cannot be instantiated or used in its current form. Do not use.
- class upxo.pxtal.geotess.vtgs3d[source]
Bases:
object3D Voronoi / geometric tessellation grain structure (API stub).
Placeholder for future work. Intended 3D counterpart of
geotess2dwith bounds, seeds, grains, junction topology, and property storage. Every method, including__init__, currently raisesNotImplementedError; this class cannot be instantiated or used in its current form. Do not use.Attributes (planned)
- bounds, seeds, grid, xtals, gid, jp, gbedges, neigh_gid, prop, info
Same roles as the 2D tessellation base, extended to 3D.
- bounds
- xtals
- seeds
- grid
- gid
- jp
- gbedges
- neigh_gid
- prop
- info