Source
#vis='/lustre/naasc/sciops/comm/rindebet/pipeline/root/2013.1.01194.S_2016_05_23T02_55_30.859/SOUS_uid___A001_X11f_X4a/GOUS_uid___A001_X11f_X4b/MOUS_uid___A001_X11f_X4c/working/uid___A002_X960614_X1379.ms',
###########################################################################
# test_task_plotbandpass.py
# Copyright (C) 2018
# Associated Universities, Inc. Washington DC, USA.
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
# License for more details.
#
#
# Based on the requirements listed in casadocs found here:
# https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.visualization.plotbandpass.html
#
##########################################################################
import os
import struct
import unittest
from casatasks import plotbandpass
from casatools import ctsys
datapath = ctsys.resolve('unittest/plotbandpass/')
figdir= os.getcwd() + '/'
# Set to False to Leave PNGs and PDFs
delete_artifacts = True
def pngWidthHeight(filename):
"""
Reads the width and height of a png image (in pixels).
-Todd Hunter
"""
if (os.path.exists(filename) == False):
print("Cannot find file = ", filename)
return Exception("{} not Found".format(filename)), False
f = open(filename, 'rb')
data = f.read()
f.close()
if (data[12:16].decode("utf-8") == 'IHDR'):
w, h = struct.unpack('>LL', data[16:24])
width = int(w)
height = int(h)
return width, height
class plotbandpass_1_test(unittest.TestCase):
def setUpClass(cls):
pass
def setUp(self):
os.symlink(datapath+'Band7multi_april22.ms', os.getcwd() + '/Band7multi_april22.ms')
os.symlink(datapath+'bandpass.bcal', os.getcwd() + '/bandpass.bcal')
def tearDown(self):
os.unlink(os.getcwd() + '/Band7multi_april22.ms')
os.unlink(os.getcwd() + '/bandpass.bcal')
if delete_artifacts:
artifacts = os.listdir(figdir)
for artifact in artifacts:
if artifact.endswith(".pdf") or artifact.endswith(".png"):
os.remove(artifact)
def tearDownClass(cls):
pass
# 0
def test_createImage_regression00(self):
'''test_plotbandpass: test_createImage_regression00'''
#regression00.pdf
#regression00.spw00.t00.png
#regression00.spw01.t01.png
#regression00.spw02.t02.png
plotbandpass(datapath + 'bandpass.bcal',showtsky=False,xaxis='freq',yaxis='amp',overlay='antenna',spw='',field='0', interactive=False,buildpdf=True,figfile=figdir+'regression%02d'%(0),debug=False)
width,height = pngWidthHeight(os.getcwd()+'/regression00.spw02.t02.png')
self.assertTrue(width == 864,"Observed: {}, Expected: {}".format(width, 864) )
#1