With h5_merger.py
it is possible to merge H5parm solution files (typically with extension .h5).
Within these solution sets there has to be a source, antenna, and solXXX tables.
They should also contain 'amplitude000' and/or 'phase000' solution tables.
This script has also other functionalities, such as time and frequency averaging or linear to circular conversion and vice versa.
These can be independently used from the merging functionality. You can find all the options below.
h5_merger.py
is compatible with both Python 2 and Python 3 but is likely most reliable with Python 3.
h5_mergers.py
uses the following libraries:
losoto
(install withpip install lososto
)casacore.tables
(install withpip install python-casacore
)numpy
scipy
tables
Import the main function in Python with
from h5_merger import merge_h5
Or use the script on the command line with
python h5_merger.py <PARAM>
List all the options in your version of h5_merger.py
with:
python h5_merger.py -h
You can also import the functionalities to perform the output check and to get the summary of the solution file separately:
from h5_merger import h5_check
or run the script on the command line
from h5_merger import output_check
where you can insert a solution file in the function.
This script is being used in:
https://github.com/rvweeren/lofar_facet_selfcal
https://github.com/lmorabit/lofar-vlbi
Examples below demonstrate how to use h5_merger.py for specific cases:
python h5_merger.py -in *.h5 -out out.h5
By adding --propagate_flags
it also propagate the weights from the input h5 file, which usually corresponds with the flagged data.
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 -ms <YOUR_MS>
The input MS can also be multiple measurement sets (where the script will generate one time and freq axis convering all these MS).
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 --h5_time_freq <H5>
This will take the time and freq axis from H5 to interpolate to.
You can also give a boolean to --h5_time_freq
which means that all input h5 files will be used to generate the time and freq axis from (this is the default if -ms
is not used).
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 --merge_all_in_one
The script merges by default the same directions with each other, but if the user wishes to merge all h5 files in one direction, you can add the --merge_all_in_one
option.
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 --keep_tec
The script converts by default TEC input to phases (see Equation 1 in Sweijen et al +22), but user can also turn this conversion off.
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 --circ2lin
or
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 --lin2circ
--circ2lin
and -lin2circ
can be added to any type of merge, as this conversion will be done at the end of the algorithm.
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 --merge_diff_freq
This is for example useful if you wish to merge solution files from different frequency bands together into 1 big solution file.
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 -ms <YOUR_MS> --add_cs
This functionality will replace the super station (ST001) in the h5 file with the core stations from a given MS file.
python h5_merger.py --propagate_flags -in *.h5 -out out.h5 -ms <YOUR_MS> --add_ms_stations
This functionality will return in the output H5 file only the stations that are present in the MS file.
For international stations default values will be returned (amplitudes=1 for diagonals, amplitudes=0 for off-diagonals, phases=0).
Combinations of all the above are possible to merge more exotic cases, such as for example a merge like this:
python h5_merger.py -in *.h5 -out test.h5 -ms <YOUR_MS> --h5_time_freq=true --add_ms_stations --propagate_flags --merge_diff_freq --merge_all_in_one --keep_tec --circ2lin
Let me know if you are using this script or other scripts and have any issues or suggestions for improvements. You can contact me on: jurjendejong(AT)strw.leidenuniv.nl