In Python (using pytables), it is easy to create HDF5 tables with rows containing timestamps (column datatype Time64
, see http://pytables.github.io/usersguide/datatypes.html).
Is it possible to read in tables containing columns with type Time64 in IDL 8.2? The default approach of
fid = H5F_OPEN(filename)
tabID = H5D_OPEN(fid, '/path/to/table')
data = H5D_READ(tabID)
seems to choke if the node /path/to/table
contains a column of type Time64. I guess there is a way of converting/interpreting the datatype in IDL, even if it is not natively supported by IDL, or not? After all, the Time64 columns are just 8 byte values...
The most relevant IDL documentation that I could find was http://www.exelisvis.com/docs/HDF5_Overview.html.
As a side question: HDFView from the HDF5 Group seems to not support Time64 either, although a special 8-byte column type exists in HDF5 (sorry, I'm not allowed to post another link). Is this column type used by pytables somehow not a standard column type?
Edit: I have created an exemplary hdf5 file containing a table with a Time64 column, see comments for a link. The file was created with the following Python code:
import tables as T
import time
exampleTableColumns = {
'id': T.Int32Col(pos=0),
'value': T.Float32Col(pos=1),
'timestamp': T.Time64Col(pos=2),
}
with T.openFile('time64-example.h5', 'w') as h5:
exampleTab = h5.createTable(
'/', 'example', exampleTableColumns)
# Add some test values
t = time.time()
for i in range(10):
exampleTab.row['id'] = i
exampleTab.row['value'] = i**2
exampleTab.row['timestamp'] = t + 0.5*i
exampleTab.row.append()
exampleTab.flush()
My attempt at reading it from IDL is:
fid = h5f_open(filename)
exampleTab = H5D_OPEN(fid, '/example')
; id: 32 bit signed integer, value: float32, timestamp: 8 byte value
struct = {id:0L, value:0.0, timestamp:0LL}
dt = H5T_IDL_CREATE(struct)
exampleData = H5D_READ(exampleTab, dt)
print, 'exampleData.id:', exampleData.id
print, 'exampleData.value', exampleData.value
print, 'exampleData.timestamp', exampleData.timestamp
h5d_close, exampleTab
h5f_close, fid
The H5D_READ
does not choke anymore once it gets a custom datatype, but already the values in the id
and value
field are garbled. This is the output I get from the print statements:
exampleData.id: 0 0 0 1095914052 174536304 153749104 0 172915600 1095914052 910565433
exampleData.value 0.000000 0.000000 0.000000 13.1451 0.000000 0.000000 0.000000 0.000000 13.1451 640.894
exampleData.timestamp 0 0 0 3833484811918717440 5858206660165639 153997792
5858318295760901 154274128 4051322254670378805 5858331130331138
If I change the struct
to (what I would believe equivalent definition) struct = {id:lonarr(1), value:0.0, timestamp:0LL}
, the print statements yield:
exampleData.id: 262404320 3 262404416 4 262404512 14 0 172915600 1095914052 910565433
exampleData.value 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 13.1451 640.894
exampleData.timestamp 0 0 0 3833484811918717440 0 153997568
5858318295760901 154274128 4051322254670378805 791781549539330