-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathadd_table.py
executable file
·35 lines (28 loc) · 986 Bytes
/
add_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import random, sys
import numpy, tables
from particle import Particle
def create_data_file(name):
h5file = tables.openFile(name, mode='a')
final_state = h5file.createTable(h5file.root.particles, 'final',
Particle, 'final state of particles')
initial_state = h5file.root.particles.initial
particle = final_state.row
for init_particle in initial_state:
particle['particle_id'] = init_particle['particle_id']
particle['mass'] = init_particle['mass']
particle['x_pos'] = random.gauss(0.0, 1.0)
particle['y_pos'] = random.gauss(0.0, 1.0)
particle['x_vel'] = random.gauss(0.0, 1.0)
particle['y_vel'] = random.gauss(0.0, 1.0)
particle.append()
h5file.flush()
return h5file
def main():
h5file = create_data_file('test.h5')
print h5file
h5file.close()
return 0
if __name__ == '__main__':
status = main()
sys.exit(status)