source: trunk/src/NROFiller.cpp @ 2272

Last change on this file since 2272 was 2272, checked in by Takeshi Nakazato, 13 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...

Need some conversions for weather monitor data.

temperature: C->K
windaz: deg->rad
humidity: P[H2O] -> relative humidity


File size: 6.9 KB
Line 
1//
2// C++ Interface: NROFiller
3//
4// Description:
5// This class is a concrete class that derives from FillerBase class.
6// The class implements the following methods to be able to read NRO
7// data (45m and ASTE).
8//
9//    open()
10//    close()
11//    fill()
12//
13//
14// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2010
15//
16// Copyright: See COPYING file that comes with this distribution
17//
18//
19
20#include "NROFiller.h"
21#include "STHeader.h"
22#include <casa/Containers/Record.h>
23#include <casa/Quanta/MVTime.h>
24#include <atnf/PKSIO/SrcType.h>
25
26using namespace casa;
27
28namespace asap
29{
30NROFiller::NROFiller(CountedPtr<Scantable> stable)
31  : FillerBase(stable)
32{
33}
34
35NROFiller::~NROFiller()
36{
37  close() ;
38}
39
40  bool NROFiller::open(const std::string& filename, const Record& rec)
41{
42  bool status = true ;
43
44  // get appropriate reader object
45  String format ;
46  reader_ = getNROReader( filename, format ) ;
47  if ( reader_.null() == True ) {
48    status = false ;
49    return status ;
50  } 
51
52  // get header information
53  STHeader hdr ;
54  if ( reader_->getHeaderInfo( hdr.nchan,
55                               hdr.npol,
56                               hdr.nif,
57                               hdr.nbeam,
58                               hdr.observer,
59                               hdr.project,
60                               hdr.obstype,
61                               hdr.antennaname,
62                               hdr.antennaposition,
63                               hdr.equinox,
64                               hdr.freqref,
65                               hdr.reffreq,
66                               hdr.bandwidth,
67                               hdr.utc,
68                               hdr.fluxunit,
69                               hdr.epoch,
70                               hdr.poltype ) ) {
71    status = false ;
72    return status ;
73  }
74
75  // 2010/07/30 TBD: Do we need to set frame here?
76  table_->frequencies().setFrame( hdr.freqref, true ) ;
77  table_->frequencies().setFrame( hdr.freqref, false ) ;
78
79  // set Header
80  setHeader( hdr ) ;
81
82  return status ;
83}
84
85void NROFiller::fill()
86{
87  // for each row
88  uInt nRow = reader_->getRowNum() ;
89  vector< vector<double > > freqs ;
90  uInt scanno ;
91  uInt cycleno ;
92  uInt ifno ;
93  uInt beamno ;
94  uInt polno ;
95  vector<double> fqs ;
96  Vector<Double> restfreq ;
97  uInt refbeamno ;
98  Double scantime ;
99  Double interval ;
100  String srcname ;
101  String fieldname ;
102  Array<Float> spectra ;
103  Array<uChar> flagtra ;
104  Array<Float> tsys ;
105  Array<Double> direction ;
106  Float azimuth ;
107  Float elevation ;
108  Float parangle ;
109  Float opacity ;
110  uInt tcalid ;
111  Int fitid ;
112  uInt focusid ;
113  Float temperature ;
114  Float pressure ;
115  Float humidity ;
116  Float windvel ;
117  Float winddir ;
118  Double srcvel ;
119  Array<Double> propermotion ;
120  Vector<Double> srcdir ;
121  Array<Double> scanrate ;
122  Int rowCount = 0 ;
123
124  STHeader header = table_->getHeader() ;
125  String obsType = header.obstype.substr( 0, 3 ) ;
126  Vector<Float> defaultTcal( 1, 1.0 ) ;
127  String tcalTime = MVTime( header.utc ).string( MVTime::YMD ) ;
128  for ( Int irow = 0 ; irow < (Int)nRow ; irow++ ) {
129    // check scan intent
130    string scanType = reader_->getScanType( irow ) ;
131    SrcType::type srcType = SrcType::NOTYPE ;
132
133    // skip "ZERO" scan
134    if ( scanType.compare( 0, 4, "ZERO" ) == 0 ) {
135      continue ;
136    }
137
138    // set srcType
139    if ( obsType == "POS" || obsType == "BEA" ) {
140      if ( scanType.compare( 0, 2, "ON" ) == 0 )
141        srcType = SrcType::PSON ;
142      else if ( scanType.compare( 0, 3, "OFF" ) == 0 )
143        srcType = SrcType::PSOFF ;
144    }
145    else if ( obsType == "FRE" ) {
146      if ( scanType.compare( 0, 2, "ON" ) == 0 )
147        srcType = SrcType::FSON ;
148      else if ( scanType.compare( 0, 3, "OFF" ) == 0 )
149        srcType = SrcType::FSOFF ;
150    }
151 
152    // get scan ifnromation
153    if ( reader_->getScanInfo( irow,
154                               scanno,
155                               cycleno,
156                               ifno,
157                               beamno,
158                               polno,
159                               fqs,
160                               restfreq,
161                               refbeamno,
162                               scantime,
163                               interval,
164                               srcname,
165                               fieldname,
166                               spectra,
167                               flagtra,
168                               tsys,
169                               direction,
170                               azimuth,
171                               elevation,
172                               parangle,
173                               opacity,
174                               tcalid,
175                               fitid,
176                               focusid,
177                               temperature,
178                               pressure,
179                               humidity,
180                               windvel,
181                               winddir,
182                               srcvel,
183                               propermotion,
184                               srcdir,
185                               scanrate ) ) {
186      throw AipsError( "Failed to read scan record" ) ;
187      return ;
188    }
189
190    // set IDs and subtable rows
191    // FREQUENCIES subtable row
192    setFrequency( (Double)fqs[0], (Double)fqs[1], (Double)fqs[2] ) ;
193
194    // MOLECULES subtable row
195    setMolecule( restfreq ) ;
196
197    // FOCUS subtable row
198    setFocus( parangle ) ;
199
200    // WEATHER subtable row
201    float p = 7.5 * temperature / ( 273.3 + temperature ) ;
202    float sh = 6.11 * powf( 10, p ) ;
203    temperature += 273.15 ; // C->K
204    winddir *= C::degree ; // deg->rad
205    humidity /= sh ; // P_H2O->relative humidity
206    setWeather( temperature, pressure, humidity, windvel, winddir ) ;
207
208    // TCAL subtable row
209    // use default since NRO input is calibrated data
210    setTcal( tcalTime, defaultTcal ) ;
211   
212
213    // set row attributes
214    // SPECTRA, FLAGTRA, and TSYS
215    Vector<Float> spectrum( spectra );
216    Vector<uChar> flags( flagtra ) ;
217    Vector<Float> Tsys( tsys ) ;
218    setSpectrum( spectrum, flags, Tsys ) ;
219
220    // SCANNO, CYCLENO, IFNO, POLNO, and BEAMNO
221    //uInt ifno = table_->frequencies().addEntry( (Double)fqs[0], (Double)fqs[1], (Double)fqs[2] ) ;
222    setIndex( scanno, cycleno, ifno, polno, beamno ) ;
223
224    // REFBEAMNO
225    setReferenceBeam( (Int)refbeamno ) ;
226
227    // DIRECTION
228    Vector<Double> dir( direction ) ;
229    setDirection(dir, azimuth, elevation ) ;
230
231    // TIME and INTERVAL
232    setTime( scantime, interval ) ;
233
234    // SRCNAME, SRCTYPE, FIELDNAME, SRCDIRECTION, SRCPROPERMOTION, and SRCVELOCITY
235    Vector<Double> propermot( propermotion ) ;
236    setSource( srcname, srcType, fieldname, srcdir, propermot, srcvel ) ;
237
238    // SCANRATE
239    Vector<Double> srate( scanrate ) ;
240    setScanRate( srate ) ;
241
242    // OPACITY
243    setOpacity( opacity ) ;
244
245    // finally, commit row
246    commitRow() ;
247
248    // count up number of row committed
249    rowCount++ ;
250  }
251}
252
253void NROFiller::close()
254{
255  if (reader_.null() != False) {
256    reader_ = 0;
257  }
258  table_ = 0;
259}
260
261};
262
Note: See TracBrowser for help on using the repository browser.