source: trunk/src/SDLineFinder.h@ 343

Last change on this file since 343 was 343, checked in by vor010, 20 years ago

SDLineFinder - now algorithm does many iterations
to ensure that weak lines, which are close to the strong ones, are also found

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1//#---------------------------------------------------------------------------
2//# SDLineFinder.h: A class for automated spectral line search
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# ATNF
6//#
7//# This program is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU General Public License as published by the Free
9//# Software Foundation; either version 2 of the License, or (at your option)
10//# any later version.
11//#
12//# This program is distributed in the hope that it will be useful, but
13//# WITHOUT ANY WARRANTY; without even the implied warranty of
14//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15//# Public License for more details.
16//#
17//# You should have received a copy of the GNU General Public License along
18//# with this program; if not, write to the Free Software Foundation, Inc.,
19//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning this software should be addressed as follows:
22//# Internet email: Malte.Marquarding@csiro.au
23//# Postal address: Malte Marquarding,
24//# Australia Telescope National Facility,
25//# P.O. Box 76,
26//# Epping, NSW, 2121,
27//# AUSTRALIA
28//#
29//# $Id:
30//#---------------------------------------------------------------------------
31#ifndef SDLINEFINDER_H
32#define SDLINEFINDER_H
33
34// STL
35#include <vector>
36#include <list>
37#include <utility>
38#include <exception>
39
40// boost
41#include <boost/python.hpp>
42
43// AIPS++
44#include <casa/aips.h>
45#include <casa/Exceptions/Error.h>
46#include <casa/Arrays/Vector.h>
47#include <casa/Utilities/Assert.h>
48#include <casa/Utilities/CountedPtr.h>
49
50// ASAP
51#include "SDMemTableWrapper.h"
52#include "SDMemTable.h"
53
54namespace asap {
55
56// SDLineFinder - a class for automated spectral line search
57struct SDLineFinder {
58 SDLineFinder() throw();
59 virtual ~SDLineFinder() throw(casa::AipsError);
60
61 // set the scan to work with (in_scan parameter), associated mask (in_mask
62 // parameter) and the edge channel rejection (in_edge parameter)
63 // if in_edge has zero length, all channels chosen by mask will be used
64 // if in_edge has one element only, it represents the number of
65 // channels to drop from both sides of the spectrum
66 // in_edge is introduced for convinience, although all functionality
67 // can be achieved using a spectrum mask only
68 void setScan(const SDMemTableWrapper &in_scan,
69 const std::vector<bool> &in_mask,
70 const boost::python::tuple &in_edge) throw(casa::AipsError);
71
72 // search for spectral lines. Number of lines found is returned
73 int findLines() throw(casa::AipsError);
74
75 // get the mask to mask out all lines that have been found (default)
76 // if invert=true, only channels belong to lines will be unmasked
77 // Note: all channels originally masked by the input mask (in_mask
78 // in setScan) or dropped out by the edge parameter (in_edge
79 // in setScan) are still excluded regardless on the invert option
80 std::vector<bool> getMask(bool invert=false) const throw(casa::AipsError);
81
82 // get range for all lines found. If defunits is true (default), the
83 // same units as used in the scan will be returned (e.g. velocity
84 // instead of channels). If defunits is false, channels will be returned
85 std::vector<int> getLineRanges(bool defunits=true)
86 const throw(casa::AipsError);
87protected:
88 // concatenate two lists preserving the order. If two lines appear to
89 // be adjacent or have a non-void intersection, they are joined into
90 // the new line
91 void addNewSearchResult(const std::list<std::pair<int, int> > &newlines)
92 throw(casa::AipsError);
93
94 // An auxiliary object function to test whether two lines have a non-void
95 // intersection
96 class IntersectsWith : public std::unary_function<pair<int,int>, bool> {
97 std::pair<int,int> line1; // range of the first line
98 // start channel and stop+1
99 public:
100 IntersectsWith(const std::pair<int,int> &in_line1);
101 // return true if line2 intersects with line1 with at least one
102 // common channel, and false otherwise
103 bool operator()(const std::pair<int,int> &line2) const throw();
104 };
105
106 // An auxiliary object function to build a union of several lines
107 // to account for a possibility of merging the nearby lines
108 class BuildUnion {
109 std::pair<int,int> temp_line; // range of the first line
110 // start channel and stop+1
111 public:
112 BuildUnion(const std::pair<int,int> &line1);
113 // update temp_line with a union of temp_line and new_line
114 // provided there is no gap between the lines
115 void operator()(const std::pair<int,int> &new_line) throw();
116 // return the result (temp_line)
117 const std::pair<int,int>& result() const throw();
118 };
119
120 // An auxiliary object function to test whether a specified line
121 // is at lower spectral channels (to preserve the order in the line list)
122 class LaterThan : public std::unary_function<pair<int,int>, bool> {
123 std::pair<int,int> line1; // range of the first line
124 // start channel and stop+1
125 public:
126 LaterThan(const std::pair<int,int> &in_line1);
127
128 // return true if line2 should be placed later than line1
129 // in the ordered list (so, it is at greater channel numbers)
130 bool operator()(const std::pair<int,int> &line2) const throw();
131 };
132
133private:
134 casa::CountedConstPtr<SDMemTable> scan; // the scan to work with
135 casa::Vector<casa::Bool> mask; // associated mask
136 std::pair<int,int> edge; // start and stop+1 channels
137 // to work with
138 casa::Float threshold; // detection threshold - the
139 // minimal signal to noise ratio
140 casa::Double box_size; // size of the box for running
141 // mean calculations, specified as
142 // a fraction of the whole spectrum
143 int min_nchan; // A minimum number of consequtive
144 // channels, which should satisfy
145 // the detection criterion, to be
146 // a detection
147 std::list<std::pair<int, int> > lines; // container of start and stop+1
148 // channels of the spectral lines
149 // a buffer for the spectrum
150 mutable casa::Vector<casa::Float> spectrum;
151
152};
153} // namespace asap
154#endif // #ifndef SDLINEFINDER_H
Note: See TracBrowser for help on using the repository browser.