source: trunk/src/EdgeMarker.cpp@ 2736

Last change on this file since 2736 was 2617, 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

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Minor refactoring.


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 Block<uInt> wvr( st_->getIFNos().size() ) ;
75 uInt n = 0 ;
76 {
77 ROArrayColumn<uChar> flagCol( st_->table(), "FLAGTRA" ) ;
78 vector<string> cols( 1, "IFNO" ) ;
79 STIdxIterAcc iter( st_, cols ) ;
80 while( !iter.pastEnd() ) {
81 uInt current = iter.current()[0] ;
82 uInt firstRow = iter.getRows()[0] ;
83 uInt nchan = flagCol( firstRow ).nelements() ;
84 if ( nchan == 4 )
85 wvr[n++] = current ;
86 iter.next() ;
87 }
88 }
89 wvr_.takeStorage( IPosition(1,n), wvr.storage(), COPY ) ;
90
91 if ( wvr_.nelements() > 0 ) {
92 os_ << LogIO::DEBUGGING
93 << "IFNO for WVR scan: " << wvr_ << LogIO::POST ;
94 }
95}
96
97void EdgeMarker::setoption( const Record &option )
98{
99 detector_->setOption( option ) ;
100}
101
102void EdgeMarker::detect()
103{
104 os_.origin(LogOrigin( "EdgeMarker", "detect", WHERE )) ;
105
106 initDetect() ;
107 vector<string> cols( 4 ) ;
108 cols[0] = "BEAMNO" ;
109 cols[1] = "POLNO" ;
110 cols[2] = "IFNO" ;
111 cols[3] = "SRCTYPE" ;
112 STIdxIterExAcc iter( st_, cols ) ;
113 ROScalarColumn<Double> timeCol( st_->table(), "TIME" ) ;
114 ROArrayColumn<Double> directionCol( st_->table(), "DIRECTION" ) ;
115 while( !iter.pastEnd() ) {
116 Vector<uInt> current = iter.current() ;
117 Int srcType = iter.getSrcType() ;
118 os_ << LogIO::DEBUGGING
119 << "BEAMNO=" << current[0]
120 << " POLNO=" << current[1]
121 << " IFNO=" << current[2]
122 << " SRCTYPE=" << srcType << LogIO::POST ;
123 // only process ON position and no WVR
124 Vector<uInt> rows = iter.getRows( SHARE ) ;
125 uInt nrow = rows.nelements() ;
126 if ( srcType == Int(SrcType::PSON) && allNE( wvr_, current[2] ) && nrow > 0 ) {
127 Vector<Double> t( nrow ) ;
128 Matrix<Double> d( 2, nrow ) ;
129 for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
130 t[irow] = timeCol( rows[irow] ) ;
131 Vector<Double> v( d.column( irow ) ) ;
132 directionCol.get( rows[irow], v ) ;
133 }
134 detector_->setTime( t ) ;
135 detector_->setDirection( d ) ;
136 Vector<uInt> offids = detector_->detect() ;
137 uInt len = offids.nelements() ;
138 for ( uInt i = 0 ; i < len ; i++ ) {
139 off_[noff_++] = rows[offids[i]] ;
140 }
141 }
142 iter.next() ;
143 }
144
145 os_ << "detected " << noff_ << " integrations near edge" << LogIO::POST ;
146}
147
148void EdgeMarker::mark()
149{
150 os_.origin(LogOrigin( "EdgeMarker", "mark", WHERE )) ;
151
152 os_ << "marked " << noff_ << " points as OFF" << LogIO::POST ;
153 ScalarColumn<Int> srcTypeCol( st_->table(), "SRCTYPE" ) ;
154 Int psoff = Int(SrcType::PSOFF) ;
155 Vector<Int> srcType = srcTypeCol.getColumn() ;
156 for ( uInt i = 0 ; i < noff_ ; i++ ) {
157 srcType[off_[i]] = psoff ;
158 }
159 srcTypeCol.putColumn( srcType ) ;
160}
161
162CountedPtr<Scantable> EdgeMarker::get()
163{
164 return st_ ;
165}
166
167} // namespace asap
Note: See TracBrowser for help on using the repository browser.