source: trunk/python/asaplinefind.py @ 369

Last change on this file since 369 was 369, checked in by vor010, 19 years ago

SDLineFinder: bug corrections, setOption method
has been added + fitting baseline at each iterations to cope with bad
baselines

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1import _asap
2
3class linefinder:
4    """
5    The class for automated spectral line search in ASAP.
6    """
7
8    def __init__(self):
9        """
10        Create a line finder object.
11        """
12        self.finder = _asap.linefinder()
13        return
14
15    def set_options(self,threshold=1.7320508075688772,min_nchan=3,
16        avg_limit=8,box_size=0.2):
17        """
18        Set the parameters of the algorithm
19        Parameters:
20             threshold    a single channel S/N ratio above which the
21                          channel is considered to be a detection
22                          Default is sqrt(3), which together with
23                          min_nchan=3 gives a 3-sigma criterion
24             min_nchan    a minimal number of consequtive channels,
25                          which should satisfy a threshold criterion to
26                          be a detection. Default is 3.
27             avg_limit    A number of consequtive channels not greater than
28                          this parameter can be averaged to search for
29                          broad lines. Default is 8.
30             box_size     A running mean box size specified as a fraction
31                          of the total spectrum length. Default is 1/5
32        Note:  For bad baselines threshold should be increased,
33               and avg_limit decreased (or even switched off completely by
34               setting this parameter to 1) to avoid detecting baseline
35               undulations instead of real lines. 
36        """
37        self.finder.setoptions(threshold,min_nchan,avg_limit,box_size)
38        return
39             
40    def set_scan(self,scan,mask=None,edge=(0,0)):
41        """
42        Set the 'data' (scantable) to work with.
43        Parameters:
44             scan:    a scantable
45             mask:       an optional mask retreived from scantable
46             edge:       an optional number of channel to drop at
47                         the edge of spectrum. If only one value is
48                         specified, the same number will be dropped from
49                         both sides of the spectrum. Default is to keep
50                         all channels
51        """
52        if not scan:
53           raise RuntimeError, 'Please give a correct scan'
54        if len(edge)>2:
55           raise RuntimeError, "The edge parameter should have two \
56           or less elements"
57        if mask is None:
58            from numarray import ones
59            self.finder.setscan(scan,ones(scan.nchan()),edge)
60        else:   
61            self.finder.setscan(scan,mask,edge)
62        return
63    def find_lines(self):
64        """
65        Search for spectral lines in the scan assigned in set_scan.
66        A number of lines found will be returned
67        """
68        return self.finder.findlines()
69    def get_mask(self,invert=False):
70        """
71        Get the mask to mask out all lines that have been found (default)
72
73        Parameters:
74              invert  if True, only channels belong to lines will be unmasked
75
76        Note: all channels originally masked by the input mask or
77              dropped out by the edge parameter will still be excluded
78              regardless on the invert option
79        """
80        return self.finder.getmask(invert)
81    def get_ranges(self,defunits=True):
82        """
83        Get ranges (start and end channels or velocities) for all spectral
84        lines found.
85
86        Parameters:
87              defunits  if True (default), the range will use the same units
88                        as set for the scan (e.g. LSR velocity)
89                        if False, the range will be expressed in channels
90        """
91        return self.finder.getlineranges(defunits)
Note: See TracBrowser for help on using the repository browser.