forked from cyriltasse/DynSpecMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ms2dynspec.py
executable file
·153 lines (129 loc) · 6.08 KB
/
ms2dynspec.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
from __future__ import division
from __future__ import absolute_import
from past.builtins import cmp
__author__ = "Cyril Tasse, and Alan Loh"
__credits__ = ["Cyril Tasse", "Alan Loh"]
from dynspecms_version import version
__version__ = version()
SaveFile = "last_dynspec.obj"
"""
=========================================================================
DESCRIPTION
Blablabla
Modif
Example:
python ms2dynspec.py --msfile /usr/data/ --data CORRECTED --model PREDICT --sols killms.npz --srclist SRCPOS.txt --rad 10
-------------------------------------------------------------------------
TO DO
- convertSrclist: only keep (RA, Dec) wich are within the field -- DONE
- convertSrclist: add some other ~random positions on wich to compute dynamic spectra for comparison
- stokes computation: CHECK correct I Q U V computation! -- DONE
=========================================================================
"""
import sys
import os
import argparse
from distutils.spawn import find_executable
import matplotlib
matplotlib.use('Agg')
from matplotlib import rc
fontsize=12
rc('font',**{'family':'serif','serif':['Times'],'size':fontsize})
if find_executable("latex") is not None:
rc('text', usetex=True)
from pyrap.tables import table
from astropy.time import Time
from astropy import units as uni
from astropy.io import fits
from astropy import coordinates as coord
from astropy import constants as const
import numpy as np
import glob, os
import pylab
from DDFacet.Other import MyPickle
import logo
logo.PrintLogo(__version__)
from ClassDynSpecMS import ClassDynSpecMS
import ClassSaveResults
from DDFacet.Data.ClassMS import expandMSList
from DDFacet.Other import ModColor
from DDFacet.Other import progressbar
# # ##############################
# # Catch numpy warning
# np.seterr(all='raise')
# import warnings
# warnings.filterwarnings('error')
# #with warnings.catch_warnings():
# # warnings.filterwarnings('error')
# # ##############################
# =========================================================================
# =========================================================================
def angSep(ra1, dec1, ra2, dec2):
""" Find the angular separation of two sources (ra# dec# in deg) in deg
(Stolen from the LOFAR scripts), works --> compared with astropy (A. Loh)
"""
b = np.pi/2 - np.radians(dec1)
c = np.pi/2 - np.radians(dec2)
temp = (np.cos(b) * np.cos(c)) + (np.sin(b) * np.sin(c) * np.cos(np.radians(ra1 - ra2)))
if abs(temp) > 1.0:
temp = 1.0 * cmp(temp, 0)
return np.degrees(np.arccos(temp))
def main(args=None, messages=[]):
if args is None:
args = MyPickle.Load(SaveFile)
MSList=None
if args.ms:
MSList=expandMSList(args.ms)
MSList=[mstuple[0] for mstuple in MSList]
D = ClassDynSpecMS(ListMSName=MSList,
ColName=args.data, ModelName=args.model,
SolsName=args.sols,
ColWeights=args.WeightCol,
UVRange=args.uv,
FileCoords=args.srclist,
Radius=args.rad,
NOff=args.noff,
ImageI=args.imageI,
ImageV=args.imageV,
SolsDir=args.SolsDir,NCPU=args.NCPU,
BaseDirSpecs=args.BaseDirSpecs,
BeamModel=args.BeamModel,
BeamNBand=args.BeamNBand)
if D.NDirSelected==0:
return
if D.Mode=="Spec": D.StackAll()
SaveMachine=ClassSaveResults.ClassSaveResults(D)
if D.Mode=="Spec":
SaveMachine.WriteFits()
SaveMachine.PlotSpec()
SaveMachine.SaveCatalog()
SaveMachine.tarDirectory()
else:
SaveMachine.SaveCatalog()
SaveMachine.PlotSpec(Prefix="_replot")
# =========================================================================
# =========================================================================
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ms", type=str, help="Name of MS file / directory", required=False)
parser.add_argument("--data", type=str, default="CORRECTED", help="Name of DATA column", required=False)
parser.add_argument("--WeightCol", type=str, default=None, help="Name of weights column to be taken into account", required=False)
parser.add_argument("--model", type=str, help="Name of MODEL column",default="")#, required=True)
parser.add_argument("--sols", type=str, help="Jones solutions",default="")
parser.add_argument("--srclist", type=str, default="Transient_LOTTS.csv", help="List of targets --> 'source_name ra dec'")
parser.add_argument("--rad", type=float, default=3., help="Radius of the field", required=False)
parser.add_argument("--noff", type=float, default=-1, help="Number of off sources. -1 means twice as much as there are sources in the catalog", required=False)
parser.add_argument("--LogBoring", type=int, default=0, help="Boring?", required=False)
parser.add_argument("--imageI", type=str, default=None, help="Survey image to plot", required=False)
parser.add_argument("--imageV", type=str, default=None, help="Survey image to plot", required=False)
parser.add_argument("--BaseDirSpecs", type=str, default=None, help="Path to the precomputed specs", required=False)
parser.add_argument("--uv", type=list, default=[1., 1000.], help="UV range in km [UVmin, UVmax]", required=False)
parser.add_argument("--SolsDir", type=str, default="", help="Base directory for the DDE solutions", required=False)
parser.add_argument("--NCPU", type=int, default=0, help="NCPU", required=False)
parser.add_argument("--BeamModel", type=str, default=None, help="Beam Model to be used", required=False)
parser.add_argument("--BeamNBand", type=int, default=1, help="Number of channels in the Beam Jones matrix", required=False)
args = parser.parse_args()
MyPickle.Save(args, SaveFile)
ModColor.silent = progressbar.ProgressBar.silent = args.LogBoring
main(args)