upxo.pxtal.fm_steel_3d.raw_export module

Raw pipeline-state export.

Gathers whatever grain-structure / hierarchy data currently exists across the pipeline’s stage objects – fm_base, fm_with_pags, fm_with_blocks, fm_with_orientations, fm_with_subblocks (in pipeline order) – and writes it out as plain files. fm_base’s own data (the grain-ID array and its immediate companions) is always included. On top of that, the caller selects which of the four hierarchy LEVELS to include – PAG, Packet, Block, Sub-block (mirroring the PAG/PCK/BLK/SBLK elset levels of the Abaqus mesh export) – each with its own filename prefix. Every selected level contributes its own 3D labeled array (“<prefix>_lgi”, the same shape as the base structure, built via feature_props_3d’s per-level LGI builders – the same ones the hierarchy visualizations already use) alongside its other hierarchy metadata, and, when it has orientation data, that gets written as its OWN dedicated pickle file (<prefix>_orientations.pkl) rather than folded into the shared bundle, since a level’s orientations are the one thing about it most likely to be consumed on its own downstream.

Three output formats are supported: .npy (one file per array), pickle (one raw_export.pkl holding every non-array/array field together, plus one dedicated *_orientations.pkl per level that has orientation data), and .npz (one compressed archive bundling every array together). Every non-underscore __slots__ field of the relevant stage object is collected automatically rather than hand-listed per class, so this stays correct if a stage class’s own fields ever change.

upxo.pxtal.fm_steel_3d.raw_export.level_availability(app)[source]

{level_key: bool} – whether each of the 4 hierarchy levels has been reached yet this session. Packet and Block both key off fm_with_blocks (a packet, in this pipeline, IS a grain viewed at the block-hierarchy scale – grain_to_blocks_map is packet membership; it and block_orientations/all_blocks appear together the moment blocks exist).

upxo.pxtal.fm_steel_3d.raw_export.collect_base_data(app)[source]

{“base_<field>”: value} for fm_base’s own fields – the foundation every export includes unconditionally, independent of level selection. Empty if fm_base doesn’t exist yet.

upxo.pxtal.fm_steel_3d.raw_export.collect_level_data(app, level_key)[source]

Returns (orientations, fields) for one hierarchy level: orientations is that level’s own {id: (phi1, Phi, phi2)} dict (or None if not available/derivable yet), fields is {field_name: value} for its other, non-orientation hierarchy data – always including “lgi”, a 3D array the same shape as the base grain structure with every voxel stamped by that level’s own ID (built via feature_props_3d’s per-level LGI builders – the same ones the 2D/3D hierarchy visualizations already use), plus, for Block and Sub-block (whose IDs are strings, not plain integers), “lgi_id_to_int” / “lgi_int_to_id” so the array’s integer labels can be mapped back to the real block/sub-block IDs used elsewhere (all_blocks, …). Both return values are empty/None if the level hasn’t been reached yet.

upxo.pxtal.fm_steel_3d.raw_export.export_raw_data(app, out_dir, formats, levels=None, prefixes=None)[source]

Writes fm_base’s data plus the requested hierarchy levels (any subset of {“pag”, “pck”, “blk”, “sblk”}; default: every level currently available, see level_availability) to out_dir, in the requested formats (any non-empty subset of {“npy”, “pkl”, “npz”}):

  • “npy”: one <name>.npy per collected entry that is a real numpy ndarray.

  • “npz”: a single raw_export.npz bundling every ndarray entry together via numpy.savez_compressed.

  • “pkl”: a single raw_export.pkl holding every collected entry (arrays and non-array hierarchy metadata alike), PLUS one dedicated “<prefix>_orientations.pkl” per requested level that has orientation data – pickle is the only format here that can hold a plain {id: euler} dict at all, so this is gated on “pkl” being selected, same as the merged bundle.

prefixes: {level_key: filename_prefix}: overrides DEFAULT_LEVEL_PREFIXES for the given level(s); every field this level contributes to the merged bundle is named “<prefix>_<field>”.

Returns {“out_dir”: str, “files”: {filename: size_bytes}, “n_entries”: int, “levels_exported”: [level_key, …], “levels_skipped”: {level_key: reason}}. Raises ValueError if fm_base doesn’t exist yet.