source: trunk/src/EdgeMarker.cpp@ 2779

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

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs:

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

First version of Calibrator class for OTF scan without OFF.


File size: 4.2 KB
RevLine 
[2613]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{
[2615]32 EdgeMarker( false ) ;
[2613]33}
34
35EdgeMarker::EdgeMarker( bool israster )
36{
[2615]37 os_.origin(LogOrigin( "EdgeMarker", "EdgeMarker", WHERE )) ;
38
39 if ( israster ) {
40 os_ << "edge detection by RasterEdgeDetector" << LogIO::POST ;
[2613]41 detector_ = new RasterEdgeDetector() ;
[2615]42 }
43 else {
44 os_ << "edge detection by GenericEdgeDetector" << LogIO::POST ;
[2613]45 detector_ = new GenericEdgeDetector() ;
[2615]46 }
[2613]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{
[2615]71 os_.origin(LogOrigin( "EdgeMarker", "examine", WHERE )) ;
72
[2613]73 // exclude WVR
[2617]74 Block<uInt> wvr( st_->getIFNos().size() ) ;
75 uInt n = 0 ;
[2613]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 )
[2617]85 wvr[n++] = current ;
[2613]86 iter.next() ;
87 }
88 }
[2617]89 wvr_.takeStorage( IPosition(1,n), wvr.storage(), COPY ) ;
[2615]90
91 if ( wvr_.nelements() > 0 ) {
92 os_ << LogIO::DEBUGGING
93 << "IFNO for WVR scan: " << wvr_ << LogIO::POST ;
94 }
[2613]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() ;
[2615]118 os_ << LogIO::DEBUGGING
119 << "BEAMNO=" << current[0]
120 << " POLNO=" << current[1]
121 << " IFNO=" << current[2]
122 << " SRCTYPE=" << srcType << LogIO::POST ;
[2613]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 }
[2615]144
145 os_ << "detected " << noff_ << " integrations near edge" << LogIO::POST ;
[2613]146}
147
148void EdgeMarker::mark()
149{
[2615]150 os_.origin(LogOrigin( "EdgeMarker", "mark", WHERE )) ;
151
152 os_ << "marked " << noff_ << " points as OFF" << LogIO::POST ;
[2613]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
[2757]162Block<uInt> EdgeMarker::getDetectedRows()
163{
164 uInt *p = off_.storage();
165 return Block<uInt>(noff_, p, False);
166}
167
[2613]168CountedPtr<Scantable> EdgeMarker::get()
169{
170 return st_ ;
171}
172
173} // namespace asap
Note: See TracBrowser for help on using the repository browser.