casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_ia_imageconcat.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 ia.imageconcat() tool method
00034 # </summary>
00035 #
00036 # <reviewed reviwer="" date="" tests="" demos="">
00037 # </reviewed
00038 #
00039 # <prerequisite>
00040 # <ul>
00041 #   <li> <linkto class="image:description">ia.imageconcat()</linkto> 
00042 # </ul>
00043 # </prerequisite>
00044 #
00045 # <etymology>
00046 # ia_imageconcat_test stands for ia.imageconcat test
00047 # </etymology>
00048 #
00049 # <synopsis>
00050 # test_ia_imageconcat.py is a Python script that tests the correctness
00051 # of the ia.imageconcat() tool method.
00052 # </synopsis> 
00053 #
00054 # <example>
00055 # `echo $CASAPATH/bin/casapy | sed -e 's$ $/$'` --nologger --log2term -c `echo $CASAPATH | awk '{print $1}'`/code/xmlcasa/scripts/regressions/admin/runUnitTest.py test_ia_imageconcat[test1,test2,...]
00056 # </example>
00057 #
00058 # <motivation>
00059 # To provide a test standard to the ia.imageconcat() method to ensure
00060 # coding changes do not break the associated bits 
00061 # </motivation>
00062 #
00063 
00064 ###########################################################################
00065 import os
00066 import casac
00067 from tasks import *
00068 from taskinit import *
00069 import hashlib
00070 import shutil
00071 from __main__ import *
00072 import unittest
00073 
00074 class ia_imageconcat_test(unittest.TestCase):
00075     
00076     def setUp(self):
00077         self._myia = iatool()
00078 
00079     def tearDown(self):
00080         self._myia.done()
00081 
00082 
00083     def test_multibeam(self):
00084         """Test concatenating images with different beams"""
00085         myia = self._myia
00086         shape = [4, 4, 20]
00087         myia.fromshape("", shape)
00088         print "*** here 1"
00089         blc1=[0, 0, 0]
00090         trc1=[shape[0]-1, shape[1]-1, shape[2]/2-1]
00091         rg1 = rg.box(blc=blc1, trc=trc1)
00092         im1 = "image1.im"
00093         sub1 = myia.subimage(im1, region=rg1)
00094         im2 = "image2.im"
00095         blc2 = [0, 0, trc1[2]+1]
00096         trc2 = [shape[0]-1, shape[1]-1, shape[2]-1]
00097         rg2 = rg.box(blc=blc2, trc=trc2)
00098         sub2 = myia.subimage(im2, region=rg2)
00099         major = qa.quantity("3arcmin")
00100         minor = qa.quantity("2arcmin")
00101         pa = qa.quantity("0deg")
00102         major2 = qa.quantity("4arcmin")
00103         minor2 = qa.quantity("3arcmin")
00104         pa2 = qa.quantity("10deg")
00105         major3 = qa.quantity("5arcmin")
00106         minor3 = qa.quantity("4arcmin")
00107         pa3 = qa.quantity("20deg")
00108         print "*** here 2"
00109 
00110         # first image has no beam while second does
00111         sub1.setbrightnessunit("Jy/pixel") 
00112         sub2.setrestoringbeam(major=major, minor=minor, pa=pa)
00113         sub2.setbrightnessunit("Jy/beam")
00114         self.assertRaises(Exception, myia.imageconcat, "", [im1, im2])
00115         concat = myia.imageconcat("", [im1, im2], relax=True)
00116         self.assertTrue((concat.shape() == shape).all())
00117         
00118         # first image has a single beam, second has per plane beams
00119         sub1.setbrightnessunit("Jy/beam")
00120         sub1.setrestoringbeam(major=major, minor=minor, pa=pa)
00121         sub2.setbrightnessunit("Jy/beam")
00122         sub2.setrestoringbeam(remove=True)
00123         sub2.setrestoringbeam(
00124             major=major2, minor=minor2, pa=pa2,
00125             channel=0, polarization=-1
00126         )
00127         
00128         sub2.setrestoringbeam(
00129             major=major3, minor=minor3, pa=pa3,
00130             channel=5, polarization=-1
00131         )
00132         concat = myia.imageconcat("", [im1, im2])
00133         for i in range(concat.shape()[2]):
00134             beam = concat.restoringbeam(channel=i)
00135             if i < sub1.shape()[2]:
00136                 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00137                 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00138                 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00139             elif i == sub1.shape()[2] + 5:
00140                 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major3))
00141                 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor3))
00142                 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa3))
00143             else:
00144                 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major2))
00145                 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor2))
00146                 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa2))
00147                 
00148         # both images have a single beam which is the same
00149         sub1.setbrightnessunit("Jy/beam")
00150         sub1.setrestoringbeam(major=major, minor=minor, pa=pa)
00151         sub2.setrestoringbeam(remove=True)
00152         sub2.setbrightnessunit("Jy/beam")
00153         sub2.setrestoringbeam(major=major, minor=minor, pa=pa)
00154         concat = myia.imageconcat("", [im1, im2])
00155         beam = concat.restoringbeam()
00156         self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00157         self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00158         self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00159         
00160         # both images have single, unequal beams
00161         sub1.setbrightnessunit("Jy/beam")
00162         sub1.setrestoringbeam(major=major, minor=minor, pa=pa)
00163         sub2.setrestoringbeam(remove=True)
00164         sub2.setbrightnessunit("Jy/beam")
00165         sub2.setrestoringbeam(major=major2, minor=minor2, pa=pa2)
00166         concat = myia.imageconcat("", [im1, im2])
00167         for i in range(concat.shape()[2]):
00168             beam = concat.restoringbeam(channel=i)
00169             if i < sub1.shape()[2]:
00170                 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00171                 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00172                 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00173             else:
00174                 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major2))
00175                 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor2))
00176                 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa2))
00177         
00178         # first image has per plane beams, second has single beam
00179         sub2.setbrightnessunit("Jy/beam")
00180         sub2.setrestoringbeam(remove=True)
00181         sub2.setrestoringbeam(major=major, minor=minor, pa=pa)
00182         sub1.setbrightnessunit("Jy/beam")
00183         sub1.setrestoringbeam(remove=True)
00184         sub1.setrestoringbeam(
00185             major=major2, minor=minor2, pa=pa2,
00186             channel=0, polarization=-1
00187         )
00188         sub1.setrestoringbeam(
00189             major=major3, minor=minor3, pa=pa3,
00190             channel=5, polarization=-1
00191         )
00192         concat = myia.imageconcat("", [im1, im2])
00193         for i in range(concat.shape()[2]):
00194             beam = concat.restoringbeam(channel=i)
00195             if i == 5:
00196                 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major3))
00197                 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor3))
00198                 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa3))
00199             elif i < sub1.shape()[2]:
00200                 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major2))
00201                 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor2))
00202                 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa2))
00203             else:
00204                 self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00205                 self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00206                 self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00207                 
00208         # both images have a single beam which is the same
00209         sub1.setbrightnessunit("Jy/beam")
00210         sub1.setrestoringbeam(remove=True)
00211         sub1.setrestoringbeam(major=major, minor=minor, pa=pa)
00212         sub2.setrestoringbeam(remove=True)
00213         sub2.setbrightnessunit("Jy/beam")
00214         sub2.setrestoringbeam(major=major, minor=minor, pa=pa)
00215         concat = myia.imageconcat("", [im1, im2])
00216         beam = concat.restoringbeam()
00217         self.assertTrue(qa.eq(qa.quantity(beam["major"]), major))
00218         self.assertTrue(qa.eq(qa.quantity(beam["minor"]), minor))
00219         self.assertTrue(qa.eq(qa.quantity(beam["positionangle"]), pa))
00220         
00221 
00222 def suite():
00223     return [ia_imageconcat_test]