Commits
18 18 | # |
19 19 | # Based on the requirements listed in plone found here: |
20 20 | # https://casa.nrao.edu/casadocs-devel/stable/global-task-list/task_gaincal/about |
21 21 | # |
22 22 | # |
23 23 | ########################################################################## |
24 24 | |
25 25 | CASA6 = False |
26 26 | try: |
27 27 | import casatools |
28 - | from casatasks import gaincal, casalog |
28 + | from casatasks import gaincal, casalog, mstransform |
29 29 | CASA6 = True |
30 30 | tb = casatools.table() |
31 31 | |
32 32 | except ImportError: |
33 33 | from __main__ import default |
34 34 | from tasks import * |
35 35 | from taskinit import * |
36 36 | |
37 37 | import sys |
38 38 | import os |
451 451 | |
452 452 | Check that the output with gaintype k is equal to a reference calibration table |
453 453 | ''' |
454 454 | |
455 455 | gaincal(vis=datacopy, caltable=tempCal, field='0', smodel=[1,0,0,0], solint='inf', combine='scan', gaintype='KCROSS', refant='0') |
456 456 | |
457 457 | self.assertTrue(np.all(tableComp(tempCal, typeCalK)[:,1] == 'True')) |
458 458 | |
459 459 | def test_gainTypeSpline(self): |
460 460 | ''' |
461 - | test_gainTypeK |
461 + | test_gainTypeSpline |
462 462 | ---------------- |
463 463 | |
464 464 | Check that the output with gaintype GSPLINE is equal to a reference calibration table |
465 465 | ''' |
466 466 | |
467 467 | gaincal(vis=datacopy, caltable=tempCal, field='0', smodel=[1,0,0,0], solint='inf', combine='scan', gaintype='GSPLINE', refant='0') |
468 468 | |
469 469 | self.assertTrue(np.all(tableComp(tempCal, typeCalSpline)[:,1] == 'True')) |
470 470 | |
471 471 | def test_spwMap(self): |
500 500 | def test_mergedSpwSelect(self): |
501 501 | ''' Gaincal 1b: Create a gain table for an MS with many spws ''' |
502 502 | |
503 503 | |
504 504 | gaincal(vis=merged_copy2, caltable=tempCal, uvrange='>0.0', field='0,1', spw='0', gaintype='G', minsnr=2.0, refant='ANT5', solint='inf', combine='') |
505 505 | self.assertTrue(os.path.exists(tempCal)) |
506 506 | |
507 507 | self.assertTrue(th.compTables(tempCal, merged_refcal3, ['WEIGHT'])) |
508 508 | |
509 509 | |
510 + | def test_corrDepFlags(self): |
511 + | ''' |
512 + | test_corrDepFlags |
513 + | ----------------- |
514 + | ''' |
515 + | |
516 + | |
517 + | # This test exercises the corrdepflags parameter |
518 + | # |
519 + | # With corrdepflags=False (the default), one (or more) flagged correlations causes |
520 + | # all correlations (per channel, per baseline) to behave as flagged, thereby |
521 + | # causing both polarizations to be flagged in the output cal table |
522 + | # |
523 + | # With corrdepflags=True, unflagged correlations will be used as normal, and |
524 + | # only the implicated polarization will be flagged in the output cal table |
525 + | # |
526 + | # NB: when some data are flagged, we expect solutions to change slightly, |
527 + | # since available data is different. For now, we are testing only the |
528 + | # resulting flags. |
529 + | |
530 + | cdfdata='testcorrdepflags.ms' |
531 + | # slice out just scan 2 |
532 + | mstransform(vis=datacopy,outputvis=cdfdata,scan='2',datacolumn='data') |
533 + | |
534 + | # modify flags in interesting corr-dep ways in scan 2 for subset of antennas |
535 + | tb.open(cdfdata,nomodify=False) |
536 + | |
537 + | # we modify the flags as follows: |
538 + | # spw=0: one antenna, one correlation (YY) |
539 + | # spw=1: one antenna, one correlation (XX) |
540 + | # spw=2: two antennas, opposite correlations |
541 + | # spw=3: one antenna, both cross-hands flagged |
542 + | |
543 + | # set flags for spw=0, antenna=3, corr=YY |
544 + | st=tb.query('SCAN_NUMBER==2 && DATA_DESC_ID==0 && (ANTENNA1==3 || ANTENNA2==3)') |
545 + | fl=st.getcol('FLAG') |
546 + | fl[3,:,:]=True |
547 + | st.putcol('FLAG',fl) |
548 + | st.close() |
549 + | |
550 + | # set flags for spw=1, antenna=6, corr=XX |
551 + | st=tb.query('SCAN_NUMBER==2 && DATA_DESC_ID==1 && (ANTENNA1==6 || ANTENNA2==6)') |
552 + | fl=st.getcol('FLAG') |
553 + | fl[0,:,:]=True |
554 + | st.putcol('FLAG',fl) |
555 + | st.close() |
556 + | |
557 + | # set flags for spw=2, antenna=2, corr=XX |
558 + | st=tb.query('SCAN_NUMBER==2 && DATA_DESC_ID==2 && (ANTENNA1==2 || ANTENNA2==2)') |
559 + | fl=st.getcol('FLAG') |
560 + | fl[0,:,:]=True |
561 + | st.putcol('FLAG',fl) |
562 + | st.close() |
563 + | # set flags for spw=2, antenna=7, corr=YY |
564 + | st=tb.query('SCAN_NUMBER==2 && DATA_DESC_ID==2 && (ANTENNA1==7 || ANTENNA2==7)') |
565 + | fl=st.getcol('FLAG') |
566 + | fl[3,:,:]=True |
567 + | st.putcol('FLAG',fl) |
568 + | st.close() |
569 + | |
570 + | # set flags for spw=3, antenna=8, corr=XY,YX |
571 + | st=tb.query('SCAN_NUMBER==2 && DATA_DESC_ID==3 && (ANTENNA1==8 || ANTENNA2==8)') |
572 + | fl=st.getcol('FLAG') |
573 + | fl[1:3,:,:]=True |
574 + | st.putcol('FLAG',fl) |
575 + | st.close() |
576 + | |
577 + | tb.close() |
578 + | |
579 + | # Run gaincal on scan 2, solint='inf' with corrdepflags=False |
580 + | # expect both pols to be flagged for ants with one or more corr flagged |
581 + | cdfF='testcorrdepflagsF.G' |
582 + | gaincal(vis=cdfdata,caltable=cdfF,solint='inf',refant='0',smodel=[1,0,0,0],corrdepflags=False) |
583 + | |
584 + | tb.open(cdfF) |
585 + | flF=tb.getcol('FLAG') |
586 + | tb.close() |
587 + | |
588 + | # flag count per spw (both pols in every case) |
589 + | self.assertTrue(np.sum(flF[:,0,0:10])==2) |
590 + | self.assertTrue(np.sum(flF[:,0,10:20])==2) |
591 + | self.assertTrue(np.sum(flF[:,0,20:30])==4) |
592 + | self.assertTrue(np.sum(flF[:,0,30:40])==2) |
593 + | |
594 + | # check flags set for specific antennas, each spw (both pols each antenna) |
595 + | self.assertTrue(np.all(flF[:,0,0:10][:,3])) # spw 0 |
596 + | self.assertTrue(np.all(flF[:,0,10:20][:,6])) # spw 1 |
597 + | self.assertTrue(np.all(flF[:,0,20:30][:,[2,7]])) # spw 2 |
598 + | self.assertTrue(np.all(flF[:,0,30:40][:,8])) # spw 3 |
599 + | |
600 + | # Run gaincal on scan 2, solint='inf' with corrdepflags=True |
601 + | # expect unflagged solutions for unflagged pol |
602 + | cdfT='testcorrdepflagsT.G' |
603 + | gaincal(vis=cdfdata,caltable=cdfT,solint='inf',refant='0',smodel=[1,0,0,0],corrdepflags=True) |
604 + | |
605 + | tb.open(cdfT) |
606 + | flT=tb.getcol('FLAG') |
607 + | tb.close() |
608 + | |
609 + | # flag count per spw (one pol per antenna, at most) |
610 + | self.assertTrue(np.sum(flT[:,0,0:10])==1) |
611 + | self.assertTrue(np.sum(flT[:,0,10:20])==1) |
612 + | self.assertTrue(np.sum(flT[:,0,20:30])==2) |
613 + | self.assertTrue(np.sum(flT[:,0,30:40])==0) |
614 + | |
615 + | # check flags set for specific antennas, each spw (one pol per antenna, at most) |
616 + | self.assertTrue(flT[1,0,0:10][3]) # spw 0, antenna 3, pol=Y |
617 + | self.assertTrue(flT[0,0,10:20][6]) # spw 1, antenna 6, pol=X |
618 + | self.assertTrue(flT[0,0,20:30][2]) # spw 2, antenna 2, pol=X |
619 + | self.assertTrue(flT[1,0,20:30][7]) # spw 2, antenna 7, pol=Y |
620 + | # (spw 3 tested above) |
621 + | |
622 + | # clean up locally-made files |
623 + | shutil.rmtree(cdfdata) |
624 + | shutil.rmtree(cdfF) |
625 + | shutil.rmtree(cdfT) |
626 + | |
627 + | |
628 + | |
629 + | |
630 + | |
631 + | |
632 + | |
633 + | |
510 634 | def suite(): |
511 635 | return[gaincal_test] |
512 636 | |
513 637 | |
514 638 | if __name__ == '__main__': |
515 639 | unittest.main() |