[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 |
|
---|
| 26 | using namespace std ;
|
---|
[3106] | 27 | using namespace casacore;
|
---|
[2613] | 28 |
|
---|
| 29 | namespace asap {
|
---|
| 30 | EdgeMarker::EdgeMarker()
|
---|
| 31 | {
|
---|
[2615] | 32 | EdgeMarker( false ) ;
|
---|
[2613] | 33 | }
|
---|
| 34 |
|
---|
| 35 | EdgeMarker::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 |
|
---|
| 49 | EdgeMarker::~EdgeMarker()
|
---|
| 50 | {}
|
---|
| 51 |
|
---|
| 52 | void 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 |
|
---|
| 63 | void EdgeMarker::initDetect()
|
---|
| 64 | {
|
---|
| 65 | off_.resize( st_->nrow() ) ;
|
---|
| 66 | noff_ = 0 ;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | void 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" ) ;
|
---|
[2916] | 79 | STIdxIter2 iter( st_, cols ) ;
|
---|
[2613] | 80 | while( !iter.pastEnd() ) {
|
---|
[2916] | 81 | uInt current = iter.currentValue().asuInt("IFNO") ;
|
---|
[2613] | 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 |
|
---|
| 97 | void EdgeMarker::setoption( const Record &option )
|
---|
| 98 | {
|
---|
| 99 | detector_->setOption( option ) ;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | void 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" ;
|
---|
[2916] | 112 | STIdxIter2 iter( st_, cols ) ;
|
---|
[2613] | 113 | ROScalarColumn<Double> timeCol( st_->table(), "TIME" ) ;
|
---|
| 114 | ROArrayColumn<Double> directionCol( st_->table(), "DIRECTION" ) ;
|
---|
| 115 | while( !iter.pastEnd() ) {
|
---|
[2916] | 116 | Record current = iter.currentValue() ;
|
---|
| 117 | Int srcType = current.asInt("SRCTYPE");
|
---|
| 118 | uInt ifno = current.asuInt("IFNO");
|
---|
[2615] | 119 | os_ << LogIO::DEBUGGING
|
---|
[2916] | 120 | << "BEAMNO=" << current.asuInt("BEAMNO")
|
---|
| 121 | << " POLNO=" << current.asuInt("POLNO")
|
---|
| 122 | << " IFNO=" << ifno
|
---|
[2615] | 123 | << " SRCTYPE=" << srcType << LogIO::POST ;
|
---|
[2613] | 124 | // only process ON position and no WVR
|
---|
| 125 | Vector<uInt> rows = iter.getRows( SHARE ) ;
|
---|
| 126 | uInt nrow = rows.nelements() ;
|
---|
[2916] | 127 | if ( srcType == Int(SrcType::PSON) && allNE( wvr_, ifno ) && nrow > 0 ) {
|
---|
[2613] | 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 | }
|
---|
[2615] | 145 |
|
---|
| 146 | os_ << "detected " << noff_ << " integrations near edge" << LogIO::POST ;
|
---|
[2613] | 147 | }
|
---|
| 148 |
|
---|
| 149 | void EdgeMarker::mark()
|
---|
| 150 | {
|
---|
[2615] | 151 | os_.origin(LogOrigin( "EdgeMarker", "mark", WHERE )) ;
|
---|
| 152 |
|
---|
| 153 | os_ << "marked " << noff_ << " points as OFF" << LogIO::POST ;
|
---|
[2613] | 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 |
|
---|
[2757] | 163 | Block<uInt> EdgeMarker::getDetectedRows()
|
---|
| 164 | {
|
---|
| 165 | uInt *p = off_.storage();
|
---|
| 166 | return Block<uInt>(noff_, p, False);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
[2613] | 169 | CountedPtr<Scantable> EdgeMarker::get()
|
---|
| 170 | {
|
---|
| 171 | return st_ ;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | } // namespace asap
|
---|