source: trunk/python/sbseparator.py@ 2967

Last change on this file since 2967 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
RevLine 
[2647]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
[2707]11from asap._asap import SBSeparator
[2647]12
13class sbseparator:
14 """
[2649]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.
[2647]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):
[2772]39 self._separator = SBSeparator(infiles)
[2647]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
[2794]48 - frequency tolerance from reference IF to select data (string)
[2647]49 frame : frequency frame to select IF
50 """
[2794]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)
[2647]59
60
[2794]61 def set_dirtol(self, dirtol=["2arcsec", "2arcsec"]):
[2647]62 """
63 Set tolerance of direction to select data
64 """
[2794]65 if isinstance(dirtol, str):
66 dirtol = [dirtol]
[2647]67
[2794]68 self._separator.set_dirtol(dirtol)
69
70
71 def set_shift(self, imageshift=[]):
[2647]72 """
73 Set shift mode and channel shift of image band.
74
[2794]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.
[2647]80 """
[2794]81 if not imageshift:
82 imageshift = []
83 self._separator.set_shift(imageshift)
[2647]84
[2794]85
[2647]86 @asaplog_post_dec
87 def set_both(self, flag=False):
88 """
89 Resolve both image and signal sideband when True.
90 """
[2794]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.")
[2647]94 else:
[2794]95 asaplog.push("Only signal sideband will be solved and stored in an table.")
[2647]96
97 @asaplog_post_dec
98 def set_limit(self, threshold=0.2):
99 """
100 Set rejection limit of solution.
101 """
[2794]102 self._separator.set_limit(threshold)
[2647]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 """
[2794]111 self._separator.subtract_other(flag)
[2647]112 if flag:
113 asaplog.push("Expert mode: solution are obtained by subtraction of the other sideband.")
114
[2794]115
[2807]116 def set_lo1(self, lo1, frame="TOPO", reftime=-1, refdir=""):
[2707]117 """
118 Set LO1 frequency to calculate frequency of image sideband.
[2647]119
[2794]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.
[2707]124 """
[2807]125 self._separator.set_lo1(lo1, frame, reftime, refdir)
[2707]126
127
[2711]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 """
[2712]136 self._separator.set_lo1root(name)
[2711]137
[2647]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 """
[2794]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")
[2647]153
[2794]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
[2712]163
[2794]164 self._separator.separate(outname)
[2647]165
Note: See TracBrowser for help on using the repository browser.