Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_phaseshift.py: 6%
100 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 19:10 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 19:10 +0000
3from .mstools import write_history
4from casatools import table, ms, mstransformer
5from casatools import measures as me
6from casatasks import casalog
7from .parallel.parallel_data_helper import ParallelDataHelper
10def phaseshift(
11 vis=None, outputvis=None, keepmms=None, field=None,
12 spw=None, scan=None, intent=None, array=None,
13 observation=None, datacolumn=None, phasecenter=None
14):
15 """
16 Changes the phase center for either short or large
17 offsets/angles w.r.t. the original
18 """
19 casalog.origin('phaseshift')
21 if len(phasecenter) == 0:
22 raise ValueError('phasecenter parameter must be specified')
23 # Initiate the helper class
24 pdh = ParallelDataHelper("phaseshift", locals())
26 # Validate input and output parameters
27 try:
28 pdh.setupIO()
29 except Exception as instance:
30 casalog.post(str(instance), 'ERROR')
31 raise RuntimeError(str(instance))
33 # Input vis is an MMS
34 if pdh.isMMSAndNotServer(vis) and keepmms:
35 if not pdh.validateInputParams():
36 raise RuntimeError('Unable to continue with MMS processing')
38 pdh.setupCluster('phaseshift')
40 # Execute the jobs
41 try:
42 pdh.go()
43 except Exception as instance:
44 casalog.post(str(instance), 'ERROR')
45 raise RuntimeError(str(instance))
46 return
48 # Create local copies of tools (has to be here, otherwise
49 # ParallelDataHelper has a porblem digest the locals
51 tblocal = table()
52 mslocal = ms()
53 mtlocal = mstransformer()
54 melocal = me()
56 # Actual task code starts here
57 try:
58 dirstr = phasecenter.split(' ')
59 if not melocal.direction(dirstr[0], dirstr[1], dirstr[2]):
60 raise ValueError("Illegal phacecenter specification " + phasecenter)
61 try:
62 # Gather all the parameters in a dictionary.
63 config = {}
65 config = pdh.setupParameters(
66 inputms=vis, outputms=outputvis, field=field,
67 spw=spw, array=array, scan=scan, intent=intent,
68 observation=observation
69 )
71 # Check if CORRECTED column exists, when requested
72 datacolumn = datacolumn.upper()
73 if datacolumn == 'CORRECTED':
74 tblocal.open(vis)
75 if 'CORRECTED_DATA' not in tblocal.colnames():
76 casalog.post(
77 'Input CORRECTED_DATA does not exist. Will use DATA',
78 'WARN'
79 )
80 datacolumn = 'DATA'
81 tblocal.close()
83 casalog.post('Will use datacolumn = ' + datacolumn, 'DEBUG')
84 config['datacolumn'] = datacolumn
86 # Call MSTransform framework with tviphaseshift=True
87 config['tviphaseshift'] = True
88 tviphaseshift_config = {}
89 tviphaseshift_config['phasecenter'] = phasecenter
90 config['tviphaseshiftlib'] = dict(tviphaseshift_config)
92 # Configure the tool
93 casalog.post(str(config), 'DEBUG1')
94 mtlocal.config(config)
96 # Open the MS, select the data and configure the output
97 mtlocal.open()
99 # Run the tool
100 casalog.post('Shift phase center')
101 mtlocal.run()
103 mtlocal.done()
105 except Exception as instance:
106 mtlocal.done()
107 casalog.post(str(instance), 'ERROR')
108 raise RuntimeError(str(instance))
110 # Write history to output MS, not the input ms.
111 try:
112 param_names = phaseshift.__code__.co_varnames[
113 :phaseshift.__code__.co_argcount
114 ]
115 vars = locals()
116 param_vals = [vars[p] for p in param_names]
118 casalog.post('Updating the history in the output', 'DEBUG1')
119 write_history(
120 mslocal, outputvis, 'phaseshift', param_names,
121 param_vals, casalog
122 )
123 except Exception as instance:
124 casalog.post(
125 "*** Error " + str(instance)
126 + " updating HISTORY", 'WARN'
127 )
128 raise RuntimeError(str(instance))
130 # Update field table
131 try:
133 # Parse phase center string to obtain ra/dec
134 dirstr = phasecenter.split(' ')
135 try:
136 thedir = melocal.direction(dirstr[0], dirstr[1], dirstr[2])
137 if (dirstr[0] != 'J2000'):
138 # Convert to J2000
139 thedir = melocal.measure(thedir, 'J2000')
140 thenewra_rad = thedir['m0']['value']
141 thenewdec_rad = thedir['m1']['value']
142 except Exception as instance:
143 casalog.post(
144 "*** Error " + str(instance)
145 + " when interpreting parameter \'phasecenter\': ",
146 'SEVERE'
147 )
148 raise RuntimeError(str(instance))
150 # modify FIELD table
151 tblocal.open(outputvis + '/FIELD', nomodify=False)
152 pcol = tblocal.getcol('PHASE_DIR')
153 for row in range(0, tblocal.nrows()):
154 pcol[0][0][row] = thenewra_rad
155 pcol[1][0][row] = thenewdec_rad
156 tblocal.putcol('PHASE_DIR', pcol)
157 except Exception as instance:
158 casalog.post(
159 "*** Error \'%s\' updating FIELD" + str(instance), 'WARN'
160 )
161 raise RuntimeError(str(instance))
163 finally:
164 if tblocal:
165 tblocal.done()
166 tblocal = None
167 if mslocal:
168 mslocal.done()
169 mslocal = None
170 if mtlocal:
171 mtlocal.done()
172 mtlocal = None
173 if melocal:
174 melocal.done()
175 melocal = None