Skip to content

Commit 6c915c8

Browse files
committed
Update material/grid and results handling
1 parent bc5ba31 commit 6c915c8

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

python/damask/_configmaterial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ def load_DREAM3D(fname: str,
156156

157157

158158
@staticmethod
159-
def load_kanapy(src: Union[str, Path, Mapping[str, Any]], outputs: list) -> 'ConfigMaterial':
159+
def load_MiMedat(src: Union[str, Path, Mapping[str, Any]], outputs: list) -> 'ConfigMaterial':
160160

161161
"""
162-
Build a DAMASK ConfigMaterial from a Kanapy-style JSON/dict.
162+
Build a DAMASK ConfigMaterial from a JSON file path following the MiMedat schema.
163163
164164
This function reads phase-level information from a Kanapy JSON file
165165
(or a pre-loaded dict) that follows the microstructure-sensitive
@@ -281,7 +281,7 @@ def load_kanapy(src: Union[str, Path, Mapping[str, Any]], outputs: list) -> 'Con
281281
all_phase_labels = []
282282
for phase in phases:
283283
phase_id = phase.get("phase_id")
284-
phase_name = phase.get("phase_identifier")
284+
phase_name = phase.get("phase_name")
285285
phase_key = str(phase_name if phase_name is not None else phase_id)
286286

287287
lattice_str = phase.get("lattice_structure")

python/damask/_geomgrid.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ def load_DREAM3D(fname: Union[str, Path],
399399
)
400400

401401
@staticmethod
402-
def load_kanapy(src: Union[str, Path, Mapping[str, Any]],keys: Dict[str, str] = None) -> 'GeomGrid':
402+
def load_MiMedat(src: Union[str, Path, Mapping[str, Any]],keys: Dict[str, str] = None) -> 'GeomGrid':
403403
"""
404-
Read geometry from a Kanapy JSON **file path**, a **JSON string**, or a **dict**,
404+
Read geometry from a JSON file path according to MiMedat schema, a JSON string, or a dict,
405405
normalize lengths to meters (m), and return a GeomGrid with:
406406
- material: int64 (Nx, Ny, Nz), Fortran-order (grain labels, 0..G-1; zeros if absent)
407407
- size: axis lengths in m (float[3])
@@ -465,7 +465,12 @@ def _length_unit_to_m_factor(u: str) -> float:
465465

466466
size_m = np.asarray(data[keys["size"]], float) * f_m # (3,)
467467
spacing_m = np.asarray(data[keys["spacing"]], float) * f_m # (3,)
468-
origin_m = np.asarray(data.get(keys["origin"], [0.0, 0.0, 0.0]), float) * f_m
468+
origin_raw = data.get(keys["origin"], [0.0, 0.0, 0.0])
469+
# If origin is not a 3-vector (e.g., your provenance dict), fall back.
470+
if not (isinstance(origin_raw, (list, tuple, np.ndarray)) and len(origin_raw) == 3):
471+
origin_raw = [0.0, 0.0, 0.0]
472+
473+
origin_m = np.asarray(origin_raw, dtype=float) * f_m
469474
N_json = int(data[keys["count"]])
470475

471476
if size_m.shape != (3,) or spacing_m.shape != (3,) or origin_m.shape != (3,):

python/damask/_result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ def create_and_open(obj,name):
21682168
for name,value in zip(names,values):
21692169
add_attribute(geom,name,value)
21702170

2171-
def export_kanapy(
2171+
def export_MiMedat(
21722172
self,
21732173
json_path: Union[str, Path],
21742174
quantities: Sequence[str] = ("O", "F"),
@@ -2177,7 +2177,7 @@ def export_kanapy(
21772177
) -> Path:
21782178
"""
21792179
Export selected voxel-resolved DAMASK results from this Result (HDF5) into a
2180-
Kanapy-style JSON microstructure time series.
2180+
MiMedat-style JSON microstructure time series.
21812181
21822182
The JSON file must contain exactly one microstructure snapshot (the initial,
21832183
undeformed state). This function appends one new snapshot per DAMASK increment
@@ -2289,7 +2289,7 @@ def _msg(s: str) -> None:
22892289

22902290
grid_status = str(grid_meta.get("status", "unknown")).lower()
22912291
_msg(f"[INFO] Initial grid status: '{grid_status}'")
2292-
if grid_status != "regular":
2292+
if grid_status != "undeformed":
22932293
raise ValueError(
22942294
f"Expected initial grid status 'regular' (undeformed), got '{grid_status}'.")
22952295

0 commit comments

Comments
 (0)