Commits
smcastro authored 836c2337a6d
1 + | ######################################################################## |
2 + | # test_regression_alma_sim_componentlist.py |
3 + | # Copyright (C) 2018 |
4 + | # Associated Universities, Inc. Washington DC, USA. |
5 + | # |
6 + | # This script is free software; you can redistribute it and/or modify it |
7 + | # under the terms of the GNU Library General Public License as published by |
8 + | # the Free Software Foundation; either version 2 of the License, or (at your |
9 + | # option) any later version. |
10 + | # |
11 + | # This library is distributed in the hope that it will be useful, but WITHOUT |
12 + | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 + | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
14 + | # License for more details. |
15 + | # |
16 + | # Based on CASAguides |
17 + | # https://casaguides.nrao.edu/index.php/Simulation_Guide_Component_Lists_(CASA_5.4) |
18 + | # |
19 + | ########################################################################## |
20 + | |
21 + | import os |
22 + | import shutil |
23 + | import unittest |
24 + | |
25 + | # On purpose this script does not import any casatool or casatask |
26 + | # It is meant to run with casa -c testscript using a CASA monolithic tarball, |
27 + | # which will verify if tasks are automatically imported in the tarball |
28 + | |
29 + | class ALMASimComponentListTest(unittest.TestCase): |
30 + | |
31 + | def setUp(self) -> None: |
32 + | self.imname = 'Gaussian.im' |
33 + | self.imfits = 'Gaussian.fits' |
34 + | self.point = 'point.cl' |
35 + | self.imagelist = 'Image_list' |
36 + | |
37 + | def tearDown(self) -> None: |
38 + | # the .png files created by simobserve and simanalyse will be kept |
39 + | # inside a directory called png_list. These png images will be available |
40 + | # at the Artifacts tab of the Bamboo plan that runs these tests |
41 + | shutil.rmtree(self.imname) |
42 + | os.remove(self.imfits) |
43 + | shutil.rmtree(self.point) |
44 + | if os.path.exists('png_list'): |
45 + | shutil.rmtree('png_list') |
46 + | os.system('mkdir png_list') |
47 + | os.system('cp '+self.imagelist+'/*.png png_list') |
48 + | shutil.rmtree(self.imagelist) |
49 + | cl.done() |
50 + | ia.done() |
51 + | |
52 + | def test_simulation_with_componentlist(self): |
53 + | """Make FITS image and simulate observations with component list""" |
54 + | direction = "J2000 10h00m00.0s -30d00m00.0s" |
55 + | cl.done() |
56 + | cl.addcomponent(dir=direction, flux=1.0, fluxunit='Jy', freq='230.0GHz', shape="Gaussian", |
57 + | majoraxis="0.1arcmin", minoraxis='0.05arcmin', positionangle='45.0deg') |
58 + | |
59 + | ia.fromshape(self.imname,[256,256,1,1],overwrite=True) |
60 + | self.assertTrue(os.path.exists(self.imname),"Cannot find %s"%self.imname) |
61 + | |
62 + | cs = ia.coordsys() |
63 + | cs.setunits(['rad','rad','','Hz']) |
64 + | cell_rad = qa.convert(qa.quantity("0.1arcsec"),"rad")['value'] |
65 + | cs.setincrement([-cell_rad,cell_rad],'direction') |
66 + | cs.setreferencevalue([qa.convert("10h",'rad')['value'],qa.convert("-30deg",'rad')['value']],type="direction") |
67 + | cs.setreferencevalue("230GHz",'spectral') |
68 + | cs.setincrement('1GHz','spectral') |
69 + | ia.setcoordsys(cs.torecord()) |
70 + | ia.setbrightnessunit("Jy/pixel") |
71 + | ia.modify(cl.torecord(),subtract=False) |
72 + | ia.done() |
73 + | |
74 + | # Export the image to a FITS file |
75 + | exportfits(imagename=self.imname,fitsimage=self.imfits,overwrite=True) |
76 + | self.assertTrue(os.path.exists(self.imname),"Cannot find %s"%self.imname) |
77 + | |
78 + | cl.done() |
79 + | cl.addcomponent(dir="J2000 10h00m00.08s -30d00m02.0s", flux=0.1, fluxunit='Jy', freq='230.0GHz', shape="point") |
80 + | cl.addcomponent(dir="J2000 09h59m59.92s -29d59m58.0s", flux=0.1, fluxunit='Jy', freq='230.0GHz', shape="point") |
81 + | cl.addcomponent(dir="J2000 10h00m00.40s -29d59m55.0s", flux=0.1, fluxunit='Jy', freq='230.0GHz', shape="point") |
82 + | cl.addcomponent(dir="J2000 09h59m59.60s -30d00m05.0s", flux=0.1, fluxunit='Jy', freq='230.0GHz', shape="point") |
83 + | cl.rename(self.point) |
84 + | cl.done() |
85 + | self.assertTrue(os.path.exists(self.point),"Cannot find %s"%self.point) |
86 + | |
87 + | # Simulate observations of the point sources the Gaussian flux distribution in the FITS file |
88 + | simobserve(project = self.imagelist, skymodel = self.imfits, inwidth = "1GHz", complist = self.point, |
89 + | compwidth = '1GHz', direction = "J2000 10h00m00.0s -30d00m00.0s", obsmode = "int", |
90 + | antennalist = 'alma.cycle6.1.cfg', totaltime = "28800s", thermalnoise = '') |
91 + | |
92 + | self.assertTrue(os.path.exists(self.imagelist),"Cannot find %s"%self.imagelist) |
93 + | self.assertTrue(os.path.exists(os.path.join(self.imagelist,"Image_list.alma.cycle6.1.ms"))) |
94 + | |
95 + | # Make a map of the emision using the project created in the previous simobser step |
96 + | simanalyze(project = self.imagelist, imsize = [256,256], imdirection = "J2000 10h00m00.0s -30d00m00.0s", |
97 + | cell = '0.1arcsec', niter = 5000, threshold = '10.0mJy/beam', analyze = True) |
98 + | |
99 + | self.assertTrue(os.path.exists(os.path.join(self.imagelist,"Image_list.alma.cycle6.1.image"))) |
100 + | |
101 + | if __name__ == "__main__": |
102 + | unittest.main() |
103 + | |