Commits

Takeshi Nakazato authored 0583dddda90 Merge
Merge pull request #468 in CASA/casa6 from CAS-13640 to master

* commit '52c525927c0169d46606d6c42cbdb4bb0fdba04f': Removed the casa5 code Replaced time.clock with time.perf_counter for compatibility with Python 3.8.

casatests/regression/test_regression_alma_M100_sd.py

Modified
60 60
61 61 # global defs
62 62 basename=['X54','X220']
63 63 makeplots=False
64 64 print(("Make plots?: {}".format(makeplots)))
65 65 therefant = 'DV01'
66 66 mynumsubmss = 4
67 67 mms = False
68 68
69 69 ############ Imports #################
70 -CASA6 = False
71 -try:
72 - import casatools
73 - cu = casatools.utils
74 - from casatasks import importasdm, listobs, flagdata, sdcal, sdbaseline, sdimaging, imhead, immoments, imstat, exportfits, casalog
75 - from casaplotms import plotms
76 - CASA6 = True
77 -except ImportError:
78 - from __main__ import *
79 - from tasks import *
80 - from taskinit import *
81 -
82 70 import time
83 71 import os
84 72 import numpy
85 73 #from recipes.almahelpers import tsysspwmap
86 74 import shutil
87 75 import traceback
88 76 import unittest
89 77 import glob
90 78
79 +import casatools
80 +cu = casatools.utils
81 +from casatasks import importasdm, listobs, flagdata, sdcal, sdbaseline, sdimaging, imhead, immoments, imstat, exportfits, casalog
82 +from casaplotms import plotms
91 83
92 84
93 85 #############################
94 86
95 87 # Some infrastructure to make repeating individual parts
96 88 # of this workflow more convenient.
97 89
98 90 # Calibration
99 91 # thesteps = range(19)
100 92
145 137 # ttime = thetime
146 138 # casalog.origin('TIMING')
147 139 # casalog.post( 'Step '+str(mystep)+': '+step_title[mystep], 'WARN')
148 140 # casalog.post( 'Time now: '+str(ttime), 'WARN')
149 141 # casalog.post( 'Time used this step: '+str(dtime), 'WARN')
150 142 # casalog.post( 'Total time used so far: ' + str(totaltime), 'WARN')
151 143 # casalog.post( 'Step Time used (s) Fraction of total time (percent) [description]', 'WARN')
152 144 # for i in range(0, len(steptime)):
153 145 # casalog.post( ' '+str(thesteps[i])+' '+str(steptime[i])+' '+str(steptime[i]/totaltime*100.) +' ['+step_title[thesteps[i]]+']', 'WARN')
154 146
155 -if CASA6:
156 - datapath = casatools.ctsys.resolve('regression/alma_M100_sd/')
157 -else:
158 - pass
147 +datapath = casatools.ctsys.resolve('regression/alma_M100_sd/')
159 148
160 149 class regression_alma_m100_test(unittest.TestCase):
161 150
162 151 def setUp(self):
163 152 rawname = 'uid___A002_X6218fb_X264'
164 153 msname = rawname + '.ms'
165 154 listname = msname + '.listobs.txt'
166 155 blname = rawname + '.ms_bl'
167 156 for name in [rawname, listname, msname, blname]:
168 157 if os.path.exists(name):
211 200 try:
212 201
213 202 rawname = 'uid___A002_X6218fb_X264'
214 203 msname = rawname + '.ms'
215 204 listname = msname + '.listobs.txt'
216 205 blname = rawname + '.ms_bl'
217 206 target_spws = ['9', '11', '13', '15']
218 207
219 208
220 209 startTime=time.time()
221 - startProc=time.clock()
210 + startProc=time.perf_counter()
222 211
223 212
224 213
225 214
226 215 # ASDM Data #
227 216
228 217 basename = [rawname]
229 218
230 219
231 220 # Create Measurement Sets from ASDM Data ##
232 221 # importasdm func converts ASDM format to MS format
233 222
234 223 print('--Import--')
235 224
236 225 importasdm(asdm = rawname, vis=msname, overwrite=True)
237 226
238 - importproc=time.clock()
227 + importproc=time.perf_counter()
239 228 importtime=time.time()
240 229
241 230 # listobs task generates detailed information of the MS
242 231 # ~.listobs.txt
243 232
244 233 listobs(vis = msname, listfile = listname)
245 234
246 235
247 236
248 237 # Initial inspection of the data with plotms task.
291 280 # Flagging #
292 281 print('--Flagging--')
293 282 flagdata(
294 283 vis = msname,
295 284 mode = 'manual',
296 285 spw = '9; 11; 13; 15: 0~119;3960~4079',
297 286 antenna = 'PM03&&&;PM04&&&;CM03&&&;CM05&&&',
298 287 action = 'apply'
299 288 )
300 289
301 - flagproc = time.clock()
290 + flagproc = time.perf_counter()
302 291 flagtime = time.time()
303 292
304 293
305 294 # Apply Calibration and Inspect #
306 295
307 296 print('--Calibration sdcal--')
308 297
309 298 sdcal(
310 299 infile = msname,
311 300 calmode = 'ps,tsys,apply',
312 301 spwmap = {'1':[9],'3':[11],'5':[13],'7':[15]},
313 302 )
314 303
315 - sdcalproc=time.clock()
304 + sdcalproc=time.perf_counter()
316 305 sdcaltime=time.time()
317 306
318 307
319 308
320 309 # Baseline Subtraction and Inspect #
321 310
322 311 print('--Caribration Baseline --')
323 312
324 313 sdbaseline(
325 314 infile = msname,
326 315 datacolumn = 'corrected',
327 316 spw = str(',').join(target_spws),
328 317 maskmode = 'auto',
329 318 thresh = 3.0,
330 319 avg_limit = 8,
331 320 blfunc = 'poly',
332 321 order = 1,
333 322 outfile = blname,
334 323 overwrite = True
335 324 )
336 325
337 - sdbaselineproc = time.clock()
326 + sdbaselineproc = time.perf_counter()
338 327 sdbaselinetime = time.time()
339 328
340 329 # Plot the calibrated spectra, using the plotms task.
341 330 # The commands below will plot one spectrum per scan, spw and polarization.
342 331
343 332 for i in range(len(target_spws)):
344 333 org_spw = target_spws[i]
345 334 for antname in ['PM03', 'PM04', 'CM03', 'CM05']:
346 335 plotms(
347 336 vis = msname,
429 418 cell=['10arcsec','10arcsec'],
430 419 phasecenter = 'J2000 12h22m54.9 +15d49m15',
431 420 outfile='M100_SD_cube_CM_03_05.image'
432 421 )
433 422
434 423 # CONVERT image unit to K
435 424 outfile='M100_SD_cube_CM_03_05.image'
436 425 imhead(imagename=outfile, mode='put', hdkey='bunit', hdvalue='K')
437 426
438 427
439 - combproc=time.clock()
428 + combproc=time.perf_counter()
440 429 combtime=time.time()
441 430
442 431
443 432
444 433 ## Image Analysis : Moment Maps
445 434
446 435 os.system('rm -rf M100_SD_cube_PM_03_04.image.mom*')
447 436 immoments(imagename = 'M100_SD_cube_PM_03_04.image',moments = [0],axis = 'spectral',chans = '1~24',outfile = 'M100_SD_cube_PM_03_04.image.mom0')
448 437 #immoments(imagename = 'M100_SD_cube_PM_03_04.image',moments = [1],axis = 'spectral',chans = '1~24',outfile = 'M100_SD_cube_PM_03_04.image.mom1')
449 438
457 446
458 447 os.system('rm -rf M100_SD_*.fits')
459 448 exportfits(imagename='M100_SD_cube_PM_03_04.image', fitsimage='M100_SD_cube_PM_03_04.image.fits')
460 449 exportfits(imagename='M100_SD_cube_PM_03_04.image.mom0', fitsimage='M100_SD_cube_PM_03_04.image.mom0.fits')
461 450 #exportfits(imagename='M100_SD_cube_PM_03_04.image.mom1', fitsimage='M100_SD_cube_PM_03_04.image.mom1.fits')
462 451
463 452
464 453
465 454
466 455
467 - #imageproc=time.clock()
456 + #imageproc=time.perf_counter()
468 457 #imagetime = time.time()
469 458
470 459 # -- endl of M100 script
471 460 endProc = combproc
472 461 endTime = combtime
473 462
474 463
475 464
476 465
477 466
733 722 self.assertTrue(regstate, msg = "FAILED Regression test for M100_SD_PM_03_04")
734 723
735 724 except:
736 725 formatted_traceback = traceback.format_exc()
737 726 casalog.post("Exception running regression: %s" % str(formatted_traceback),"WARN")
738 727 self.assertTrue(False, msg="Exception running regression: %s" % str(formatted_traceback))
739 728
740 729 def suite():
741 730 return [regression_alma_m100_test]
742 731
743 -from casatasks.private.casa_transition import is_CASA6
744 -if is_CASA6:
745 - if __name__ == '__main__':
746 - unittest.main()
732 +if __name__ == '__main__':
733 + unittest.main()
747 734

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut