How can I automatically process ascending file names and array names in Numpy:
I have a series of HDF5 files named:
20120101.hdf5, 20120102.hdf5, 20120103.hdf5, ..., 20120130.hdf5, 20120131.hdf5
each of the hdf5 file contains several arrays naming:
array1, array2, array3, ..., array24
I want to modify each of the arrays seperately and then create corresponding new hdf5 files. For example, using 20120101.hdf5:
import numpy
import tables
file = openFile("20120101.hdf5","r")
b1 = file.root.array1
c1 = (b1<=1)
new20120101_array1 = creatArray('/','1',c1)
c2 = ((b1<=2) and (b>1))
new20120101_array1 = creatArray('/','2',c2)
.
.
.
c20 = ((b1<=20) and (b>19))
new20120101_array1 = creatArray('/','20',c20)
and repeat it for arrays 2-24. As a result, I want to have:
new20120101.hdf5 ---- new20120101_array1 ---- 1
2
...
20
---- new20120101_array2 ---- 1
...
20
...
---- new20120101_array24 --- 1
...
20
new20120102.hdf5
....
new20120131.hdf5
If you have several files in a directory, you can use the
os.listdirfunction, which returns a list containing the names of the entries in the directory.Example:
The other part of your question is already answered in your other question, I guess (you can use the
walkNodesfunction ).