casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_ia_subimage.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.subimage
00034 # </summary>
00035 #
00036 # <reviewed reviwer="" date="" tests="" demos="">
00037 # </reviewed
00038 #
00039 # <prerequisite>
00040 # <ul>
00041 #   <li> <linkto class="ia.subimage:description">ia.subimage</linkto> 
00042 # </ul>
00043 # </prerequisite>
00044 #
00045 # <etymology>
00046 # Test for the ia subimage tool method
00047 # </etymology>
00048 #
00049 # <synopsis>
00050 # Test the ia.subimage tool method
00051 # </synopsis> 
00052 #
00053 # <example>
00054 #
00055 # This test runs as part of the CASA python unit test suite and can be run from
00056 # the command line via eg
00057 # 
00058 # `echo $CASAPATH/bin/casapy | sed -e 's$ $/$'` --nologger --log2term -c `echo $CASAPATH | awk '{print $1}'`/code/xmlcasa/scripts/regressions/admin/runUnitTest.py test_ia_subimage[test1,test2,...]
00059 #
00060 # </example>
00061 #
00062 # <motivation>
00063 # To provide a test standard for the ia.subimage tool method to ensure
00064 # coding changes do not break the associated bits 
00065 # </motivation>
00066 #
00067 
00068 ###########################################################################
00069 import shutil
00070 import casac
00071 from tasks import *
00072 from taskinit import *
00073 from __main__ import *
00074 import unittest
00075 
00076 
00077 class ia_subimage_test(unittest.TestCase):
00078     
00079     def setUp(self):
00080         self.myia = iatool()
00081     
00082     def tearDown(self):
00083         self.myia.done()
00084 
00085     def test_stretch(self):
00086         """Test the stretch parameter"""
00087         myia = self.myia
00088         myia.fromshape("mask1.im", [20, 30, 4, 10])
00089         myia.fromshape("mask2.im", [20, 30, 4, 1])
00090         myia.fromshape("mask3.im", [20, 30, 4, 2])
00091 
00092         imname = "xx.im"
00093         myia.fromshape(imname, [20,30,4,10])
00094         mask1 = "mask1.im > 10"
00095         mm = myia.subimage("", mask=mask1)
00096         self.assertTrue(mm)
00097         mm = imsubimage(imagename=imname, mask=mask1)
00098         self.assertTrue(mm)
00099         mask2 = "mask2.im > 10"
00100         self.assertRaises(Exception, myia.subimage, "", mask=mask2, stretch=False)
00101         self.assertFalse(imsubimage(imname, "", mask=mask2, stretch=False))
00102         self.assertTrue(myia.subimage("", mask=mask2, stretch=True))
00103         self.assertTrue(imsubimage(imname, "", mask=mask2, stretch=True))
00104         mask3 = "mask3.im > 10"
00105         self.assertRaises(Exception, myia.subimage, "", mask=mask3, stretch=True)
00106         self.assertFalse(imsubimage(imname, "", mask=mask3, stretch=True))
00107 
00108     def test_beams(self):
00109         """ Test per plane beams """
00110         myia = self.myia
00111 
00112         # simple copy
00113         myia.fromshape("", [10, 10, 10, 4])
00114         myia.setrestoringbeam(
00115             "4arcsec", "2arcsec", "5deg", channel=0, polarization=0
00116         )
00117         for i in range(10):
00118             for j in range(4):
00119                 myia.setrestoringbeam(
00120                     qa.quantity(i + j + 2, "arcsec"),
00121                     qa.quantity(i + j + 1, "arcsec"),
00122                     qa.quantity("5deg"),
00123                     channel=i, polarization=j
00124                 )
00125         box = rg.box([2, 2, 2, 2], [5, 5, 5, 3])
00126         subim = myia.subimage("", region=box)
00127         for i in range(subim.shape()[2]):
00128             for j in range(subim.shape()[3]):
00129                 self.assertTrue(
00130                     subim.restoringbeam(channel=i, polarization=j)
00131                     == myia.restoringbeam(channel=i+2, polarization=j+2)
00132                 )
00133         box = rg.box([2, 2, 2, 2], [5, 5, 5, 2])
00134         subim = myia.subimage("", region=box, dropdeg=T)
00135         for i in range(subim.shape()[2]):
00136             self.assertTrue(
00137                 subim.restoringbeam(channel=i, polarization=-1)
00138                 == myia.restoringbeam(channel=i+2, polarization=2)
00139             )
00140         box = rg.box([2, 2, 6, 1], [5, 5, 6, 3])
00141         subim = myia.subimage("", region=box, dropdeg=T)
00142         for i in range(subim.shape()[2]):
00143             self.assertTrue(
00144                 subim.restoringbeam(channel=-1, polarization=i)
00145                 == myia.restoringbeam(channel=6, polarization=i+1)
00146             )
00147 
00148 def suite():
00149     return [ia_subimage_test]