casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_ia_deconvolvecomponentlist.py
Go to the documentation of this file.
00001 ##########################################################################
00002 # imfit_test.py
00003 #
00004 # Copyright (C) 2008, 2009
00005 # Associated Universities, Inc. Washington DC, USA.
00006 #
00007 # This script is free software; you can redistribute it and/or modify it
00008 # under the terms of the GNU Library General Public License as published by
00009 # the Free Software Foundation; either version 2 of the License, or (at your
00010 # option) any later version.
00011 #
00012 # This library is distributed in the hope that it will be useful, but WITHOUT
00013 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015 # License for more details.
00016 #
00017 # You should have received a copy of the GNU Library General Public License
00018 # along with this library; if not, write to the Free Software Foundation,
00019 # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00020 #
00021 # Correspondence concerning AIPS++ should be adressed as follows:
00022 #        Internet email: aips2-request@nrao.edu.
00023 #        Postal address: AIPS++ Project Office
00024 #                        National Radio Astronomy Observatory
00025 #                        520 Edgemont Road
00026 #                        Charlottesville, VA 22903-2475 USA
00027 #
00028 # <author>
00029 # Dave Mehringer
00030 # </author>
00031 #
00032 # <summary>
00033 # Test suite for the CASA method ia.deconvolvecomponentlist()
00034 # </summary>
00035 #
00036 # <reviewed reviwer="" date="" tests="" demos="">
00037 # </reviewed
00038 #
00039 #
00040 # <etymology>
00041 # Test for the method ia.deconvolvecomponentlist()
00042 # </etymology>
00043 #
00044 # <synopsis>
00045 # Test the method ia.deconvolvecomponentlist().
00046 # </synopsis> 
00047 #
00048 # <example>
00049 #
00050 # This test runs as part of the CASA python unit test suite and can be run from
00051 # the command line via eg
00052 # 
00053 # `echo $CASAPATH/bin/casapy | sed -e 's$ $/$'` --nologger --log2term -c `echo $CASAPATH | awk '{print $1}'`/code/xmlcasa/scripts/regressions/admin/runUnitTest.py test_ia_deconvolvecomponentlist[test1,test2,...]
00054 #
00055 # </example>
00056 #
00057 # <motivation>
00058 # To provide a test standard for the method ia.deconvolvecomponentlist() to ensure
00059 # coding changes do not break the associated bits 
00060 # </motivation>
00061 #
00062 
00063 ###########################################################################
00064 import shutil
00065 import casac
00066 from tasks import *
00067 from taskinit import *
00068 from __main__ import *
00069 import unittest
00070 
00071 def _near(got, exp, tol):
00072     qgot = qa.quantity(got)
00073     qexp = qa.quantity(exp)
00074     return qa.abs(qa.div(qa.sub(qgot, qexp), qexp))["value"] < tol
00075 
00076 class ia_deconvolvecomponentlist_test(unittest.TestCase):
00077     
00078     def setUp(self):
00079         self.ia = iatool()
00080         self.cl = cltool()
00081     
00082     def tearDown(self):
00083         self.ia.done()
00084         self.cl.done()
00085     
00086     def test_multibeams(self):
00087         """ ia.deconvolvecomponentlist(): Test multi beams"""
00088         myia = self.ia
00089         mycl = self.cl
00090         mycl.addcomponent(
00091             flux=1, dir=["J2000", "2h0m0s", "40d0m0s"], shape="gauss",
00092             majoraxis="4arcsec", minoraxis="3arcsec", positionangle="20deg"
00093         )
00094         
00095         myia.fromshape("", [2, 2, 2])
00096         mycs = myia.coordsys()
00097         mycs.setunits(["deg","deg",""])
00098         mycs.setdirection(
00099             refcode="J2000", refval=[30,40],
00100             incr=[-1.0/36000,1.0/36000]
00101         )
00102         myia.setcoordsys(mycs.torecord())
00103         myia.setrestoringbeam(
00104             major="2arcsec", minor="1arcsec", pa="20deg",
00105             polarization=0
00106         )
00107         myia.setrestoringbeam(
00108             major="3arcsec", minor="2arcsec", pa="50deg",
00109             polarization=1
00110         )
00111         bb = cltool()
00112         emaj = [
00113             qa.quantity({'unit': 'arcsec', 'value': 3.4641016151377548}),
00114             qa.quantity({'unit': 'arcsec', 'value': 3.0203474964295665})
00115         ]
00116         emin = [
00117             qa.quantity({'unit': 'arcsec', 'value': 2.8284271247461894}),
00118             qa.quantity({'unit': 'arcsec', 'value': 1.6963198403637358})
00119         ]
00120         epa = [
00121             qa.quantity({'unit': 'deg', 'value': 20}),
00122             qa.quantity({'unit': 'deg', 'value': -1.948943124031587 + 180})
00123         ]
00124         tol = 1e-10
00125         for i in [0, 1]:
00126             res = myia.deconvolvecomponentlist(mycl.torecord(), polarization=i)
00127             bb.fromrecord(res)
00128             shape = bb.getshape(0)
00129             bb.done()
00130             self.assertTrue(_near(shape["majoraxis"], emaj[i], tol))
00131             self.assertTrue(_near(shape["minoraxis"], emin[i], tol))
00132             print "*** pa " + str(shape["positionangle"])
00133             self.assertTrue(_near(shape["positionangle"], epa[i], tol))
00134         
00135 def suite():
00136     return [ia_deconvolvecomponentlist_test]