I have about 1300 h5 files to sort into a dictionary using h5py. When I run my code on about 250 files it works fine, but any amount larger gives me the error:
Traceback (most recent call last):
File "solution_script.py", line 31, in <module>
File "build/bdist.macosx-10.7-intel/egg/h5py/_hl/files.py", line 165, in __init__
File "build/bdist.macosx-10.7-intel/egg/h5py/_hl/files.py", line 57, in make_fid
File "h5f.pyx", line 70, in h5py.h5f.open (h5py/h5f.c:1626)
IOError: unable to open file (File accessability: Unable to open file)'
I'm not sure if I set up the dictionary incorrectly or if there is a better way to do this.
Here's my code if anyone can see some obvious mistakes I've made:
nodesDictionary = {}
velDictionary = {}
cellsDictionary={}
num_h5file = -1;
for root, directory, files in os.walk(rootDirectory):
for file in sorted(files):
if file.endswith(".h5"):
num_h5file = num_h5file + 1
curh5file = h5py.File(file, 'r')
nodes_list = curh5file["nodes"]
cells_list = curh5file["cells"]
velocity_list = curh5file["velocity"]
for i in range(0, len(nodes_list)-1):
if num_h5file not in nodesDictionary:
nodesDictionary[num_h5file] = [curh5file["nodes"][i]]
velDictionary[num_h5file] = [curh5file["velocity"][i]]
else:
nodesDictionary[num_h5file].append(curh5file["nodes"][i])
velDictionary[num_h5file].append(curh5file["velocity"][i])
for j in range(0, len(cells_list)-1):
if num_h5file not in cellsDictionary:
cellsDictionary[num_h5file] = [curh5file["cells"][j]]
else:
cellsDictionary[num_h5file].append(curh5file["cells"][j])
Any help/advice/insight would be greatly appreciated :)