source: trunk/python/edgemarker.py @ 2613

Last change on this file since 2613 was 2613, checked in by Takeshi Nakazato, 12 years ago

New Development: Yes

JIRA Issue: Yes CAS-2825

Ready for Test: No

Interface Changes: Yes

What Interface Changed: added new python module sd.edgemarker

Test Programs: not available

Put in Release Notes: Yes

Module(s): Module Names change impacts.

Description: Describe your changes here...

New python module edgemarker is available. The edgemarker is a tool to
detect edge of observed area and mark data near edge as OFF. It can be
used to calibrate OTF data without explicit OFF scan.


File size: 5.4 KB
Line 
1from asap.scantable import scantable
2from asap._asap import _edgemarker
3
4class edgemarker:
5    """
6    The edgemarker is a helper tool to calibrate OTF observation
7    without explicit OFF scans. According to a few user-specified
8    options, the class automatically detects an edge region of the
9    map and mark integrations within this region as OFF.
10
11    The edgemarker supports raster pattern as well as other generic
12    ones (e.g. lissajous, double circle). The constructor takes
13    one boolean parameter to specify whether scan pattern is raster
14    or not. This is because that edge detection algorithms for raster
15    and others are different.
16
17    Current limitation of this class is that it cannot handle some
18    complicated observed area. Typical case is that the area has
19    clear 'dent' (e.g. a composite area consisting of two diamond-
20    shaped areas that partially overlap). In such case, the class
21    will fail to detect such feature.
22
23    Note that the class takes a copy of input data so that input
24    data will not be overwritten. Result will be provided as a
25    separate data whose contents are essentially the same as input
26    except for that some integrations are marked as OFF.
27
28    Here is typical usage:
29
30       s = scantable( 'otf.asap', average=False )
31       marker = edgemarker( israster=False )
32       marker.setdata( s )
33       marker.setoption( fraction='15%', width=0.5 )
34       marker.mark()
35
36       # get result as scantable instance
37       s2 = marker.getresult()
38
39       # save result on disk
40       marker.save( 'otfwithoff.asap', overwrite=True )
41    """
42    def __init__( self, israster=False ):
43        """
44        Constructor.
45
46        israster -- Whether scan pattern is raster or not. Set True
47                    if scan pattern is raster. Default is False.
48        """
49        self.israster = israster
50        self.marker = _edgemarker( self.israster )
51        self.st = None
52
53    def setdata( self, st ):
54        """
55        Set data to be processed.
56
57        st -- Data as scantable instance.
58        """
59        self.st = st
60        self.marker._setdata( self.st, False )
61        self.marker._examine()
62
63    def setoption( self, *args, **kwargs ):
64        """
65        Set options for edge detection. Valid options depend on
66        whether scan pattern is raster or not.
67
68        FOR RASTER:
69        fraction -- Fraction of OFF integration in each raster
70                    row. Either numerical value (<1.0) or string
71                    is accepted. For string, its value should be
72                    'auto' or format 'xx%'. For example, '10%'
73                    is same as 0.1. The 'auto' option estimates
74                    number of OFFs based on t_OFF = sqrt(N) t_ON.
75                    Default is 0.1.
76        npts -- Number of OFF integration in each raster row.
77                Default is -1 (use fraction).
78
79        Note that number of integrations specified by the above
80        parameters will be marked as OFF from both ends. So, twice
81        of specified number/fraction will be marked as OFF. For
82        example, if you specify fraction='10%', resultant fraction
83        of OFF integrations will be 20%.
84       
85        Note also that, if both fraction and npts are specified,
86        specification by npts will come before.
87
88        FOR NON-RASTER:
89        fraction -- Fraction of edge area with respect to whole
90                    observed area. Either numerical value (<1.0)
91                    or string is accepted. For string, its value
92                    should be in 'xx%' format. For example, '10%'
93                    is same as 0.1. Default is 0.1.
94        width -- Pixel width for edge detection. It should be given
95                 as a fraction with respect to the median spatial
96                 separation between neighboring integrations in time.
97                 Default is 0.5. In the most case, default value
98                 will be fine. Larger value will cause worse result.
99                 Smaller value may improve result. However, if too
100                 small value is set (e.g. 1.0e-5), the algorithm may
101                 not work.
102        elongated -- Set True only if observed area is extremely
103                     elongated in one direction. Default is False.
104                     In most cases, default value will be fine.
105        """
106        option = {}
107        if self.israster:
108            keys = [ 'fraction', 'npts' ]
109        else:
110            keys = [ 'fraction', 'width', 'elongated' ]
111        for key in keys:
112            if kwargs.has_key( key ):
113                option[key] = kwargs[key]
114
115        if len(option) > 0:
116            self.marker._setoption( option )
117
118    def mark( self ):
119        """
120        Process data. Edge region is detected according to detection
121        parameters given by setoption(). Then, integrations within
122        edge region will be marked as OFF.
123        """
124        self.marker._detect()
125        self.marker._mark()
126
127    def getresult( self ):
128        """
129        Get result as scantable instance. Returned scantable is
130        copy of input scantable except for that some data are
131        marked as OFF as a result of edge detection and marking.
132        """
133        return scantable( self.marker._get() )
134
135    def save( self, name, overwrite=False ):
136        """
137        Save result as scantable.
138
139        name -- Name of the scantable.
140        overwrite -- Overwrite existing data if True. Default is
141                     False.
142        """
143        s = self.getresult()
144        s.save( name, overwrite=overwrite )
Note: See TracBrowser for help on using the repository browser.