casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_ia_deconvolvefrombeam.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.deconvolvefrombeam()
00034 # </summary>
00035 #
00036 # <reviewed reviwer="" date="" tests="" demos="">
00037 # </reviewed
00038 #
00039 #
00040 # <etymology>
00041 # Test for the method ia.deconvolvefrombeam()
00042 # </etymology>
00043 #
00044 # <synopsis>
00045 # Test the method ia.deconvolvefrombeam().
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_deconvolvefrombeam[test1,test2,...]
00054 #
00055 # </example>
00056 #
00057 # <motivation>
00058 # To provide a test standard for the method ia.deconvolvefrombeam() 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_deconvolvefrombeam_test(unittest.TestCase):
00077     
00078     def setUp(self):
00079         self.ia = iatool()
00080     
00081     def tearDown(self):
00082         self.ia.done()
00083     
00084     def test_multibeams(self):
00085         """ ia.deconvolvefrombeam(): Basic tests"""
00086         print "*** start "
00087         myia = self.ia
00088         source = ["4arcsec","3arcsec", "20deg"]
00089         beam = [
00090             ["2arcsec", "1arcsec", "20deg"],
00091             ["3arcsec", "2arcsec", "50deg"]
00092         ]
00093         emaj = [
00094             qa.quantity({'unit': 'arcsec', 'value': 3.4641016151377548}),
00095             qa.quantity({'unit': 'arcsec', 'value': 3.0203474964295665})
00096         ]
00097         emin = [
00098             qa.quantity({'unit': 'arcsec', 'value': 2.8284271247461894}),
00099             qa.quantity({'unit': 'arcsec', 'value': 1.6963198403637358})
00100         ]
00101         epa = [
00102             qa.quantity({'unit': 'deg', 'value': 20}),
00103             qa.quantity({'unit': 'deg', 'value': -1.9489431240069859})
00104         ]
00105         tol = 1e-10
00106         for i in [0, 1]:
00107             res = myia.deconvolvefrombeam(source, beam[i])
00108             fit = res["fit"]
00109             self.assertTrue(_near(fit["major"], emaj[i], tol))
00110             self.assertTrue(_near(fit["minor"], emin[i], tol))
00111             print "*** got " + str(fit["pa"])
00112             print "*** exp " + str(epa[i])
00113             self.assertTrue(_near(fit["pa"], epa[i], tol))
00114         
00115 def suite():
00116     return [ia_deconvolvefrombeam_test]