[1791] | 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 |
|
---|
[1792] | 20 | #include "NROFiller.h"
|
---|
[1791] | 21 | #include "STHeader.h"
|
---|
[1904] | 22 | #include <casa/Containers/Record.h>
|
---|
[2019] | 23 | #include <casa/Quanta/MVTime.h>
|
---|
[1791] | 24 | #include <atnf/PKSIO/SrcType.h>
|
---|
[2761] | 25 | #include <casa/Logging/LogIO.h>
|
---|
[1791] | 26 |
|
---|
[3106] | 27 | using namespace casacore;
|
---|
[1791] | 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 |
|
---|
[2761] | 41 | bool NROFiller::open(const std::string& filename, const Record& rec)
|
---|
[1791] | 42 | {
|
---|
| 43 | bool status = true ;
|
---|
| 44 |
|
---|
[2761] | 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 |
|
---|
[1791] | 58 | // get appropriate reader object
|
---|
| 59 | String format ;
|
---|
[1817] | 60 | reader_ = getNROReader( filename, format ) ;
|
---|
| 61 | if ( reader_.null() == True ) {
|
---|
[1791] | 62 | status = false ;
|
---|
| 63 | return status ;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[2761] | 66 | // Apply options
|
---|
[2776] | 67 | if ( freqref == "REST" || freqref == "DEFAULT (REST)" ) {
|
---|
[2761] | 68 | reader_->setFreqRefFromVREF( false ) ;
|
---|
| 69 | }
|
---|
| 70 | else if ( freqref == "VREF" ) {
|
---|
| 71 | reader_->setFreqRefFromVREF( true ) ;
|
---|
| 72 | }
|
---|
[2776] | 73 |
|
---|
[1791] | 74 | // get header information
|
---|
[1792] | 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 ) ) {
|
---|
[1791] | 93 | status = false ;
|
---|
| 94 | return status ;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[2764] | 97 | // FREQUENCIES table setup
|
---|
[1799] | 98 | table_->frequencies().setFrame( hdr.freqref, true ) ;
|
---|
[2199] | 99 | table_->frequencies().setFrame( hdr.freqref, false ) ;
|
---|
[2764] | 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 | }
|
---|
[1791] | 113 |
|
---|
| 114 | // set Header
|
---|
[1792] | 115 | setHeader( hdr ) ;
|
---|
[1791] | 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 ;
|
---|
[2201] | 127 | uInt ifno ;
|
---|
[1791] | 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 ;
|
---|
[2289] | 137 | Vector<Float> spectra ;
|
---|
| 138 | Vector<uChar> flagtra ;
|
---|
| 139 | Vector<Float> tsys ;
|
---|
| 140 | Vector<Double> direction ;
|
---|
[1791] | 141 | Float azimuth ;
|
---|
| 142 | Float elevation ;
|
---|
[2289] | 143 | Float parangle = 0.0 ;
|
---|
[1791] | 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 ;
|
---|
[2289] | 154 | Vector<Double> propermotion( 2, 0.0 ) ;
|
---|
[1791] | 155 | Vector<Double> srcdir ;
|
---|
[2289] | 156 | Vector<Double> scanrate( 2, 0.0 ) ;
|
---|
[1791] | 157 | Int rowCount = 0 ;
|
---|
| 158 |
|
---|
[1799] | 159 | STHeader header = table_->getHeader() ;
|
---|
[1791] | 160 | String obsType = header.obstype.substr( 0, 3 ) ;
|
---|
[2019] | 161 | Vector<Float> defaultTcal( 1, 1.0 ) ;
|
---|
| 162 | String tcalTime = MVTime( header.utc ).string( MVTime::YMD ) ;
|
---|
[2289] | 163 |
|
---|
| 164 | // TCAL subtable rows
|
---|
| 165 | setTcal( tcalTime, defaultTcal ) ;
|
---|
| 166 |
|
---|
| 167 | // FOCUS subtable rows
|
---|
| 168 | setFocus( parangle ) ;
|
---|
| 169 |
|
---|
[1791] | 170 | for ( Int irow = 0 ; irow < (Int)nRow ; irow++ ) {
|
---|
| 171 | // check scan intent
|
---|
[1812] | 172 | string scanType = reader_->getScanType( irow ) ;
|
---|
[1791] | 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
|
---|
[1792] | 195 | if ( reader_->getScanInfo( irow,
|
---|
[1791] | 196 | scanno,
|
---|
| 197 | cycleno,
|
---|
[2201] | 198 | ifno,
|
---|
[1791] | 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 ) ) {
|
---|
[1792] | 228 | throw AipsError( "Failed to read scan record" ) ;
|
---|
[1791] | 229 | return ;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
[1792] | 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 |
|
---|
[2272] | 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
|
---|
[2289] | 245 | setWeather2( temperature, pressure, humidity, windvel, winddir ) ;
|
---|
[1792] | 246 |
|
---|
[1791] | 247 | // set row attributes
|
---|
| 248 | // SPECTRA, FLAGTRA, and TSYS
|
---|
[2289] | 249 | setSpectrum( spectra, flagtra, tsys ) ;
|
---|
[1791] | 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
|
---|
[2289] | 258 | setDirection( direction, azimuth, elevation ) ;
|
---|
[1791] | 259 |
|
---|
| 260 | // TIME and INTERVAL
|
---|
| 261 | setTime( scantime, interval ) ;
|
---|
| 262 |
|
---|
| 263 | // SRCNAME, SRCTYPE, FIELDNAME, SRCDIRECTION, SRCPROPERMOTION, and SRCVELOCITY
|
---|
[2289] | 264 | setSource( srcname, srcType, fieldname, srcdir, propermotion, srcvel ) ;
|
---|
[1791] | 265 |
|
---|
| 266 | // SCANRATE
|
---|
[2289] | 267 | setScanRate( scanrate ) ;
|
---|
[1791] | 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 | {
|
---|
[1817] | 282 | if (reader_.null() != False) {
|
---|
| 283 | reader_ = 0;
|
---|
| 284 | }
|
---|
| 285 | table_ = 0;
|
---|
[1791] | 286 | }
|
---|
| 287 |
|
---|
| 288 | };
|
---|
| 289 |
|
---|