ensure closing of file

This commit is contained in:
Martin Diehl 2023-12-04 22:53:35 +01:00
parent b5e34e7949
commit 5923aa2493
1 changed files with 45 additions and 45 deletions

View File

@ -1989,18 +1989,18 @@ class Result:
cell_orientation[at_cell_ph[c][label],:] = \
Rotation(data[in_data_ph[c][label],:]).as_Euler_angles().astype(np.float32)
except ValueError:
except KeyError:
crystal_structure.append(999)
phase_ID_array[at_cell_ph[c][label]] = count + 1
o = h5py.File(f'{out_dir}/{self.fname.stem}_inc{inc.split(prefix_inc)[-1].zfill(N_digits)}.dream3d','w')
add_attribute(o,'FileVersion','7.0')
with h5py.File(f'{out_dir}/{self.fname.stem}_inc{inc.split(prefix_inc)[-1].zfill(N_digits)}.dream3d','w') as f_out:
add_attribute(f_out,'FileVersion','7.0')
for g in ['DataContainerBundles','Pipeline']: # empty groups (needed)
o.create_group(g)
f_out.create_group(g)
data_container = create_and_open(o,'DataContainers/SyntheticVolumeDataContainer')
data_container = create_and_open(f_out,'DataContainers/SyntheticVolumeDataContainer')
cell = create_and_open(data_container,'CellData')
add_attribute(cell,'AttributeMatrixType',np.array([3],np.uint32))
@ -2043,7 +2043,7 @@ class Result:
geom['ORIGIN'] = np.array(self.origin,np.float32)
geom['SPACING'] = np.float32(self.size/self.cells)
names = ['GeometryName', 'GeometryTypeName','GeometryType','SpatialDimensionality','UnitDimensionality']
values = ['ImageGeometry','ImageGeometry',np.array([0],np.uint32),np.array([3],np.uint32),np.array([3],np.uint32)]
values = ['ImageGeometry','ImageGeometry', np.array([0],np.uint32)] + [np.array([3],np.uint32)]*2
for name,value in zip(names,values):
add_attribute(geom,name,value)