Reading he5 (like hdf5) file

This is the place for queries that don't fit in any of the other categories.

Reading he5 (like hdf5) file

Postby tnknepp » Wed May 29, 2013 5:43 pm

I am reading hdf5 files that have been tweaked to conform to who knows what standards, and have hit a snag. I am got this far:
Code: Select all
import tables

r = os.listdir(os.getcwd())[5] # Any file will do
f = tables.openFile(r,'r',rootUEP='/HDFEOS/SWATHS/O3 column-MLS/')
data = f.getNode('/','Data Fields')

What's in "data" you may ask?
>>>data
/Data Fields (Group) ''
children := ['Status' (CArray), 'O3 column-MLSPrecision' (SoftLink), 'L2gpPrecision' (CArray), 'O3 column-MLS' (SoftLink), 'Convergence' (CArray), 'Quality' (CArray), 'L2gpValue' (CArray)]

Now, I should be able to get the O3 column-MLS data out via
Code: Select all
data = data.O3 column-MLS


but I get the error:
File "<stdin>", line 1
data.O3 column-MLS
^
SyntaxError: invalid syntax

I think the problem is that "O3 column-MLS" has a space in it, which is making tables angry. Can anyone suggest how to overcome this? I have also tried pandas.HDFStore, and h5py, but they have problems reading the he5 format. All of the he5 files, and the he5 extension is not allowed for upload, so, if you want to take a crack at it, you can get an example file here.
Python: 2.7 via Anaconda
Numpy: 1.7
Pandas: 0.11
OS: Windows 7
IDE: Spyder/IPython
User avatar
tnknepp
 
Posts: 123
Joined: Mon Mar 11, 2013 7:41 pm

Re: Reading he5 (like hdf5) file

Postby stranac » Wed May 29, 2013 7:31 pm

From a quick google search, it looks like you're using PyTables.

The library probably (you should check the docs/code) offers a way to access attributes like these, but if it doesn't, you could use getattr():
Code: Select all
your_thing = getattr(data, 'O3 column-MLS')
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: Reading he5 (like hdf5) file

Postby tnknepp » Wed May 29, 2013 8:06 pm

Thanks stranac. I figured it out. The data I want is not labeled in an intuitive way (unless you read the documentation :oops: ). I made the assumption that the field labeled O3 column was the one I wanted, but I really wanted the "L2gpValue" field. Apparently, "O3 column-MLS" really is a symbolic link within the file. I don't know what purpose this holds, but it can get'cha.

Sorry for the embarrassing question.

Now I can get data via previous posted code, while making the following correction:

Code: Select all
data = data.L2gpValue
Python: 2.7 via Anaconda
Numpy: 1.7
Pandas: 0.11
OS: Windows 7
IDE: Spyder/IPython
User avatar
tnknepp
 
Posts: 123
Joined: Mon Mar 11, 2013 7:41 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 5 guests

cron