source: trunk/src/EdgeMarker.cpp @ 2613

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

New Development: Yes

JIRA Issue: Yes CAS-2825

Ready for Test: No

Interface Changes: Yes

What Interface Changed: added new python module sd.edgemarker

Test Programs: not available

Put in Release Notes: Yes

Module(s): Module Names change impacts.

Description: Describe your changes here...

New python module edgemarker is available. The edgemarker is a tool to
detect edge of observed area and mark data near edge as OFF. It can be
used to calibrate OTF data without explicit OFF scan.


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