source: trunk/src/EdgeMarker.cpp@ 2616

Last change on this file since 2616 was 2615, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: Yes CAS-2825

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: not available yet

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Logging updated. Priorities for most of the logs are changed to
DEBUGGING since those are mainly for debug use.


File size: 4.0 KB
Line 
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
26using namespace std ;
27using namespace casa ;
28
29namespace asap {
30EdgeMarker::EdgeMarker()
31{
32 EdgeMarker( false ) ;
33}
34
35EdgeMarker::EdgeMarker( bool israster )
36{
37 os_.origin(LogOrigin( "EdgeMarker", "EdgeMarker", WHERE )) ;
38
39 if ( israster ) {
40 os_ << "edge detection by RasterEdgeDetector" << LogIO::POST ;
41 detector_ = new RasterEdgeDetector() ;
42 }
43 else {
44 os_ << "edge detection by GenericEdgeDetector" << LogIO::POST ;
45 detector_ = new GenericEdgeDetector() ;
46 }
47}
48
49EdgeMarker::~EdgeMarker()
50{}
51
52void EdgeMarker::setdata( const CountedPtr<Scantable> &s,
53 const Bool &insitu )
54{
55 if ( insitu ) {
56 st_ = s ;
57 }
58 else {
59 st_ = new Scantable( *s, false ) ;
60 }
61}
62
63void EdgeMarker::initDetect()
64{
65 off_.resize( st_->nrow() ) ;
66 noff_ = 0 ;
67}
68
69void EdgeMarker::examine()
70{
71 os_.origin(LogOrigin( "EdgeMarker", "examine", WHERE )) ;
72
73 // exclude WVR
74 vector<uInt> wvr ;
75 {
76 ROArrayColumn<uChar> flagCol( st_->table(), "FLAGTRA" ) ;
77 vector<string> cols( 1, "IFNO" ) ;
78 STIdxIterAcc iter( st_, cols ) ;
79 while( !iter.pastEnd() ) {
80 uInt current = iter.current()[0] ;
81 uInt firstRow = iter.getRows()[0] ;
82 uInt nchan = flagCol( firstRow ).nelements() ;
83 if ( nchan == 4 )
84 wvr.push_back( current ) ;
85 iter.next() ;
86 }
87 }
88 wvr_ = Vector<uInt>( wvr ) ;
89
90 if ( wvr_.nelements() > 0 ) {
91 os_ << LogIO::DEBUGGING
92 << "IFNO for WVR scan: " << wvr_ << LogIO::POST ;
93 }
94}
95
96void EdgeMarker::setoption( const Record &option )
97{
98 detector_->setOption( option ) ;
99}
100
101void EdgeMarker::detect()
102{
103 os_.origin(LogOrigin( "EdgeMarker", "detect", WHERE )) ;
104
105 initDetect() ;
106 vector<string> cols( 4 ) ;
107 cols[0] = "BEAMNO" ;
108 cols[1] = "POLNO" ;
109 cols[2] = "IFNO" ;
110 cols[3] = "SRCTYPE" ;
111 STIdxIterExAcc iter( st_, cols ) ;
112 ROScalarColumn<Double> timeCol( st_->table(), "TIME" ) ;
113 ROArrayColumn<Double> directionCol( st_->table(), "DIRECTION" ) ;
114 while( !iter.pastEnd() ) {
115 Vector<uInt> current = iter.current() ;
116 Int srcType = iter.getSrcType() ;
117 os_ << LogIO::DEBUGGING
118 << "BEAMNO=" << current[0]
119 << " POLNO=" << current[1]
120 << " IFNO=" << current[2]
121 << " SRCTYPE=" << srcType << LogIO::POST ;
122 // only process ON position and no WVR
123 Vector<uInt> rows = iter.getRows( SHARE ) ;
124 uInt nrow = rows.nelements() ;
125 if ( srcType == Int(SrcType::PSON) && allNE( wvr_, current[2] ) && nrow > 0 ) {
126 Vector<Double> t( nrow ) ;
127 Matrix<Double> d( 2, nrow ) ;
128 for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
129 t[irow] = timeCol( rows[irow] ) ;
130 Vector<Double> v( d.column( irow ) ) ;
131 directionCol.get( rows[irow], v ) ;
132 }
133 detector_->setTime( t ) ;
134 detector_->setDirection( d ) ;
135 Vector<uInt> offids = detector_->detect() ;
136 uInt len = offids.nelements() ;
137 for ( uInt i = 0 ; i < len ; i++ ) {
138 off_[noff_++] = rows[offids[i]] ;
139 }
140 }
141 iter.next() ;
142 }
143
144 os_ << "detected " << noff_ << " integrations near edge" << LogIO::POST ;
145}
146
147void EdgeMarker::mark()
148{
149 os_.origin(LogOrigin( "EdgeMarker", "mark", WHERE )) ;
150
151 os_ << "marked " << noff_ << " points as OFF" << LogIO::POST ;
152 ScalarColumn<Int> srcTypeCol( st_->table(), "SRCTYPE" ) ;
153 Int psoff = Int(SrcType::PSOFF) ;
154 Vector<Int> srcType = srcTypeCol.getColumn() ;
155 for ( uInt i = 0 ; i < noff_ ; i++ ) {
156 srcType[off_[i]] = psoff ;
157 }
158 srcTypeCol.putColumn( srcType ) ;
159}
160
161CountedPtr<Scantable> EdgeMarker::get()
162{
163 return st_ ;
164}
165
166} // namespace asap
Note: See TracBrowser for help on using the repository browser.