graintrace.tess_to_gnn#
Parse Neper .tess files into torch_geometric graph representations.
- graintrace.tess_to_gnn.encode_signed_index(value)[source]#
Encode a signed 1-based
.tessindex as a signed 0-based one.Neper writes edge and face references as signed 1-based integers, where the sign is the traversal direction. The obvious shift
sign * (abs(v) - 1)is lossy: integers have no-0, so+1and-1both collapse to0and the direction of index 0 is destroyed. Negative entries are therefore stored as the bitwise complement~(abs(v) - 1), which keeps the mapping one-to-one over the whole range.- Parameters:
value (int) – a signed, 1-based index as written in the
.tessfile.- Returns:
the encoded signed 0-based index. Decode it with
decode_signed_index().- Return type:
- graintrace.tess_to_gnn.decode_signed_index(value)[source]#
Decode an entry of
face_edgesorcell_to_faces.Inverse of
encode_signed_index(). Note thatabs()is not a valid decoder: the complement of index 0 is-1, whose absolute value names a different entity.
- class graintrace.tess_to_gnn.NeperTessToGraphNN(tess_path, geometry_cell_file=None, geometry_face_file=None, device='cpu', dtype=torch.float64)[source]#
Bases:
objectParse a Neper .tess file and build a graph representation (pytorch_geometric Data) with grains as nodes and faces as edges.
- load_geometry_information(cell_file, face_file)[source]#
Placeholder hook for loading precomputed cell/face geometry (not implemented).
- run_neper_for_geometry_information(tess_path)[source]#
Placeholder hook for computing geometry via NEPER (not implemented).
- validate_topology(verbose=True, strict=True)[source]#
Validate the graph connectivity: each face must belong to 1 or 2 cells.
- Parameters:
verbose (bool) – print the per-category face counts. Printing only – whether a broken tessellation is tolerated is
strict’s job.strict (bool) – raise on a face claimed by more than two cells, or by none. Independent of
verbose, so a quiet call will not hand back a verdict on a broken tessellation and let the caller sail past it. Passstrict=Falseto inspect the report instead.
- Returns:
lists of face indices under the keys
internal(2 cells),boundary(1 cell),nonmanifold(>2 cells) andisolated(0 cells).- Return type:
- Raises:
ValueError – if
strictand any face is non-manifold or isolated.
- register_dataframe_features(data, verbose=True)[source]#
Register every column in a pandas DataFrame as a node feature.
- activate_all_registered_features()[source]#
Activate all currently registered node and edge features.
- Return type:
None