From 186605610d69e13fd735f3646fde5764cb7a79bd Mon Sep 17 00:00:00 2001 From: Vitesh Shah Date: Fri, 13 Dec 2019 09:53:47 +0100 Subject: [PATCH 1/7] No phase name for generic datasets --- processing/post/DADF5_vtk_cells.py | 5 ++++- processing/post/DADF5_vtk_points.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/processing/post/DADF5_vtk_cells.py b/processing/post/DADF5_vtk_cells.py index b8875f4e9..9e8585773 100755 --- a/processing/post/DADF5_vtk_cells.py +++ b/processing/post/DADF5_vtk_cells.py @@ -2,6 +2,7 @@ import os import argparse +import re import h5py import numpy as np @@ -89,10 +90,12 @@ for filename in options.filenames: x = results.get_dataset_location(label) if len(x) == 0: continue + ph_name = re.compile(r'(\/[1-9])_([A-Z][a-z]*)_(([a-z]*)|([A-Z]*))') #looking for phase name in dataset name array = results.read_dataset(x,0) shape = [array.shape[0],np.product(array.shape[1:])] vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE)) - vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) + dset_name = '1_' + re.sub(ph_name,r'',x[0].split('/',1)[1]) #removing phase name from generic dataset + vtk_data[-1].SetName(dset_name) grid.GetCellData().AddArray(vtk_data[-1]) results.set_visible('constituents', False) diff --git a/processing/post/DADF5_vtk_points.py b/processing/post/DADF5_vtk_points.py index 9265cc3a0..908474336 100755 --- a/processing/post/DADF5_vtk_points.py +++ b/processing/post/DADF5_vtk_points.py @@ -2,6 +2,7 @@ import os import argparse +import re import numpy as np import vtk @@ -76,10 +77,12 @@ for filename in options.filenames: x = results.get_dataset_location(label) if len(x) == 0: continue + ph_name = re.compile(r'(\/[1-9])_([A-Z][a-z]*)_(([a-z]*)|([A-Z]*))') #looking for phase name in dataset name array = results.read_dataset(x,0) shape = [array.shape[0],np.product(array.shape[1:])] vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE)) - vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) + dset_name = '1_' + re.sub(ph_name,r'',x[0].split('/',1)[1]) #removing phase name from generic dataset + vtk_data[-1].SetName(dset_name) Polydata.GetCellData().AddArray(vtk_data[-1]) results.set_visible('constituents', False) From b14c15fd9ee6720d79677ed30d4558e3928269a5 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Dec 2019 12:15:45 +0100 Subject: [PATCH 2/7] directly output DADF5 to vtk from python --- python/damask/dadf5.py | 120 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/python/damask/dadf5.py b/python/damask/dadf5.py index beced188d..1142d02b4 100644 --- a/python/damask/dadf5.py +++ b/python/damask/dadf5.py @@ -1,7 +1,10 @@ from queue import Queue import re import glob +import os +import vtk +from vtk.util import numpy_support import h5py import numpy as np @@ -841,3 +844,120 @@ class DADF5(): N_added +=1 pool.wait_completion() + + + def to_vtk(self,labels): + """ + Export to vtk cell data. + + Parameters + ---------- + labels : list of str + Labels of the datasets to be exported. + + """ + if self.structured: + + coordArray = [vtk.vtkDoubleArray(),vtk.vtkDoubleArray(),vtk.vtkDoubleArray()] + for dim in [0,1,2]: + for c in np.linspace(0,self.size[dim],1+self.grid[dim]): + coordArray[dim].InsertNextValue(c) + + grid = vtk.vtkRectilinearGrid() + grid.SetDimensions(*(self.grid+1)) + grid.SetXCoordinates(coordArray[0]) + grid.SetYCoordinates(coordArray[1]) + grid.SetZCoordinates(coordArray[2]) + + else: + + nodes = vtk.vtkPoints() + with h5py.File(self.fname) as f: + nodes.SetData(numpy_support.numpy_to_vtk(f['/geometry/x_n'][()],deep=True)) + + grid = vtk.vtkUnstructuredGrid() + grid.SetPoints(nodes) + grid.Allocate(f['/geometry/T_c'].shape[0]) + for i in f['/geometry/T_c']: + grid.InsertNextCell(vtk.VTK_HEXAHEDRON,8,i-1) # not for all elements! + + N_digits = int(np.floor(np.log10(int(self.increments[-1][3:]))))+1 + + for i,inc in enumerate(self.iter_visible('increments')): + vtk_data = [] + + materialpoints_backup = self.visible['materialpoints'].copy() + self.set_visible('materialpoints',False) + for label in labels: + for p in self.iter_visible('con_physics'): + if p != 'generic': + for c in self.iter_visible('constituents'): + x = self.get_dataset_location(label) + if len(x) == 0: + continue + array = self.read_dataset(x,0) + shape = [array.shape[0],np.product(array.shape[1:])] + vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), + deep=True,array_type= vtk.VTK_DOUBLE)) + vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) #ToDo: hard coded 1! + grid.GetCellData().AddArray(vtk_data[-1]) + else: + x = self.get_dataset_location(label) + if len(x) == 0: + continue + array = self.read_dataset(x,0) + shape = [array.shape[0],np.product(array.shape[1:])] + vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), + deep=True,array_type= vtk.VTK_DOUBLE)) + ph_name = re.compile(r'(\/[1-9])_([A-Z][a-z]*)_(([a-z]*)|([A-Z]*))') #looking for phase name in dataset name + dset_name = '1_' + re.sub(ph_name,r'',x[0].split('/',1)[1]) #removing phase name from generic dataset + vtk_data[-1].SetName(dset_name) + grid.GetCellData().AddArray(vtk_data[-1]) + self.set_visible('materialpoints',materialpoints_backup) + + constituents_backup = self.visible['constituents'].copy() + self.set_visible('constituents',False) + for label in labels: + for p in self.iter_visible('mat_physics'): + if p != 'generic': + for m in self.iter_visible('materialpoints'): + x = self.get_dataset_location(label) + if len(x) == 0: + continue + array = self.read_dataset(x,0) + shape = [array.shape[0],np.product(array.shape[1:])] + vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), + deep=True,array_type= vtk.VTK_DOUBLE)) + vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) #ToDo: why 1_? + grid.GetCellData().AddArray(vtk_data[-1]) + else: + x = self.get_dataset_location(label) + if len(x) == 0: + continue + array = self.read_dataset(x,0) + shape = [array.shape[0],np.product(array.shape[1:])] + vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), + deep=True,array_type= vtk.VTK_DOUBLE)) + vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) + grid.GetCellData().AddArray(vtk_data[-1]) + self.set_visible('constituents',constituents_backup) + + writer = vtk.vtkXMLRectilinearGridWriter() if self.structured else \ + vtk.vtkXMLUnstructuredGridWriter() + + x = self.get_dataset_location('u_n') + vtk_data.append(numpy_support.numpy_to_vtk(num_array=self.read_dataset(x,0), + deep=True,array_type=vtk.VTK_DOUBLE)) + vtk_data[-1].SetName('u') + grid.GetPointData().AddArray(vtk_data[-1]) + + file_out = '{}_inc{}.{}'.format(os.path.splitext(os.path.basename(self.fname))[0], + inc[3:].zfill(N_digits), + writer.GetDefaultFileExtension()) + + writer.SetCompressorTypeToZLib() + writer.SetDataModeToBinary() + writer.SetFileName(file_out) + writer.SetInputData(grid) + + writer.Write() From 7d849b639b1bb0de2175eb41c7f15d16dac94973 Mon Sep 17 00:00:00 2001 From: Vitesh Shah Date: Fri, 13 Dec 2019 14:20:18 +0100 Subject: [PATCH 3/7] Point based vtk file in DADF5 class --- python/damask/dadf5.py | 115 +++++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 40 deletions(-) diff --git a/python/damask/dadf5.py b/python/damask/dadf5.py index 1142d02b4..1f4af8de3 100644 --- a/python/damask/dadf5.py +++ b/python/damask/dadf5.py @@ -846,41 +846,58 @@ class DADF5(): pool.wait_completion() - def to_vtk(self,labels): + def to_vtk(self,labels,mode='Cell'): """ - Export to vtk cell data. + Export to vtk cell/point data. Parameters ---------- labels : list of str Labels of the datasets to be exported. + mode : str + Export in cell format or point format. + Default value is 'Cell' """ - if self.structured: + if mode=='Cell': - coordArray = [vtk.vtkDoubleArray(),vtk.vtkDoubleArray(),vtk.vtkDoubleArray()] - for dim in [0,1,2]: - for c in np.linspace(0,self.size[dim],1+self.grid[dim]): - coordArray[dim].InsertNextValue(c) - - grid = vtk.vtkRectilinearGrid() - grid.SetDimensions(*(self.grid+1)) - grid.SetXCoordinates(coordArray[0]) - grid.SetYCoordinates(coordArray[1]) - grid.SetZCoordinates(coordArray[2]) - - else: - - nodes = vtk.vtkPoints() - with h5py.File(self.fname) as f: - nodes.SetData(numpy_support.numpy_to_vtk(f['/geometry/x_n'][()],deep=True)) + if self.structured: + + coordArray = [vtk.vtkDoubleArray(),vtk.vtkDoubleArray(),vtk.vtkDoubleArray()] + for dim in [0,1,2]: + for c in np.linspace(0,self.size[dim],1+self.grid[dim]): + coordArray[dim].InsertNextValue(c) + + grid = vtk.vtkRectilinearGrid() + grid.SetDimensions(*(self.grid+1)) + grid.SetXCoordinates(coordArray[0]) + grid.SetYCoordinates(coordArray[1]) + grid.SetZCoordinates(coordArray[2]) + + else: - grid = vtk.vtkUnstructuredGrid() - grid.SetPoints(nodes) - grid.Allocate(f['/geometry/T_c'].shape[0]) - for i in f['/geometry/T_c']: - grid.InsertNextCell(vtk.VTK_HEXAHEDRON,8,i-1) # not for all elements! - + nodes = vtk.vtkPoints() + with h5py.File(self.fname) as f: + nodes.SetData(numpy_support.numpy_to_vtk(f['/geometry/x_n'][()],deep=True)) + + grid = vtk.vtkUnstructuredGrid() + grid.SetPoints(nodes) + grid.Allocate(f['/geometry/T_c'].shape[0]) + for i in f['/geometry/T_c']: + grid.InsertNextCell(vtk.VTK_HEXAHEDRON,8,i-1) # not for all elements! + else: + Points = vtk.vtkPoints() + Vertices = vtk.vtkCellArray() + for c in self.cell_coordinates(): + pointID = Points.InsertNextPoint(c) + Vertices.InsertNextCell(1) + Vertices.InsertCellPoint(pointID) + + Polydata = vtk.vtkPolyData() + Polydata.SetPoints(Points) + Polydata.SetVerts(Vertices) + Polydata.Modified() + N_digits = int(np.floor(np.log10(int(self.increments[-1][3:]))))+1 for i,inc in enumerate(self.iter_visible('increments')): @@ -900,7 +917,10 @@ class DADF5(): vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), deep=True,array_type= vtk.VTK_DOUBLE)) vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) #ToDo: hard coded 1! - grid.GetCellData().AddArray(vtk_data[-1]) + if mode=='Cell': + grid.GetCellData().AddArray(vtk_data[-1]) + else: + Polydata.GetCellData().AddArray(vtk_data[-1]) else: x = self.get_dataset_location(label) if len(x) == 0: @@ -912,9 +932,12 @@ class DADF5(): ph_name = re.compile(r'(\/[1-9])_([A-Z][a-z]*)_(([a-z]*)|([A-Z]*))') #looking for phase name in dataset name dset_name = '1_' + re.sub(ph_name,r'',x[0].split('/',1)[1]) #removing phase name from generic dataset vtk_data[-1].SetName(dset_name) - grid.GetCellData().AddArray(vtk_data[-1]) + if mode=='Cell': + grid.GetCellData().AddArray(vtk_data[-1]) + else: + Polydata.GetCellData().AddArray(vtk_data[-1]) self.set_visible('materialpoints',materialpoints_backup) - + constituents_backup = self.visible['constituents'].copy() self.set_visible('constituents',False) for label in labels: @@ -929,7 +952,10 @@ class DADF5(): vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), deep=True,array_type= vtk.VTK_DOUBLE)) vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) #ToDo: why 1_? - grid.GetCellData().AddArray(vtk_data[-1]) + if mode=='Cell': + grid.GetCellData().AddArray(vtk_data[-1]) + else: + Polydata.GetCellData().AddArray(vtk_data[-1]) else: x = self.get_dataset_location(label) if len(x) == 0: @@ -939,17 +965,23 @@ class DADF5(): vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), deep=True,array_type= vtk.VTK_DOUBLE)) vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) - grid.GetCellData().AddArray(vtk_data[-1]) + if mode=='Cell': + grid.GetCellData().AddArray(vtk_data[-1]) + else: + Polydata.GetCellData().AddArray(vtk_data[-1]) self.set_visible('constituents',constituents_backup) - - writer = vtk.vtkXMLRectilinearGridWriter() if self.structured else \ - vtk.vtkXMLUnstructuredGridWriter() + + if mode=='Cell': + writer = vtk.vtkXMLRectilinearGridWriter() if self.structured else \ + vtk.vtkXMLUnstructuredGridWriter() + x = self.get_dataset_location('u_n') + vtk_data.append(numpy_support.numpy_to_vtk(num_array=self.read_dataset(x,0), + deep=True,array_type=vtk.VTK_DOUBLE)) + vtk_data[-1].SetName('u') + grid.GetPointData().AddArray(vtk_data[-1]) + else: + writer = vtk.vtkXMLPolyDataWriter() - x = self.get_dataset_location('u_n') - vtk_data.append(numpy_support.numpy_to_vtk(num_array=self.read_dataset(x,0), - deep=True,array_type=vtk.VTK_DOUBLE)) - vtk_data[-1].SetName('u') - grid.GetPointData().AddArray(vtk_data[-1]) file_out = '{}_inc{}.{}'.format(os.path.splitext(os.path.basename(self.fname))[0], inc[3:].zfill(N_digits), @@ -958,6 +990,9 @@ class DADF5(): writer.SetCompressorTypeToZLib() writer.SetDataModeToBinary() writer.SetFileName(file_out) - writer.SetInputData(grid) - + if mode=='Cell': + writer.SetInputData(grid) + else: + writer.SetInputData(Polydata) + writer.Write() From e5448fc381b8524cfeaf7ea89e8a6423d6b62f80 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Dec 2019 14:36:52 +0100 Subject: [PATCH 4/7] avoid code duplication --- python/damask/dadf5.py | 63 +++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/python/damask/dadf5.py b/python/damask/dadf5.py index 1f4af8de3..0f32b4b5e 100644 --- a/python/damask/dadf5.py +++ b/python/damask/dadf5.py @@ -854,9 +854,9 @@ class DADF5(): ---------- labels : list of str Labels of the datasets to be exported. - mode : str + mode : str, either 'Cell' or 'Point' Export in cell format or point format. - Default value is 'Cell' + Default value is 'Cell'. """ if mode=='Cell': @@ -868,11 +868,11 @@ class DADF5(): for c in np.linspace(0,self.size[dim],1+self.grid[dim]): coordArray[dim].InsertNextValue(c) - grid = vtk.vtkRectilinearGrid() - grid.SetDimensions(*(self.grid+1)) - grid.SetXCoordinates(coordArray[0]) - grid.SetYCoordinates(coordArray[1]) - grid.SetZCoordinates(coordArray[2]) + vtk_geom = vtk.vtkRectilinearGrid() + vtk_geom.SetDimensions(*(self.grid+1)) + vtk_geom.SetXCoordinates(coordArray[0]) + vtk_geom.SetYCoordinates(coordArray[1]) + vtk_geom.SetZCoordinates(coordArray[2]) else: @@ -880,12 +880,12 @@ class DADF5(): with h5py.File(self.fname) as f: nodes.SetData(numpy_support.numpy_to_vtk(f['/geometry/x_n'][()],deep=True)) - grid = vtk.vtkUnstructuredGrid() - grid.SetPoints(nodes) - grid.Allocate(f['/geometry/T_c'].shape[0]) + vtk_geom = vtk.vtkUnstructuredGrid() + vtk_geom.SetPoints(nodes) + vtk_geom.Allocate(f['/geometry/T_c'].shape[0]) for i in f['/geometry/T_c']: - grid.InsertNextCell(vtk.VTK_HEXAHEDRON,8,i-1) # not for all elements! - else: + vtk_geom.InsertNextCell(vtk.VTK_HEXAHEDRON,8,i-1) # not for all elements! + elif mode == 'Point': Points = vtk.vtkPoints() Vertices = vtk.vtkCellArray() for c in self.cell_coordinates(): @@ -893,10 +893,10 @@ class DADF5(): Vertices.InsertNextCell(1) Vertices.InsertCellPoint(pointID) - Polydata = vtk.vtkPolyData() - Polydata.SetPoints(Points) - Polydata.SetVerts(Vertices) - Polydata.Modified() + vtk_geom = vtk.vtkPolyData() + vtk_geom.SetPoints(Points) + vtk_geom.SetVerts(Vertices) + vtk_geom.Modified() N_digits = int(np.floor(np.log10(int(self.increments[-1][3:]))))+1 @@ -917,10 +917,8 @@ class DADF5(): vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), deep=True,array_type= vtk.VTK_DOUBLE)) vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) #ToDo: hard coded 1! - if mode=='Cell': - grid.GetCellData().AddArray(vtk_data[-1]) - else: - Polydata.GetCellData().AddArray(vtk_data[-1]) + vtk_geom.GetCellData().AddArray(vtk_data[-1]) + else: x = self.get_dataset_location(label) if len(x) == 0: @@ -932,10 +930,8 @@ class DADF5(): ph_name = re.compile(r'(\/[1-9])_([A-Z][a-z]*)_(([a-z]*)|([A-Z]*))') #looking for phase name in dataset name dset_name = '1_' + re.sub(ph_name,r'',x[0].split('/',1)[1]) #removing phase name from generic dataset vtk_data[-1].SetName(dset_name) - if mode=='Cell': - grid.GetCellData().AddArray(vtk_data[-1]) - else: - Polydata.GetCellData().AddArray(vtk_data[-1]) + vtk_geom.GetCellData().AddArray(vtk_data[-1]) + self.set_visible('materialpoints',materialpoints_backup) constituents_backup = self.visible['constituents'].copy() @@ -952,10 +948,7 @@ class DADF5(): vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), deep=True,array_type= vtk.VTK_DOUBLE)) vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) #ToDo: why 1_? - if mode=='Cell': - grid.GetCellData().AddArray(vtk_data[-1]) - else: - Polydata.GetCellData().AddArray(vtk_data[-1]) + vtk_geom.GetCellData().AddArray(vtk_data[-1]) else: x = self.get_dataset_location(label) if len(x) == 0: @@ -965,10 +958,7 @@ class DADF5(): vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), deep=True,array_type= vtk.VTK_DOUBLE)) vtk_data[-1].SetName('1_'+x[0].split('/',1)[1]) - if mode=='Cell': - grid.GetCellData().AddArray(vtk_data[-1]) - else: - Polydata.GetCellData().AddArray(vtk_data[-1]) + vtk_geom.GetCellData().AddArray(vtk_data[-1]) self.set_visible('constituents',constituents_backup) if mode=='Cell': @@ -978,8 +968,8 @@ class DADF5(): vtk_data.append(numpy_support.numpy_to_vtk(num_array=self.read_dataset(x,0), deep=True,array_type=vtk.VTK_DOUBLE)) vtk_data[-1].SetName('u') - grid.GetPointData().AddArray(vtk_data[-1]) - else: + vtk_geom.GetPointData().AddArray(vtk_data[-1]) + elif mode == 'Point': writer = vtk.vtkXMLPolyDataWriter() @@ -990,9 +980,6 @@ class DADF5(): writer.SetCompressorTypeToZLib() writer.SetDataModeToBinary() writer.SetFileName(file_out) - if mode=='Cell': - writer.SetInputData(grid) - else: - writer.SetInputData(Polydata) + writer.SetInputData(vtk_geom) writer.Write() From 5b376712ef80091a618b384cf723a8b02a927e8b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Dec 2019 14:39:10 +0100 Subject: [PATCH 5/7] bugfix: wrong coordinates --- python/damask/dadf5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/dadf5.py b/python/damask/dadf5.py index 0f32b4b5e..367d15f36 100644 --- a/python/damask/dadf5.py +++ b/python/damask/dadf5.py @@ -436,7 +436,7 @@ class DADF5(): np.linspace(delta[1],self.size[1]-delta[1],self.grid[1]), np.linspace(delta[0],self.size[0]-delta[0],self.grid[0]), ) - return np.concatenate((x[:,:,:,None],y[:,:,:,None],y[:,:,:,None]),axis = 3).reshape([np.product(self.grid),3]) + return np.concatenate((x[:,:,:,None],y[:,:,:,None],z[:,:,:,None]),axis = 3).reshape([np.product(self.grid),3]) else: with h5py.File(self.fname,'r') as f: return f['geometry/x_c'][()] From 4469f2f8f0712202d8175a6e1ea3ceb3b05073e4 Mon Sep 17 00:00:00 2001 From: Vitesh Shah Date: Wed, 18 Dec 2019 10:14:19 +0100 Subject: [PATCH 6/7] More general regex --- processing/post/DADF5_vtk_cells.py | 2 +- processing/post/DADF5_vtk_points.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processing/post/DADF5_vtk_cells.py b/processing/post/DADF5_vtk_cells.py index 9e8585773..b3afe939d 100755 --- a/processing/post/DADF5_vtk_cells.py +++ b/processing/post/DADF5_vtk_cells.py @@ -90,7 +90,7 @@ for filename in options.filenames: x = results.get_dataset_location(label) if len(x) == 0: continue - ph_name = re.compile(r'(\/[1-9])_([A-Z][a-z]*)_(([a-z]*)|([A-Z]*))') #looking for phase name in dataset name + ph_name = re.compile(r'(?<=(constituent\/))(.*?)(?=(generic))') #looking for phase name in dataset name array = results.read_dataset(x,0) shape = [array.shape[0],np.product(array.shape[1:])] vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE)) diff --git a/processing/post/DADF5_vtk_points.py b/processing/post/DADF5_vtk_points.py index 908474336..925a73a5c 100755 --- a/processing/post/DADF5_vtk_points.py +++ b/processing/post/DADF5_vtk_points.py @@ -77,7 +77,7 @@ for filename in options.filenames: x = results.get_dataset_location(label) if len(x) == 0: continue - ph_name = re.compile(r'(\/[1-9])_([A-Z][a-z]*)_(([a-z]*)|([A-Z]*))') #looking for phase name in dataset name + ph_name = re.compile(r'(?<=(constituent\/))(.*?)(?=(generic))') #looking for phase name in dataset name array = results.read_dataset(x,0) shape = [array.shape[0],np.product(array.shape[1:])] vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE)) From 3c42368f6681313a6efcd55afe9b145f1a5166a8 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 18 Dec 2019 11:29:13 +0100 Subject: [PATCH 7/7] also use newer regex --- python/damask/dadf5.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/damask/dadf5.py b/python/damask/dadf5.py index 367d15f36..2b86cb5f0 100644 --- a/python/damask/dadf5.py +++ b/python/damask/dadf5.py @@ -833,7 +833,7 @@ class DADF5(): N_not_calculated = len(todo) while N_not_calculated > 0: result = results.get() - with h5py.File(self.fname,'a') as f: # write to file + with h5py.File(self.fname,'a') as f: # write to file dataset_out = f[result['group']].create_dataset(result['label'],data=result['data']) for k in result['meta'].keys(): dataset_out.attrs[k] = result['meta'][k].encode() @@ -927,8 +927,8 @@ class DADF5(): shape = [array.shape[0],np.product(array.shape[1:])] vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape), deep=True,array_type= vtk.VTK_DOUBLE)) - ph_name = re.compile(r'(\/[1-9])_([A-Z][a-z]*)_(([a-z]*)|([A-Z]*))') #looking for phase name in dataset name - dset_name = '1_' + re.sub(ph_name,r'',x[0].split('/',1)[1]) #removing phase name from generic dataset + ph_name = re.compile(r'(?<=(constituent\/))(.*?)(?=(generic))') # identify phase name + dset_name = '1_' + re.sub(ph_name,r'',x[0].split('/',1)[1]) # removing phase name vtk_data[-1].SetName(dset_name) vtk_geom.GetCellData().AddArray(vtk_data[-1])