source: trunk/python/sbseparator.py @ 2843

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

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sbseparator

Description: Removed obsolete codes and variables.


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