casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_gencal.py
Go to the documentation of this file.
00001 import os
00002 import sys
00003 import shutil
00004 import commands
00005 import numpy
00006 import numpy.ma as ma
00007 import testhelper as th
00008 from __main__ import default
00009 from tasks import gencal
00010 from taskinit import *
00011 import unittest
00012 
00013 '''
00014 Unit tests for gencal 
00015 '''
00016 #
00017 # ToDo:
00018 # add more tests
00019 # once more independent tests (e.g. comparison
00020 # the AIPS REWAY results) add reference mses
00021 # and do tests against them
00022 # 
00023 
00024 datapath=os.environ.get('CASAPATH').split()[0]+'/data/regression/unittest/gencal/'
00025 
00026 # Pick up alternative data directory to run tests on MMSs
00027 testmms = False
00028 if os.environ.has_key('TEST_DATADIR'):   
00029     DATADIR = str(os.environ.get('TEST_DATADIR'))+'/gencal/'
00030     if os.path.isdir(DATADIR):
00031         testmms = True
00032         datapath = DATADIR
00033     else:
00034         print 'WARN: directory '+DATADIR+' does not exist'
00035 
00036 print 'gencal tests will use data from '+datapath         
00037 
00038 
00039 class gencal_antpostest(unittest.TestCase):
00040 
00041     # Input and output names
00042     msfile = 'tdem0003gencal.ms'
00043     if testmms:
00044         msfile = 'tdem0003gencal.mms'
00045     caltable = 'anpos.cal'
00046     reffile1 = datapath+'anpos.manual.cal'
00047     reffile2 = datapath+'anpos.auto.cal'
00048     res = False
00049 
00050     def setUp(self):
00051         if (os.path.exists(self.msfile)):
00052             shutil.rmtree(self.msfile)
00053 
00054         shutil.copytree(datapath+self.msfile, self.msfile, symlinks=True)
00055 
00056     def tearDown(self):
00057         if (os.path.exists(self.msfile)):
00058             shutil.rmtree(self.msfile)
00059             
00060         shutil.rmtree(self.caltable,ignore_errors=True)
00061 
00062     def test_antpos_manual(self):
00063         """
00064         gencal: test manual antenna position correction 
00065         """
00066         gencal(vis=self.msfile,
00067                caltable=self.caltable, 
00068                caltype='antpos',
00069                antenna='ea12,ea22',
00070                parameter=[-0.0072,0.0045,-0.0017, -0.0220,0.0040,-0.0190])
00071 
00072         self.assertTrue(os.path.exists(self.caltable))
00073 
00074         # ToDo:check generated caltable. Wait for new caltable
00075         
00076         # Compare with reference file from the repository
00077         reference = self.reffile1
00078         self.assertTrue(th.compTables(self.caltable, reference, ['WEIGHT']))
00079 
00080     def test_antpos_auto(self):
00081         """
00082         gencal: test automated antenna position correction
00083         """
00084         # check if the URL is reachable
00085         import urllib2
00086         # current EVLA baseline correction URL
00087         evlabslncorrURL="http://www.vla.nrao.edu/cgi-bin/evlais_blines.cgi?Year="
00088         try: 
00089           urlaccess=urllib2.urlopen(evlabslncorrURL+"2010")
00090           gencal(vis=self.msfile,
00091                  caltable=self.caltable,
00092                  caltype='antpos',
00093                  antenna='',
00094                  parameter='')
00095 
00096           self.assertTrue(os.path.exists(self.caltable))
00097           
00098           # ToDo: check for generated caltable
00099           
00100           # Compare with reference file from the repository
00101           reference = self.reffile2
00102           self.assertTrue(th.compTables(self.caltable, reference, ['WEIGHT']))
00103 
00104         except urllib2.URLError, err:
00105           print "Cannot access %s , skip this test" % evlabslncorrURL
00106           self.res=True
00107 
00108 def suite():
00109     return [gencal_antpostest]