From 4b57954c58c23cc5f7d44e02ca8dbfb6a38ba7ba Mon Sep 17 00:00:00 2001 From: jurjen93 Date: Tue, 6 Aug 2024 19:07:26 +0200 Subject: [PATCH] closest --- h5_helpers/find_closest_h5.py | 51 ++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/h5_helpers/find_closest_h5.py b/h5_helpers/find_closest_h5.py index 6e6a4053..8a1ba721 100644 --- a/h5_helpers/find_closest_h5.py +++ b/h5_helpers/find_closest_h5.py @@ -4,6 +4,7 @@ import numpy as np import sys from argparse import ArgumentParser +from casacore.tables import table class FindClosestDir: @@ -80,15 +81,16 @@ def closest_dir(self, coor): """ Find closest directions, using the astropy SkyCoord class - :param coor: coordinate in arcseconds + :param coor: coordinate in radian """ min_sep, min_sep_idx = 999, 999 for n, dir in enumerate(self.dirs): - c1 = SkyCoord(dir[0], dir[1], unit='arcsecond', frame='icrs') # your coords - c2 = SkyCoord(coor[0], coor[1], unit='arcsecond', frame='icrs') + c1 = SkyCoord(dir[0], dir[1], unit='radian', frame='icrs') # your coords + c2 = SkyCoord(coor[0], coor[1], unit='radian', frame='icrs') sep = c1.separation(c2).value if sep < min_sep: min_sep_idx = n + min_sep = sep # Make sure this function selects a closest direction assert min_sep_idx != 999, "ERROR: coordinate comparison went wrong?! (most likely a bug in h5 or code)" @@ -96,7 +98,7 @@ def closest_dir(self, coor): return min_sep_idx - def add_closest_values(self, coor): + def add_closest_values(self, coor, outcoor): """ Add closest phase, amplitude, and weights to new output h5 """ @@ -113,8 +115,12 @@ def add_closest_values(self, coor): # modify source table ss._f_get_child('source')._f_remove() - values = np.array([(b'Dir00', coor)], - dtype=[('name', 'S128'), ('dir', ' output_h5s') @@ -187,11 +212,7 @@ def main(): for n, dir in enumerate(dirs): T = FindClosestDir(inputh5, f'output_h5s/source_{n}.h5') T.make_template() - T.add_closest_values(dir) - - print('See output in --> output_h5s\n' - 'You can optionally use h5_merger.py to merge all the directions into 1 big h5 file\n' - 'Example command --> python h5_merger.py -in output_h5s/source_*.h5 -out merged.h5 --propagate_flags') + T.add_closest_values(dir, args.outcoor) if __name__ == '__main__':