source: trunk/python/edgemarker.py@ 2623

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

New Development: No

JIRA Issue: Yes CAS-2825

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: not available

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Help document updated.


File size: 5.5 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 slightly 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 (i.e. constructor
67 is called with israster=True or False).
68
69 === for raster (israster=True) ===
70 fraction -- Fraction of OFF integration in each raster
71 row. Either numerical value (<1.0) or string
72 is accepted. For string, its value should be
73 'auto' or format 'xx%'. For example, '10%'
74 is same as 0.1. The 'auto' option estimates
75 number of OFFs based on t_OFF = sqrt(N) t_ON.
76 Default is 0.1.
77 npts -- Number of OFF integration in each raster row.
78 Default is -1 (use fraction).
79
80 Note that number of integrations specified by the above
81 parameters will be marked as OFF from both ends. So, twice
82 of specified number/fraction will be marked as OFF. For
83 example, if you specify fraction='10%', resultant fraction
84 of OFF integrations will be 20%.
85
86 Note also that, if both fraction and npts are specified,
87 specification by npts will come before.
88
89 === for non-raster (israster=False) ===
90 fraction -- Fraction of edge area with respect to whole
91 observed area. Either numerical value (<1.0)
92 or string is accepted. For string, its value
93 should be in 'xx%' format. For example, '10%'
94 is same as 0.1. Default is 0.1.
95 width -- Pixel width for edge detection. It should be given
96 as a fraction of the median spatial separation
97 between neighboring integrations in time. Default
98 is 0.5. In the most case, default value will be fine.
99 Larger value will cause worse result. Smaller value
100 may improve result. However, if too small value is
101 set (e.g. 1.0e-5), the algorithm may 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.