take care to treat hdf5 files by using h5py

If y open a hdf5 file and do some oeprations in such a way:

 

f = h5py.File(outfile)
data4 = f["data4"]
condition = f["condition"]
for yindx in range(0, condition.shape[1]):
    for eindx in range(0, condition.shape[3]):
       if (abs(yindx - 84)**2 + abs(eindx - 180)**2) < 20**2:
         condition[:, yindx, :, eindx] = False

 

The content in the hdf5 file, in this case "condition", is modified!!

 

To prevent the overwriting, y should write instead:

 

f = h5py.File(outfile, 'r')
data4 = np.array(f["data4"])
condition = np.array(f["condition"])
for yindx in range(0, condition.shape[1]):
    for eindx in range(0, condition.shape[3]):
       if (abs(yindx - 84)**2 + abs(eindx - 180)**2) < 20**2:
         condition[:, yindx, :, eindx] = False

 

It is always safer that you add 'r' mode if you do not like to alter the original hdf5 file.