-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path1GC.py
217 lines (159 loc) · 6.37 KB
/
1GC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env python
import glob
import json
import os.path as o
import sys
sys.path.append(o.abspath(o.join(o.dirname(sys.modules[__name__].__file__), "..")))
from oxkat import generate_jobs as gen
from oxkat import config as cfg
def main():
USE_SINGULARITY = cfg.USE_SINGULARITY
gen.preamble()
print(gen.col()+'1GC (referenced calibration) setup')
gen.print_spacer()
if cfg.PRE_FIELDS != '':
print(gen.col('Field selection')+cfg.PRE_FIELDS)
if cfg.PRE_SCANS != '':
print(gen.col('Scan selection')+cfg.PRE_SCANS)
gen.print_spacer()
# ------------------------------------------------------------------------------
#
# Setup paths, required containers, infrastructure
#
# ------------------------------------------------------------------------------
gen.setup_dir(cfg.LOGS)
gen.setup_dir(cfg.SCRIPTS)
gen.setup_dir(cfg.GAINTABLES)
INFRASTRUCTURE, CONTAINER_PATH = gen.set_infrastructure(sys.argv)
if CONTAINER_PATH is not None:
CONTAINER_RUNNER='singularity exec '
else:
CONTAINER_RUNNER=''
CASA_CONTAINER = gen.get_container(CONTAINER_PATH,cfg.CASA_PATTERN,USE_SINGULARITY)
OWLCAT_CONTAINER = gen.get_container(CONTAINER_PATH,cfg.OWLCAT_PATTERN,USE_SINGULARITY)
RAGAVI_CONTAINER = gen.get_container(CONTAINER_PATH,cfg.RAGAVI_PATTERN,USE_SINGULARITY)
SHADEMS_CONTAINER = gen.get_container(CONTAINER_PATH,cfg.SHADEMS_PATTERN,USE_SINGULARITY)
# ------------------------------------------------------------------------------
#
# 1GC recipe definition
#
# ------------------------------------------------------------------------------
with open('project_info.json') as f:
project_info = json.load(f)
myms = project_info['master_ms']
code = gen.get_code(myms)
steps = []
step = {}
step['step'] = 0
step['comment'] = 'Split and average master MS'
step['dependency'] = None
step['id'] = 'SPPRE'+code
syscall = CONTAINER_RUNNER+CASA_CONTAINER+' ' if USE_SINGULARITY else ''
syscall += gen.generate_syscall_casa(casascript=cfg.OXKAT+'/PRE_casa_average_to_1k_add_wtspec.py')
step['syscall'] = syscall
steps.append(step)
step = {}
step['step'] = 1
step['comment'] = 'Apply basic flagging steps to all fields'
step['dependency'] = 0
step['id'] = 'FGBAS'+code
syscall = CONTAINER_RUNNER+CASA_CONTAINER+' ' if USE_SINGULARITY else ''
syscall += gen.generate_syscall_casa(casascript=cfg.OXKAT+'/1GC_02_casa_basic_flags.py')
step['syscall'] = syscall
steps.append(step)
step = {}
step['step'] = 2
step['comment'] = 'Run auto-flaggers on calibrators'
step['dependency'] = 1
step['id'] = 'FGCAL'+code
syscall = CONTAINER_RUNNER+CASA_CONTAINER+' ' if USE_SINGULARITY else ''
syscall += gen.generate_syscall_casa(casascript=cfg.OXKAT+'/1GC_05_casa_autoflag_cals_DATA.py')
step['syscall'] = syscall
steps.append(step)
step = {}
step['step'] = 3
step['comment'] = 'Generate reference calibration solutions and apply to target(s)'
step['dependency'] = 2
step['id'] = 'CL1GC'+code
syscall = CONTAINER_RUNNER+CASA_CONTAINER+' ' if USE_SINGULARITY else ''
syscall += gen.generate_syscall_casa(casascript=cfg.OXKAT+'/1GC_casa_refcal.py')
step['syscall'] = syscall
steps.append(step)
step = {}
step['step'] = 4
step['comment'] = 'Plot the gain solutions'
step['dependency'] = 3
step['id'] = 'PLTAB'+code
syscall = CONTAINER_RUNNER+RAGAVI_CONTAINER+' ' if USE_SINGULARITY else ''
syscall += 'python3 '+cfg.OXKAT+'/PLOT_gaintables.py cal_1GC_*'
step['syscall'] = syscall
steps.append(step)
step = {}
step['step'] = 5
step['comment'] = 'Split the corrected target data'
step['dependency'] = 3
step['id'] = 'SPTRG'+code
syscall = CONTAINER_RUNNER+CASA_CONTAINER+' ' if USE_SINGULARITY else ''
syscall += gen.generate_syscall_casa(casascript=cfg.OXKAT+'/1GC_09_casa_split_targets.py')
step['syscall'] = syscall
steps.append(step)
step = {}
step['step'] = 6
step['comment'] = 'Plot the corrected calibrator visibilities'
step['dependency'] = 5
step['id'] = 'PLVIS'+code
syscall = CONTAINER_RUNNER+SHADEMS_CONTAINER+' ' if USE_SINGULARITY else ''
syscall += 'python3 '+cfg.OXKAT+'/1GC_10_plot_visibilities.py'
step['syscall'] = syscall
steps.append(step)
# ------------------------------------------------------------------------------
#
# Write the run file and kill file based on the recipe
#
# ------------------------------------------------------------------------------
submit_file = 'submit_1GC_jobs.sh'
kill_file = cfg.SCRIPTS+'/kill_1GC_jobs.sh'
f = open(submit_file,'w')
f.write('#!/usr/bin/env bash\n')
f.write('export SINGULARITY_BINDPATH='+cfg.BINDPATH+'\n')
id_list = []
for step in steps:
step_id = step['id']
id_list.append(step_id)
if step['dependency'] is not None:
dependency = steps[step['dependency']]['id']
else:
dependency = None
syscall = step['syscall']
if 'slurm_config' in step.keys():
slurm_config = step['slurm_config']
else:
slurm_config = cfg.SLURM_DEFAULTS
if 'pbs_config' in step.keys():
pbs_config = step['pbs_config']
else:
pbs_config = cfg.PBS_DEFAULTS
comment = step['comment']
run_command = gen.job_handler(syscall = syscall,
jobname = step_id,
infrastructure = INFRASTRUCTURE,
dependency = dependency,
slurm_config = slurm_config,
pbs_config = pbs_config)
f.write('\n# '+comment+'\n')
f.write(run_command)
if INFRASTRUCTURE == 'idia' or INFRASTRUCTURE == 'hippo':
kill = '\necho "scancel "$'+'" "$'.join(id_list)+' > '+kill_file+'\n'
f.write(kill)
elif INFRASTRUCTURE == 'chpc':
kill = '\necho "qdel "$'+'" "$'.join(id_list)+' > '+kill_file+'\n'
f.write(kill)
f.close()
gen.make_executable(submit_file)
gen.print_spacer()
print(gen.col('Run file')+submit_file)
gen.print_spacer()
# ------------------------------------------------------------------------------
if __name__ == "__main__":
main()