1 | // |
---|
2 | // C++ Implementation: EdgeMarker |
---|
3 | // |
---|
4 | // Description: |
---|
5 | // |
---|
6 | // |
---|
7 | // Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2012 |
---|
8 | // |
---|
9 | // Copyright: See COPYING file that comes with this distribution |
---|
10 | // |
---|
11 | // |
---|
12 | #include <vector> |
---|
13 | |
---|
14 | #include <casa/BasicSL/String.h> |
---|
15 | #include <casa/Containers/Record.h> |
---|
16 | #include <casa/Utilities/GenSort.h> |
---|
17 | #include <casa/Arrays/ArrayIO.h> |
---|
18 | |
---|
19 | #include <atnf/PKSIO/SrcType.h> |
---|
20 | |
---|
21 | #include "EdgeMarker.h" |
---|
22 | #include "RasterEdgeDetector.h" |
---|
23 | #include "GenericEdgeDetector.h" |
---|
24 | #include "STIdxIter.h" |
---|
25 | |
---|
26 | using namespace std ; |
---|
27 | using namespace casa ; |
---|
28 | |
---|
29 | namespace asap { |
---|
30 | EdgeMarker::EdgeMarker() |
---|
31 | { |
---|
32 | detector_ = new GenericEdgeDetector() ; |
---|
33 | } |
---|
34 | |
---|
35 | EdgeMarker::EdgeMarker( bool israster ) |
---|
36 | { |
---|
37 | if ( israster ) |
---|
38 | detector_ = new RasterEdgeDetector() ; |
---|
39 | else |
---|
40 | detector_ = new GenericEdgeDetector() ; |
---|
41 | } |
---|
42 | |
---|
43 | EdgeMarker::~EdgeMarker() |
---|
44 | {} |
---|
45 | |
---|
46 | void EdgeMarker::setdata( const CountedPtr<Scantable> &s, |
---|
47 | const Bool &insitu ) |
---|
48 | { |
---|
49 | if ( insitu ) { |
---|
50 | st_ = s ; |
---|
51 | } |
---|
52 | else { |
---|
53 | st_ = new Scantable( *s, false ) ; |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | void EdgeMarker::initDetect() |
---|
58 | { |
---|
59 | off_.resize( st_->nrow() ) ; |
---|
60 | noff_ = 0 ; |
---|
61 | } |
---|
62 | |
---|
63 | void EdgeMarker::examine() |
---|
64 | { |
---|
65 | // exclude WVR |
---|
66 | vector<uInt> wvr ; |
---|
67 | { |
---|
68 | ROArrayColumn<uChar> flagCol( st_->table(), "FLAGTRA" ) ; |
---|
69 | vector<string> cols( 1, "IFNO" ) ; |
---|
70 | STIdxIterAcc iter( st_, cols ) ; |
---|
71 | while( !iter.pastEnd() ) { |
---|
72 | uInt current = iter.current()[0] ; |
---|
73 | uInt firstRow = iter.getRows()[0] ; |
---|
74 | uInt nchan = flagCol( firstRow ).nelements() ; |
---|
75 | if ( nchan == 4 ) |
---|
76 | wvr.push_back( current ) ; |
---|
77 | iter.next() ; |
---|
78 | } |
---|
79 | } |
---|
80 | wvr_ = Vector<uInt>( wvr ) ; |
---|
81 | os_.origin(LogOrigin( "EdgeMarker", "examine", WHERE )) ; |
---|
82 | os_ << "IFNO for WVR scan: " << wvr_ << LogIO::POST ; |
---|
83 | } |
---|
84 | |
---|
85 | void EdgeMarker::setoption( const Record &option ) |
---|
86 | { |
---|
87 | detector_->setOption( option ) ; |
---|
88 | } |
---|
89 | |
---|
90 | void EdgeMarker::detect() |
---|
91 | { |
---|
92 | os_.origin(LogOrigin( "EdgeMarker", "detect", WHERE )) ; |
---|
93 | |
---|
94 | initDetect() ; |
---|
95 | vector<string> cols( 4 ) ; |
---|
96 | cols[0] = "BEAMNO" ; |
---|
97 | cols[1] = "POLNO" ; |
---|
98 | cols[2] = "IFNO" ; |
---|
99 | cols[3] = "SRCTYPE" ; |
---|
100 | STIdxIterExAcc iter( st_, cols ) ; |
---|
101 | ROScalarColumn<Double> timeCol( st_->table(), "TIME" ) ; |
---|
102 | ROArrayColumn<Double> directionCol( st_->table(), "DIRECTION" ) ; |
---|
103 | while( !iter.pastEnd() ) { |
---|
104 | Vector<uInt> current = iter.current() ; |
---|
105 | Int srcType = iter.getSrcType() ; |
---|
106 | os_ << "BEAMNO=" << current[0] |
---|
107 | << ",POLNO=" << current[1] |
---|
108 | << ",IFNO=" << current[2] |
---|
109 | << ",SRCTYPE=" << srcType << LogIO::POST ; |
---|
110 | // only process ON position and no WVR |
---|
111 | Vector<uInt> rows = iter.getRows( SHARE ) ; |
---|
112 | uInt nrow = rows.nelements() ; |
---|
113 | if ( srcType == Int(SrcType::PSON) && allNE( wvr_, current[2] ) && nrow > 0 ) { |
---|
114 | Vector<Double> t( nrow ) ; |
---|
115 | Matrix<Double> d( 2, nrow ) ; |
---|
116 | for ( uInt irow = 0 ; irow < nrow ; irow++ ) { |
---|
117 | t[irow] = timeCol( rows[irow] ) ; |
---|
118 | Vector<Double> v( d.column( irow ) ) ; |
---|
119 | directionCol.get( rows[irow], v ) ; |
---|
120 | } |
---|
121 | detector_->setTime( t ) ; |
---|
122 | detector_->setDirection( d ) ; |
---|
123 | Vector<uInt> offids = detector_->detect() ; |
---|
124 | uInt len = offids.nelements() ; |
---|
125 | for ( uInt i = 0 ; i < len ; i++ ) { |
---|
126 | off_[noff_++] = rows[offids[i]] ; |
---|
127 | } |
---|
128 | } |
---|
129 | iter.next() ; |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | void EdgeMarker::mark() |
---|
134 | { |
---|
135 | ScalarColumn<Int> srcTypeCol( st_->table(), "SRCTYPE" ) ; |
---|
136 | Int psoff = Int(SrcType::PSOFF) ; |
---|
137 | Vector<Int> srcType = srcTypeCol.getColumn() ; |
---|
138 | for ( uInt i = 0 ; i < noff_ ; i++ ) { |
---|
139 | srcType[off_[i]] = psoff ; |
---|
140 | } |
---|
141 | srcTypeCol.putColumn( srcType ) ; |
---|
142 | } |
---|
143 | |
---|
144 | CountedPtr<Scantable> EdgeMarker::get() |
---|
145 | { |
---|
146 | return st_ ; |
---|
147 | } |
---|
148 | |
---|
149 | } // namespace asap |
---|