diff --git a/scripts/TargetListToCoords.py b/scripts/TargetListToCoords.py old mode 100644 new mode 100755 index 0f3a2da718fc5b3c19d81b393831e06065e4b86a..13fec11728622049b0fd57c26f741fe59e38eb59 --- a/scripts/TargetListToCoords.py +++ b/scripts/TargetListToCoords.py @@ -1,5 +1,11 @@ +#!/usr/bin/env python3 + +import argparse +import json + from astropy.table import Table + def plugin_main(**kwargs): """ Takes in a catalogue with a target and returns appropriate coordinates @@ -19,32 +25,69 @@ def plugin_main(**kwargs): """ # parse the input - target_file = kwargs['target_file'] - mode = kwargs['mode'] + target_file = kwargs["target_file"] + mode = kwargs["mode"] # read in the catalogue to get source_id, RA, and DEC - t = Table.read(target_file, format='csv') - RA_val = t['RA'].data - DEC_val = t['DEC'].data - Source_id = t['Source_id'].data - if mode == 'delay_calibration': + t = Table.read(target_file, format="csv") + RA_val = t["RA"].data + DEC_val = t["DEC"].data + Source_id = t["Source_id"].data + if mode == "delay_calibration": RA_val = [RA_val[0]] DEC_val = [DEC_val[0]] Source_id = Source_id[0] if isinstance(Source_id, str): Source_id = [Source_id] else: - Source_id = ['S' + str(Source_id)] + Source_id = ["S" + str(Source_id)] # make a string of coordinates for the DP3 command - ss = [ '[' + str(x) + 'deg,' + str(y) + 'deg]' for x, y in zip(RA_val, DEC_val) ] + ss = ["[" + str(x) + "deg," + str(y) + "deg]" for x, y in zip(RA_val, DEC_val)] if mode == "delay_calibration": ss = ss[0] elif mode == "split_directions": ss = "[" + (ss[0] if len(ss) == 1 else ",".join(ss)) + "]" else: - raise ValueError("Argument mode must be one of" - + " \"delay_calibration\", \"split_directions\"" - + f" but was \"{mode}\".") + raise ValueError( + "Argument mode must be one of" + + ' "delay_calibration", "split_directions"' + + f' but was "{mode}".' + ) + + return {"name": ",".join(Source_id), "coords": ss} + + +def parse_arguments(): + parser = argparse.ArgumentParser() + + parser.add_argument( + "--target_file", + help="The path of the file containing the properties and coordinates of the delay calibrator", + type=str, + ) + parser.add_argument( + "--mode", + help="The name of the processing mode", + choices=["delay_calibration", "split_directions"], + type=str, + ) + + return parser.parse_args() + + +def main(): + + arguments = parse_arguments() + + output = plugin_main( + target_file=arguments.target_file, + mode=arguments.mode, + ) + + with open("./out.json", "w") as fp: + json.dump(output, fp) + - return {'name' : ",".join(Source_id), 'coords' : ss} +if __name__ == "__main__": + main() diff --git a/steps/prep_delay.cwl b/steps/prep_delay.cwl index 44b8dd3842a0eada901233a09164effc42f71857..1577217ab6770b77e0093b3a051e27a998ecc74f 100644 --- a/steps/prep_delay.cwl +++ b/steps/prep_delay.cwl @@ -5,9 +5,7 @@ label: Prepare delay doc: | Converts the delay calibrator information into strings. -baseCommand: - - python3 - - prep_delay.py +baseCommand: TargetListToCoords.py inputs: - id: delay_calibrator @@ -15,32 +13,25 @@ inputs: doc: | The file containing the properties and coordinates of the delay calibrator. + inputBinding: + prefix: --target_file + separate: true - id: mode - type: string + type: + type: enum + symbols: + - "delay_calibration" + - "split_directions" doc: | - A boolean that, if set to true, ensures that - the step will only extract the source_id and - coordinates of the first entry of the catalogue. + The name of the processing mode. + Must be either 'delay_calibration' or 'split_directions'. + inputBinding: + prefix: --mode + separate: true requirements: - class: InlineJavascriptRequirement - - class: InitialWorkDirRequirement - listing: - - entryname: prep_delay.py - entry: | - import json - from TargetListToCoords import plugin_main as targetListToCoords - - inputs = json.loads(r"""$(inputs)""") - - target_file = inputs['delay_calibrator']['path'] - mode = inputs['mode'] - - output = targetListToCoords(target_file=target_file, mode=mode) - - with open('./out.json', 'w') as fp: - json.dump(output, fp) hints: - class: DockerRequirement