In [13]:
import os
import tables, pandas
import numpy as np
results_dir = "/data/GLM-wkshp/flashsort/results/"
h5name = os.path.join(results_dir, "h5_files/2009/Apr/10/LYLOUT_090410_160000_3600.dat.flash.h5")
h5 = tables.open_file(h5name, 'a')
print h5
table_name = h5.root.flashes._v_children.keys()[0]
print table_name
In [14]:
h5.remove_node(h5.root.NLDN, recursive=True)
print h5
In [15]:
group = h5.root.flashes
table = getattr(h5.root.flashes, table_name)
descr = table.description._v_colobjects
revised_table_title = table.title[:-3]
print revised_table_title
# Create the new description
descr2 = descr.copy()
# remove the CG key from the descriptor dictionary
descr2.pop('CG')
table2 = h5.createTable(group, table_name+'_temp', descr2, revised_table_title)
table.attrs._f_copy(table2)
for i in range(table.nrows):
table2.row.append()
table2.flush()
for col in descr2:
getattr(table2.cols, col)[:] = getattr(table.cols, col)[:]
# for value in results[-np.isnan(results)]:
# for row in table2.where('flash_id == value'):
# row['CG'] = True
# row.update()
table.remove()
table2.move('/flashes',table_name)
print 'h5 rewritten'
h5.close()
In [ ]:
In [ ]: