Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
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_tofits_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_stretch(self):
00084 """ ia.tofits(): Test stretch parameter"""
00085 yy = self.myia
00086 mymask = "maskim"
00087 yy.fromshape(mymask, [200, 200, 1, 1])
00088 yy.addnoise()
00089 yy.done()
00090 shape = [200,200,1,20]
00091 yy.fromshape("", shape)
00092 yy.addnoise()
00093 self.assertRaises(
00094 Exception,
00095 yy.tofits, outfile="blah1.fits",
00096 mask=mymask + ">0", stretch=False
00097 )
00098 zz = yy.tofits(
00099 outfile="blah2.fits",
00100 mask=mymask + ">0", stretch=True
00101 )
00102 self.assertTrue(zz and type(zz) == type(True))
00103 yy.done()
00104
00105 def test_CAS3675(self):
00106 """ test fix for CAS 3675, outfile must be specified """
00107 name = "my.im"
00108 yy = self.myia
00109 yy.fromshape(name, [1,1,1,1])
00110 self.assertRaises(Exception, yy.tofits, overwrite=T)
00111 yy.done()
00112 self.assertFalse(exportfits(imagename=name, overwrite=T))
00113
00114 def test_multibeam(self):
00115 """Test exporting and importing an image with multiple beams"""
00116 myia = self.myia
00117 shape = [10,10,10,4]
00118 myia.fromshape("", shape)
00119 bmaj = qa.quantity("10arcsec")
00120 bmin = qa.quantity("7arcsec")
00121 bpa = qa.quantity("45deg")
00122 myia.setrestoringbeam(
00123 major=bmaj, minor=bmin, pa=bpa,
00124 channel=0, polarization=0
00125 )
00126 cmaj = qa.quantity("12arcsec")
00127 cmin = qa.quantity("8arcsec")
00128 cpa = qa.quantity("50deg")
00129 myia.setrestoringbeam(
00130 major=cmaj, minor=cmin, pa=cpa,
00131 channel=6, polarization=3
00132 )
00133 myia.addnoise()
00134 exppix = myia.getchunk()
00135 fitsname = "myfits.fits"
00136 myia.tofits(outfile=fitsname)
00137 myia.done()
00138 for i in range(4):
00139 if i == 0:
00140 myia.fromfits("", fitsname)
00141 elif i == 1:
00142 myia.open(fitsname)
00143 elif i == 2:
00144 zz = iatool()
00145 myia = zz.newimagefromfits("", fitsname)
00146 else:
00147 zz = iatool()
00148 myia = zz.newimagefromfile(fitsname)
00149 ep = 1e-7
00150 for c in range(shape[2]):
00151 for p in range(shape[3]):
00152 beam = myia.restoringbeam(c, p)
00153 majax = qa.convert(beam["major"], "arcsec")["value"]
00154 minax = qa.convert(beam["minor"], "arcsec")["value"]
00155 pa = qa.convert(beam["positionangle"], "deg")["value"]
00156 if c == 6 and p == 3:
00157 self.assertTrue(abs(1 - majax/cmaj["value"]) < ep)
00158 self.assertTrue(abs(1 - minax/cmin["value"]) < ep)
00159 self.assertTrue(abs(1 - pa/cpa["value"]) < ep)
00160 else:
00161 self.assertTrue(abs(1 - majax/bmaj["value"]) < ep)
00162 self.assertTrue(abs(1 - minax/bmin["value"]) < ep)
00163 self.assertTrue(abs(1 - pa/bpa["value"]) < ep)
00164
00165 gotpix = myia.getchunk()
00166 self.assertTrue((gotpix == exppix).all())
00167 myia.done()
00168
00169 def suite():
00170 return [ia_tofits_test]