I am taking a previously generated .h5 file which is 3D and taking a 2D slice. The new 2D h5 file looks complete and as expected, however I then pass this into some modeling software (GPRMax) and get the error KeyError: "Unable to open object (object 'data' doesn't exist)". Previous 2D and 3D .h5 files have been fine, so im not sure whats different. Below is the code used to generate the .h5 file. Any help is appreciated.
hf = h5py.File(dir_path+'\ModelMC0105\ModelA3d1_15102020_170900005701.h5', 'r')
dset = hf['data']
if os.path.exists(dir_path+'\ModelMC0105\ModelA3d1_15102020_170900005701-slice.h5'):
os.remove(dir_path+'\ModelMC0105\ModelA3d1_15102020_170900005701-slice.h5')
hf2 = h5py.File(dir_path+'\ModelMC0105\ModelA3d1_15102020_170900005701-slice.h5','w')
dz_dy_dz = (0.001,0.001,0.001)
hf2.attrs['dx_dy_dz'] = dz_dy_dz
data = hf2.create_dataset("data", (100,1,100))
for i in range(100):
data[i]=(dset[i,50,:])
data=data.ref
print(data)
hf2.close()
hf.close()