Skip to content
Snippets Groups Projects
Commit aee9fb8a authored by Matthijs van der Wild's avatar Matthijs van der Wild
Browse files

Allow prep_delay to execute TargetListToCoords.py

parent 3dafe748
No related branches found
No related tags found
1 merge request!95Allow prep_delay to execute TargetListToCoords.py
#!/usr/bin/env python3
import argparse
import json
from astropy.table import Table from astropy.table import Table
def plugin_main(**kwargs): def plugin_main(**kwargs):
""" """
Takes in a catalogue with a target and returns appropriate coordinates Takes in a catalogue with a target and returns appropriate coordinates
...@@ -19,32 +25,69 @@ def plugin_main(**kwargs): ...@@ -19,32 +25,69 @@ def plugin_main(**kwargs):
""" """
# parse the input # parse the input
target_file = kwargs['target_file'] target_file = kwargs["target_file"]
mode = kwargs['mode'] mode = kwargs["mode"]
# read in the catalogue to get source_id, RA, and DEC # read in the catalogue to get source_id, RA, and DEC
t = Table.read(target_file, format='csv') t = Table.read(target_file, format="csv")
RA_val = t['RA'].data RA_val = t["RA"].data
DEC_val = t['DEC'].data DEC_val = t["DEC"].data
Source_id = t['Source_id'].data Source_id = t["Source_id"].data
if mode == 'delay_calibration': if mode == "delay_calibration":
RA_val = [RA_val[0]] RA_val = [RA_val[0]]
DEC_val = [DEC_val[0]] DEC_val = [DEC_val[0]]
Source_id = Source_id[0] Source_id = Source_id[0]
if isinstance(Source_id, str): if isinstance(Source_id, str):
Source_id = [Source_id] Source_id = [Source_id]
else: else:
Source_id = ['S' + str(Source_id)] Source_id = ["S" + str(Source_id)]
# make a string of coordinates for the DP3 command # 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": if mode == "delay_calibration":
ss = ss[0] ss = ss[0]
elif mode == "split_directions": elif mode == "split_directions":
ss = "[" + (ss[0] if len(ss) == 1 else ",".join(ss)) + "]" ss = "[" + (ss[0] if len(ss) == 1 else ",".join(ss)) + "]"
else: else:
raise ValueError("Argument mode must be one of" raise ValueError(
+ " \"delay_calibration\", \"split_directions\"" "Argument mode must be one of"
+ f" but was \"{mode}\".") + ' "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()
...@@ -5,9 +5,7 @@ label: Prepare delay ...@@ -5,9 +5,7 @@ label: Prepare delay
doc: | doc: |
Converts the delay calibrator information into strings. Converts the delay calibrator information into strings.
baseCommand: baseCommand: TargetListToCoords.py
- python3
- prep_delay.py
inputs: inputs:
- id: delay_calibrator - id: delay_calibrator
...@@ -15,32 +13,25 @@ inputs: ...@@ -15,32 +13,25 @@ inputs:
doc: | doc: |
The file containing the properties and The file containing the properties and
coordinates of the delay calibrator. coordinates of the delay calibrator.
inputBinding:
prefix: --target_file
separate: true
- id: mode - id: mode
type: string type:
type: enum
symbols:
- "delay_calibration"
- "split_directions"
doc: | doc: |
A boolean that, if set to true, ensures that The name of the processing mode.
the step will only extract the source_id and Must be either 'delay_calibration' or 'split_directions'.
coordinates of the first entry of the catalogue. inputBinding:
prefix: --mode
separate: true
requirements: requirements:
- class: InlineJavascriptRequirement - 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: hints:
- class: DockerRequirement - class: DockerRequirement
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment