source: trunk/python/sbseparator.py@ 3060

Last change on this file since 3060 was 2859, checked in by Kana Sugimoto, 11 years ago

New Development: No

JIRA Issue: Yes (CAS-5139)

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sbseparator

Description: Removed an obsolete known issue from document.


File size: 5.5 KB
Line 
1import os, shutil
2import numpy
3import numpy.fft as FFT
4import math
5
6from asap.scantable import scantable
7from asap.parameters import rcParams
8from asap.logging import asaplog, asaplog_post_dec
9from asap.selector import selector
10from asap.asapgrid import asapgrid2
11from asap._asap import SBSeparator
12
13class sbseparator:
14 """
15 The sbseparator class is defined to separate SIGNAL and IMAGE
16 sideband spectra observed by frequency-switching technique.
17 It also helps supressing emmission of IMAGE sideband.
18 *** WARNING *** THIS MODULE IS EXPERIMENTAL
19 Known issues:
20 - Frequencies of IMAGE sideband cannot be reconstructed from
21 information in scantable in sideband sparation. Frequency
22 setting of SIGNAL sideband is stored in output table for now.
23
24 Example:
25 # Create sideband separator instance whith 3 input data
26 sbsep = sbseparator(['test1.asap', 'test2.asap', 'test3.asap'])
27 # Set reference IFNO and tolerance to select data
28 sbsep.set_frequency(5, 30, frame='TOPO')
29 # Set direction tolerance to select data in unit of radian
30 sbsep.set_dirtol(1.e-5)
31 # Set rejection limit of solution
32 sbsep.set_limit(0.2)
33 # Solve image sideband as well
34 sbsep.set_both(True)
35 # Invoke sideband separation
36 sbsep.separate('testout.asap', overwrite = True)
37 """
38 def __init__(self, infiles):
39 self._separator = SBSeparator(infiles)
40
41
42 def set_frequency(self, baseif, freqtol, frame=""):
43 """
44 Set IFNO and frequency tolerance to select data to process.
45
46 Parameters:
47 - reference IFNO to process in the first table in the list
48 - frequency tolerance from reference IF to select data (string)
49 frame : frequency frame to select IF
50 """
51 if type(freqtol) in (float, int):
52 freqtol = str(freqtol)
53 elif isinstance(freqtol, dict):
54 try:
55 freqtol = str(freqtol['value']) + freqtol['unit']
56 except:
57 raise ValueError, "Invalid frequency tolerance."
58 self._separator.set_freq(baseif, freqtol, frame)
59
60
61 def set_dirtol(self, dirtol=["2arcsec", "2arcsec"]):
62 """
63 Set tolerance of direction to select data
64 """
65 if isinstance(dirtol, str):
66 dirtol = [dirtol]
67
68 self._separator.set_dirtol(dirtol)
69
70
71 def set_shift(self, imageshift=[]):
72 """
73 Set shift mode and channel shift of image band.
74
75 imageshift : a list of number of channels shifted in image
76 side band of each scantable.
77 If the shifts are not set, they are assumed to be
78 equal to those of signal side band, but in opposite
79 direction as usual by LO1 offsetting of DSB receivers.
80 """
81 if not imageshift:
82 imageshift = []
83 self._separator.set_shift(imageshift)
84
85
86 @asaplog_post_dec
87 def set_both(self, flag=False):
88 """
89 Resolve both image and signal sideband when True.
90 """
91 self._separator.solve_both(flag)
92 if flag:
93 asaplog.push("Both signal and image sidebands will be solved and stored in separate tables.")
94 else:
95 asaplog.push("Only signal sideband will be solved and stored in an table.")
96
97 @asaplog_post_dec
98 def set_limit(self, threshold=0.2):
99 """
100 Set rejection limit of solution.
101 """
102 self._separator.set_limit(threshold)
103
104
105 @asaplog_post_dec
106 def set_solve_other(self, flag=False):
107 """
108 Calculate spectra by subtracting the solution of the other sideband
109 when True.
110 """
111 self._separator.subtract_other(flag)
112 if flag:
113 asaplog.push("Expert mode: solution are obtained by subtraction of the other sideband.")
114
115
116 def set_lo1(self, lo1, frame="TOPO", reftime=-1, refdir=""):
117 """
118 Set LO1 frequency to calculate frequency of image sideband.
119
120 lo1 : LO1 frequency
121 frame : the frequency frame of LO1
122 reftime : the reference time used in frequency frame conversion.
123 refdir : the reference direction used in frequency frame conversion.
124 """
125 self._separator.set_lo1(lo1, frame, reftime, refdir)
126
127
128 def set_lo1root(self, name):
129 """
130 Set MS name which stores LO1 frequency of signal side band.
131 It is used to calculate frequency of image sideband.
132
133 name : MS name which contains 'ASDM_SPECTRALWINDOW' and
134 'ASDM_RECEIVER' tables.
135 """
136 self._separator.set_lo1root(name)
137
138 @asaplog_post_dec
139 def separate(self, outname="", overwrite=False):
140 """
141 Invoke sideband separation.
142
143 outname : a name of output scantable
144 overwrite : overwrite existing table
145 """
146 out_default = "sbseparated.asap"
147 if len(outname) == 0:
148 outname = out_default
149 asaplog.post()
150 asaplog.push("The output file name is not specified.")
151 asaplog.push("Using default name '%s'" % outname)
152 asaplog.post("WARN")
153
154 if os.path.exists(outname):
155 if overwrite:
156 asaplog.push("removing the old file '%s'" % outname)
157 shutil.rmtree(outname)
158 else:
159 asaplog.post()
160 asaplog.push("Output file '%s' already exists." % outname)
161 asaplog.post("ERROR")
162 return False
163
164 self._separator.separate(outname)
165
Note: See TracBrowser for help on using the repository browser.