casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LineFinder.h
Go to the documentation of this file.
1 //# --------------------------------------------------------------------
2 //# LineFinder.h: this defines utility functions of line finding
3 //# --------------------------------------------------------------------
4 //# Copyright (C) 2015
5 //# National Astronomical Observatory of Japan
6 //#
7 //# This library is free software; you can redistribute it and/or modify it
8 //# under the terms of the GNU Library General Public License as published by
9 //# the Free Software Foundation; either version 2 of the License, or (at your
10 //# option) any later version.
11 //#
12 //# This library is distributed in the hope that it will be useful, but WITHOUT
13 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 //# License for more details.
16 //#
17 //# You should have received a copy of the GNU Library General Public License
18 //# along with this library; if not, write to the Free Software Foundation,
19 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20 //#
21 //# Correspondence concerning AIPS++ should be addressed as follows:
22 //# Internet email: aips2-request@nrao.edu.
23 //# Postal address: AIPS++ Project Office
24 //# National Radio Astronomy Observatory
25 //# 520 Edgemont Road
26 //# Charlottesville, VA 22903-2475 USA
27 //#
28 //# $Id$
29 #ifndef _CASA_LINEFINDER_H_
30 #define _CASA_LINEFINDER_H_
31 
32 #include <list>
33 
34 #include <casa/aipstype.h>
35 #include <casa/Arrays/Vector.h>
36 
37 namespace casa { //# NAMESPACE CASA - BEGIN
38 
39 namespace linefinder {
40 /*
41  * Find spectral lines of a spectrum using a threshold based on median
42  * absolute deviation (MAD).
43  * The median of lower 80% of MAD values are used to define the
44  * threshold of line channels.
45  *
46  * @param[in] num_data : the number of elements in data and mask vector.
47  * @param[in] data : a float vector of data to detect lines. should be aligned.
48  * @param[in] mask : a boolean vector which indecates if the corresponding elements
49  * in data should be used in line detection.
50  * Note mask is modified in the function. Edge channels are masked.
51  * @param[in] threshold: a multiplication factor to define threshold.
52  * @param[in] max_iteration : the maximum number of iteration to detect line,
53  * and eliminate the line channels to redefine MAD array.
54  * @param[in] minwidth : minimum line width (in channel) to detect as lines
55  * @param[in] maxwidth : maximum line width (in channel) to detect as lines
56  * @param[in] avg_limit : maximum width of channel binning to run line detection.
57  * @param[in] edge : the number of elements at the begining and end of data array
58  * that should be ignored in line detection.
59  * @return a list of line channel ranges
60  *
61  * [overview of line detection algorithm]
62  * 1. Median absolute deviation of each data element is calculated and
63  * defined as MAD array.
64  * 2. Calculate median of MAD array. Only lower 80% of valid elements
65  * (mask=true and not in lines) are used to calculate the value.
66  * 3. Compare each element of MAD array and the product of
67  * threshold and median of MAD. Elements that exceeds
68  * the threshold value are detected as channels.
69  * 4. Line range modifications,e.g., extend line ranges for wing component,
70  * merge overlapping lines, and check if line meets maxwidth and
71  * minwidth criteria.
72  * 5. Go to step 1 and repeat line detection by removing line channels
73  * from MAD calculations. stop iteration either if loop reaches
74  * max_iteration, no lines found in the bin level, no new line channel
75  * is detected, or MAD threshold increased compared to the previous
76  * iteration.
77  * 6. bin data with 4 times coarser width and repeat line detection again
78  * untill bin width reaches to avg_limit.
79  * Merge line ranges detected in the current bin level to previous result.
80  */
81 std::list<std::pair<size_t, size_t>> MADLineFinder(size_t const num_data,
82  float const data[/*num_data*/], bool mask[/*num_data*/],
83  float const threshold, uint8_t max_iteration, size_t const minwidth,
84  size_t const maxwidth, size_t const avg_limit,
85  std::pair<size_t, size_t> edge);
86 
87 /*
88  Create a boolean mask vector from ranges.
89  mask : a boolean vector that stores output mask. see below for
90  the values set to each elements of mask.
91  ranges : a list of start and end idices pairs to set value in mask.
92  invert : a flag to define values of elements inbetween ranges.
93  the elements of mask vector whose values are inbetween
94  one of start end idices in ranges list are set to
95  true if invert=false (default), otherwise, false.
96  initialize : whether or not initialize all elements in mask vector.
97  when initialize=true, mask array is initialized by
98  false if invert=false (default) or true if invert=true.
99  when initilize=false, only elements inbetween ranges
100  list will be modified.
101  */
102 void getMask(size_t const num_mask, bool mask[/*num_mask*/],
103  std::list<std::pair<size_t, size_t>>& ranges, bool invert = false,
104  bool initialize = true);
105 }
106 } //# NAMESPACE CASA - END
107 
108 #endif /* _CASA_LINEFINDER_H_ */
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
std::list< std::pair< size_t, size_t > > MADLineFinder(size_t const num_data, float const data[], bool mask[], float const threshold, uint8_t max_iteration, size_t const minwidth, size_t const maxwidth, size_t const avg_limit, std::pair< size_t, size_t > edge)
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
void getMask(size_t const num_mask, bool mask[], std::list< std::pair< size_t, size_t >> &ranges, bool invert=false, bool initialize=true)