source: trunk/src/EdgeMarker.cpp@ 3003

Last change on this file since 3003 was 2916, checked in by Takeshi Nakazato, 11 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Replaced STIdxIter classes with STIdxIter2 as much as possible.
Also disabled python interface for STIdxIter since the iterator has
a problem.


File size: 4.2 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 STIdxIter2 iter( st_, cols ) ;
80 while( !iter.pastEnd() ) {
81 uInt current = iter.currentValue().asuInt("IFNO") ;
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 STIdxIter2 iter( st_, cols ) ;
113 ROScalarColumn<Double> timeCol( st_->table(), "TIME" ) ;
114 ROArrayColumn<Double> directionCol( st_->table(), "DIRECTION" ) ;
115 while( !iter.pastEnd() ) {
116 Record current = iter.currentValue() ;
117 Int srcType = current.asInt("SRCTYPE");
118 uInt ifno = current.asuInt("IFNO");
119 os_ << LogIO::DEBUGGING
120 << "BEAMNO=" << current.asuInt("BEAMNO")
121 << " POLNO=" << current.asuInt("POLNO")
122 << " IFNO=" << ifno
123 << " SRCTYPE=" << srcType << LogIO::POST ;
124 // only process ON position and no WVR
125 Vector<uInt> rows = iter.getRows( SHARE ) ;
126 uInt nrow = rows.nelements() ;
127 if ( srcType == Int(SrcType::PSON) && allNE( wvr_, ifno ) && nrow > 0 ) {
128 Vector<Double> t( nrow ) ;
129 Matrix<Double> d( 2, nrow ) ;
130 for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
131 t[irow] = timeCol( rows[irow] ) ;
132 Vector<Double> v( d.column( irow ) ) ;
133 directionCol.get( rows[irow], v ) ;
134 }
135 detector_->setTime( t ) ;
136 detector_->setDirection( d ) ;
137 Vector<uInt> offids = detector_->detect() ;
138 uInt len = offids.nelements() ;
139 for ( uInt i = 0 ; i < len ; i++ ) {
140 off_[noff_++] = rows[offids[i]] ;
141 }
142 }
143 iter.next() ;
144 }
145
146 os_ << "detected " << noff_ << " integrations near edge" << LogIO::POST ;
147}
148
149void EdgeMarker::mark()
150{
151 os_.origin(LogOrigin( "EdgeMarker", "mark", WHERE )) ;
152
153 os_ << "marked " << noff_ << " points as OFF" << LogIO::POST ;
154 ScalarColumn<Int> srcTypeCol( st_->table(), "SRCTYPE" ) ;
155 Int psoff = Int(SrcType::PSOFF) ;
156 Vector<Int> srcType = srcTypeCol.getColumn() ;
157 for ( uInt i = 0 ; i < noff_ ; i++ ) {
158 srcType[off_[i]] = psoff ;
159 }
160 srcTypeCol.putColumn( srcType ) ;
161}
162
163Block<uInt> EdgeMarker::getDetectedRows()
164{
165 uInt *p = off_.storage();
166 return Block<uInt>(noff_, p, False);
167}
168
169CountedPtr<Scantable> EdgeMarker::get()
170{
171 return st_ ;
172}
173
174} // namespace asap
Note: See TracBrowser for help on using the repository browser.