polishing

This commit is contained in:
Martin Diehl 2021-04-03 08:08:48 +02:00
parent 1b2d892b42
commit 39c0bc9de6
4 changed files with 18 additions and 23 deletions

View File

@ -1,5 +1,3 @@
import os.path
import numpy as np import numpy as np
import h5py import h5py
@ -159,18 +157,18 @@ class ConfigMaterial(Config):
f = h5py.File(fname,'r') f = h5py.File(fname,'r')
if grain_data is None: if grain_data is None:
phase = f[os.path.join(b,c,phases)][()].flatten() phase = f['/'.join((b,c,phases))][()].flatten()
O = Rotation.from_Euler_angles(f[os.path.join(b,c,Euler_angles)]).as_quaternion().reshape(-1,4) # noqa O = Rotation.from_Euler_angles(f['/'.join((b,c,Euler_angles))]).as_quaternion().reshape(-1,4) # noqa
_,idx = np.unique(np.hstack([O,phase.reshape(-1,1)]),return_index=True,axis=0) _,idx = np.unique(np.hstack([O,phase.reshape(-1,1)]),return_index=True,axis=0)
idx = np.sort(idx) idx = np.sort(idx)
else: else:
phase = f[os.path.join(b,grain_data,phases)][()] phase = f['/'.join((b,grain_data,phases))][()]
O = Rotation.from_Euler_angles(f[os.path.join(b,grain_data,Euler_angles)]).as_quaternion() # noqa O = Rotation.from_Euler_angles(f['/'.join((b,grain_data,Euler_angles))]).as_quaternion() # noqa
idx = np.arange(phase.size) idx = np.arange(phase.size)
if cell_ensemble_data is not None and phase_names is not None: if cell_ensemble_data is not None and phase_names is not None:
try: try:
names = np.array([s.decode() for s in f[os.path.join(b,cell_ensemble_data,phase_names)]]) names = np.array([s.decode() for s in f['/'.join((b,cell_ensemble_data,phase_names))]])
phase = names[phase] phase = names[phase]
except KeyError: except KeyError:
pass pass

View File

@ -305,18 +305,18 @@ class Grid:
c = util.DREAM3D_cell_data_group(fname) if cell_data is None else cell_data c = util.DREAM3D_cell_data_group(fname) if cell_data is None else cell_data
f = h5py.File(fname, 'r') f = h5py.File(fname, 'r')
cells = f[os.path.join(b,'_SIMPL_GEOMETRY','DIMENSIONS')][()] cells = f['/'.join((b,'_SIMPL_GEOMETRY','DIMENSIONS'))][()]
size = f[os.path.join(b,'_SIMPL_GEOMETRY','SPACING')] * cells size = f['/'.join((b,'_SIMPL_GEOMETRY','SPACING'))] * cells
origin = f[os.path.join(b,'_SIMPL_GEOMETRY','ORIGIN')][()] origin = f['/'.join((b,'_SIMPL_GEOMETRY','ORIGIN'))][()]
if feature_IDs is None: if feature_IDs is None:
phase = f[os.path.join(b,c,phases)][()].reshape(-1,1) phase = f['/'.join((b,c,phases))][()].reshape(-1,1)
O = Rotation.from_Euler_angles(f[os.path.join(b,c,Euler_angles)]).as_quaternion().reshape(-1,4) # noqa O = Rotation.from_Euler_angles(f['/'.join((b,c,Euler_angles))]).as_quaternion().reshape(-1,4) # noqa
unique,unique_inverse = np.unique(np.hstack([O,phase]),return_inverse=True,axis=0) unique,unique_inverse = np.unique(np.hstack([O,phase]),return_inverse=True,axis=0)
ma = np.arange(cells.prod()) if len(unique) == cells.prod() else \ ma = np.arange(cells.prod()) if len(unique) == cells.prod() else \
np.arange(unique.size)[np.argsort(pd.unique(unique_inverse))][unique_inverse] np.arange(unique.size)[np.argsort(pd.unique(unique_inverse))][unique_inverse]
else: else:
ma = f[os.path.join(b,c,feature_IDs)][()].flatten() ma = f['/'.join((b,c,feature_IDs))][()].flatten()
return Grid(ma.reshape(cells,order='F'),size,origin,util.execution_stamp('Grid','load_DREAM3D')) return Grid(ma.reshape(cells,order='F'),size,origin,util.execution_stamp('Grid','load_DREAM3D'))

View File

@ -420,11 +420,8 @@ class Result:
for d in f[group].keys(): for d in f[group].keys():
try: try:
dataset = f['/'.join([group,d])] dataset = f['/'.join([group,d])]
if un in dataset.attrs:
unit = f" / {dataset.attrs[un]}" if h5py3 else \ unit = f" / {dataset.attrs[un]}" if h5py3 else \
f" / {dataset.attrs[un].decode()}" f" / {dataset.attrs[un].decode()}"
else:
unit = ''
description = dataset.attrs[de] if h5py3 else \ description = dataset.attrs[de] if h5py3 else \
dataset.attrs[de].decode() dataset.attrs[de].decode()
message += f' {d}{unit}: {description}\n' message += f' {d}{unit}: {description}\n'
@ -1127,8 +1124,8 @@ class Result:
dataset.attrs[l.lower()]=v if h5py3 else v.encode() dataset.attrs[l.lower()]=v if h5py3 else v.encode()
creator = dataset.attrs['creator'] if h5py3 else \ creator = dataset.attrs['creator'] if h5py3 else \
dataset.attrs['creator'].decode() dataset.attrs['creator'].decode()
dataset.attrs['creator'] = f"damask.Result.{creator} v{damask.version}" if h5py3 else \ dataset.attrs['creator'] = f'damask.Result.{creator} v{damask.version}' if h5py3 else \
f"damask.Result.{creator} v{damask.version}".encode() f'damask.Result.{creator} v{damask.version}'.encode()
except (OSError,RuntimeError) as err: except (OSError,RuntimeError) as err:
print(f'Could not add dataset: {err}.') print(f'Could not add dataset: {err}.')

View File

@ -59,9 +59,9 @@ def srepr(arg,glue = '\n'):
Glue used for joining operation. Defaults to \n. Glue used for joining operation. Defaults to \n.
""" """
if (not hasattr(arg, "strip") and if (not hasattr(arg, 'strip') and
(hasattr(arg, "__getitem__") or (hasattr(arg, '__getitem__') or
hasattr(arg, "__iter__"))): hasattr(arg, '__iter__'))):
return glue.join(str(x) for x in arg) return glue.join(str(x) for x in arg)
return arg if isinstance(arg,str) else repr(arg) return arg if isinstance(arg,str) else repr(arg)