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 | #include <casa/Logging/LogIO.h> |
---|
26 | |
---|
27 | using namespace casa; |
---|
28 | |
---|
29 | namespace asap |
---|
30 | { |
---|
31 | NROFiller::NROFiller(CountedPtr<Scantable> stable) |
---|
32 | : FillerBase(stable) |
---|
33 | { |
---|
34 | } |
---|
35 | |
---|
36 | NROFiller::~NROFiller() |
---|
37 | { |
---|
38 | close() ; |
---|
39 | } |
---|
40 | |
---|
41 | bool NROFiller::open(const std::string& filename, const Record& rec) |
---|
42 | { |
---|
43 | bool status = true ; |
---|
44 | |
---|
45 | // Parse options |
---|
46 | String freqref = "DEFAULT (REST)" ; |
---|
47 | if ( rec.isDefined( "nro" ) ) { |
---|
48 | Record nrorec = rec.asRecord( "nro" ) ; |
---|
49 | if ( nrorec.isDefined( "freqref" ) ) { |
---|
50 | freqref = nrorec.asString( "freqref" ) ; |
---|
51 | freqref.upcase() ; |
---|
52 | } |
---|
53 | LogIO os( LogOrigin( "NROFiller", "open", WHERE ) ) ; |
---|
54 | os << "Parsing NRO options" << endl ; |
---|
55 | os << " freqref = " << freqref << LogIO::POST ; |
---|
56 | } |
---|
57 | |
---|
58 | // get appropriate reader object |
---|
59 | String format ; |
---|
60 | reader_ = getNROReader( filename, format ) ; |
---|
61 | if ( reader_.null() == True ) { |
---|
62 | status = false ; |
---|
63 | return status ; |
---|
64 | } |
---|
65 | |
---|
66 | // Apply options |
---|
67 | if ( freqref == "REST" || freqref == "DEFAULT (REST)" ) { |
---|
68 | reader_->setFreqRefFromVREF( false ) ; |
---|
69 | } |
---|
70 | else if ( freqref == "VREF" ) { |
---|
71 | reader_->setFreqRefFromVREF( true ) ; |
---|
72 | } |
---|
73 | |
---|
74 | // get header information |
---|
75 | STHeader hdr ; |
---|
76 | if ( reader_->getHeaderInfo( hdr.nchan, |
---|
77 | hdr.npol, |
---|
78 | hdr.nif, |
---|
79 | hdr.nbeam, |
---|
80 | hdr.observer, |
---|
81 | hdr.project, |
---|
82 | hdr.obstype, |
---|
83 | hdr.antennaname, |
---|
84 | hdr.antennaposition, |
---|
85 | hdr.equinox, |
---|
86 | hdr.freqref, |
---|
87 | hdr.reffreq, |
---|
88 | hdr.bandwidth, |
---|
89 | hdr.utc, |
---|
90 | hdr.fluxunit, |
---|
91 | hdr.epoch, |
---|
92 | hdr.poltype ) ) { |
---|
93 | status = false ; |
---|
94 | return status ; |
---|
95 | } |
---|
96 | |
---|
97 | // FREQUENCIES table setup |
---|
98 | table_->frequencies().setFrame( hdr.freqref, true ) ; |
---|
99 | table_->frequencies().setFrame( hdr.freqref, false ) ; |
---|
100 | const string vref = reader_->dataset().getVREF() ; |
---|
101 | if ( vref.compare( 0, 3, "RAD" ) ) { |
---|
102 | table_->frequencies().setDoppler( "RADIO" ) ; |
---|
103 | } |
---|
104 | else if ( vref.compare( 0, 3, "OPT" ) ) { |
---|
105 | table_->frequencies().setDoppler( "OPTICAL" ) ; |
---|
106 | } |
---|
107 | else { |
---|
108 | LogIO os( LogOrigin( "NROFiller", "open", WHERE ) ) ; |
---|
109 | os << LogIO::WARN |
---|
110 | << "VREF " << vref << " is not supported. Use default (RADIO)." |
---|
111 | << LogIO::POST ; |
---|
112 | } |
---|
113 | |
---|
114 | // set Header |
---|
115 | setHeader( hdr ) ; |
---|
116 | |
---|
117 | return status ; |
---|
118 | } |
---|
119 | |
---|
120 | void NROFiller::fill() |
---|
121 | { |
---|
122 | // for each row |
---|
123 | uInt nRow = reader_->getRowNum() ; |
---|
124 | vector< vector<double > > freqs ; |
---|
125 | uInt scanno ; |
---|
126 | uInt cycleno ; |
---|
127 | uInt ifno ; |
---|
128 | uInt beamno ; |
---|
129 | uInt polno ; |
---|
130 | vector<double> fqs ; |
---|
131 | Vector<Double> restfreq ; |
---|
132 | uInt refbeamno ; |
---|
133 | Double scantime ; |
---|
134 | Double interval ; |
---|
135 | String srcname ; |
---|
136 | String fieldname ; |
---|
137 | Vector<Float> spectra ; |
---|
138 | Vector<uChar> flagtra ; |
---|
139 | Vector<Float> tsys ; |
---|
140 | Vector<Double> direction ; |
---|
141 | Float azimuth ; |
---|
142 | Float elevation ; |
---|
143 | Float parangle = 0.0 ; |
---|
144 | Float opacity ; |
---|
145 | uInt tcalid ; |
---|
146 | Int fitid ; |
---|
147 | uInt focusid ; |
---|
148 | Float temperature ; |
---|
149 | Float pressure ; |
---|
150 | Float humidity ; |
---|
151 | Float windvel ; |
---|
152 | Float winddir ; |
---|
153 | Double srcvel ; |
---|
154 | Vector<Double> propermotion( 2, 0.0 ) ; |
---|
155 | Vector<Double> srcdir ; |
---|
156 | Vector<Double> scanrate( 2, 0.0 ) ; |
---|
157 | Int rowCount = 0 ; |
---|
158 | |
---|
159 | STHeader header = table_->getHeader() ; |
---|
160 | String obsType = header.obstype.substr( 0, 3 ) ; |
---|
161 | Vector<Float> defaultTcal( 1, 1.0 ) ; |
---|
162 | String tcalTime = MVTime( header.utc ).string( MVTime::YMD ) ; |
---|
163 | |
---|
164 | // TCAL subtable rows |
---|
165 | setTcal( tcalTime, defaultTcal ) ; |
---|
166 | |
---|
167 | // FOCUS subtable rows |
---|
168 | setFocus( parangle ) ; |
---|
169 | |
---|
170 | for ( Int irow = 0 ; irow < (Int)nRow ; irow++ ) { |
---|
171 | // check scan intent |
---|
172 | string scanType = reader_->getScanType( irow ) ; |
---|
173 | SrcType::type srcType = SrcType::NOTYPE ; |
---|
174 | |
---|
175 | // skip "ZERO" scan |
---|
176 | if ( scanType.compare( 0, 4, "ZERO" ) == 0 ) { |
---|
177 | continue ; |
---|
178 | } |
---|
179 | |
---|
180 | // set srcType |
---|
181 | if ( obsType == "POS" || obsType == "BEA" ) { |
---|
182 | if ( scanType.compare( 0, 2, "ON" ) == 0 ) |
---|
183 | srcType = SrcType::PSON ; |
---|
184 | else if ( scanType.compare( 0, 3, "OFF" ) == 0 ) |
---|
185 | srcType = SrcType::PSOFF ; |
---|
186 | } |
---|
187 | else if ( obsType == "FRE" ) { |
---|
188 | if ( scanType.compare( 0, 2, "ON" ) == 0 ) |
---|
189 | srcType = SrcType::FSON ; |
---|
190 | else if ( scanType.compare( 0, 3, "OFF" ) == 0 ) |
---|
191 | srcType = SrcType::FSOFF ; |
---|
192 | } |
---|
193 | |
---|
194 | // get scan ifnromation |
---|
195 | if ( reader_->getScanInfo( irow, |
---|
196 | scanno, |
---|
197 | cycleno, |
---|
198 | ifno, |
---|
199 | beamno, |
---|
200 | polno, |
---|
201 | fqs, |
---|
202 | restfreq, |
---|
203 | refbeamno, |
---|
204 | scantime, |
---|
205 | interval, |
---|
206 | srcname, |
---|
207 | fieldname, |
---|
208 | spectra, |
---|
209 | flagtra, |
---|
210 | tsys, |
---|
211 | direction, |
---|
212 | azimuth, |
---|
213 | elevation, |
---|
214 | parangle, |
---|
215 | opacity, |
---|
216 | tcalid, |
---|
217 | fitid, |
---|
218 | focusid, |
---|
219 | temperature, |
---|
220 | pressure, |
---|
221 | humidity, |
---|
222 | windvel, |
---|
223 | winddir, |
---|
224 | srcvel, |
---|
225 | propermotion, |
---|
226 | srcdir, |
---|
227 | scanrate ) ) { |
---|
228 | throw AipsError( "Failed to read scan record" ) ; |
---|
229 | return ; |
---|
230 | } |
---|
231 | |
---|
232 | // set IDs and subtable rows |
---|
233 | // FREQUENCIES subtable row |
---|
234 | setFrequency( (Double)fqs[0], (Double)fqs[1], (Double)fqs[2] ) ; |
---|
235 | |
---|
236 | // MOLECULES subtable row |
---|
237 | setMolecule( restfreq ) ; |
---|
238 | |
---|
239 | // WEATHER subtable row |
---|
240 | float p = 7.5 * temperature / ( 273.3 + temperature ) ; |
---|
241 | float sh = 6.11 * powf( 10, p ) ; |
---|
242 | temperature += 273.15 ; // C->K |
---|
243 | winddir *= C::degree ; // deg->rad |
---|
244 | humidity /= sh ; // P_H2O->relative humidity |
---|
245 | setWeather2( temperature, pressure, humidity, windvel, winddir ) ; |
---|
246 | |
---|
247 | // set row attributes |
---|
248 | // SPECTRA, FLAGTRA, and TSYS |
---|
249 | setSpectrum( spectra, flagtra, tsys ) ; |
---|
250 | |
---|
251 | // SCANNO, CYCLENO, IFNO, POLNO, and BEAMNO |
---|
252 | setIndex( scanno, cycleno, ifno, polno, beamno ) ; |
---|
253 | |
---|
254 | // REFBEAMNO |
---|
255 | setReferenceBeam( (Int)refbeamno ) ; |
---|
256 | |
---|
257 | // DIRECTION |
---|
258 | setDirection( direction, azimuth, elevation ) ; |
---|
259 | |
---|
260 | // TIME and INTERVAL |
---|
261 | setTime( scantime, interval ) ; |
---|
262 | |
---|
263 | // SRCNAME, SRCTYPE, FIELDNAME, SRCDIRECTION, SRCPROPERMOTION, and SRCVELOCITY |
---|
264 | setSource( srcname, srcType, fieldname, srcdir, propermotion, srcvel ) ; |
---|
265 | |
---|
266 | // SCANRATE |
---|
267 | setScanRate( scanrate ) ; |
---|
268 | |
---|
269 | // OPACITY |
---|
270 | setOpacity( opacity ) ; |
---|
271 | |
---|
272 | // finally, commit row |
---|
273 | commitRow() ; |
---|
274 | |
---|
275 | // count up number of row committed |
---|
276 | rowCount++ ; |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | void NROFiller::close() |
---|
281 | { |
---|
282 | if (reader_.null() != False) { |
---|
283 | reader_ = 0; |
---|
284 | } |
---|
285 | table_ = 0; |
---|
286 | } |
---|
287 | |
---|
288 | }; |
---|
289 | |
---|