easier to read, more flexible
This commit is contained in:
parent
4f495a7a05
commit
c5d0c7e52e
|
@ -1,9 +1,9 @@
|
||||||
"""Tools for pre and post processing of DAMASK simulations."""
|
"""Tools for pre and post processing of DAMASK simulations."""
|
||||||
import os as _os
|
from pathlib import Path as _Path
|
||||||
import re as _re
|
import re as _re
|
||||||
|
|
||||||
name = 'damask'
|
name = 'damask'
|
||||||
with open(_os.path.join(_os.path.dirname(__file__),'VERSION')) as _f:
|
with open(_Path(__file__).parent/_Path('VERSION')) as _f:
|
||||||
version = _re.sub(r'^v','',_f.readline().strip())
|
version = _re.sub(r'^v','',_f.readline().strip())
|
||||||
|
|
||||||
# make classes directly accessible as damask.Class
|
# make classes directly accessible as damask.Class
|
||||||
|
|
|
@ -6,6 +6,7 @@ import os
|
||||||
import datetime
|
import datetime
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
from pathlib import Path
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import h5py
|
import h5py
|
||||||
|
@ -88,7 +89,7 @@ class Result:
|
||||||
'con_physics': self.con_physics, 'mat_physics': self.mat_physics
|
'con_physics': self.con_physics, 'mat_physics': self.mat_physics
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fname = os.path.abspath(fname)
|
self.fname = Path(fname).absolute()
|
||||||
|
|
||||||
self._allow_overwrite = False
|
self._allow_overwrite = False
|
||||||
|
|
||||||
|
@ -1163,7 +1164,7 @@ class Result:
|
||||||
'Dimensions': '{} {} {} {}'.format(*self.grid,np.prod(shape))}
|
'Dimensions': '{} {} {} {}'.format(*self.grid,np.prod(shape))}
|
||||||
data_items[-1].text='{}:{}'.format(os.path.split(self.fname)[1],name)
|
data_items[-1].text='{}:{}'.format(os.path.split(self.fname)[1],name)
|
||||||
|
|
||||||
with open(os.path.splitext(self.fname)[0]+'.xdmf','w') as f:
|
with open(self.fname.with_suffix('.xdmf').name,'w') as f:
|
||||||
f.write(xml.dom.minidom.parseString(ET.tostring(xdmf).decode()).toprettyxml())
|
f.write(xml.dom.minidom.parseString(ET.tostring(xdmf).decode()).toprettyxml())
|
||||||
|
|
||||||
|
|
||||||
|
@ -1239,7 +1240,4 @@ class Result:
|
||||||
u = self.read_dataset(self.get_dataset_location('u_n' if mode.lower() == 'cell' else 'u_p'))
|
u = self.read_dataset(self.get_dataset_location('u_n' if mode.lower() == 'cell' else 'u_p'))
|
||||||
v.add(u,'u')
|
v.add(u,'u')
|
||||||
|
|
||||||
file_out = '{}_inc{}'.format(os.path.splitext(os.path.basename(self.fname))[0],
|
v.write('{}_inc{}'.format(self.fname.stem,inc[3:].zfill(N_digits)))
|
||||||
inc[3:].zfill(N_digits))
|
|
||||||
|
|
||||||
v.write(file_out)
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import os
|
from pathlib import Path
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
@ -126,8 +126,8 @@ class VTK:
|
||||||
vtkUnstructuredGrid, and vtkPolyData.
|
vtkUnstructuredGrid, and vtkPolyData.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ext = os.path.splitext(fname)[1]
|
ext = Path(fname).suffix
|
||||||
if ext == '.vtk':
|
if ext == '.vtk' or dataset_type:
|
||||||
reader = vtk.vtkGenericDataObjectReader()
|
reader = vtk.vtkGenericDataObjectReader()
|
||||||
reader.SetFileName(fname)
|
reader.SetFileName(fname)
|
||||||
reader.Update()
|
reader.Update()
|
||||||
|
@ -176,10 +176,10 @@ class VTK:
|
||||||
writer = vtk.vtkXMLPolyDataWriter()
|
writer = vtk.vtkXMLPolyDataWriter()
|
||||||
|
|
||||||
default_ext = writer.GetDefaultFileExtension()
|
default_ext = writer.GetDefaultFileExtension()
|
||||||
name, ext = os.path.splitext(fname)
|
ext = Path(fname).suffix
|
||||||
if ext and ext != '.'+default_ext:
|
if ext and ext != '.'+default_ext:
|
||||||
raise ValueError('Given extension {} is not .{}'.format(ext,default_ext))
|
raise ValueError('Given extension {} does not match default .{}'.format(ext,default_ext))
|
||||||
writer.SetFileName('{}.{}'.format(name,default_ext))
|
writer.SetFileName(str(Path(fname).with_suffix('.'+default_ext)))
|
||||||
writer.SetCompressorTypeToZLib()
|
writer.SetCompressorTypeToZLib()
|
||||||
writer.SetDataModeToBinary()
|
writer.SetDataModeToBinary()
|
||||||
writer.SetInputData(self.geom)
|
writer.SetInputData(self.geom)
|
||||||
|
|
Loading…
Reference in New Issue