On Thu, Jun 14, 2012 at 4:30 PM, Andre' Walker-Loud <walksl...@gmail.com>wrote:
> Hi Anthony,
>
> On Jun 14, 2012, at 11:30 AM, Anthony Scopatz wrote:
>
> > On Wed, Jun 13, 2012 at 8:23 PM, Andre' Walker-Loud <walksl...@gmail.com>
> wrote:
> > Hi All,
> >
> > Still trying to sort out a recursive walk through an hdf5 file using
> pytables.
> >
> > I have an hdf5 file with an unknown depth of groups/nodes.
> >
> > I am trying to write a little function to walk down the tree (with user
> input help) until a data file is found.
> >
> > I am hoping there is some function one can use to query whether you have
> found simply a group/node or an actual numpy array of data. So I can do
> something like
> >
> > if f.getNode('/',some_path) == "data_array":
> > return f.getNode('/',some_path), True
> > else:
> > return f.getNode('/',some_path), False
> >
> > where I have some function that if the second returned variable is True,
> will recognize the file as data, where as if it is False, it will query the
> user for a further path down the tree.
> >
> >
> > I suppose I could set this up with a try: except: but was hoping there
> is some built in functionality to handle this.
> >
> > Yup, I think that you are looking for the File.walkNodes() method.
> http://pytables.github.com/usersguide/libref.html#tables.File.walkNodes
>
> I wasn't sure how to use walkNodes in an interactive search. Here is what
> I came up with so far (it works on test cases I have given it). Comments
> are welcome.
>
> One feature I would like to add to the while loop in the second function
> is an iterator counting the depth of the search. I want to compare this to
> the maximum tree/node/group depth in the file, so if the search goes over
> (maybe my collaborators used createTable instead of createArray) the while
> loop won't run forever.
>
> Is there a function to ask the deepest recursion into the hdf5 file?
>
Hello Andre,
Every Node object has a _v_depth attr that you can access (
http://pytables.github.com/usersguide/libref.html#tables.Node._v_depth).
In your walk function, therefore, you could test to see if you are over or
under the maximal value that you set.
>
> Cheers,
>
> Andre
>
>
> def is_array(file,path):
> data = file.getNode(path)
> if str(type(data)) == "<class 'tables.array.Array'>":
> found_array = True
>
Just one quick comment. You probably shouldn't test the string of the
type of the data.
Use the builtin isinstance() instead:
found_array = isinstance(data, tables.Array)
Be Well
Anthony
> else:
> found_array = False
> for g in file.getNode(path):
> print g
> return data, found_array
>
> def pytable_walk(file):
> found_data = False
> path = ''
> while found_data == False:
> for g in file.getNode('/',path):
> print g
> path_new = raw_input('which node would you like?\n ')
> path = path+'/'+path_new
> data,found_data = is_array(file,path)
> return path,data
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Pytables-users mailing list
> Pytables-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pytables-users
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users