casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_ia_adddegaxes.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 tool method ia.adddegaxes()
00034 # </summary>
00035 #
00036 # <reviewed reviwer="" date="" tests="" demos="">
00037 # </reviewed
00038 #
00039 # <prerequisite>
00040 # <ul>
00041 # </ul>
00042 # </prerequisite>
00043 #
00044 # <etymology>
00045 # Test for the ia.adddegaxes() tool method
00046 # </etymology>
00047 #
00048 # <synopsis>
00049 # Test for the ia.adddegaxes tool method
00050 # </synopsis> 
00051 #
00052 # <example>
00053 #
00054 # This test runs as part of the CASA python unit test suite and can be run from
00055 # the command line via eg
00056 # 
00057 # `echo $CASAPATH/bin/casapy | sed -e 's$ $/$'` --nologger --log2term -c `echo $CASAPATH | awk '{print $1}'`/code/xmlcasa/scripts/regressions/admin/runUnitTest.py test_ia_adddegaxes[test1,test2,...]
00058 #
00059 # </example>
00060 #
00061 # <motivation>
00062 # To provide a test standard for the ia.adddegaxes() tool method to ensure
00063 # coding changes do not break the associated bits 
00064 # </motivation>
00065 #
00066 
00067 ###########################################################################
00068 import shutil
00069 import casac
00070 from tasks import *
00071 from taskinit import *
00072 from __main__ import *
00073 import unittest
00074 
00075 class ia_adddegaxes_test(unittest.TestCase):
00076     
00077     def setUp(self):
00078         self._myia = iatool()
00079     
00080     def tearDown(self):
00081         self._myia.done()
00082     
00083     def test_general(self):
00084         """general tests"""
00085         myia = self._myia
00086         # Make RA/DEC image
00087         imname = 'ia.fromshape.image'
00088         imshape = [10,10]
00089         myim = myia.newimagefromshape(imname, imshape)
00090         self.assertTrue(myim)
00091         self.assertRaises(Exception, myim.adddegaxes, direction=T)
00092         myim2 = myim.adddegaxes(spectral=T)
00093         self.assertTrue(myim2)
00094         s = myim2.shape()
00095         s2 = [imshape[0],imshape[1],1]
00096         self.assertTrue((s == s2).all())
00097         mycs = myim2.coordsys()
00098         types = mycs.axiscoordinatetypes()
00099         self.assertTrue(types[2] == 'Spectral')
00100         self.assertTrue(mycs.done())
00101         self.assertTrue(myim2.done())
00102         myim2 = myim.adddegaxes(stokes='i')
00103         self.assertTrue(myim2)
00104         s = myim2.shape()
00105         s2 = [imshape[0],imshape[1],1]
00106         self.assertTrue((s == s2).all())
00107         mycs = myim2.coordsys()
00108         types = mycs.axiscoordinatetypes()
00109         self.assertTrue(types[2] == 'Stokes')
00110         self.assertTrue(mycs.done())
00111         self.assertTrue(myim2.done())
00112         #
00113         myim2 = myim.adddegaxes(linear=T)
00114         self.assertTrue(myim2)
00115         s = myim2.shape()
00116         s2 = [imshape[0],imshape[1],1]
00117         self.assertTrue((s == s2).all())
00118         mycs = myim2.coordsys()
00119         types = mycs.axiscoordinatetypes()
00120         self.assertTrue(types[2] == 'Linear')
00121         self.assertTrue(mycs.done())
00122         self.assertTrue(myim2.done())
00123         
00124         myim2 = myim.adddegaxes(tabular=T)
00125         self.assertTrue(myim2)
00126         s = myim2.shape()
00127         s2 = [imshape[0],imshape[1],1]
00128         self.assertTrue((s == s2).all())
00129         mycs = myim2.coordsys()
00130         types = mycs.axiscoordinatetypes()
00131         self.assertTrue(types[2] == 'Tabular')
00132         self.assertTrue(mycs.done())
00133         self.assertTrue(myim2.done())
00134         self.assertTrue(myim.done())
00135         #
00136         # Make Spectral image
00137         #
00138         mycs = cs.newcoordsys(spectral=T)
00139         self.assertTrue(mycs)
00140         imname = 'ia.fromshape2.image'
00141         imshape = [10]
00142         myim = myia.newimagefromshape(imname, imshape, csys=mycs.torecord())
00143         self.assertTrue(myim)
00144         myim2 = myim.adddegaxes(direction=T)
00145         self.assertTrue(myim2)
00146         s = myim2.shape()
00147         s2 = [imshape[0],1,1]
00148         self.assertTrue((s == s2).all())
00149         mycs2 = myim2.coordsys()
00150         types = mycs2.axiscoordinatetypes()
00151         self.assertTrue(types[1] == 'Direction' and types[2] == 'Direction')
00152         self.assertTrue(mycs2.done())
00153         self.assertTrue(myim2.done())
00154         self.assertTrue(mycs.done())
00155         self.assertTrue(myim.done())
00156         
00157     def test_beams(self):
00158         """test hyperbeams get accounted for correctly"""
00159         myia = self._myia
00160         myia.fromshape(shape=[10, 10, 10])
00161         major = "4arcsec"
00162         minor = "3arcsec"
00163         pa = "4deg"
00164         nminor = "2arcsec"
00165         myia.setrestoringbeam(major=major, minor=minor, pa=pa, channel=1)
00166         myia.setrestoringbeam(major=major, minor=nminor, pa=pa, channel=3)
00167         deg = myia.adddegaxes(stokes="I")
00168         self.assertTrue((deg.shape() == [10, 10, 10, 1]).all())
00169         beam = deg.restoringbeam(channel=1)
00170         self.assertTrue(beam["major"] == qa.quantity(major))
00171         self.assertTrue(beam["minor"] == qa.quantity(minor))
00172         self.assertTrue(beam["positionangle"] == qa.quantity(pa))
00173         beam = deg.restoringbeam(channel=3)
00174         self.assertTrue(beam["major"] == qa.quantity(major))
00175         self.assertTrue(beam["minor"] == qa.quantity(nminor))
00176         self.assertTrue(beam["positionangle"] == qa.quantity(pa))
00177 
00178         
00179         deg.done()
00180         
00181 
00182 def suite():
00183     return [ia_adddegaxes_test]