casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_sdimaging.py
Go to the documentation of this file.
00001 import os
00002 import sys
00003 import shutil
00004 from __main__ import default
00005 from tasks import *
00006 from taskinit import *
00007 import unittest
00008 import sha
00009 import time
00010 import numpy
00011 import re
00012 import string
00013 
00014 from sdimaging import sdimaging
00015 import asap as sd
00016 
00017 #
00018 # Unit test of sdimaging task.
00019 # 
00020 
00021 ###
00022 # Base class for sdimaging unit test
00023 ###
00024 class sdimaging_unittest_base:
00025     """
00026     Base class for sdimaging unit test
00027 
00028     Test data is originally FLS3_all_newcal_SP and created
00029     by the following script:
00030 
00031     asap_init()
00032     sd.rc('scantable',storage='disk')
00033     s=sd.scantable('FLS3_all_newcal_SP',average=False,getpt=False)
00034     s0=s.get_scan('FLS3a')
00035     s0.save('FLS3a_HI.asap')
00036     del s,s0
00037     s=sd.scantable('FLS3a_HI.asap',average=False)
00038     s.set_fluxunit('K')
00039     scannos=s.getscannos()
00040     res=sd.calfs(s,scannos)
00041     del s
00042     res.save('FLS3a_calfs','MS2')
00043     tb.open('FLS3a_calfs')
00044     tbsel=tb.query('SCAN_NUMBER<100')
00045     tbc=tbsel.copy('sdimaging.ms',deep=True,valuecopy=True)
00046     tbsel.close()
00047     tb.close()
00048     tbc.close()
00049 
00050     Furthermore, SYSCAL and POINTING tables are downsized.
00051     
00052     """
00053     taskname='sdimaging'
00054     datapath=os.environ.get('CASAPATH').split()[0] + '/data/regression/unittest/sdimaging/'
00055     rawfile='sdimaging.ms'
00056     postfix='.im'
00057     phasecenter='J2000 17:18:29 +59.31.23'
00058     imsize=[75,75]
00059     cell=['3.0arcmin','3.0arcmin']
00060     gridfunction='PB'
00061     statsinteg={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00062                 'blcf': '17:32:18.690, +57.37.28.536, I, 1.42064e+09Hz',
00063                 'max': numpy.array([ 0.6109162]),
00064                 'maxpos': numpy.array([4, 62,  0,  0], dtype=numpy.int32),
00065                 'maxposf': '17:31:59.439, +60.43.52.421, I, 1.42064e+09Hz',
00066                 'mean': numpy.array([ 0.39524983]),
00067                 'min': numpy.array([ 0.]),
00068                 'minpos': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00069                 'minposf': '17:32:18.690, +57.37.28.536, I, 1.42064e+09Hz',
00070                 'npts': numpy.array([ 5625.]),
00071                 'rms': numpy.array([ 0.43127564]),
00072                 'sigma': numpy.array([ 0.17257331]),
00073                 'sum': numpy.array([ 2223.28028646]),
00074                 'sumsq': numpy.array([ 1046.2425779]),
00075                 'trc': numpy.array([74, 74,  0,  0], dtype=numpy.int32),
00076                 'trcf': '17:03:03.151, +61.19.10.757, I, 1.42064e+09Hz'}
00077     keys=['max','mean','min','npts','rms','blc','blcf','trc','trcf','sigma','sum','sumsq']
00078 
00079     def _checkfile( self, name ):
00080         isthere=os.path.exists(name)
00081         self.assertEqual(isthere,True,
00082                          msg='output file %s was not created because of the task failure'%(name))
00083 
00084     def _checkshape(self,name,nx,ny,npol,nchan):
00085         self._checkfile(name)
00086         ia.open(name)
00087         imshape=ia.shape()
00088         ia.close()
00089         self.assertEqual(nx,imshape[0],
00090                     msg='nx does not match')
00091         self.assertEqual(ny,imshape[1],
00092                     msg='ny does not match')
00093         self.assertEqual(npol,imshape[2],
00094                     msg='npol does not match')
00095         self.assertEqual(nchan,imshape[3],
00096                     msg='nchan does not match')
00097         
00098     def _checkstats(self,name,ref):
00099         self._checkfile(name)
00100         ia.open(name)
00101         stats=ia.statistics()
00102         ia.close()
00103         #for key in stats.keys():
00104         for key in self.keys:
00105             message='statistics \'%s\' does not match'%(key)
00106             if type(stats[key])==str:
00107                 self.assertEqual(stats[key],ref[key],
00108                                  msg=message)
00109             else:
00110                 #print stats[key]-ref[key]
00111                 ret=numpy.allclose(stats[key],ref[key])
00112                 self.assertEqual(ret,True,
00113                                  msg=message)
00114 
00115 ###
00116 # Test on bad parameter settings
00117 ###
00118 class sdimaging_test0(sdimaging_unittest_base,unittest.TestCase):
00119     """
00120     Test on bad parameter setting
00121     """
00122     # Input and output names
00123     prefix=sdimaging_unittest_base.taskname+'Test0'
00124     badid=99
00125     outfile=prefix+sdimaging_unittest_base.postfix
00126 
00127     def setUp(self):
00128         if os.path.exists(self.rawfile):
00129             shutil.rmtree(self.rawfile)
00130         shutil.copytree(self.datapath+self.rawfile, self.rawfile)
00131 
00132         default(sdimaging)
00133 
00134     def tearDown(self):
00135         if (os.path.exists(self.rawfile)):
00136             shutil.rmtree(self.rawfile)
00137         os.system( 'rm -rf '+self.prefix+'*' )
00138 
00139     def test000(self):
00140         """Test 000: Default parameters"""
00141         # argument verification error
00142         res=sdimaging()
00143         self.assertFalse(res)
00144 
00145     def test001(self):
00146         """Test001: Bad specunit"""
00147         # argument verification error
00148         res=sdimaging(infile=self.rawfile,specunit='frequency',outfile=self.outfile)
00149         self.assertFalse(res)
00150 
00151     def test002(self):
00152         """Test002: Bad field id"""
00153         outfile=self.prefix+self.postfix
00154         try:
00155             res=sdimaging(infile=self.rawfile,field=self.badid,outfile=self.outfile)
00156             self.assertTrue(False,
00157                             msg='The task must throw exception')
00158         except Exception, e:
00159             pos=str(e).find('field id %s does not exist'%(self.badid))
00160             self.assertNotEqual(pos,-1,
00161                                 msg='Unexpected exception was thrown: %s'%(str(e)))
00162 
00163     def test003(self):
00164         """Test003: Bad spectral window id"""
00165         try:
00166             res=sdimaging(infile=self.rawfile,spw=self.badid,outfile=self.outfile)
00167             self.assertTrue(False,
00168                             msg='The task must throw exception')
00169         except Exception, e:
00170             pos=str(e).find('spw id %s does not exist'%(self.badid))
00171             self.assertNotEqual(pos,-1,
00172                                 msg='Unexpected exception was thrown: %s'%(str(e)))
00173 
00174     def test004(self):
00175         """Test004: Bad antenna id"""
00176         # not throw any exception, but return False
00177         res=sdimaging(infile=self.rawfile,antenna=self.badid,outfile=self.outfile)
00178         self.assertFalse(res)
00179         
00180     def test005(self):
00181         """Test005: Bad stokes parameter"""
00182         try:
00183             res=sdimaging(infile=self.rawfile,stokes='BAD',outfile=self.outfile)
00184             self.assertTrue(False,
00185                             msg='The task must throw exception')
00186         except Exception, e:
00187             pos=str(e).find('Stokes selection BAD is currently not supported.')
00188             self.assertNotEqual(pos,-1,
00189                                 msg='Unexpected exception was thrown: %s'%(str(e)))
00190         
00191     def test006(self):
00192         """Test006: Bad gridfunction"""
00193         # argument verification error
00194         res=sdimaging(infile=self.rawfile,gridfunction='BAD',outfile=self.outfile)
00195         self.assertFalse(res)
00196 
00197     def test007(self):
00198         """Test007: Bad scanlist"""
00199         # empty selection, but not throw exception
00200         res=sdimaging(infile=self.rawfile,scanlist=[self.badid],outfile=self.outfile)
00201         self.assertFalse(res)
00202 
00203     def test008(self):
00204         """Test008: Existing outfile with overwrite=False"""
00205         f=open(self.outfile,'w')
00206         print >> f, 'existing file'
00207         f.close()
00208         try:
00209             res=sdimaging(infile=self.rawfile,outfile=self.outfile)
00210             self.assertTrue(False,
00211                             msg='The task must throw exception')
00212         except Exception, e:
00213             pos=str(e).find('Output file \'%s\' exists.'%(self.outfile))
00214             self.assertNotEqual(pos,-1,
00215                                 msg='Unexpected exception was thrown: %s'%(str(e)))
00216 
00217     def test009(self):
00218         """Test009: Bad phasecenter string"""
00219         try:
00220             res=sdimaging(infile=self.rawfile,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter='This is bad')
00221             self.assertTrue(False,
00222                             msg='The task must throw exception')
00223         except Exception, e:
00224             pos=str(e).find('Empty QuantumHolder argument for asQuantumDouble')
00225             self.assertNotEqual(pos,-1,
00226                                 msg='Unexpected exception was thrown: %s'%(str(e)))
00227 
00228     def test010(self):
00229         """Test010: Bad phasecenter reference (J2000 is assumed)"""
00230         # default for unknown direction frame is J2000 
00231         refimage=self.outfile+'2'
00232         sdimaging(infile=self.rawfile,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter.replace('J2000','J3000'))
00233         sdimaging(infile=self.rawfile,outfile=refimage,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter)
00234         tb.open(self.outfile)
00235         chunk=tb.getcol('map')
00236         tb.close()
00237         tb.open(refimage)
00238         refchunk=tb.getcol('map')
00239         tb.close()
00240         ret=all(chunk.flatten()==refchunk.flatten())
00241         #print ret
00242         self.assertTrue(ret)
00243 
00244     def test011(self):
00245         """Test011: Bad pointingcolumn name"""
00246         # argument verification error
00247         res=sdimaging(infile=self.rawfile,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,pointingcolumn='non_exist')
00248         self.assertFalse(res)
00249 
00250     def test012(self):
00251         """Test012: Bad imsize"""
00252         try:
00253             res=sdimaging(infile=self.rawfile,outfile=self.outfile,cell=self.cell,imsize=[0,0],phasecenter=self.phasecenter)
00254             self.assertTrue(False,
00255                             msg='The task must throw exception')
00256         except Exception, e:
00257             pos=str(e).find('%s does not exist'%(self.outfile))
00258             self.assertNotEqual(pos,-1,
00259                                 msg='Unexpected exception was thrown: %s'%(str(e)))
00260         
00261     def test013(self):
00262         """Test013: Bad cell size"""
00263         # empty image will be created
00264         res=sdimaging(infile=self.rawfile,outfile=self.outfile,cell=[0.,0.],imsize=self.imsize,phasecenter=self.phasecenter)
00265         self.assertFalse(res)
00266 
00267     def test014(self):
00268         """Test014: Too fine resolution (smaller than original channel width"""
00269         try:
00270             res=sdimaging(infile=self.rawfile,specunit='GHz',outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=True,nchan=10,start=1.4202,step=1.0e-10)
00271             self.assertTrue(False,
00272                             msg='The task must throw exception')
00273         except Exception, e:
00274             pos=str(e).find('calcChanFreqs failed, check input start and width parameters')
00275             self.assertNotEqual(pos,-1,
00276                                 msg='Unexpected exception was thrown: %s'%(str(e)))
00277 
00278 
00279 ###
00280 # Test channel imaging
00281 ###
00282 class sdimaging_test1(sdimaging_unittest_base,unittest.TestCase):
00283     """
00284     Test channel imaging
00285 
00286        - integrated image
00287        - full channel image
00288        - selected channel image
00289        - BOX and SF imaging (default is PB)
00290        - two polarization imaging (XX and YY, default is Stokes I)
00291        
00292     """
00293     # Input and output names
00294     prefix=sdimaging_unittest_base.taskname+'Test1'
00295     outfile=prefix+sdimaging_unittest_base.postfix
00296     mode='channel'
00297 
00298     def setUp(self):
00299         if os.path.exists(self.rawfile):
00300             shutil.rmtree(self.rawfile)
00301         shutil.copytree(self.datapath+self.rawfile, self.rawfile)
00302 
00303         default(sdimaging)
00304 
00305     def tearDown(self):
00306         if (os.path.exists(self.rawfile)):
00307             shutil.rmtree(self.rawfile)
00308         os.system( 'rm -rf '+self.prefix+'*' )
00309 
00310     def test100(self):
00311         """Test 100: Integrated image (dochannelmap=False)"""
00312         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=False)
00313         self.assertEqual(res,None,
00314                          msg='Any error occurred during imaging')
00315         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,1)
00316         refstats=self.statsinteg
00317         self._checkstats(self.outfile,refstats)
00318 
00319     def test101(self):
00320         """Test 101: Integrated image (dochannelmap=True,nchan=-1)"""
00321         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=True,nchan=-1,start=0,step=1)
00322         self.assertEqual(res,None,
00323                          msg='Any error occurred during imaging')
00324         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,1)
00325 ##         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00326 ##                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.419395e+09Hz',
00327 ##                   'max': numpy.array([ 0.03589965]),
00328 ##                   'maxpos': numpy.array([60, 71,  0,  0], dtype=numpy.int32),
00329 ##                   'maxposf': '17:08:55.879, +61.12.09.501, I, 1.419395e+09Hz',
00330 ##                   'mean': numpy.array([ 0.01769218]),
00331 ##                   'min': numpy.array([ 0.]),
00332 ##                   'minpos': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00333 ##                   'minposf': '17:32:18.690, +57.37.28.536, I, 1.419395e+09Hz',
00334 ##                   'npts': numpy.array([ 5625.]),
00335 ##                   'rms': numpy.array([ 0.01939845]),
00336 ##                   'sigma': numpy.array([ 0.007956]),
00337 ##                   'sum': numpy.array([ 99.51852731]),
00338 ##                   'sumsq': numpy.array([ 2.11668729]),
00339 ##                   'trc': numpy.array([74, 74,  0,  0], dtype=numpy.int32),
00340 ##                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.419395e+09Hz'}
00341         refstats = {'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00342                     'blcf': '17:32:18.690, +57.37.28.536, I, 1.42064e+09Hz',
00343                     'max': numpy.array([ 0.6109162]),
00344                     'maxpos': numpy.array([ 4, 62,  0,  0], dtype=numpy.int32),
00345                     'maxposf': '17:31:59.439, +60.43.52.421, I, 1.42064e+09Hz',
00346                     'mean': numpy.array([ 0.39524983]),
00347                     'min': numpy.array([ 0.]),
00348                     'minpos': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00349                     'minposf': '17:32:18.690, +57.37.28.536, I, 1.42064e+09Hz',
00350                     'npts': numpy.array([ 5625.]),
00351                     'rms': numpy.array([ 0.43127564]),
00352                     'sigma': numpy.array([ 0.17257331]),
00353                     'sum': numpy.array([ 2223.28028646]),
00354                     'sumsq': numpy.array([ 1046.2425779]),
00355                     'trc': numpy.array([74, 74,  0,  0], dtype=numpy.int32),
00356                     'trcf': '17:03:03.151, +61.19.10.757, I, 1.42064e+09Hz'}
00357         self._checkstats(self.outfile,refstats)
00358         
00359     def test102(self):
00360         """Test 102: Full channel image"""
00361         tb.open(self.rawfile)
00362         if 'FLOAT_DATA' in tb.colnames():
00363             nchan=tb.getcell('FLOAT_DATA').shape[1]
00364         else:
00365             nchan=tb.getcell('DATA').shape[1]
00366         tb.close()
00367         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=True,nchan=nchan,start=0,step=1)
00368         self.assertEqual(res,None,
00369                          msg='Any error occurred during imaging')
00370         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00371         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00372                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.419395e+09Hz',
00373                   'max': numpy.array([ 24.77152824]),
00374                   'maxpos': numpy.array([ 59,  21,   0, 605], dtype=numpy.int32),
00375                   'maxposf': '17:10:00.642, +58.42.19.808, I, 1.420872e+09Hz',
00376                   'mean': numpy.array([ 0.39542111]),
00377                   'min': numpy.array([-1.84636593]),
00378                   'minpos': numpy.array([  73,    6,    0, 1023], dtype=numpy.int32),
00379                   'minposf': '17:04:54.966, +57.55.36.907, I, 1.421893e+09Hz',
00380                   'npts': numpy.array([ 5760000.]),
00381                   'rms': numpy.array([ 1.01357317]),
00382                   'sigma': numpy.array([ 0.93325921]),
00383                   'sum': numpy.array([ 2277625.60731485]),
00384                   'sumsq': numpy.array([ 5917423.42281288]),
00385                   'trc': numpy.array([  74,   74,    0, 1023], dtype=numpy.int32),
00386                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.421893e+09Hz'}
00387         self._checkstats(self.outfile,refstats)
00388 
00389     def test103(self):
00390         """Test 103: Selected channel image"""
00391         nchan=40
00392         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=True,nchan=nchan,start=400,step=10)
00393         self.assertEqual(res,None,
00394                          msg='Any error occurred during imaging')
00395         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00396         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00397                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.42038e+09Hz',
00398                   'max': numpy.array([ 14.79568005]),
00399                   'maxpos': numpy.array([57, 20,  0, 20], dtype=numpy.int32),
00400                   'maxposf': '17:10:47.496, +58.39.30.813, I, 1.42087e+09Hz',
00401                   'mean': numpy.array([ 0.82293006]),
00402                   'min': numpy.array([-0.08763941]),
00403                   'minpos': numpy.array([61, 71,  0, 35], dtype=numpy.int32),
00404                   'minposf': '17:08:30.980, +61.12.02.893, I, 1.42124e+09Hz',
00405                   'npts': numpy.array([ 225000.]),
00406                   'rms': numpy.array([ 1.54734671]),
00407                   'sigma': numpy.array([ 1.31037237]),
00408                   'sum': numpy.array([ 185159.263672]),
00409                   'sumsq': numpy.array([ 538713.45272028]),
00410                   'trc': numpy.array([74, 74,  0, 39], dtype=numpy.int32),
00411                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.42133e+09Hz'}
00412         self._checkstats(self.outfile,refstats)
00413 
00414     def test104(self):
00415         """Test 104: Box-car gridding"""
00416         nchan=40
00417         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction='BOX',dochannelmap=True,nchan=nchan,start=400,step=10)
00418         self.assertEqual(res,None,
00419                          msg='Any error occurred during imaging')
00420         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00421         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00422                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.42038e+09Hz',
00423                   'max': numpy.array([ 15.64525127]),
00424                   'maxpos': numpy.array([58, 20,  0, 20], dtype=numpy.int32),
00425                   'maxposf': '17:10:24.433, +58.39.25.476, I, 1.42087e+09Hz',
00426                   'mean': numpy.array([ 0.66097592]),
00427                   'min': numpy.array([-0.42533547]),
00428                   'minpos': numpy.array([69, 62,  0, 38], dtype=numpy.int32),
00429                   'minposf': '17:05:23.086, +60.44.01.427, I, 1.42131e+09Hz',
00430                   'npts': numpy.array([ 225000.]),
00431                   'rms': numpy.array([ 1.38591599]),
00432                   'sigma': numpy.array([ 1.2181464]),
00433                   'sum': numpy.array([ 148719.58227018]),
00434                   'sumsq': numpy.array([ 432171.72687429]),
00435                   'trc': numpy.array([74, 74,  0, 39], dtype=numpy.int32),
00436                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.42133e+09Hz'}
00437         self._checkstats(self.outfile,refstats)
00438 
00439     def test105(self):
00440         """Test 105: Prolate Spheroidal gridding"""
00441         nchan=40
00442         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction='SF',dochannelmap=True,nchan=nchan,start=400,step=10)
00443         self.assertEqual(res,None,
00444                          msg='Any error occurred during imaging')
00445         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00446         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00447                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.42038e+09Hz',
00448                   'max': numpy.array([ 15.13189793]),
00449                   'maxpos': numpy.array([58, 21,  0, 20], dtype=numpy.int32),
00450                   'maxposf': '17:10:23.737, +58.42.25.413, I, 1.42087e+09Hz',
00451                   'mean': numpy.array([ 0.773227]),
00452                   'min': numpy.array([-0.07284018]),
00453                   'minpos': numpy.array([ 5, 67,  0, 30], dtype=numpy.int32),
00454                   'minposf': '17:31:41.090, +60.59.00.556, I, 1.42112e+09Hz',
00455                   'npts': numpy.array([ 225000.]),
00456                   'rms': numpy.array([ 1.49926317]),
00457                   'sigma': numpy.array([ 1.28449107]),
00458                   'sum': numpy.array([ 173976.07570213]),
00459                   'sumsq': numpy.array([ 505752.74505987]),
00460                   'trc': numpy.array([74, 74,  0, 39], dtype=numpy.int32),
00461                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.42133e+09Hz'}
00462         self._checkstats(self.outfile,refstats)
00463 
00464     def test106(self):
00465         """Test 106: Imaging two polarization separately (XX and YY, not Stokes I)"""
00466         nchan=40
00467         res=sdimaging(infile=self.rawfile,specunit=self.mode,stokes='XXYY',outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction='PB',dochannelmap=True,nchan=nchan,start=400,step=10)
00468         self.assertEqual(res,None,
00469                          msg='Any error occurred during imaging')
00470         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],2,nchan)
00471         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00472                   'blcf': '17:32:18.690, +57.37.28.536, XX, 1.42038e+09Hz',
00473                   'max': numpy.array([ 15.057868]),
00474                   'maxpos': numpy.array([57, 20,  1, 20], dtype=numpy.int32),
00475                   'maxposf': '17:10:47.496, +58.39.30.813, YY, 1.42087e+09Hz',
00476                   'mean': numpy.array([ 0.82292841]),
00477                   'min': numpy.array([-0.41953856]),
00478                   'minpos': numpy.array([10,  3,  1, 31], dtype=numpy.int32),
00479                   'minposf': '17:28:37.170, +57.47.49.422, YY, 1.42114e+09Hz',
00480                   'npts': numpy.array([ 450000.]),
00481                   'rms': numpy.array([ 1.55436146]),
00482                   'sigma': numpy.array([ 1.31864787]),
00483                   'sum': numpy.array([ 370317.78554221]),
00484                   'sumsq': numpy.array([ 1087217.77687839]),
00485                   'trc': numpy.array([74, 74,  1, 39], dtype=numpy.int32),
00486                   'trcf': '17:03:03.151, +61.19.10.757, YY, 1.42133e+09Hz'}
00487         self._checkstats(self.outfile,refstats)
00488 
00489     def test107(self):
00490         """Test 107: Gaussian gridding"""
00491         nchan=40
00492         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction='GAUSS',dochannelmap=True,nchan=nchan,start=400,step=10)
00493         self.assertEqual(res,None,
00494                          msg='Any error occurred during imaging')
00495         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00496         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00497                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.42038e+09Hz',
00498                   'max': numpy.array([ 15.28046036]),
00499                   'maxpos': numpy.array([58, 21,  0, 20], dtype=numpy.int32),
00500                   'maxposf': '17:10:23.737, +58.42.25.413, I, 1.42087e+09Hz',
00501                   'mean': numpy.array([ 0.75082603]),
00502                   'min': numpy.array([-0.14009152]),
00503                   'minpos': numpy.array([34, 69,  0, 33], dtype=numpy.int32),
00504                   'minposf': '17:19:43.545, +61.07.22.487, I, 1.42119e+09Hz',
00505                   'npts': numpy.array([ 225000.]),
00506                   'rms': numpy.array([ 1.47686982]),
00507                   'sigma': numpy.array([ 1.2717751]),
00508                   'sum': numpy.array([ 168935.85698331]),
00509                   'sumsq': numpy.array([ 490757.49952306]),
00510                   'trc': numpy.array([74, 74,  0, 39], dtype=numpy.int32),
00511                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.42133e+09Hz'}
00512         self._checkstats(self.outfile,refstats)
00513 
00514     def test108(self):
00515         """Test 108: Gaussian*Jinc gridding"""
00516         nchan=40
00517         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction='GJINC',dochannelmap=True,nchan=nchan,start=400,step=10)
00518         self.assertEqual(res,None,
00519                          msg='Any error occurred during imaging')
00520         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00521         refstats={'blc':numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00522                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.42038e+09Hz',
00523                   'max':numpy.array([ 15.31498909]),
00524                   'maxpos':numpy.array([58, 21,  0, 20], dtype=numpy.int32),
00525                   'maxposf': '17:10:23.737, +58.42.25.413, I, 1.42087e+09Hz',
00526                   'mean':numpy.array([ 0.72415226]),
00527                   'min':numpy.array([-0.16245638]),
00528                   'minpos':numpy.array([68, 69,  0, 36], dtype=numpy.int32),
00529                   'minposf': '17:05:39.206, +61.05.09.055, I, 1.42126e+09Hz',
00530                   'npts':numpy.array([ 225000.]),
00531                   'rms':numpy.array([ 1.44985926]),
00532                   'sigma':numpy.array([ 1.25606618]),
00533                   'sum':numpy.array([ 162934.25891985]),
00534                   'sumsq':numpy.array([ 472970.63791706]),
00535                   'trc':numpy.array([74, 74,  0, 39], dtype=numpy.int32),
00536                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.42133e+09Hz'}
00537         self._checkstats(self.outfile,refstats)
00538 
00539 
00540 ###
00541 # Test frequency imaging
00542 ###
00543 class sdimaging_test2(sdimaging_unittest_base,unittest.TestCase):
00544     """
00545     Test frequency imaging
00546 
00547        - integrated image
00548        - selected frequency image
00549        
00550     """
00551     # Input and output names
00552     prefix=sdimaging_unittest_base.taskname+'Test2'
00553     outfile=prefix+sdimaging_unittest_base.postfix
00554     mode='GHz'
00555 
00556     def setUp(self):
00557         if os.path.exists(self.rawfile):
00558             shutil.rmtree(self.rawfile)
00559         shutil.copytree(self.datapath+self.rawfile, self.rawfile)
00560 
00561         default(sdimaging)
00562 
00563     def tearDown(self):
00564         if (os.path.exists(self.rawfile)):
00565             shutil.rmtree(self.rawfile)
00566         os.system( 'rm -rf '+self.prefix+'*' )
00567 
00568     def test200(self):
00569         """Test 200: Integrated image (dochannelmap=False)"""
00570         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=False)
00571         self.assertEqual(res,None,
00572                          msg='Any error occurred during imaging')
00573         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,1)
00574         refstats=self.statsinteg
00575         self._checkstats(self.outfile,refstats)
00576         
00577     def test201(self):
00578         """Test 201: Selected frequency image"""
00579         nchan=100
00580         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=True,nchan=nchan,start=1.4202,step=1.0e-5)
00581         self.assertEqual(res,None,
00582                          msg='Any error occurred during imaging')
00583         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00584         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00585                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.4202e+09Hz',
00586                   'max': numpy.array([ 21.55560875]),
00587                   'maxpos': numpy.array([59, 21,  0, 67], dtype=numpy.int32),
00588                   'maxposf': '17:10:00.642, +58.42.19.808, I, 1.42087e+09Hz',
00589                   'mean': numpy.array([ 0.80467233]),
00590                   'min': numpy.array([-0.27736959]),
00591                   'minpos': numpy.array([58, 71,  0, 10], dtype=numpy.int32),
00592                   'minposf': '17:09:45.684, +61.12.21.875, I, 1.4203e+09Hz',
00593                   'npts': numpy.array([ 562500.]),
00594                   'rms': numpy.array([ 1.56429076]),
00595                   'sigma': numpy.array([ 1.3414586]),
00596                   'sum': numpy.array([ 452628.18628213]),
00597                   'sumsq': numpy.array([ 1376440.6075593]),
00598                   'trc': numpy.array([74, 74,  0, 99], dtype=numpy.int32),
00599                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.42119e+09Hz'}
00600         self._checkstats(self.outfile,refstats)
00601         
00602     def test202(self):
00603         """Test 202: Selected frequency image with other frequency unit"""
00604         nchan=100
00605         res=sdimaging(infile=self.rawfile,specunit='MHz',outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=True,nchan=nchan,start=1420.2,step=0.01)
00606         self.assertEqual(res,None,
00607                          msg='Any error occurred during imaging')
00608         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00609         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00610                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.4202e+09Hz',
00611                   'max': numpy.array([ 21.55560875]),
00612                   'maxpos': numpy.array([59, 21,  0, 67], dtype=numpy.int32),
00613                   'maxposf': '17:10:00.642, +58.42.19.808, I, 1.42087e+09Hz',
00614                   'mean': numpy.array([ 0.80467233]),
00615                   'min': numpy.array([-0.27736959]),
00616                   'minpos': numpy.array([58, 71,  0, 10], dtype=numpy.int32),
00617                   'minposf': '17:09:45.684, +61.12.21.875, I, 1.4203e+09Hz',
00618                   'npts': numpy.array([ 562500.]),
00619                   'rms': numpy.array([ 1.56429076]),
00620                   'sigma': numpy.array([ 1.3414586]),
00621                   'sum': numpy.array([ 452628.18628213]),
00622                   'sumsq': numpy.array([ 1376440.6075593]),
00623                   'trc': numpy.array([74, 74,  0, 99], dtype=numpy.int32),
00624                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.42119e+09Hz'}
00625         self._checkstats(self.outfile,refstats)
00626         
00627 ###
00628 # Test velocity imaging
00629 ###
00630 class sdimaging_test3(sdimaging_unittest_base,unittest.TestCase):
00631     """
00632     Test velocity imaging
00633 
00634        - integrated image
00635        - selected velocity image
00636        
00637     """
00638     # Input and output names
00639     prefix=sdimaging_unittest_base.taskname+'Test3'
00640     outfile=prefix+sdimaging_unittest_base.postfix
00641     mode='km/s'
00642 
00643     def setUp(self):
00644         if os.path.exists(self.rawfile):
00645             shutil.rmtree(self.rawfile)
00646         shutil.copytree(self.datapath+self.rawfile, self.rawfile)
00647 
00648         default(sdimaging)
00649 
00650     def tearDown(self):
00651         if (os.path.exists(self.rawfile)):
00652             shutil.rmtree(self.rawfile)
00653         os.system( 'rm -rf '+self.prefix+'*' )
00654 
00655     def test300(self):
00656         """Test 300: Integrated image (dochannelmap=False)"""
00657         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=False)
00658         self.assertEqual(res,None,
00659                          msg='Any error occurred during imaging')
00660         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,1)
00661         refstats=self.statsinteg
00662         self._checkstats(self.outfile,refstats)
00663         
00664     def test301(self):
00665         """Test 301: Selected velocity image"""
00666         nchan=100
00667         res=sdimaging(infile=self.rawfile,specunit=self.mode,outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=True,nchan=nchan,start=-200.0,step=2.0)
00668         self.assertEqual(res,None,
00669                          msg='Any error occurred during imaging')
00670         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00671         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00672                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.421353e+09Hz',
00673                   'max': numpy.array([ 21.97223091]),
00674                   'maxpos': numpy.array([ 4,  5,  0, 50], dtype=numpy.int32),
00675                   'maxposf': '17:30:54.243, +57.53.03.440, I, 1.42088e+09Hz',
00676                   'mean': numpy.array([ 0.84673187]),
00677                   'min': numpy.array([-0.27300295]),
00678                   'minpos': numpy.array([61, 71,  0, 16], dtype=numpy.int32),
00679                   'minposf': '17:08:30.980, +61.12.02.893, I, 1.421202e+09Hz',
00680                   'npts': numpy.array([ 562500.]),
00681                   'rms': numpy.array([ 1.6305207]),
00682                   'sigma': numpy.array([ 1.3934297]),
00683                   'sum': numpy.array([ 476286.67594505]),
00684                   'sumsq': numpy.array([ 1495461.22406453]),
00685                   'trc': numpy.array([74, 74,  0, 99], dtype=numpy.int32),
00686                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.420415e+09Hz'}
00687         self._checkstats(self.outfile,refstats)
00688 
00689     def test302(self):
00690         """Test 302: Selected velocity image (different rest frequency)"""
00691         nchan=100
00692         res=sdimaging(infile=self.rawfile,specunit=self.mode,restfreq='1.420GHz',outfile=self.outfile,cell=self.cell,imsize=self.imsize,phasecenter=self.phasecenter,gridfunction=self.gridfunction,dochannelmap=True,nchan=nchan,start=-100.0,step=2.0)
00693         self.assertEqual(res,None,
00694                          msg='Any error occurred during imaging')
00695         self._checkshape(self.outfile,self.imsize[0],self.imsize[1],1,nchan)
00696         refstats={'blc': numpy.array([0, 0, 0, 0], dtype=numpy.int32),
00697                   'blcf': '17:32:18.690, +57.37.28.536, I, 1.420474e+09Hz',
00698                   'max': numpy.array([ 1.61916351]),
00699                   'maxpos': numpy.array([ 4, 52,  0, 33], dtype=numpy.int32),
00700                   'maxposf': '17:31:47.043, +60.13.54.473, I, 1.420161e+09Hz',
00701                   'mean': numpy.array([ 0.12395606]),
00702                   'min': numpy.array([-0.41655564]),
00703                   'minpos': numpy.array([60, 71,  0, 93], dtype=numpy.int32),
00704                   'minposf': '17:08:55.879, +61.12.09.501, I, 1.419593e+09Hz',
00705                   'npts': numpy.array([ 562500.]),
00706                   'rms': numpy.array([ 0.19268371]),
00707                   'sigma': numpy.array([ 0.14751931]),
00708                   'sum': numpy.array([ 69725.28195545]),
00709                   'sumsq': numpy.array([ 20883.94443161]),
00710                   'trc': numpy.array([74, 74,  0, 99], dtype=numpy.int32),
00711                   'trcf': '17:03:03.151, +61.19.10.757, I, 1.419536e+09Hz'}
00712         self._checkstats(self.outfile,refstats)
00713 
00714 def suite():
00715     return [sdimaging_test0,sdimaging_test1,
00716             sdimaging_test2,sdimaging_test3]