Created
February 1, 2021 15:12
-
-
Save jackersson/ad6190ec5c4d5fdfc43cc6a1ba7813e1 to your computer and use it in GitHub Desktop.
PyTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tables as tb | |
class Record(tb.IsDescription): | |
first_track_id = tb.StringCol(16) # 16-character String | |
second_tracK_id = tb.StringCol(16) # 16-character String | |
distance = tb.Float32Col() # Float (single-precision) | |
# Open a file in "w"rite mode | |
fileh = tb.open_file("table1.h5", mode="w") | |
# Create a new group | |
group = fileh.create_group(fileh.root, "newgroup") | |
# Create a new table in newgroup group | |
table = fileh.create_table(group, 'table', Record, "A table", | |
tb.Filters(1)) | |
single_record = table.row | |
# Fill the table with 10 particles | |
for i in range(28000000): | |
# First, assign the values to the Particle record | |
single_record['first_track_id'] = "track_id_1" | |
single_record['second_tracK_id'] = "track_id_2" | |
single_record['distance'] = 0.5 | |
single_record.append() | |
# We need to flush the buffers in table in order to get an | |
# accurate number of records on it. | |
table.flush() | |
fileh.close() | |
k = 0 | |
with tb.open_file("table1.h5", mode="r") as h5file: | |
table = h5file.root.newgroup.table | |
for x in table.iterrows(): | |
if k < 10: | |
print(x['distance']) | |
k += 1 | |
print(k) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment