| [297] | 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 |  | 
|---|
|  | 54 | namespace asap { | 
|---|
|  | 55 |  | 
|---|
|  | 56 | // SDLineFinder  -  a class for automated spectral line search | 
|---|
|  | 57 | struct 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); | 
|---|
|  | 87 | protected: | 
|---|
| [331] | 88 | // concatenate two lists preserving the order. If two lines appear to | 
|---|
|  | 89 | // be adjacent, they are joined into the new one | 
|---|
|  | 90 | void addNewSearchResult(const std::list<std::pair<int, int> > &newlines) | 
|---|
|  | 91 | throw(casa::AipsError); | 
|---|
| [297] | 92 | private: | 
|---|
|  | 93 | casa::CountedConstPtr<SDMemTable> scan; // the scan to work with | 
|---|
|  | 94 | casa::Vector<casa::Bool> mask;          // associated mask | 
|---|
|  | 95 | std::pair<int,int> edge;                // start and stop+1 channels | 
|---|
|  | 96 | // to work with | 
|---|
|  | 97 | casa::Float threshold;                  // detection threshold - the | 
|---|
|  | 98 | // minimal signal to noise ratio | 
|---|
|  | 99 | casa::Double box_size;                  // size of the box for running | 
|---|
|  | 100 | // mean calculations, specified as | 
|---|
|  | 101 | // a fraction of the whole spectrum | 
|---|
|  | 102 | int  min_nchan;                         // A minimum number of consequtive | 
|---|
|  | 103 | // channels, which should satisfy | 
|---|
|  | 104 | // the detection criterion, to be | 
|---|
|  | 105 | // a detection | 
|---|
|  | 106 | std::list<std::pair<int, int> > lines;  // container of start and stop+1 | 
|---|
|  | 107 | // channels of the spectral lines | 
|---|
|  | 108 | // a buffer for the spectrum | 
|---|
|  | 109 | mutable casa::Vector<casa::Float>  spectrum; | 
|---|
|  | 110 |  | 
|---|
|  | 111 | }; | 
|---|
|  | 112 | } // namespace asap | 
|---|
|  | 113 | #endif // #ifndef SDLINEFINDER_H | 
|---|