test for export_DREAM3D
This commit is contained in:
parent
3462d41d8e
commit
767ba5a421
|
@ -1,4 +1,5 @@
|
||||||
import bz2
|
import bz2
|
||||||
|
from ftplib import error_temp
|
||||||
import pickle
|
import pickle
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -8,6 +9,7 @@ import hashlib
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import random
|
import random
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import vtk
|
import vtk
|
||||||
|
@ -432,6 +434,82 @@ class TestResult:
|
||||||
single_phase.export_VTK(mode='point',target_dir=export_dir,parallel=False)
|
single_phase.export_VTK(mode='point',target_dir=export_dir,parallel=False)
|
||||||
assert set(os.listdir(export_dir)) == set([f'{single_phase.fname.stem}_inc{i:02}.vtp' for i in range(0,40+1,4)])
|
assert set(os.listdir(export_dir)) == set([f'{single_phase.fname.stem}_inc{i:02}.vtp' for i in range(0,40+1,4)])
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('fname',['2phase_irregularGrid_tensionX.hdf5'],ids=range(1))
|
||||||
|
def test_export_DREAM3D(self,tmp_path,ref_path,fname):
|
||||||
|
result = Result(ref_path/fname).view(increments=0) #comparing the initial data only
|
||||||
|
result.export_VTK(target_dir=tmp_path)
|
||||||
|
|
||||||
|
ref_file = h5py.File(ref_path/'2phase_irregularGrid.dream3D','r')
|
||||||
|
job_file_no_ext = result.fname.stem
|
||||||
|
results_file = h5py.File(tmp_path/f'{job_file_no_ext}_increment_0.dream3D','r')
|
||||||
|
|
||||||
|
error_messages = []
|
||||||
|
|
||||||
|
data_container_label = 'DataContainers/SyntheticVolumeDataContainer'
|
||||||
|
cell_data_label = data_container_label + '/CellData'
|
||||||
|
ensemble_label = data_container_label + '/CellEnsembleData'
|
||||||
|
geom_label = data_container_label + '/_SIMPL_GEOMETRY'
|
||||||
|
|
||||||
|
# check phase array
|
||||||
|
results_phase = np.array(results_file[cell_data_label + '/Phases'])
|
||||||
|
ref_phase = np.array(ref_file[cell_data_label + '/Phases'])
|
||||||
|
if not np.array_equal(results_phase,ref_phase):
|
||||||
|
error_messages.append('Phase array does not match')
|
||||||
|
|
||||||
|
# check euler angles
|
||||||
|
results_eulers = np.array(results_file[cell_data_label + '/EulersAngles'])
|
||||||
|
ref_eulers = np.array(ref_file[cell_data_label + '/EulerAngles'])
|
||||||
|
if not np.allclose(results_eulers,ref_eulers,atol=1E-06):
|
||||||
|
error_messages.append('Euler angles array does not match')
|
||||||
|
|
||||||
|
# check CellData group attributes
|
||||||
|
for attrs in ['AttributeMatrixType','TupleDimensions']:
|
||||||
|
ref_val = ref_file[cell_data_label].attrs[attrs]
|
||||||
|
actual_val = results_file[cell_data_label].attrs[attrs]
|
||||||
|
if ref_val != actual_val:
|
||||||
|
error_messages.append("Cell Data attributes do not match")
|
||||||
|
|
||||||
|
# Common Attributes for groups in CellData
|
||||||
|
for dataset in ['/Phases','/EulerAngles']:
|
||||||
|
for attrs in ['DataArrayVersion','Tuple Axis Dimensions','ComponentDimensions','ObjectType','TupleDimensions']:
|
||||||
|
ref_val = ref_file[cell_data_label + '/' + dataset].attrs[attrs]
|
||||||
|
actual_val = results_file[cell_data_label + '/' + dataset].attrs[attrs]
|
||||||
|
if ref_val != actual_val:
|
||||||
|
error_messages.append("Common attributes in datasets of CellData do not match")
|
||||||
|
|
||||||
|
# TODO: check for the array of CrystalStructures too. However, currently crystal structure is set to cubic by default.
|
||||||
|
# TODO: check for the array of PhaseTypes too. However, currently phase is assumed Primary by default.
|
||||||
|
# check attributes ensemble matrix
|
||||||
|
for attrs in ['AttributeMatrixType','TupleDimensions']:
|
||||||
|
ref_val = ref_file[ensemble_label].attrs[attrs]
|
||||||
|
actual_val = results_file[ensemble_label].attrs[attrs]
|
||||||
|
if ref_val != actual_val:
|
||||||
|
error_messages.append("Attributes of CellEnsembleData do not match")
|
||||||
|
|
||||||
|
# check attributes of the data in ensemble matrix
|
||||||
|
# in the reference file the dataset PhaseTypes is in another group, so the path is different
|
||||||
|
for dataset in ['CrystalStructures','PhaseTypes']:
|
||||||
|
for attrs in ['DataArrayVersion','Tuple Axis Dimensions','ComponentDimensions','ObjectType','TupleDimensions']:
|
||||||
|
ref_value = ref_file['DataContainers/StatsGeneratorDataContainer/CellEnsembleData/' + dataset].attrs[attrs]
|
||||||
|
actual_val = results_file[ensemble_label + '/' + dataset].attrs[attrs]
|
||||||
|
if ref_val != actual_val:
|
||||||
|
error_messages.append("Attributes of datasets within CellEnsembleData do not match")
|
||||||
|
|
||||||
|
# check geometry data
|
||||||
|
for dataset in ['DIMENSIONS','ORIGIN','SPACING']:
|
||||||
|
results_val = np.array(results_file[geom_label + '/' + dataset])
|
||||||
|
ref_val = np.array(ref_file[geom_label + '/' + dataset])
|
||||||
|
if not np.array_equal(results_val,ref_val):
|
||||||
|
error_messages.append(f'The {dataset} values are incorrect')
|
||||||
|
|
||||||
|
for attrs in ['GeometryName','GeometryTypeName','GeometryType','SpatialDimensionality','UnitDimensionality']:
|
||||||
|
ref_value = ref_file[geom_label].attrs[attrs]
|
||||||
|
actual_val = results_file[geom_label].attrs[attrs]
|
||||||
|
if ref_val != actual_val:
|
||||||
|
error_messages.append("Geometry attributes do not match")
|
||||||
|
|
||||||
|
assert not error_messages
|
||||||
|
|
||||||
def test_XDMF_datatypes(self,tmp_path,single_phase,update,ref_path):
|
def test_XDMF_datatypes(self,tmp_path,single_phase,update,ref_path):
|
||||||
for what,shape in {'scalar':(),'vector':(3,),'tensor':(3,3),'matrix':(12,)}.items():
|
for what,shape in {'scalar':(),'vector':(3,),'tensor':(3,3),'matrix':(12,)}.items():
|
||||||
for dtype in ['f4','f8','i1','i2','i4','i8','u1','u2','u4','u8']:
|
for dtype in ['f4','f8','i1','i2','i4','i8','u1','u2','u4','u8']:
|
||||||
|
|
Loading…
Reference in New Issue