Skip to content

Commit

Permalink
re-add overwrite_table
Browse files Browse the repository at this point in the history
  • Loading branch information
jurjen93 committed Oct 29, 2024
1 parent 5e7b459 commit d47e067
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions h5_helpers/overwrite_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import numpy as np
import tables
import sys

def overwrite_table(h5, table, new_arr):
"""
Overwrite h5 source or antenna table
:param h5: h5parm table
:param table: table name (antenna or source)
:param new_arr: new values
"""

T = tables.open_file(h5, 'r+')

ss = T.root._f_get_child('sol000')
ss._f_get_child(table)._f_remove()
if table == 'source':
values = np.array(new_arr, dtype=[('name', 'S128'), ('dir', '<f4', (2,))])
title = 'Source names and directions'
elif table == 'antenna':
title = 'Antenna names and positions'
values = np.array(new_arr, dtype=[('name', 'S16'), ('position', '<f4', (3,))])
else:
sys.exit('ERROR: table needs to be source or antenna')

T.create_table(ss, table, values, title=title)

T.close()

return

0 comments on commit d47e067

Please sign in to comment.