7
7
"""
8
8
9
9
import numpy as np
10
- from astropy .io import fits #for python only
11
10
import matplotlib .pyplot as plt
12
- import glob
13
- import os
11
+ import glob ,os
14
12
13
+ from astropy .io import fits #for python only
15
14
from fitsconverter import * #for python only
16
15
17
16
#Convert from .uvfits to .uvfitsMS
23
22
#*******************************************************************
24
23
25
24
26
- def reorder (msname ):
25
+ def reorrder (msname ):
27
26
import casac
28
27
ms = casac .casac .table ()
29
28
ms .open (msname ,nomodify = False )
30
29
a1 , a2 , data = [ms .getcol (x ) for x in [ "ANTENNA1" , "ANTENNA2" , "DATA" ]]
31
30
m = a1 > a2
32
- data [:, :, m ]= data [:, : , m ]. conj ()
33
- x = a2 [ m ]
34
- a2 [ m ] = a1 [ m ]
35
- a1 [ m ] = x
36
- ms .putcol ("ANTENNA1" , a1 )
37
- ms .putcol ("ANTENNA2" , a2 )
38
- ms .putcol ("DATA" , data )
39
- ms .flush ()
40
- ms .close ()
31
+ data [: ,: , m ]= data [: ,: , m ]. conj ()
32
+ x = a2 [ m ]
33
+ a2 [ m ] = a1 [ m ]
34
+ a1 [ m ] = x
35
+ ms .putcol ("ANTENNA1" ,a1 )
36
+ ms .putcol ("ANTENNA2" ,a2 )
37
+ ms .putcol ("DATA" ,data )
38
+ ms .flush ()
39
+ ms .close ()
41
40
42
41
def flag (msname ): #You might have to update this
43
42
flagdata (msname , flagbackup = True , mode = 'manual' ,antenna = "22" )
@@ -46,24 +45,24 @@ def flag(msname): #You might have to update this
46
45
flagdata (msname , flagbackup = True , mode = 'manual' ,antenna = "81" )
47
46
48
47
def gen_image (msname ,imagename ): # Makes image
49
- clean (msname ,imagename = imagename , niter = 500 , weighting = 'briggs' , robust = 0 , imsize = [512 ,512 ], cell = ['500 arcsec' ], mode = 'mfs' , nterms = 1 , spw = '0:150~900' , stokes = 'IQUV' )
48
+ clean (msname ,imagename = imagename ,niter = 500 ,weighting = 'briggs' ,robust = 0 ,imsize = [512 ,512 ] , cell = ['500 arcsec' ] , mode = 'mfs' ,nterms = 1 ,spw = '0:150~900' ,stokes = 'IQUV' )
50
49
51
50
def mkinitmodel (msname ,ext ): #Model you give casa
52
- cl .addcomponent (flux = 1.0 , fluxunit = 'Jy' , shape = 'point' , dir = 'J2000 17h45m40.0409s -29d0m28.118s' )
51
+ cl .addcomponent (flux = 1.0 , fluxunit = 'Jy' , shape = 'point' , dir = 'J2000 17h45m40.0409s -29d0m28.118s' )
53
52
cl .rename ('GC' + ext + '.cl' )
54
53
cl .close ()
55
- ft (msname , complist = 'GC' + ext + '.cl' , usescratch = True )
54
+ ft (msname , complist = 'GC' + ext + '.cl' , usescratch = True )
56
55
57
56
def clear_cal (msname ):
58
57
clearcal (msname )
59
58
60
59
def phscal (msname ):
61
60
import os ,sys
62
- kc = os .path .basename (msname ) + "K.cal"
63
- bc = os .path .basename (msname ) + "B.cal"
64
- gaincal (msname ,caltable = kc , gaintype = 'K' , solint = 'inf' , refant = '10' )
61
+ kc = os .path .basename (msname ) + "K.cal"
62
+ bc = os .path .basename (msname ) + "B.cal"
63
+ gaincal (msname ,caltable = kc ,gaintype = 'K' , solint = 'inf' ,refant = '10' )
65
64
applycal (msname ,gaintable = [kc ])
66
- bandpass (msname ,caltable = bc , solint = 'inf' , combine = 'scan' , refant = '10' )
65
+ bandpass (msname ,caltable = bc ,solint = 'inf' ,combine = 'scan' ,refant = '10' )
67
66
applycal (msname ,gaintable = [bc ])
68
67
69
68
@@ -79,7 +78,7 @@ def phscal(msname):
79
78
nwms .append (msf + '.R' )
80
79
81
80
i = 0
82
- for i in np .arange (len (MSfilelist )):
81
+ for i in np .arange (len (MSfilelist )): #This is the longest part
83
82
reorrder (msname = name [i ])# Reorder antenna 1 & 2 in each correlation so 2 is greater than 1
84
83
flag (msname = name [i ])# Flagging bad frequency channels or antennas and autoccorelations in CASA
85
84
gen_image (msname = name [i ],imagename = imgnam1 + nwms [i ])# Imaging
@@ -92,9 +91,8 @@ def phscal(msname):
92
91
#%% CREATE .NPZ FILE IN CASA
93
92
MSBCALlist = glob .glob ('*MSB.cal' )
94
93
95
- i = 0
96
- for i in np .arange (len (MSBCALlist )):
97
- tb .open (MSBCALlist [i ])
94
+ for msblist in MSBCALlist :
95
+ tb .open (msblist )
98
96
gain = tb .getcol ('CPARAM' ) # use 'FPARAM' when using K.cal files
99
97
np .savez (nwms [i ]+ '.npz' ,gains = gain )
100
98
@@ -115,15 +113,10 @@ def phscal(msname):
115
113
exportfits (imagename ,fitsimagename + ext )
116
114
fitsimage = glob .glob (clean2 * .fits )
117
115
116
+
118
117
# This section is to be done in python
119
118
test = fits .open ('new_name.fits' )
120
119
test .info ()
121
120
test [0 ].header
122
121
123
- gen_image (msname = name [0 ],imagename = imgnam2 + nwms [0 ])
124
- gen_image (name [1 ],imgnam1 + nwms [1 ])
125
- gen_image (msname = name [1 ],imagename = imgnam2 + nwms [1 ])
126
- gen_image (name [2 ],imgnam1 + nwms [2 ])
127
- gen_image (msname = name [2 ],imagename = imgnam2 + nwms [2 ])
128
- gen_image (name [3 ],imgnam1 + nwms [3 ])
129
- gen_image (msname = name [3 ],imagename = imgnam2 + nwms [3 ])
122
+
0 commit comments