forked from Astroua/AstroCompute_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitial_clean.py
More file actions
84 lines (76 loc) · 3.86 KB
/
initial_clean.py
File metadata and controls
84 lines (76 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'''CASA script #1-->initial CLEAN of FUll data set
Input: Calibrated and Split MS
Output: Cleaned and deconvolved CASA image (.image,.flux,.psf,.residual,.mask,.model) & fits image
Note: This script is theoretically compatible with any data that can be imported
into CASA.
Written by A. Tetarenko'''
#Import modules
#
import os
import sys
#set path to where output is to be stored-->need to set up file system so have data and data_products directory
#in this path
path_dir = sys.argv[-1]
# path_dir='/home/ubuntu/'
param_file = sys.argv[-2]
###########################################################
#USER INPUT SECTION-->read in from parameters file
###########################################################
sys.path.append(os.path.join(path_dir, "AstroCompute_Scripts/"))
from utils import load_json,convert_param_format
data_params = load_json(param_file)
#to convert txt param file to dictionary do this,
#data_params = convert_param_format(param_file, to="dict")
# Target name.
target = data_params["target"]
# Date of observation.
obsDate = data_params["obsDate"]
# Observation frequency.
refFrequency = data_params["refFrequency"]
# Label for casa output directories and files.
label = target + '_' + refFrequency + '_' + obsDate + '_'
# Length of time bins (H,M,S)
intervalSizeH = data_params["intervalSizeH"]
intervalSizeM = data_params["intervalSizeM"]
intervalSizeS = data_params["intervalSizeS"]
#make data_products directory before start script
mkdir_string='sudo mkdir '+path_dir+'data_products/images_'+target+'_'+refFrequency+'_'+str(intervalSizeH)+'hours'+str(intervalSizeM)+'min'+str(intervalSizeS)+'sec'
mkdir_perm1='sudo chown ubuntu '+path_dir+'data_products/images_'+target+'_'+refFrequency+'_'+str(intervalSizeH)+'hours'+str(intervalSizeM)+'min'+str(intervalSizeS)+'sec'
mkdir_perm2='sudo chmod -R 777 '+path_dir+'data_products/images_'+target+'_'+refFrequency+'_'+str(intervalSizeH)+'hours'+str(intervalSizeM)+'min'+str(intervalSizeS)+'sec'
os.system(mkdir_string)
os.system(mkdir_perm1)
os.system(mkdir_perm2)
# Path to directory where all output from this script is saved.
outputPath = \
os.path.join(path_dir, 'data_products/images_'+target+'_'+refFrequency +
'_'+str(intervalSizeH)+'hours'+str(intervalSizeM)+'min' +
str(intervalSizeS)+'sec/')
# dataPath contains the path and filename in which data file will be saved.
# This script can be run on several epochs of data from the same observation without changing this path.
# In this case the data file will be appended each time.
dataPath = path_dir+'data_products/datafile_'+target+'_'+refFrequency+'_'+str(intervalSizeH)+'hours'+str(intervalSizeM)+'min'+str(intervalSizeS)+'sec.txt'
# Name of visibliity - should include full path if script is not being run from vis location.
visibility = os.path.join(path_dir, 'data/' + data_params["visibility"])
# The following arguments will be passed to casa's clean
imageSize = [data_params["imageSize"]] * 2
numberIters = data_params["numberIters"]
cellSize = [data_params["cellSize"]]
taylorTerms = data_params["taylorTerms"]
myStokes = data_params["myStokes"]
thre=data_params["thre"]
spw_choice=data_params["spw_choice"]
###########################################################
#END OF USER INPUT SECTION
###########################################################
#CLEAN and CONVERT to FITS for use with object detection script
print 'Cleaning Full Data Set to detect objects-->'
clean(vis=visibility,
imagename=os.path.join(outputPath, label+'whole_dataset'),
field='', mode='mfs', imsize=imageSize, cell=cellSize,
weighting='natural', spw=spw_choice, nterms=taylorTerms,
niter=numberIters, gain=0.1,
threshold=thre, interactive=False)
print 'Converting to fits-->'
exportfits(imagename=os.path.join(outputPath, label+'whole_dataset.image'),
fitsimage=os.path.join(outputPath, label+'whole_dataset.fits'),
history=False)