corrected the looping and target dir

This commit is contained in:
Vitesh Shah 2023-04-17 08:03:44 +02:00
parent 2ae1a20443
commit 029b830156
1 changed files with 79 additions and 72 deletions

View File

@ -1945,7 +1945,8 @@ class Result:
v.save(vtk_dir/f'{self.fname.stem}_inc{inc.split(prefix_inc)[-1].zfill(N_digits)}', v.save(vtk_dir/f'{self.fname.stem}_inc{inc.split(prefix_inc)[-1].zfill(N_digits)}',
parallel=parallel) parallel=parallel)
def export_DREAM3D(self): def export_DREAM3D(self,
target_dir: Union[None, str, Path] = None):
""" """
Export the visible components to DREAM3D compatible files. Export the visible components to DREAM3D compatible files.
@ -1957,7 +1958,8 @@ class Result:
Parameters Parameters
---------- ----------
target_dir : str or pathlib.Path, optional
Directory to save DREAM3D files. Will be created if non-existent.
""" """
Crystal_structures = {'fcc': 1, Crystal_structures = {'fcc': 1,
'bcc': 1, 'bcc': 1,
@ -1970,6 +1972,10 @@ class Result:
at_cell_ph,in_data_ph,at_cell_ho,in_data_ho = self._mappings() at_cell_ph,in_data_ph,at_cell_ho,in_data_ho = self._mappings()
dream_dir = Path.cwd() if target_dir is None else Path(target_dir)
dream_dir.mkdir(parents=True,exist_ok=True)
with h5py.File(self.fname,'r') as f:
for inc in util.show_progress(self.visible['increments']): for inc in util.show_progress(self.visible['increments']):
cell_orientation_array = np.zeros((np.prod(self.cells),3)) cell_orientation_array = np.zeros((np.prod(self.cells),3))
phase_ID_array = np.zeros((np.prod(self.cells)),dtype=np.int32) #need to reshape it later phase_ID_array = np.zeros((np.prod(self.cells)),dtype=np.int32) #need to reshape it later
@ -1977,16 +1983,17 @@ class Result:
for count,label in enumerate(self.visible['phases']): for count,label in enumerate(self.visible['phases']):
try: try:
data = ma.array(_read(f['/'.join([inc,'phase',label,'mechanical/O'])])) data = ma.array(_read(f['/'.join([inc,'phase',label,'mechanical/O'])]))
cell_orientation_array[at_cell_ph[c][label],:] = Rotation(data[in_data_ph[c][label],:]).as_Euler_angles() # TODO: convert DAMASK quats to Dream3D quats? cell_orientation_array[at_cell_ph[c][label],:] = \
Rotation(data[in_data_ph[c][label],:]).as_Euler_angles()
# Dream3D handles euler angles better
except ValueError: #check if the exception is correct except ValueError: #check if the exception is correct
print("Orientation data is not present") print("Orientation data is not present")
exit() # need to check if such a statement would really work. exit() # need to check if such a statement would really work.
phase_ID_array[at_cell_ph[c][label]] = count + 1
phase_ID_array[at_cell_ph[c][label]] = count + 1 #need to figure out these mappings a bit
job_file_no_ext = os.path.splitext(self.fname)[0] job_file_no_ext = os.path.splitext(self.fname)[0]
o = h5py.File(f'{job_file_no_ext}_increment{inc}.dream3D','w') o = h5py.File(f'{dream_dir}/{job_file_no_ext}_{inc}.dream3D','w')
o.attrs['DADF5toDREAM3D'] = '1.0' o.attrs['DADF5toDREAM3D'] = '1.0'
o.attrs['FileVersion'] = '7.0' o.attrs['FileVersion'] = '7.0'