diff --git a/scripts/get_delay_dir.py b/scripts/get_delay_dir.py new file mode 100755 index 0000000000000000000000000000000000000000..17114ceac1703c9fa7a120e35cbb69998935f3ca --- /dev/null +++ b/scripts/get_delay_dir.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +import argparse + +from astropy.coordinates import SkyCoord +from losoto.h5parm import h5parm + + +def main(h5_in: str, solset: str, direction_name: str): + """ + Obtain the direction of the delay calibrator. + + + Parameters + ---------- + h5_in : string + H5parm to use. + solset : string + Solset to use. + direction_name : string + Direction to extract the direction for. + """ + h5 = h5parm(h5_in) + ss = h5.getSolset(solset) + ss_dir = ss.getSou()[direction_name] + delay_direction = SkyCoord(ss_dir[0], ss_dir[1], unit="rad") + ra = delay_direction.ra.to("deg").value + dec = delay_direction.dec.to("deg").value + print("Source_id,RA,DEC") + print(f"DelayCal,{ra},{dec}") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Obtain the direction of the delay calibrator." + ) + parser.add_argument( + "--h5parm", + type=str, + help="H5parm solution file containing delay calibration solutions.", + ) + parser.add_argument( + "--solset", type=str, help="Solset to extract the solutions from." + ) + parser.add_argument( + "--direction_name", type=str, help="Direction to extract the solutions for." + ) + args = parser.parse_args() + main(args.h5parm, args.solset, args.direction_name) diff --git a/steps/generate_parset_split.cwl b/steps/generate_parset_split.cwl index 63a15856a611af4fb89af40ae0bd2ce3a18d4abe..45e0c35a09725330f2ef53775ea995f6cc80125e 100755 --- a/steps/generate_parset_split.cwl +++ b/steps/generate_parset_split.cwl @@ -34,6 +34,12 @@ inputs: doc: | Time resolution in seconds for the third averaging. + - id: beamdir_delay_cal + type: string + doc: | + Direction in which the primary beam correction for + the delay calibration has been done. + outputs: - id: parset type: File @@ -49,8 +55,8 @@ requirements: entry: |+ steps = [split] - split.replaceparms = [phaseshift.phasecenter, applybeam.direction, msout.name] - split.steps = [phaseshift, averager1, applybeam, averager2, applycal, averager3, msout] + split.replaceparms = [phaseshift.phasecenter, applytargetbeam.direction, msout.name] + split.steps = [phaseshift, averager1, applydelaybeam, applycal, applytargetbeam, averager2, msout] phaseshift.type = phaseshift phaseshift.phasecenter = $(inputs.phase_centers) @@ -59,23 +65,25 @@ requirements: averager1.freqresolution = 48.82kHz averager1.timeresolution = 4. - applybeam.type = applybeam - applybeam.direction = $(inputs.phase_centers) - applybeam.beammode = full - - averager2.type = averager - averager2.freqresolution = 390.56kHz - averager2.timeresolution = 32 - - # Apply solutions and more average_target + # Beam and solutions are fulljones, so they don't commute. + applydelaybeam.type = applybeam + applydelaybeam.direction = $(inputs.beamdir_delay_cal) + applydelaybeam.beammode = full + # Apply delay calibrator solutions now. applycal.type = applycal applycal.correction = fulljones applycal.soltab = [amplitude000, phase000] + + # Only now can we properly apply the primary beam of the target. + # DP3 understands the previous applybeam. No explicit undo needed. + applytargetbeam.type = applybeam + applytargetbeam.direction = $(inputs.phase_centers) + applytargetbeam.beammode = full - averager3.type = averager - averager3.freqresolution = $(inputs.frequency_resolution) - averager3.timeresolution = $(inputs.time_resolution) + averager2.type = averager + averager2.freqresolution = $(inputs.frequency_resolution) + averager2.timeresolution = $(inputs.time_resolution) msout.storagemanager = dysco msout.name = $(inputs.msout_names) diff --git a/steps/get_delay_cal_direction.cwl b/steps/get_delay_cal_direction.cwl new file mode 100644 index 0000000000000000000000000000000000000000..4c16f08d891458a3158851649dbc156b7efdfc37 --- /dev/null +++ b/steps/get_delay_cal_direction.cwl @@ -0,0 +1,50 @@ +cwlVersion: v1.2 +class: CommandLineTool +label: extract_delay_calibrator_coordinates +doc: | + Extracts the direction of the calibrator used during delay calibration + from the H5parm with delay calibration solutions. + +baseCommand: + - get_delay_dir.py + +stdout: delay_dir.csv +stderr: get_delay_dir_err.txt + +inputs: + - id: delay_solutions + label: delay_calibrator_solutions + type: File + inputBinding: + position: 0 + prefix: --h5parm + doc: | + Delay calibrator solutions in H5parm format. + - id: solset + label: solset + type: string + inputBinding: + position: 1 + prefix: --solset + doc: | + SolutionSet to get the direction from. + default: 'sol000' + - id: direction_name + label: direction_name + type: string + inputBinding: + position: 0 + prefix: --direction + doc: | + Name of the direction to extract coordinates for. + default: 'Dir00' + +outputs: + - id: delay_cal_dir + label: delay_calibrator_direction + type: File + doc: | + CSV table with coordinates of the delay calibrator. + outputBinding: + glob: delay_dir.csv + diff --git a/workflows/split-directions.cwl b/workflows/split-directions.cwl index 7d93302bc407c0d180389bdc626e38303dbc89e2..3b0592c0345f26dadb595a12da286e27172b1d95 100644 --- a/workflows/split-directions.cwl +++ b/workflows/split-directions.cwl @@ -69,6 +69,8 @@ steps: source: msin - id: image_cat source: image_cat + - id: delay_solutions + source: delay_solset out: - id: parset run: ./subworkflows/split_parset.cwl diff --git a/workflows/subworkflows/split_parset.cwl b/workflows/subworkflows/split_parset.cwl index 5fa26ed1dd7136176d12c97f3baeb55f2e39e844..b0d84363a8d6a697ef8181002ada967872358b83 100644 --- a/workflows/subworkflows/split_parset.cwl +++ b/workflows/subworkflows/split_parset.cwl @@ -24,6 +24,12 @@ inputs: The image catalogue in CSV format, containing the target directions. + - id: delay_solutions + type: File + doc: | + Delay calibrator solutions. This is used + to determine the beam direction. + outputs: - id: parset type: File @@ -32,7 +38,9 @@ outputs: steps: - id: get_coordinates - label: Get target ID and coordinates + label: get_coordinates + doc: | + Get target ID and coordinates in: - id: delay_calibrator source: image_cat @@ -45,7 +53,9 @@ steps: run: ../../steps/prep_delay.cwl - id: generate_filenames - label: Generate MeasurementSet output names + label: generate_filenames + doc: | + Generate MeasurementSet output names in: - id: msin source: msin @@ -55,13 +65,43 @@ steps: - id: msout_names run: ../../steps/generate_filenames.cwl + - id: get_delay_cal_dir + label: get_delay_cal_direction + doc: | + Obtains the direction of the primary delay calibrator that was used, + by extracting it from the delay calibration solutions. + in: + - id: delay_solutions + source: delay_solutions + out: + - id: delay_cal_dir + run: ../../steps/get_delay_cal_direction.cwl + + - id: get_delay_cal_beam_dir + label: get_delay_cal_beam_direction + doc: | + Process the coordinates for the beam correction in + a format suitable for DP3. + in: + - id: delay_calibrator + source: get_delay_cal_dir/delay_cal_dir + out: + - id: source_id + - id: coordinates + - id: logfile + run: ../../steps/prep_delay.cwl + - id: generate_parset - label: Generate direction parset. + label: generate_parset + doc: | + Generate direction parset. in: - id: msout_names source: generate_filenames/msout_names - id: phase_centers source: get_coordinates/coordinates + - id: beamdir_delay_cal + source: get_delay_cal_beam_dir/coordinates out: - id: parset run: ../../steps/generate_parset_split.cwl