From 60a337c7ee3dd4f331338d8c71eca2829793881d Mon Sep 17 00:00:00 2001 From: jurjen93 Date: Fri, 25 Aug 2023 09:49:25 +0200 Subject: [PATCH] cleanup --- dp3_helpers/circ2lin.sh | 14 ---- dp3_helpers/lin2circ.sh | 14 ---- h5_helpers/add_antenna_table.py | 2 +- h5_helpers/{openh5.py => close_h5.py} | 0 h5_helpers/h5_filter.py | 2 +- h5_helpers/pol_phase_rot.py | 71 ++++++++++--------- h5_helpers/smooth_bandpass.py | 1 - h5_helpers/testcirc2lin.py | 15 ---- .../get_history_info.py | 2 + 9 files changed, 40 insertions(+), 81 deletions(-) delete mode 100644 dp3_helpers/circ2lin.sh delete mode 100644 dp3_helpers/lin2circ.sh rename h5_helpers/{openh5.py => close_h5.py} (100%) delete mode 100644 h5_helpers/testcirc2lin.py rename {vlbi_helpers/extra_scripts => ms_helpers}/get_history_info.py (97%) diff --git a/dp3_helpers/circ2lin.sh b/dp3_helpers/circ2lin.sh deleted file mode 100644 index b401da6e..00000000 --- a/dp3_helpers/circ2lin.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -MSIN=$1 -MSOUT=$2 - -DPPP \ -msin=$MSIN \ -msout=$MSOUT \ -msout.overwrite=1 \ -steps=[pystep] \ -pystep.python.module=polconv \ -pystep.python.class=PolConv \ -pystep.type=PythonDPPP \ -pystep.circ2lin=1 \ No newline at end of file diff --git a/dp3_helpers/lin2circ.sh b/dp3_helpers/lin2circ.sh deleted file mode 100644 index 1b23c12d..00000000 --- a/dp3_helpers/lin2circ.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -MSIN=$1 -MSOUT=$2 - -DPPP \ -msin=$MSIN \ -msout=$MSOUT \ -msout.overwrite=1 \ -steps=[pystep] \ -pystep.python.module=polconv \ -pystep.python.class=PolConv \ -pystep.type=PythonDPPP \ -pystep.lin2circ=1 \ No newline at end of file diff --git a/h5_helpers/add_antenna_table.py b/h5_helpers/add_antenna_table.py index 75986c4a..77878247 100644 --- a/h5_helpers/add_antenna_table.py +++ b/h5_helpers/add_antenna_table.py @@ -4,7 +4,7 @@ def add_antenna_from_ms(ms, h5, solset=None): """ - Add antenna table to h5 from corresponding MS + Insert antenna table from MS in given h5 WARNING: this overwrites the antenna table from the h5 :param ms: Measurement set diff --git a/h5_helpers/openh5.py b/h5_helpers/close_h5.py similarity index 100% rename from h5_helpers/openh5.py rename to h5_helpers/close_h5.py diff --git a/h5_helpers/h5_filter.py b/h5_helpers/h5_filter.py index 10c0d2c4..8e4ca8da 100644 --- a/h5_helpers/h5_filter.py +++ b/h5_helpers/h5_filter.py @@ -1,5 +1,5 @@ """ -This script is meant to filter directions outside of a specific circle. +This script is meant to filter directions outside of a given circle. This can be useful for excluding directions at the boundaries of a field because the solutions are less good there. """ diff --git a/h5_helpers/pol_phase_rot.py b/h5_helpers/pol_phase_rot.py index 9a9a6611..06957fcc 100644 --- a/h5_helpers/pol_phase_rot.py +++ b/h5_helpers/pol_phase_rot.py @@ -15,7 +15,8 @@ class PhaseRotate: """ - Make template based on given h5parm file + Make template h5 with default values (phase=0 and amplitude=1) and convert to phase rotate matrix for + polarization alignment between different observations. """ def __init__(self, name_in, name_out, freqs = None): os.system(' '.join(['cp', name_in, name_out])) @@ -104,40 +105,6 @@ def make_template(self, shape = None, polrot = None): return self - def rotate(self, intercept, rotation_measure): - """ - Rotate angle by the following matrix: - /e^(i*rho) 0 \ - | | - \ 0 1/ - - :param intercept: intercept - :param rotation_measure: rotation measure in rad/m^2 - """ - print('\n2) ADD PHASE ROTATION') - - phaserot = intercept+rotation_measure*(speed_of_light/self.freqs)**2 - - mapping = list(zip(list(self.freqs), list(phaserot))) - print('########################\nFrequency to rotation in radian (circular base):\n------------------------') - for element in mapping: - print(str(int(element[0]))+'Hz --> '+str(round(element[1], 3))+'rad') - - # print('Rotate with rotation angle: '+str(intercept) + ' radian') - for solset in self.h5.root._v_groups.keys(): - ss = self.h5.root._f_get_child(solset) - for soltab in ss._v_groups.keys(): - if 'phase' in soltab: - phaseval = ss._f_get_child(soltab).val[:] - # same phaserot for all antennas - for ant_idx in range(phaseval.shape[2]): - phaseval[0, :, ant_idx, 0, 0] += phaserot - self.update_array(ss._f_get_child(soltab), phaseval, 'val') - print("########################") - - self.circ2lin() - - return self def circ2lin(self): """ @@ -192,6 +159,40 @@ def circ2lin(self): return G_new + def rotate(self, intercept, rotation_measure): + """ + Rotate angle by the following matrix: + /e^(i*rho) 0 \ + | | + \ 0 1/ + + :param intercept: intercept + :param rotation_measure: rotation measure in rad/m^2 + """ + print('\n2) ADD PHASE ROTATION') + + phaserot = intercept+rotation_measure*(speed_of_light/self.freqs)**2 + + mapping = list(zip(list(self.freqs), list(phaserot))) + print('########################\nFrequency to rotation in radian (circular base):\n------------------------') + for element in mapping: + print(str(int(element[0]))+'Hz --> '+str(round(element[1], 3))+'rad') + + # print('Rotate with rotation angle: '+str(intercept) + ' radian') + for solset in self.h5.root._v_groups.keys(): + ss = self.h5.root._f_get_child(solset) + for soltab in ss._v_groups.keys(): + if 'phase' in soltab: + phaseval = ss._f_get_child(soltab).val[:] + # same phaserot for all antennas + for ant_idx in range(phaseval.shape[2]): + phaseval[0, :, ant_idx, 0, 0] += phaserot + self.update_array(ss._f_get_child(soltab), phaseval, 'val') + print("########################") + + self.circ2lin() + + return self if __name__ == '__main__': diff --git a/h5_helpers/smooth_bandpass.py b/h5_helpers/smooth_bandpass.py index 33aaa208..0c25b690 100644 --- a/h5_helpers/smooth_bandpass.py +++ b/h5_helpers/smooth_bandpass.py @@ -1,6 +1,5 @@ """ Script for smoothing bandpass with median filter. -Useful for fitting on strange patterns in bandpass. Be careful with usage and always check the results in the plots given at the end. diff --git a/h5_helpers/testcirc2lin.py b/h5_helpers/testcirc2lin.py deleted file mode 100644 index a8a887d1..00000000 --- a/h5_helpers/testcirc2lin.py +++ /dev/null @@ -1,15 +0,0 @@ -import pyrap.tables as pt -import numpy as np - -t = pt.table('LBCS_120_168MHz_averaged.ms/') - -datalin = t.getcol('DATA_LIN') -linapplied = t.getcol('LIN_APPLIED') - -diff = datalin-linapplied -diff_amp = np.abs(datalin)-np.abs(linapplied) -diffangle = np.angle(datalin)-np.angle(linapplied) - -print("Complex diff:\n"+str(diff)) -print("Amplitude diff:\n"+str(diff_amp)) -print("Phase diff:\n"+str(diffangle)) \ No newline at end of file diff --git a/vlbi_helpers/extra_scripts/get_history_info.py b/ms_helpers/get_history_info.py similarity index 97% rename from vlbi_helpers/extra_scripts/get_history_info.py rename to ms_helpers/get_history_info.py index 19ae08d8..0bbd052e 100644 --- a/vlbi_helpers/extra_scripts/get_history_info.py +++ b/ms_helpers/get_history_info.py @@ -1,3 +1,5 @@ +"""Functions to parse history from MS""" + import os import re