Commits

Neal Schweighart authored 1488cb03826
Imporved corrupt, smoothcal, and solve gainspline tests.

Some tests were only checking for the creation of the dataset, so additional value comparisons were added. Corrupt was looking at the CORRECTED_DATA column instead of the MODEL_DATA column.

casatools/tests/tools/calibrater/test_tool_calibrater.py

Modified
53 53 class calibrater_test(unittest.TestCase):
54 54
55 55 @classmethod
56 56 def setUpClass(cls):
57 57 cls._vis = 'gaincaltest2.ms'
58 58 cls._visObs = 'Itziar.ms'
59 59 cls._cal = 'gaincaltest2.ms.G0'
60 60 cls._lib = os.path.join(datapath, 'refcalgainG.txt')
61 61
62 62 shutil.copytree(os.path.join(datapath, 'ngc5921.ms'), 'ngc5921.ms')
63 + shutil.copytree(os.path.join(datapath, 'ngc5921.gcal'), 'ngc5921.gcal')
63 64 cls._bandvis = 'ngc5921.ms'
65 + cls._bandcal = 'ngc5921.gcal'
64 66
65 67 @classmethod
66 68 def tearDownClass(cls):
67 69 shutil.rmtree(cls._bandvis)
68 70
69 71 if os.path.exists('gainspline.AMP.pol0.log'):
70 72 os.remove('gainspline.AMP.pol0.log')
71 73 if os.path.exists('gainspline.AMP.pol1.log'):
72 74 os.remove('gainspline.AMP.pol1.log')
73 75 if os.path.exists('gainspline.PHASE.pol0.log'):
616 618 cb.solve()
617 619 cb.close()
618 620 # The bpoly table should have been created
619 621 self.assertTrue(os.path.exists('bpoly'))
620 622
621 623 def test_solveGainspline(self):
622 624 """ Check that solve gain spline creates the output table """
623 625
624 626 cb.setvi(old=True, quiet=False)
625 627 cb.open(self._bandvis)
626 - cb.setsolvegainspline(table='gainspline',mode='AMP',splinetime=10800.0)
628 + cb.setsolvegainspline(table='gainspline', mode='AMP', splinetime=10800.0)
627 629 cb.solve()
628 630 cb.close()
629 631
632 + tb.open('gainspline')
633 + nPolyAmp = tb.getcol('N_POLY_AMP')
634 + nPolyPhase = tb.getcol('N_POLY_PHASE')
635 + tb.close()
636 +
630 637 # Check that the table was created
631 638 self.assertTrue(os.path.exists('gainspline'))
639 + self.assertTrue(np.all(nPolyAmp == 8))
640 + self.assertTrue(np.all(nPolyPhase == 0))
632 641
633 642 def test_smoothedCalTables(self):
634 643 """ Check that the smooth command creates a smoothed cal table """
635 644
636 645 # Open the caltable and run smooth
637 - cb.open(self._vis)
638 - cb.smooth(tablein=self._cal, tableout='testcalout.cal')
646 + cb.open(self._bandvis)
647 + cb.smooth(tablein=self._bandcal, tableout='testcalout.cal', smoothtype='mean', smoothtime=5000.0, field=1)
639 648 cb.close()
640 - # Check that the output table is created
641 - self.assertTrue(os.path.exists('testcalout.cal'))
649 +
650 + tb.open(self._bandcal)
651 + olddata = tb.getcol('CPARAM')
652 + tb.close()
653 +
654 + tb.open('testcalout.cal')
655 + data = tb.getcol('CPARAM')
656 + tb.close()
657 +
658 + # Check that the smoothed data is different than the original cal
659 + self.assertFalse(np.array_equal(olddata, data))
660 + # Compare the smoothed average to reference
661 + self.assertTrue(np.isclose(np.mean(data), (1.4439346407141005+0.017319496272897555j)))
642 662
643 663 def test_specifyCal(self):
644 664 """ Check that specifycal can set values for specific spws and antennas"""
645 665
646 666 cb.open(self._vis)
647 667 cb.specifycal(caltable='testcalout.cal', spw='1', caltype='G', parameter=[3.0])
648 668 cb.close()
649 669
650 670 tb.open('testcalout.cal')
651 671 data = tb.getcol('CPARAM')
656 676 def test_corruptCal(self):
657 677 """ Check that the MS is corrupted using the cal table """
658 678
659 679 cb.open(self._vis)
660 680 cb.setapply(table=self._cal)
661 681 cb.corrupt()
662 682 cb.close()
663 683
664 684 tb.open(self._vis)
665 685 columns = tb.colnames()
686 + modelData = tb.getcol('MODEL_DATA')
687 + corData = tb.getcol('CORRECTED_DATA')
688 + data = tb.getcol('DATA')
666 689 tb.close()
667 690
691 + # Check that both the CORRECTED_DATA and MODEL_DATA columns are created
668 692 self.assertTrue('CORRECTED_DATA' in columns)
693 + self.assertTrue('MODEL_DATA' in columns)
694 +
695 + # Check that the MODEL_DATA has been modified by the caltable
696 + np.isclose(np.mean(modelData), (0.3162506820017762+0.0490544367995527j))
697 + # Check that the CORRECTED_DATA is unchanged
698 + np.array_equal(corData, data)
699 +
669 700
670 701
671 702 def suite():
672 703 return [calibrater_test]
673 704
674 705 if __name__ == '__main__':
675 706 unittest.main()

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

Add shortcut