Commits
21 21 | DATADIR = str(os.environ.get('TEST_DATADIR'))+'/plotms/' |
22 22 | if os.path.isdir(DATADIR): |
23 23 | datapath = DATADIR |
24 24 | |
25 25 | print 'plotms tests will use data from '+ datapath |
26 26 | |
27 27 | class plotms_test_base(unittest.TestCase): |
28 28 | |
29 29 | testms = "pm_ngc5921.ms" |
30 30 | testms2 = "ngc5921.ms" |
31 + | testms3 = "sun.subset.pentagon.ms" |
31 32 | testcaltable = 'ngc5921.ref1a.gcal' |
32 33 | outputDir="/tmp/" + str(os.getpid()) + "/" |
33 34 | plotfile_jpg = "/tmp/myplot.jpg" |
34 35 | display = os.environ.get("DISPLAY") |
35 36 | ms = os.path.join(outputDir, testms) |
36 37 | ms2 = os.path.join(outputDir, testms2) |
38 + | ms3 = os.path.join(outputDir, testms3) |
37 39 | caltable = os.path.join(outputDir, testcaltable) |
38 40 | |
39 41 | def cleanUp(self): |
40 42 | if os.path.exists(self.outputDir): |
41 43 | shutil.rmtree(self.outputDir) |
42 44 | |
43 45 | def setUpdata(self): |
44 46 | res = None |
45 47 | default(plotms) |
46 48 | if not os.path.exists(self.ms): |
60 62 | res = None |
61 63 | default(plotms) |
62 64 | if not os.path.exists(self.ms2): |
63 65 | shutil.copytree(os.path.join(calpath,self.testms2), |
64 66 | self.ms2, symlinks=True) |
65 67 | testcaltable = os.path.join(self.outputDir, self.caltable) |
66 68 | if not os.path.exists(self.caltable): |
67 69 | shutil.copytree(os.path.join(calpath, self.testcaltable), |
68 70 | self.caltable, symlinks=True) |
69 71 | |
72 + | def setUppointingdata(self): |
73 + | if not os.path.exists(self.ms3): |
74 + | shutil.copytree(os.path.join(datapath,self.testms3), |
75 + | self.ms3, symlinks=True) |
76 + | |
70 77 | def checkPlotfile(self, plotfileName, minSize, maxSize=None): |
71 78 | self.assertTrue(os.path.isfile(plotfileName), "Plot was not created") |
72 79 | plotSize = os.path.getsize(plotfileName) |
73 80 | print plotfileName, 'file size is', plotSize |
74 81 | self.assertGreater(plotSize, minSize) |
75 82 | if maxSize: |
76 83 | self.assertLess(plotSize, maxSize) |
77 84 | |
78 85 | # plotms can return True if it catches an error, but makes no plot file |
79 86 | def checkNoPlotfile(self, plotfileName): |
412 419 | |
413 420 | |
414 421 | # ------------------------------------------------------------------------------ |
415 422 | |
416 423 | class test_axis(plotms_test_base): |
417 424 | ''' test axis and datacolumn options ''' |
418 425 | |
419 426 | def setUp(self): |
420 427 | self.checkDisplay() |
421 428 | self.setUpdata() |
429 + | self.setUppointingdata() |
422 430 | |
423 431 | def tearDown(self): |
424 432 | self.tearDowndata() |
425 433 | |
426 434 | def test_axis_list(self): |
427 435 | '''test_axis_list: Overplot scan and field y-axis with time x-axis.''' |
428 436 | self.plotfile_jpg = os.path.join(self.outputDir, "testAxis01.jpg") |
429 437 | self.removePlotfile() |
430 438 | time.sleep(5) |
431 439 | '''Create a (scan & field)/time plot''' |
564 572 | |
565 573 | # Removed from regular testing but available for manual testing! |
566 574 | def xtest_axis_ALL(self): |
567 575 | '''test_axis_ALL: Test ALL axis names''' |
568 576 | axes = ['scan', 'field', 'time', 'interval', 'spw', 'chan', |
569 577 | 'freq', 'vel', 'corr', 'ant1', 'ant2', 'baseline', |
570 578 | 'row', 'amp', 'phase', 'real', 'imag', 'wt', 'wtsp', |
571 579 | 'sigma', 'sigmasp', 'flag', 'flagrow', 'uvdist', |
572 580 | 'uvwave', 'u', 'v', 'w', 'uwave', 'vwave', 'wwave', |
573 581 | 'azimuth', 'elevation', 'hourang', 'parang', |
574 - | 'ant', 'ant-azimuth', 'ant-elevation', 'ant-parang', |
582 + | 'ant', 'ant-azimuth', 'ant-elevation', 'ant-parang', 'ant-ra', 'ant-dec', |
575 583 | 'observation', 'intent'] |
576 584 | for axis in axes: |
577 585 | filename = "testAxis10_" + axis + ".jpg" |
578 586 | plotfile = os.path.join(self.outputDir, filename) |
579 587 | self.removePlotfile(plotfile) |
580 - | res = plotms(vis=self.ms, plotfile=plotfile, highres=True, |
588 + | axis_vis = self.ms |
589 + | if axis in ['ant-ra','ant-dec']: |
590 + | axis_vis = self.ms3 |
591 + | res = plotms(vis=axis_vis, plotfile=plotfile, highres=True, |
581 592 | showgui=False, yaxis=axis) |
582 593 | self.assertTrue(res) |
583 594 | self.checkPlotfile(plotfile, 40000) |
584 595 | self.removePlotfile(plotfile) |
585 596 | |
586 597 | |
587 598 | def test_axis_twoDataAxes(self): |
588 599 | '''test_axis_twoDataAxes: Single plot with two y data axes.''' |
589 600 | self.plotfile_jpg = os.path.join(self.outputDir, "testAxis11.jpg") |
590 601 | self.removePlotfile() |
623 634 | self.removePlotfile() |
624 635 | # test two y-axes with default x-axis |
625 636 | res = plotms(vis=self.ms, plotfile=self.plotfile_jpg, expformat='jpg', |
626 637 | overwrite=True, showgui=False, yaxis=['amp','amp'], |
627 638 | ydatacolumn=['corrected','model'], |
628 639 | yaxislocation=['left','right']) |
629 640 | self.assertTrue(res) |
630 641 | self.checkPlotfile(self.plotfile_jpg, 190000) |
631 642 | |
632 643 | |
644 + | def test_axis_radec_params(self,debug=False): |
645 + | '''test_axis_radec_params: Test ant-ra/ant-dec parameters''' |
646 + | yx_axes = [('ant-ra','time'), |
647 + | ('ant-dec','time'), |
648 + | ('ant-dec','ant-ra') |
649 + | ] |
650 + | interp_methods = ['nearest','cubic'] |
651 + | # Sub-plots grid |
652 + | grid_cols = len(yx_axes) |
653 + | grid_rows = len(interp_methods) |
654 + | n_plots = grid_rows*grid_cols |
655 + | # Create 1 plot file per supported reference frame |
656 + | ref_frames = {'icrs':100000,'j2000':100000,'azelgeo':95000} |
657 + | for ref_frame, plot_min_size in ref_frames.iteritems(): |
658 + | # Plot file |
659 + | plot_filename = "testAxis13_radec_" + ref_frame + ".png" |
660 + | plot_dir = self.outputDir if not debug else '/tmp' |
661 + | plot_path = os.path.join(plot_dir, plot_filename) |
662 + | self.removePlotfile(plot_path) |
663 + | # Create sub-plots, export plot when plotting last sub-plot |
664 + | plot_index = 0 |
665 + | for row, interp_method in enumerate(interp_methods): |
666 + | for col, (y_axis,x_axis) in enumerate(yx_axes): |
667 + | is_first_plot = (plot_index == 0) |
668 + | is_last_plot = ( (plot_index + 1) == n_plots) |
669 + | title_fmt = 'ref={ref_frame}, interp={interp}' |
670 + | title = title_fmt.format(ref_frame=ref_frame, |
671 + | interp=interp_method) |
672 + | res = plotms( |
673 + | vis = self.ms3, |
674 + | # |
675 + | title = title, |
676 + | titlefont = 10, |
677 + | # |
678 + | gridrows = grid_rows, |
679 + | gridcols = grid_cols, |
680 + | # |
681 + | rowindex = row, |
682 + | colindex = col, |
683 + | plotindex = plot_index, |
684 + | # |
685 + | xaxis = x_axis, |
686 + | xframe = ref_frame, |
687 + | xinterp = interp_method, |
688 + | # |
689 + | yaxis = y_axis, |
690 + | yframe = ref_frame, |
691 + | yinterp = interp_method, |
692 + | # |
693 + | coloraxis = 'spw', |
694 + | # |
695 + | plotfile = plot_path if is_last_plot else '', |
696 + | width = 1024, |
697 + | height = 768, |
698 + | highres = True, |
699 + | overwrite = True, |
700 + | # |
701 + | clearplots = is_first_plot |
702 + | ) |
703 + | self.assertTrue(res) |
704 + | plot_index = plot_index + 1 |
705 + | # Note: last plotms call is blocking : plotms waits |
706 + | # until all plots are drawn before exporting |
707 + | self.checkPlotfile(plot_path, plot_min_size) |
708 + | if not debug: |
709 + | self.removePlotfile(plot_path) |
710 + | |
711 + | |
633 712 | # ------------------------------------------------------------------------------ |
634 - | |
713 + | |
635 714 | class test_calibration(plotms_test_base): |
636 715 | ''' test plotms callib parameter ''' |
637 716 | |
638 717 | def setUp(self): |
639 718 | self.checkDisplay() |
640 719 | self.setUpcaldata() |
641 720 | |
642 721 | def tearDown(self): |
643 722 | self.tearDowndata() |
644 723 | |