[2273] | 1 | #include <iostream>
|
---|
| 2 | #include <sstream>
|
---|
[2302] | 3 | #include "limits.h"
|
---|
| 4 | #include "float.h"
|
---|
[2273] | 5 |
|
---|
| 6 | #include <measures/Measures/MEpoch.h>
|
---|
| 7 | #include <measures/Measures/MPosition.h>
|
---|
| 8 | #include <measures/Measures/MDirection.h>
|
---|
| 9 | #include <measures/Measures/MCDirection.h>
|
---|
| 10 | #include <measures/Measures/MeasFrame.h>
|
---|
| 11 | #include <measures/Measures/MeasConvert.h>
|
---|
| 12 | #include <casa/Logging/LogMessage.h>
|
---|
| 13 | #include <casa/BasicSL/Constants.h>
|
---|
| 14 |
|
---|
| 15 | #include "OldASDMReader.h"
|
---|
| 16 | #include <atnf/PKSIO/SrcType.h>
|
---|
| 17 |
|
---|
| 18 | using namespace std ;
|
---|
| 19 | //using namespace casa ;
|
---|
| 20 | using namespace asdm ;
|
---|
| 21 | using namespace sdmbin ;
|
---|
| 22 |
|
---|
| 23 | // sec to day
|
---|
| 24 | double s2d = 1.0 / 86400.0 ;
|
---|
| 25 |
|
---|
| 26 | OldASDMReader::OldASDMReader()
|
---|
| 27 | : asdm_(0),
|
---|
| 28 | sdmBin_(0),
|
---|
| 29 | vmsData_(0),
|
---|
| 30 | antennaId_( -1 ),
|
---|
| 31 | antennaName_( "" ),
|
---|
[2302] | 32 | stationName_( "" ),
|
---|
[2273] | 33 | row_(-1),
|
---|
| 34 | apc_(AP_CORRECTED),
|
---|
[2302] | 35 | className_("OldASDMReader"),
|
---|
| 36 | dataIndex_( UINT_MAX ),
|
---|
| 37 | //antennaRow_p( 0 ),
|
---|
| 38 | //stationRow_p( 0 ),
|
---|
| 39 | specWinRow_p( 0 ),
|
---|
| 40 | polarizationRow_p( 0 ),
|
---|
| 41 | fieldRow_p( 0 )
|
---|
[2273] | 42 | {
|
---|
| 43 | configDescIdList_.resize(0) ;
|
---|
| 44 | feedIdList_.resize(0) ;
|
---|
| 45 | fieldIdList_.resize(0) ;
|
---|
| 46 | mainRow_.resize(0) ;
|
---|
| 47 | ifno_.clear() ;
|
---|
| 48 | corrMode_.reset() ;
|
---|
| 49 | timeSampling_.reset() ;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | OldASDMReader::~OldASDMReader()
|
---|
| 53 | {
|
---|
| 54 | close() ;
|
---|
| 55 | logsink_ = 0 ;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | bool OldASDMReader::open( const string &filename, const casa::Record &rec )
|
---|
| 59 | {
|
---|
| 60 | casa::String funcName = "open" ;
|
---|
| 61 |
|
---|
| 62 | // return value
|
---|
| 63 | bool status = true ;
|
---|
| 64 |
|
---|
| 65 | // set default
|
---|
| 66 | timeSampling_.reset() ;
|
---|
| 67 | corrMode_.reset() ;
|
---|
| 68 | resolutionType_.reset() ;
|
---|
| 69 | apc_ = AP_CORRECTED ;
|
---|
| 70 |
|
---|
| 71 | // parsing ASDM options
|
---|
| 72 | if ( rec.isDefined( "asdm" ) ) {
|
---|
| 73 | casa::Record asdmrec = rec.asRecord( "asdm" ) ;
|
---|
| 74 |
|
---|
| 75 | // antenna
|
---|
| 76 | if ( asdmrec.isDefined( "antenna" ) ) {
|
---|
| 77 | if ( asdmrec.type( asdmrec.fieldNumber( "antenna" ) ) == casa::TpInt ) {
|
---|
| 78 | antennaId_ = asdmrec.asInt( "antenna" ) ;
|
---|
| 79 | }
|
---|
| 80 | else {
|
---|
| 81 | antennaName_ = asdmrec.asString( "antenna" ) ;
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | else {
|
---|
| 85 | antennaId_ = 0 ;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | // ATM phase correction
|
---|
| 89 | if ( asdmrec.isDefined( "apc" ) ) {
|
---|
| 90 | if ( asdmrec.asBool( "apc" ) )
|
---|
| 91 | apc_ = AP_CORRECTED ;
|
---|
| 92 | else
|
---|
| 93 | apc_ = AP_UNCORRECTED ;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | // time sampling
|
---|
| 97 | String timeSampling = "all" ; // take all time sampling by default
|
---|
| 98 | if ( asdmrec.isDefined( "sampling" ) ) {
|
---|
| 99 | timeSampling = asdmrec.asString( "sampling" ) ;
|
---|
| 100 | }
|
---|
| 101 | if ( timeSampling == "all" ) {
|
---|
| 102 | timeSampling_.set( INTEGRATION ) ;
|
---|
| 103 | timeSampling_.set( SUBINTEGRATION ) ;
|
---|
| 104 | }
|
---|
| 105 | else if ( timeSampling == "integration" ) {
|
---|
| 106 | timeSampling_.set( INTEGRATION ) ;
|
---|
| 107 | }
|
---|
| 108 | else if ( timeSampling == "subintegration" ) {
|
---|
| 109 | timeSampling_.set( SUBINTEGRATION ) ;
|
---|
| 110 | }
|
---|
| 111 | else {
|
---|
| 112 | //throw AipsError( "Unrecognized option for sampling" ) ;
|
---|
| 113 | logsink_->postLocally( LogMessage( "Unrecognized option for time sampling: "+String::toString(timeSampling), LogOrigin(className_,funcName,WHERE), LogMessage::WARN ) ) ;
|
---|
| 114 | status = false ;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | // spectral resolution type
|
---|
| 118 | string resolutionType = "all" ;
|
---|
| 119 | if ( asdmrec.isDefined( "srt" ) ) {
|
---|
| 120 | resolutionType = string( asdmrec.asString( "srt" ) ) ;
|
---|
| 121 | }
|
---|
| 122 | string resolutionTypes[3] ;
|
---|
| 123 | Int numType = split( resolutionType, resolutionTypes, 3, "," ) ;
|
---|
| 124 | for ( Int it = 0 ; it < numType ; it++ ) {
|
---|
| 125 | if ( resolutionTypes[it] == "all" ) {
|
---|
| 126 | resolutionType_.reset() ;
|
---|
| 127 | resolutionType_.set( FULL_RESOLUTION ) ;
|
---|
| 128 | resolutionType_.set( BASEBAND_WIDE ) ;
|
---|
| 129 | resolutionType_.set( CHANNEL_AVERAGE ) ;
|
---|
| 130 | break ;
|
---|
| 131 | }
|
---|
| 132 | else if ( resolutionTypes[it] == "fr" ) {
|
---|
| 133 | resolutionType_.set( FULL_RESOLUTION ) ;
|
---|
| 134 | }
|
---|
| 135 | else if ( resolutionTypes[it] == "bw" ) {
|
---|
| 136 | resolutionType_.set( BASEBAND_WIDE ) ;
|
---|
| 137 | }
|
---|
| 138 | else if ( resolutionTypes[it] == "ca" ) {
|
---|
| 139 | resolutionType_.set( CHANNEL_AVERAGE ) ;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | if ( resolutionType_.size() == 0 ) {
|
---|
| 143 | logsink_->postLocally( LogMessage( "Unrecognized option for spectral resolution type: "+String::toString(resolutionType), LogOrigin(className_,funcName,WHERE), LogMessage::WARN ) ) ;
|
---|
| 144 | status = false ;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | // input correlation mode
|
---|
| 148 | string corrMode = "ao,ca" ;
|
---|
| 149 | if ( asdmrec.isDefined( "corr" ) ) {
|
---|
| 150 | corrMode = string( asdmrec.asString( "corr" ) ) ;
|
---|
| 151 | //logsink_->postLocally( LogMessage("corrMode = "+String(corrMode),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 152 | }
|
---|
| 153 | string corrModes[3] ;
|
---|
| 154 | Int numCorr = split( corrMode, corrModes, 3, "," ) ;
|
---|
| 155 | for ( Int ic = 0 ; ic < numCorr ; ic++ ) {
|
---|
| 156 | if ( corrModes[ic] == "ao" ) {
|
---|
| 157 | corrMode_.set( AUTO_ONLY ) ;
|
---|
| 158 | }
|
---|
| 159 | else if ( corrModes[ic] == "ca" ) {
|
---|
| 160 | corrMode_.set( CROSS_AND_AUTO ) ;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 | if ( corrMode_.size() == 0 ) {
|
---|
| 164 | logsink_->postLocally( LogMessage( "Invalid option for correlation mode: "+String::toString(corrMode), LogOrigin(className_,funcName,WHERE), LogMessage::WARN ) ) ;
|
---|
| 165 | status = false ;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | // logsink_->postLocally( LogMessage( "### asdmrec summary ###", LogOrigin(className_,funcName,WHERE) ) ) ;
|
---|
| 169 | // ostringstream oss ;
|
---|
| 170 | // asdmrec.print( oss ) ;
|
---|
| 171 | // logsink_->postLocally( LogMessage( oss.str(), LogOrigin(className_,funcName,WHERE) ) ) ;
|
---|
| 172 | // logsink_->postLocally( LogMessage( "#######################", LogOrigin(className_,funcName,WHERE) ) ) ;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | // create ASDM object
|
---|
| 176 | asdm_ = new ASDM() ;
|
---|
| 177 | asdm_->setFromFile( filename ) ;
|
---|
| 178 |
|
---|
[2302] | 179 | AntennaTable &atab = asdm_->getAntenna() ;
|
---|
| 180 | AntennaRow *antennaRow ;
|
---|
[2273] | 181 | if ( antennaId_ == -1 ) {
|
---|
| 182 | vector<AntennaRow *> rows = atab.get() ;
|
---|
| 183 | int idx = -1 ;
|
---|
| 184 | for ( casa::uInt irow = 0 ; irow < rows.size() ; irow++ ) {
|
---|
| 185 | if ( casa::String(rows[irow]->getName()) == antennaName_ ) {
|
---|
| 186 | idx = rows[irow]->getAntennaId().getTagValue() ;
|
---|
| 187 | break ;
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 | if ( idx == -1 ) {
|
---|
| 191 | close() ;
|
---|
| 192 | throw (casa::AipsError( antennaName_ + " not found." )) ;
|
---|
| 193 | }
|
---|
| 194 | else {
|
---|
| 195 | antennaId_ = idx ;
|
---|
| 196 | }
|
---|
[2302] | 197 | antennaTag_ = Tag( antennaId_, TagType::Antenna ) ;
|
---|
| 198 | antennaRow = rows[antennaId_] ;
|
---|
[2273] | 199 | }
|
---|
[2302] | 200 | else {
|
---|
| 201 | antennaTag_ = Tag( antennaId_, TagType::Antenna ) ;
|
---|
| 202 | antennaRow = atab.getRowByKey( antennaTag_ ) ;
|
---|
| 203 | if ( antennaRow == 0 ) {
|
---|
| 204 | close() ;
|
---|
| 205 | throw (casa::AipsError( "AntennaId " + casa::String::toString(antennaId_) + " is invalid." ) ) ;
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 |
|
---|
[2273] | 209 |
|
---|
| 210 | // set antenna name
|
---|
| 211 | if ( antennaName_.size() == 0 ) {
|
---|
[2302] | 212 | antennaName_ = casa::String( antennaRow->getName() ) ;
|
---|
[2273] | 213 | }
|
---|
| 214 |
|
---|
[2302] | 215 | // get Station row
|
---|
| 216 | StationRow *stationRow = antennaRow->getStationUsingStationId() ;
|
---|
| 217 |
|
---|
| 218 | // station name
|
---|
| 219 | stationName_ = casa::String( stationRow->getName() ) ;
|
---|
| 220 |
|
---|
| 221 | // antenna position
|
---|
| 222 | antennaPosition_.resize( 3 ) ;
|
---|
| 223 | vector<Length> antpos = stationRow->getPosition() ;
|
---|
| 224 | for ( casa::uInt i = 0 ; i < 3 ; i++ )
|
---|
| 225 | antennaPosition_[i] = Quantity( casa::Double( antpos[i].get() ), Unit( "m" ) ) ;
|
---|
| 226 |
|
---|
[2273] | 227 | // create SDMBinData object
|
---|
| 228 | sdmBin_ = new SDMBinData( asdm_, filename ) ;
|
---|
| 229 |
|
---|
| 230 | // get Main rows
|
---|
| 231 | //mainRow_ = casa::Vector<MainRow *>(asdm_->getMain().get()) ;
|
---|
| 232 |
|
---|
| 233 | // set up IFNO
|
---|
| 234 | setupIFNO() ;
|
---|
| 235 |
|
---|
| 236 | // process Station table
|
---|
| 237 | processStation() ;
|
---|
| 238 |
|
---|
[2302] | 239 | //logsink_->postLocally( LogMessage( "antennaId_ = "+String::toString(antennaId_), LogOrigin(className_,funcName,WHERE) ) ) ;
|
---|
| 240 | //logsink_->postLocally( LogMessage( "antennaName_ = "+antennaName_, LogOrigin(className_,funcName,WHERE) ) ) ;
|
---|
[2273] | 241 |
|
---|
| 242 | return true ;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | // void OldASDMReader::fill()
|
---|
| 246 | // {
|
---|
| 247 | // }
|
---|
| 248 |
|
---|
| 249 | void OldASDMReader::close()
|
---|
| 250 | {
|
---|
| 251 | clearMainRow() ;
|
---|
| 252 |
|
---|
| 253 | if ( sdmBin_ )
|
---|
| 254 | delete sdmBin_ ;
|
---|
| 255 | sdmBin_ = 0 ;
|
---|
| 256 |
|
---|
| 257 | if ( asdm_ )
|
---|
| 258 | delete asdm_ ;
|
---|
| 259 | asdm_ = 0 ;
|
---|
| 260 |
|
---|
| 261 | return ;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | void OldASDMReader::fillHeader( casa::Int &nchan,
|
---|
| 265 | casa::Int &npol,
|
---|
| 266 | casa::Int &nif,
|
---|
| 267 | casa::Int &nbeam,
|
---|
| 268 | casa::String &observer,
|
---|
| 269 | casa::String &project,
|
---|
| 270 | casa::String &obstype,
|
---|
| 271 | casa::String &antennaname,
|
---|
| 272 | casa::Vector<casa::Double> &antennaposition,
|
---|
| 273 | casa::Float &equinox,
|
---|
| 274 | casa::String &freqref,
|
---|
| 275 | casa::Double &reffreq,
|
---|
| 276 | casa::Double &bandwidth,
|
---|
| 277 | casa::Double &utc,
|
---|
| 278 | casa::String &fluxunit,
|
---|
| 279 | casa::String &epoch,
|
---|
| 280 | casa::String &poltype )
|
---|
| 281 | {
|
---|
| 282 | casa::String funcName = "fillHeader" ;
|
---|
| 283 |
|
---|
| 284 | ExecBlockTable &ebtab = asdm_->getExecBlock() ;
|
---|
| 285 | // at the moment take first row of ExecBlock table
|
---|
| 286 | ExecBlockRow *ebrow = ebtab.get()[0] ;
|
---|
| 287 | casa::String telescopeName( ebrow->getTelescopeName() ) ;
|
---|
[2302] | 288 | //casa::String stationName( stationRow_p->getName() ) ;
|
---|
[2273] | 289 |
|
---|
| 290 | // antennaname
|
---|
| 291 | // <telescopeName>//<antennaName>@stationName
|
---|
[2302] | 292 | antennaname = telescopeName + "//" + antennaName_ + "@" + stationName_ ;
|
---|
[2273] | 293 | //logsink_->postLocally( LogMessage("antennaName = "+antennaname,LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 294 |
|
---|
| 295 | // antennaposition
|
---|
| 296 | antennaposition.resize( 3 ) ;
|
---|
| 297 | for ( casa::uInt i = 0 ; i < 3 ; i++ )
|
---|
[2302] | 298 | antennaposition[i] = antennaPosition_[i].getValue( Unit("m") ) ;
|
---|
[2273] | 299 |
|
---|
| 300 | // observer
|
---|
| 301 | observer = ebrow->getObserverName() ;
|
---|
| 302 |
|
---|
| 303 | // project
|
---|
| 304 | // T.B.D. (project UID?)
|
---|
| 305 | project = "T.B.D. (" + ebrow->getProjectId().toString() + ")" ;
|
---|
| 306 |
|
---|
| 307 | // utc
|
---|
| 308 | // start time of the project
|
---|
| 309 | utc = casa::Double( ebrow->getStartTime().getMJD() ) ;
|
---|
| 310 |
|
---|
| 311 |
|
---|
| 312 | SpectralWindowTable &spwtab = asdm_->getSpectralWindow() ;
|
---|
| 313 | vector<SpectralWindowRow *> spwrows = spwtab.get() ;
|
---|
| 314 | int nspwrow = spwrows.size() ;
|
---|
| 315 |
|
---|
| 316 | // nif
|
---|
| 317 | //nif = spwrows.size() ;
|
---|
| 318 | nif = getNumIFs() ;
|
---|
| 319 |
|
---|
| 320 | // nchan
|
---|
| 321 | int refidx = -1 ;
|
---|
| 322 | vector<int> nchans ;
|
---|
| 323 | for ( int irow = 0 ; irow < nspwrow ; irow++ ) {
|
---|
| 324 | nchans.push_back( spwrows[irow]->getNumChan() ) ;
|
---|
| 325 | if ( refidx == -1 && nchans[irow] != 1 && nchans[irow] != 4 )
|
---|
| 326 | refidx = irow ;
|
---|
| 327 | }
|
---|
| 328 | nchan = casa::Int( *max_element( nchans.begin(), nchans.end() ) ) ;
|
---|
| 329 |
|
---|
| 330 | //logsink_->postLocally( LogMessage("refidx = "+String::toString(refidx),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 331 |
|
---|
| 332 | // bandwidth
|
---|
| 333 | vector<double> bws ;
|
---|
| 334 | for ( int irow = 0 ; irow < nspwrow ; irow++ ) {
|
---|
| 335 | if ( nchans[irow] != 4 ) { // exclude WVR data
|
---|
| 336 | bws.push_back( spwrows[irow]->getTotBandwidth().get() ) ;
|
---|
| 337 | }
|
---|
| 338 | }
|
---|
| 339 | bandwidth = casa::Double( *max_element( bws.begin(), bws.end() ) ) ;
|
---|
| 340 |
|
---|
| 341 | // reffreq
|
---|
| 342 | reffreq = casa::Double( spwrows[refidx]->getRefFreq().get() ) ;
|
---|
| 343 |
|
---|
| 344 | // freqref
|
---|
| 345 | if ( spwrows[refidx]->isMeasFreqRefExists() ) {
|
---|
| 346 | string mfr = CFrequencyReferenceCode::name( spwrows[refidx]->getMeasFreqRef() ) ;
|
---|
| 347 | // if (mfr == "TOPO") {
|
---|
| 348 | // freqref = "TOPOCENT";
|
---|
| 349 | // } else if (mfr == "GEO") {
|
---|
| 350 | // freqref = "GEOCENTR";
|
---|
| 351 | // } else if (mfr == "BARY") {
|
---|
| 352 | // freqref = "BARYCENT";
|
---|
| 353 | // } else if (mfr == "GALACTO") {
|
---|
| 354 | // freqref = "GALACTOC";
|
---|
| 355 | // } else if (mfr == "LGROUP") {
|
---|
| 356 | // freqref = "LOCALGRP";
|
---|
| 357 | // } else if (mfr == "CMB") {
|
---|
| 358 | // freqref = "CMBDIPOL";
|
---|
| 359 | // } else if (mfr == "REST") {
|
---|
| 360 | // freqref = "SOURCE";
|
---|
| 361 | // }
|
---|
| 362 | freqref = String( mfr ) ;
|
---|
| 363 | }
|
---|
| 364 | else {
|
---|
| 365 | // frequency reference is TOPOCENT by default
|
---|
| 366 | //freqref = "TOPOCENT" ;
|
---|
| 367 | freqref = "TOPO" ;
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 |
|
---|
| 371 | PolarizationTable &ptab = asdm_->getPolarization() ;
|
---|
| 372 | vector<PolarizationRow *> prows = ptab.get() ;
|
---|
| 373 | vector<int> npols ;
|
---|
| 374 | refidx = -1 ;
|
---|
| 375 | for ( unsigned int irow = 0 ; irow < prows.size() ; irow++ ) {
|
---|
| 376 | npols.push_back( prows[irow]->getNumCorr() ) ;
|
---|
| 377 | if ( refidx == -1 && npols[irow] != 1 )
|
---|
| 378 | refidx = irow ;
|
---|
| 379 | }
|
---|
| 380 | if ( refidx == -1 )
|
---|
| 381 | refidx = 0 ;
|
---|
| 382 |
|
---|
| 383 | // npol
|
---|
| 384 | npol = casa::Int( *max_element( npols.begin(), npols.end() ) ) ;
|
---|
| 385 |
|
---|
| 386 | // poltype
|
---|
| 387 | vector<StokesParameter> corrType = prows[refidx]->getCorrType() ;
|
---|
| 388 | if ( corrType[0] == I ||
|
---|
| 389 | corrType[0] == Q ||
|
---|
| 390 | corrType[0] == U ||
|
---|
| 391 | corrType[0] == V )
|
---|
| 392 | poltype = "stokes" ;
|
---|
| 393 | else if ( corrType[0] == RR ||
|
---|
| 394 | corrType[0] == RL ||
|
---|
| 395 | corrType[0] == LR ||
|
---|
| 396 | corrType[0] == LL )
|
---|
| 397 | poltype = "circular" ;
|
---|
| 398 | else if ( corrType[0] == XX ||
|
---|
| 399 | corrType[0] == XY ||
|
---|
| 400 | corrType[0] == YX ||
|
---|
| 401 | corrType[0] == YY )
|
---|
| 402 | poltype = "linear" ;
|
---|
| 403 | else if ( corrType[0] == PLINEAR ||
|
---|
| 404 | corrType[0] == PANGLE ) {
|
---|
| 405 | poltype = "linpol" ;
|
---|
| 406 | }
|
---|
| 407 | else {
|
---|
| 408 | poltype = "notype" ;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 |
|
---|
| 412 | FeedTable &ftab = asdm_->getFeed() ;
|
---|
| 413 | vector<FeedRow *> frows = ftab.get() ;
|
---|
| 414 | vector<int> nbeams ;
|
---|
| 415 | for ( unsigned int irow = 0 ; irow < frows.size() ; irow++ ) {
|
---|
| 416 | if ( frows[irow]->isFeedNumExists() )
|
---|
| 417 | nbeams.push_back( frows[irow]->getFeedNum() ) ;
|
---|
| 418 | else
|
---|
| 419 | nbeams.push_back( 1 ) ;
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 | // nbeam
|
---|
| 423 | nbeam = casa::Int( *max_element( nbeams.begin(), nbeams.end() ) ) ;
|
---|
| 424 |
|
---|
| 425 | // fluxunit
|
---|
| 426 | // tentatively set 'K'? or empty?
|
---|
| 427 | fluxunit = "K" ;
|
---|
| 428 |
|
---|
| 429 | // equinox
|
---|
| 430 | // tentatively set 2000.0
|
---|
| 431 | equinox = 2000.0 ;
|
---|
| 432 |
|
---|
| 433 | // epoch
|
---|
| 434 | // tentatively set "UTC"
|
---|
| 435 | epoch = "UTC" ;
|
---|
| 436 |
|
---|
| 437 | // obstype
|
---|
| 438 | // at the moment take observingMode attribute in SBSummary table
|
---|
| 439 | SBSummaryRow *sbrow = ebrow->getSBSummaryUsingSBSummaryId() ;
|
---|
| 440 | vector<string> obsmode = sbrow->getObservingMode() ;
|
---|
| 441 | obstype = "" ;
|
---|
| 442 | for ( unsigned int imode = 0 ; imode < obsmode.size() ; imode++ ) {
|
---|
| 443 | obstype += casa::String(obsmode[imode]) ;
|
---|
| 444 | if ( imode != obsmode.size()-1 )
|
---|
| 445 | obstype += "#" ;
|
---|
| 446 | }
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | void OldASDMReader::selectConfigDescription()
|
---|
| 450 | {
|
---|
| 451 | casa::String funcName = "selectConfigDescription" ;
|
---|
| 452 |
|
---|
| 453 | vector<ConfigDescriptionRow *> cdrows = asdm_->getConfigDescription().get() ;
|
---|
| 454 | vector<Tag> cdidTags ;
|
---|
| 455 | for ( unsigned int irow = 0 ; irow < cdrows.size() ; irow++ ) {
|
---|
| 456 | //logsink_->postLocally( LogMessage("correlationMode["+String::toString(irow)+"] = "+String::toString(cdrows[irow]->getCorrelationMode()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 457 | if ( cdrows[irow]->getCorrelationMode() != CROSS_ONLY ) {
|
---|
| 458 | cdidTags.push_back( cdrows[irow]->getConfigDescriptionId() ) ;
|
---|
| 459 | }
|
---|
| 460 | }
|
---|
| 461 |
|
---|
| 462 | configDescIdList_.resize( cdidTags.size() ) ;
|
---|
| 463 | for ( unsigned int i = 0 ; i < cdidTags.size() ; i++ ) {
|
---|
| 464 | configDescIdList_[i] = casa::uInt( cdidTags[i].getTagValue() ) ;
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | void OldASDMReader::selectFeed()
|
---|
| 469 | {
|
---|
| 470 | feedIdList_.resize(0) ;
|
---|
| 471 | vector<FeedRow *> frows = asdm_->getFeed().get() ;
|
---|
| 472 | Tag atag( antennaId_, TagType::Antenna ) ;
|
---|
| 473 | for ( unsigned int irow = 0 ; irow < frows.size() ; irow++ ) {
|
---|
| 474 | casa::uInt feedId = (casa::uInt)(frows[irow]->getFeedId() ) ;
|
---|
| 475 | if ( casa::anyEQ( feedIdList_, feedId ) )
|
---|
| 476 | continue ;
|
---|
| 477 | if ( frows[irow]->getAntennaId() == atag ) {
|
---|
| 478 | unsigned int oldsize = feedIdList_.size() ;
|
---|
| 479 | feedIdList_.resize( oldsize+1, true ) ;
|
---|
| 480 | feedIdList_[oldsize] = feedId ;
|
---|
| 481 | }
|
---|
| 482 | }
|
---|
| 483 | }
|
---|
| 484 |
|
---|
| 485 | casa::Vector<casa::uInt> OldASDMReader::getFieldIdList()
|
---|
| 486 | {
|
---|
| 487 | casa::String funcName = "getFieldIdList" ;
|
---|
| 488 |
|
---|
| 489 | vector<FieldRow *> frows = asdm_->getField().get() ;
|
---|
| 490 | fieldIdList_.resize( frows.size() ) ;
|
---|
| 491 | for ( unsigned int irow = 0 ; irow < frows.size() ; irow++ ) {
|
---|
| 492 | //logsink_->postLocally( LogMessage("fieldId["+String::toString(irow)+"]="+String(frows[irow]->getFieldId().toString()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 493 | fieldIdList_[irow] = frows[irow]->getFieldId().getTagValue() ;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | return fieldIdList_ ;
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | casa::uInt OldASDMReader::getNumMainRow()
|
---|
| 500 | {
|
---|
| 501 | casa::uInt nrow = casa::uInt( mainRow_.size() ) ;
|
---|
| 502 |
|
---|
| 503 | return nrow ;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | void OldASDMReader::select()
|
---|
| 507 | {
|
---|
| 508 | // selection by input CorrelationMode
|
---|
| 509 | EnumSet<CorrelationMode> esCorrs ;
|
---|
| 510 | sdmBin_->select( corrMode_ ) ;
|
---|
| 511 |
|
---|
| 512 | // selection by TimeSampling
|
---|
| 513 | sdmBin_->select( timeSampling_ ) ;
|
---|
| 514 |
|
---|
| 515 | // selection by SpectralResolutionType
|
---|
| 516 | sdmBin_->select( resolutionType_ ) ;
|
---|
| 517 |
|
---|
| 518 | // selection by AtmPhaseCorrection and output CorrelationMode
|
---|
| 519 | EnumSet<AtmPhaseCorrection> esApcs ;
|
---|
| 520 | esApcs.set( apc_ ) ;
|
---|
| 521 | // always take only autocorrelation data
|
---|
| 522 | Enum<CorrelationMode> esCorr = AUTO_ONLY ;
|
---|
| 523 | sdmBin_->selectDataSubset( esCorr, esApcs ) ;
|
---|
| 524 |
|
---|
| 525 | // select valid configDescriptionId
|
---|
| 526 | selectConfigDescription() ;
|
---|
| 527 |
|
---|
| 528 | // select valid feedId
|
---|
| 529 | selectFeed() ;
|
---|
| 530 | }
|
---|
| 531 |
|
---|
| 532 | casa::Bool OldASDMReader::setMainRow( casa::uInt irow )
|
---|
| 533 | {
|
---|
| 534 | casa::Bool status = true ;
|
---|
| 535 | row_ = irow ;
|
---|
[2302] | 536 | execBlockTag_ = mainRow_[row_]->getExecBlockId() ;
|
---|
[2273] | 537 |
|
---|
| 538 | unsigned int cdid = mainRow_[row_]->getConfigDescriptionId().getTagValue() ;
|
---|
| 539 | if ( (int)count(configDescIdList_.begin(),configDescIdList_.end(),cdid) == 0 )
|
---|
| 540 | status = false ;
|
---|
| 541 | else {
|
---|
| 542 | status = (casa::Bool)(sdmBin_->acceptMainRow( mainRow_[row_] )) ;
|
---|
| 543 | }
|
---|
| 544 | return status ;
|
---|
| 545 | }
|
---|
| 546 |
|
---|
| 547 | casa::Bool OldASDMReader::setMainRow( casa::uInt configDescId, casa::uInt fieldId )
|
---|
| 548 | {
|
---|
| 549 | clearMainRow() ;
|
---|
| 550 |
|
---|
| 551 | Tag configDescTag( (unsigned int)configDescId, TagType::ConfigDescription ) ;
|
---|
| 552 | Tag fieldTag( (unsigned int)fieldId, TagType::Field ) ;
|
---|
| 553 | mainRow_ = casa::Vector<MainRow *>( *(asdm_->getMain().getByContext( configDescTag, fieldTag ) ) ) ;
|
---|
| 554 |
|
---|
| 555 | return true ;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | void OldASDMReader::clearMainRow()
|
---|
| 559 | {
|
---|
| 560 | mainRow_.resize(0) ;
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 | void OldASDMReader::setupIFNO()
|
---|
| 564 | {
|
---|
| 565 | casa::String funcName = "setupIFNO" ;
|
---|
| 566 |
|
---|
| 567 | vector<SpectralWindowRow *> spwrows = asdm_->getSpectralWindow().get() ;
|
---|
| 568 | unsigned int nrow = spwrows.size() ;
|
---|
| 569 | ifno_.clear() ;
|
---|
| 570 | casa::uInt idx = 0 ;
|
---|
| 571 | casa::uInt wvridx = 0 ;
|
---|
| 572 | for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 573 | casa::uInt index ;
|
---|
| 574 | if ( isWVR( spwrows[irow] ) ) {
|
---|
| 575 | //logsink_->postLocally( LogMessage(spwrows[irow]->getSpectralWindowId().toString()+" is WVR",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 576 | index = wvridx ;
|
---|
| 577 | }
|
---|
| 578 | else {
|
---|
| 579 | index = ++idx ;
|
---|
| 580 | }
|
---|
| 581 | ifno_.insert( pair<Tag,casa::uInt>(spwrows[irow]->getSpectralWindowId(),index) ) ;
|
---|
| 582 | //logsink_->postLocally( LogMessage(spwrows[irow]->getSpectralWindowId().toString()+": IFNO="+String::toString(index),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 583 | }
|
---|
| 584 | }
|
---|
| 585 |
|
---|
| 586 | bool OldASDMReader::isWVR( SpectralWindowRow *row )
|
---|
| 587 | {
|
---|
| 588 | BasebandName bbname = row->getBasebandName() ;
|
---|
| 589 | int nchan = row->getNumChan() ;
|
---|
| 590 | if ( bbname == NOBB && nchan == 4 )
|
---|
| 591 | return true ;
|
---|
| 592 | else
|
---|
| 593 | return false ;
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | casa::Bool OldASDMReader::setData()
|
---|
| 597 | {
|
---|
| 598 | casa::String funcName = "setData" ;
|
---|
| 599 |
|
---|
| 600 | //logsink_->postLocally( LogMessage("try to retrieve binary data",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 601 |
|
---|
| 602 | // EnumSet<AtmPhaseCorrection> esApcs ;
|
---|
| 603 | // esApcs.set( apc_ ) ;
|
---|
| 604 | // // always take only autocorrelation data
|
---|
| 605 | // Enum<CorrelationMode> esCorr = AUTO_ONLY ;
|
---|
| 606 | // vmsData_ = sdmBin_->getDataCols( esCorr, esApcs ) ;
|
---|
| 607 |
|
---|
| 608 | // 2011/07/06 TN
|
---|
| 609 | // Workaround to avoid unwanted message from SDMBinData::getDataCols()
|
---|
| 610 | ostringstream oss ;
|
---|
| 611 | streambuf *buforg = cout.rdbuf(oss.rdbuf()) ;
|
---|
| 612 | vmsData_ = sdmBin_->getDataCols() ;
|
---|
| 613 | cout.rdbuf(buforg) ;
|
---|
| 614 |
|
---|
| 615 | // logsink_->postLocally( LogMessage("oss.str() = "+oss.str(),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 616 | // cout << "This is test: oss.str()=" << oss.str() << endl ;
|
---|
| 617 |
|
---|
| 618 |
|
---|
| 619 | //logsink_->postLocally( LogMessage("processorId = "+String::toString(vmsData_->processorId),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 620 | //logsink_->postLocally( LogMessage("v_time.size() = "+String::toString(vmsData_->v_time.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 621 | //logsink_->postLocally( LogMessage(" v_time[0] = "+String::toString(vmsData_->v_time[0]),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 622 | //logsink_->postLocally( LogMessage("v_interval.size() = "+String::toString(vmsData_->v_interval.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 623 | //logsink_->postLocally( LogMessage(" v_interval[0] = "+String::toString(vmsData_->v_interval[0]),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 624 | //logsink_->postLocally( LogMessage("v_atmPhaseCorrection.size() = "+String::toString(vmsData_->v_atmPhaseCorrection.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 625 | //logsink_->postLocally( LogMessage("binNum = "+String::toString(vmsData_->binNum),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 626 | //logsink_->postLocally( LogMessage("v_projectPath.size() = "+String::toString(vmsData_->v_projectPath.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 627 | //logsink_->postLocally( LogMessage("v_antennaId1.size() = "+String::toString(vmsData_->v_antennaId1.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 628 | //logsink_->postLocally( LogMessage("v_antennaId2.size() = "+String::toString(vmsData_->v_antennaId2.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 629 | //logsink_->postLocally( LogMessage("v_feedId1.size() = "+String::toString(vmsData_->v_feedId1.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 630 | //logsink_->postLocally( LogMessage("v_feedId2.size() = "+String::toString(vmsData_->v_feedId2.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 631 | //logsink_->postLocally( LogMessage("v_dataDescId.size() = "+String::toString(vmsData_->v_dataDescId.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 632 | //logsink_->postLocally( LogMessage("v_timeCentroid.size() = "+String::toString(vmsData_->v_timeCentroid.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 633 | //logsink_->postLocally( LogMessage("v_exposure.size() = "+String::toString(vmsData_->v_exposure.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 634 | //logsink_->postLocally( LogMessage("v_numData.size() = "+String::toString(vmsData_->v_numData.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 635 | //logsink_->postLocally( LogMessage("vv_dataShape.size() = "+String::toString(vmsData_->vv_dataShape.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 636 | //logsink_->postLocally( LogMessage("v_m_data.size() = "+String::toString(vmsData_->v_m_data.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 637 | //logsink_->postLocally( LogMessage("v_phaseDir.size() = "+String::toString(vmsData_->v_phaseDir.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 638 | //logsink_->postLocally( LogMessage("v_stateId.size() = "+String::toString(vmsData_->v_stateId.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 639 | //logsink_->postLocally( LogMessage("v_msState.size() = "+String::toString(vmsData_->v_msState.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 640 | //logsink_->postLocally( LogMessage("v_flag.size() = "+String::toString(vmsData_->v_flag.size()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 641 |
|
---|
| 642 | dataIdList_.clear() ;
|
---|
| 643 | unsigned int numTotalData = vmsData_->v_m_data.size() ;
|
---|
| 644 | for ( unsigned int idata = 0 ; idata < numTotalData ; idata++ ) {
|
---|
| 645 | if ( vmsData_->v_antennaId1[idata] == (int)antennaId_
|
---|
| 646 | && vmsData_->v_antennaId2[idata] == (int)antennaId_ )
|
---|
| 647 | dataIdList_.push_back( idata ) ;
|
---|
| 648 | }
|
---|
| 649 | numData_ = dataIdList_.size() ;
|
---|
| 650 | //logsink_->postLocally( LogMessage("numData_ = "+String::toString(numData_),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 651 | //logsink_->postLocally( LogMessage("dataSize = "+String::toString(mainRow_[row_]->getDataSize()),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 652 |
|
---|
| 653 | return true ;
|
---|
| 654 | }
|
---|
| 655 |
|
---|
[2302] | 656 | void OldASDMReader::prepareData( unsigned int idx )
|
---|
| 657 | {
|
---|
| 658 | unsigned int i = dataIdList_[idx] ;
|
---|
| 659 | if ( i != dataIndex_ ) {
|
---|
| 660 | dataIndex_ = dataIdList_[idx] ;
|
---|
| 661 | Tag dataDescTag( vmsData_->v_dataDescId[dataIndex_], TagType::DataDescription ) ;
|
---|
| 662 | DataDescriptionRow *dataDescRow = asdm_->getDataDescription().getRowByKey( dataDescTag ) ;
|
---|
| 663 | specWinTag_ = dataDescRow->getSpectralWindowId() ;
|
---|
| 664 | specWinRow_p = dataDescRow->getSpectralWindowUsingSpectralWindowId() ;
|
---|
| 665 | polarizationRow_p = dataDescRow->getPolarizationUsingPolOrHoloId() ;
|
---|
| 666 | Tag fieldTag( vmsData_->v_fieldId[dataIndex_], TagType::Field ) ;
|
---|
| 667 | fieldRow_p = asdm_->getField().getRowByKey( fieldTag ) ;
|
---|
| 668 | double startSec = vmsData_->v_time[dataIndex_] - 0.5 * vmsData_->v_interval[dataIndex_] ;
|
---|
| 669 | timeInterval_ = ArrayTimeInterval( startSec*s2d, vmsData_->v_interval[dataIndex_]*s2d ) ;
|
---|
| 670 | }
|
---|
| 671 | }
|
---|
| 672 |
|
---|
[2273] | 673 | casa::uInt OldASDMReader::getIFNo( unsigned int idx )
|
---|
| 674 | {
|
---|
[2302] | 675 | prepareData( idx ) ;
|
---|
| 676 | return getIFNo() ;
|
---|
| 677 | }
|
---|
| 678 |
|
---|
| 679 | casa::uInt OldASDMReader::getIFNo()
|
---|
| 680 | {
|
---|
| 681 | map<Tag,casa::uInt>::iterator iter = ifno_.find( specWinTag_ ) ;
|
---|
[2273] | 682 | if ( iter != ifno_.end() )
|
---|
| 683 | return iter->second ;
|
---|
| 684 | else {
|
---|
| 685 | return 0 ;
|
---|
| 686 | }
|
---|
| 687 | }
|
---|
| 688 |
|
---|
| 689 | int OldASDMReader::getNumPol( unsigned int idx )
|
---|
| 690 | {
|
---|
[2302] | 691 | prepareData( idx ) ;
|
---|
| 692 | return getNumPol() ;
|
---|
[2273] | 693 | }
|
---|
| 694 |
|
---|
[2302] | 695 | int OldASDMReader::getNumPol()
|
---|
| 696 | {
|
---|
| 697 | return polarizationRow_p->getNumCorr() ;
|
---|
| 698 | }
|
---|
| 699 |
|
---|
[2273] | 700 | void OldASDMReader::getFrequency( unsigned int idx,
|
---|
| 701 | double &refpix,
|
---|
| 702 | double &refval,
|
---|
| 703 | double &incr,
|
---|
| 704 | string &freqref )
|
---|
| 705 | {
|
---|
[2302] | 706 | prepareData( idx ) ;
|
---|
| 707 | getFrequency( refpix, refval, incr, freqref ) ;
|
---|
| 708 | }
|
---|
| 709 |
|
---|
| 710 | void OldASDMReader::getFrequency( double &refpix,
|
---|
| 711 | double &refval,
|
---|
| 712 | double &incr,
|
---|
| 713 | string &freqref )
|
---|
| 714 | {
|
---|
[2273] | 715 | casa::String funcName = "getFrequency" ;
|
---|
| 716 |
|
---|
[2302] | 717 | int nchan = specWinRow_p->getNumChan() ;
|
---|
[2273] | 718 | freqref = "TOPO" ;
|
---|
[2302] | 719 | if ( specWinRow_p->isMeasFreqRefExists() )
|
---|
| 720 | freqref = CFrequencyReferenceCode::toString( specWinRow_p->getMeasFreqRef() ) ;
|
---|
[2273] | 721 | if ( nchan == 1 ) {
|
---|
| 722 | //logsink_->postLocally( LogMessage("channel averaged data",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 723 | refpix = 0.0 ;
|
---|
[2302] | 724 | incr = specWinRow_p->getTotBandwidth().get() ;
|
---|
| 725 | if ( specWinRow_p->isChanFreqStartExists() ) {
|
---|
| 726 | refval = specWinRow_p->getChanFreqStart().get() ;
|
---|
[2273] | 727 | }
|
---|
[2302] | 728 | else if ( specWinRow_p->isChanFreqArrayExists() ) {
|
---|
| 729 | refval = specWinRow_p->getChanFreqArray()[0].get() ;
|
---|
[2273] | 730 | }
|
---|
| 731 | else {
|
---|
| 732 | throw (casa::AipsError( "Either chanFreqArray or chanFreqStart must exist." )) ;
|
---|
| 733 | }
|
---|
| 734 | }
|
---|
| 735 | else if ( nchan % 2 ) {
|
---|
| 736 | // odd
|
---|
| 737 | //logsink_->postLocally( LogMessage("odd case",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 738 | refpix = 0.5 * ( (double)nchan - 1.0 ) ;
|
---|
| 739 | int ic = ( nchan - 1 ) / 2 ;
|
---|
[2302] | 740 | if ( specWinRow_p->isChanWidthExists() ) {
|
---|
| 741 | incr = specWinRow_p->getChanWidth().get() ;
|
---|
[2273] | 742 | }
|
---|
[2302] | 743 | else if ( specWinRow_p->isChanWidthArrayExists() ) {
|
---|
| 744 | incr = specWinRow_p->getChanWidthArray()[0].get() ;
|
---|
[2273] | 745 | }
|
---|
| 746 | else {
|
---|
| 747 | throw (casa::AipsError( "Either chanWidthArray or chanWidth must exist." )) ;
|
---|
| 748 | }
|
---|
[2302] | 749 | if ( specWinRow_p->isChanFreqStepExists() ) {
|
---|
| 750 | if ( specWinRow_p->getChanFreqStep().get() < 0.0 )
|
---|
[2273] | 751 | incr *= -1.0 ;
|
---|
| 752 | }
|
---|
[2302] | 753 | else if ( specWinRow_p->isChanFreqArrayExists() ) {
|
---|
| 754 | vector<Frequency> chanFreqArr = specWinRow_p->getChanFreqArray() ;
|
---|
[2273] | 755 | if ( chanFreqArr[0].get() > chanFreqArr[1].get() )
|
---|
| 756 | incr *= -1.0 ;
|
---|
| 757 | }
|
---|
| 758 | else {
|
---|
| 759 | throw (casa::AipsError( "Either chanFreqArray or chanFreqStep must exist." )) ;
|
---|
| 760 | }
|
---|
[2302] | 761 | if ( specWinRow_p->isChanFreqStartExists() ) {
|
---|
| 762 | refval = specWinRow_p->getChanFreqStart().get() + refpix * incr ;
|
---|
[2273] | 763 | }
|
---|
[2302] | 764 | else if ( specWinRow_p->isChanFreqArrayExists() ) {
|
---|
| 765 | refval = specWinRow_p->getChanFreqArray()[ic].get() ;
|
---|
[2273] | 766 | }
|
---|
| 767 | else {
|
---|
| 768 | throw (casa::AipsError( "Either chanFreqArray or chanFreqStart must exist." )) ;
|
---|
| 769 | }
|
---|
| 770 | }
|
---|
| 771 | else {
|
---|
| 772 | // even
|
---|
| 773 | //logsink_->postLocally( LogMessage("even case",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 774 | refpix = 0.5 * ( (double)nchan - 1.0 ) ;
|
---|
| 775 | int ic = nchan / 2 ;
|
---|
[2302] | 776 | if ( specWinRow_p->isChanWidthExists() ) {
|
---|
| 777 | incr = specWinRow_p->getChanWidth().get() ;
|
---|
[2273] | 778 | }
|
---|
[2302] | 779 | else if ( specWinRow_p->isChanWidthArrayExists() ) {
|
---|
| 780 | incr = specWinRow_p->getChanWidthArray()[0].get() ;
|
---|
[2273] | 781 | }
|
---|
| 782 | else {
|
---|
| 783 | throw (casa::AipsError( "Either chanWidthArray or chanWidth must exist." )) ;
|
---|
| 784 | }
|
---|
[2302] | 785 | if ( specWinRow_p->isChanFreqStepExists() ) {
|
---|
| 786 | if ( specWinRow_p->getChanFreqStep().get() < 0.0 )
|
---|
[2273] | 787 | incr *= -1.0 ;
|
---|
| 788 | }
|
---|
[2302] | 789 | else if ( specWinRow_p->isChanFreqArrayExists() ) {
|
---|
| 790 | vector<Frequency> chanFreqArr = specWinRow_p->getChanFreqArray() ;
|
---|
[2273] | 791 | if ( chanFreqArr[0].get() > chanFreqArr[1].get() )
|
---|
| 792 | incr *= -1.0 ;
|
---|
| 793 | }
|
---|
| 794 | else {
|
---|
| 795 | throw (casa::AipsError( "Either chanFreqArray or chanFreqStep must exist." )) ;
|
---|
| 796 | }
|
---|
[2302] | 797 | if ( specWinRow_p->isChanFreqStartExists() ) {
|
---|
| 798 | refval = specWinRow_p->getChanFreqStart().get() + refpix * incr ;
|
---|
[2273] | 799 | }
|
---|
[2302] | 800 | else if ( specWinRow_p->isChanFreqArrayExists() ) {
|
---|
| 801 | vector<Frequency> freqs = specWinRow_p->getChanFreqArray() ;
|
---|
[2273] | 802 | refval = 0.5 * ( freqs[ic-1].get() + freqs[ic].get() ) ;
|
---|
| 803 | }
|
---|
| 804 | else {
|
---|
| 805 | throw (casa::AipsError( "Either chanFreqArray or chanFreqStart must exist." )) ;
|
---|
| 806 | }
|
---|
| 807 | }
|
---|
| 808 | }
|
---|
| 809 |
|
---|
[2302] | 810 | double OldASDMReader::getTime( unsigned int idx )
|
---|
[2273] | 811 | {
|
---|
[2302] | 812 | prepareData( idx ) ;
|
---|
| 813 | return getTime() ;
|
---|
[2273] | 814 | }
|
---|
| 815 |
|
---|
[2302] | 816 | double OldASDMReader::getTime()
|
---|
[2273] | 817 | {
|
---|
[2302] | 818 | double tsec = vmsData_->v_time[dataIndex_] ;
|
---|
[2273] | 819 | return tsec * s2d ;
|
---|
| 820 | }
|
---|
| 821 |
|
---|
| 822 | double OldASDMReader::getInterval( unsigned int idx )
|
---|
| 823 | {
|
---|
[2302] | 824 | prepareData( idx ) ;
|
---|
| 825 | return getInterval() ;
|
---|
[2273] | 826 | }
|
---|
| 827 |
|
---|
[2302] | 828 | double OldASDMReader::getInterval()
|
---|
[2273] | 829 | {
|
---|
[2302] | 830 | return vmsData_->v_interval[dataIndex_] ;
|
---|
| 831 | }
|
---|
| 832 |
|
---|
| 833 | void OldASDMReader::getSourceProperty( unsigned int idx,
|
---|
| 834 | string &srcname,
|
---|
| 835 | string &fieldname,
|
---|
| 836 | vector<double> &srcdir,
|
---|
| 837 | vector<double> &srcpm,
|
---|
| 838 | double &sysvel,
|
---|
| 839 | vector<double> &restfreq )
|
---|
| 840 | {
|
---|
| 841 | prepareData( idx ) ;
|
---|
| 842 | getSourceProperty( srcname, fieldname, srcdir, srcpm, sysvel, restfreq ) ;
|
---|
| 843 | }
|
---|
| 844 |
|
---|
| 845 | void OldASDMReader::getSourceProperty( string &srcname,
|
---|
| 846 | string &fieldname,
|
---|
| 847 | vector<double> &srcdir,
|
---|
| 848 | vector<double> &srcpm,
|
---|
| 849 | double &sysvel,
|
---|
| 850 | vector<double> &restfreq )
|
---|
| 851 | {
|
---|
| 852 | ostringstream oss ;
|
---|
| 853 | oss << fieldRow_p->getFieldName() << "__" << vmsData_->v_fieldId[dataIndex_] ;
|
---|
| 854 | fieldname = oss.str() ;
|
---|
| 855 | if ( fieldRow_p->isSourceIdExists() ) {
|
---|
| 856 | int sourceId = fieldRow_p->getSourceId() ;
|
---|
| 857 | SourceRow *srow = asdm_->getSource().getRowByKey( sourceId, timeInterval_, specWinTag_ ) ;
|
---|
| 858 |
|
---|
| 859 | // source name
|
---|
[2273] | 860 | srcname = srow->getSourceName() ;
|
---|
[2302] | 861 |
|
---|
| 862 | // source direction
|
---|
| 863 | vector<Angle> srcdirA = srow->getDirection() ;
|
---|
| 864 | srcdir.resize( 2 ) ;
|
---|
| 865 | srcdir[0] = limitedAngle( srcdirA[0].get() ) ;
|
---|
| 866 | srcdir[1] = limitedAngle( srcdirA[1].get() ) ;
|
---|
| 867 | if ( srow->isDirectionCodeExists() ) {
|
---|
| 868 | DirectionReferenceCode dircode = srow->getDirectionCode() ;
|
---|
| 869 | //logsink_->postLocally( LogMessage("dircode="+CDirectionReferenceCode::toString(dircode),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 870 | if ( dircode != J2000 ) {
|
---|
| 871 | // if not J2000, need direction conversion
|
---|
| 872 | String ref( CDirectionReferenceCode::toString( dircode ) ) ;
|
---|
| 873 | double mjd = vmsData_->v_time[dataIndex_] * s2d ;
|
---|
| 874 | srcdir = toJ2000( srcdir, ref, mjd, antennaPosition_ ) ;
|
---|
| 875 | }
|
---|
| 876 | }
|
---|
| 877 |
|
---|
| 878 | // source proper motion
|
---|
| 879 | srcpm.resize( 2 ) ;
|
---|
| 880 | vector<AngularRate> srcpmA = srow->getProperMotion() ;
|
---|
| 881 | srcpm[0] = srcpmA[0].get() ;
|
---|
| 882 | srcpm[1] = srcpmA[1].get() ;
|
---|
| 883 |
|
---|
| 884 | // systemic velocity
|
---|
| 885 | if ( srow->isSysVelExists() ) {
|
---|
| 886 | vector<Speed> sysvelV = srow->getSysVel() ;
|
---|
| 887 | if ( sysvelV.size() > 0 )
|
---|
| 888 | sysvel = sysvelV[0].get() ;
|
---|
| 889 | }
|
---|
| 890 | else {
|
---|
| 891 | sysvel = 0.0 ;
|
---|
| 892 | }
|
---|
| 893 |
|
---|
| 894 | // rest frequency
|
---|
| 895 | if ( srow->isRestFrequencyExists() ) {
|
---|
| 896 | //logsink_->postLocally( LogMessage("restFrequency exists",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 897 | vector<Frequency> rf = srow->getRestFrequency() ;
|
---|
| 898 | restfreq.resize( rf.size() ) ;
|
---|
| 899 | for ( unsigned int i = 0 ; i < restfreq.size() ; i++ )
|
---|
| 900 | restfreq[i] = rf[i].get() ;
|
---|
| 901 | }
|
---|
| 902 | else {
|
---|
| 903 | restfreq.resize( 0 ) ;
|
---|
| 904 | }
|
---|
[2273] | 905 | }
|
---|
| 906 | else {
|
---|
[2302] | 907 | srcname = fieldRow_p->getFieldName() ;
|
---|
| 908 | srcdir.resize( 2 ) ;
|
---|
| 909 | srcdir[0] = 0.0 ;
|
---|
| 910 | srcdir[1] = 0.0 ;
|
---|
| 911 | srcpm = srcdir ;
|
---|
| 912 | sysvel = 0.0 ;
|
---|
| 913 | restfreq.resize( 0 ) ;
|
---|
[2273] | 914 | }
|
---|
| 915 | }
|
---|
| 916 |
|
---|
| 917 | int OldASDMReader::getSrcType( unsigned int scan,
|
---|
| 918 | unsigned int subscan )
|
---|
| 919 | {
|
---|
| 920 | int srctype = SrcType::NOTYPE ;
|
---|
[2302] | 921 | ScanRow *scanrow = asdm_->getScan().getRowByKey( execBlockTag_, (int)scan ) ;
|
---|
[2273] | 922 | ScanIntent scanIntent = scanrow->getScanIntent()[0] ;
|
---|
[2302] | 923 | SubscanRow *subrow = asdm_->getSubscan().getRowByKey( execBlockTag_, (int)scan, (int)subscan ) ;
|
---|
[2273] | 924 | SubscanIntent subIntent = subrow->getSubscanIntent() ;
|
---|
[2299] | 925 | SwitchingMode swmode = NO_SWITCHING ;
|
---|
| 926 | if ( subrow->isSubscanModeExists() )
|
---|
| 927 | swmode = subrow->getSubscanMode() ;
|
---|
[2273] | 928 | if ( scanIntent == OBSERVE_TARGET ) {
|
---|
| 929 | // on sky scan
|
---|
| 930 | if ( swmode == NO_SWITCHING || swmode == POSITION_SWITCHING ) {
|
---|
| 931 | // position switching
|
---|
| 932 | // tentatively set NO_SWITCHING = POSITION_SWITCHING
|
---|
| 933 | if ( subIntent == ON_SOURCE ) {
|
---|
| 934 | srctype = SrcType::PSON ;
|
---|
| 935 | }
|
---|
| 936 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 937 | srctype = SrcType::PSOFF ;
|
---|
| 938 | }
|
---|
| 939 | }
|
---|
| 940 | else if ( swmode == FREQUENCY_SWITCHING ) {
|
---|
| 941 | // frequency switching
|
---|
| 942 | if ( subIntent == ON_SOURCE ) {
|
---|
| 943 | srctype = SrcType::FSON ;
|
---|
| 944 | }
|
---|
| 945 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 946 | srctype = SrcType::FSOFF ;
|
---|
| 947 | }
|
---|
| 948 | }
|
---|
| 949 | else if ( swmode == NUTATOR_SWITCHING ) {
|
---|
| 950 | // nutator switching
|
---|
| 951 | if ( subIntent == ON_SOURCE ) {
|
---|
| 952 | srctype = SrcType::PSON ;
|
---|
| 953 | }
|
---|
| 954 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 955 | srctype = SrcType::PSOFF ;
|
---|
| 956 | }
|
---|
| 957 | }
|
---|
| 958 | else {
|
---|
| 959 | // other switching mode
|
---|
| 960 | if ( subIntent == ON_SOURCE ) {
|
---|
| 961 | srctype = SrcType::SIG ;
|
---|
| 962 | }
|
---|
| 963 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 964 | srctype = SrcType::REF ;
|
---|
| 965 | }
|
---|
| 966 | }
|
---|
| 967 | }
|
---|
| 968 | else if ( scanIntent == CALIBRATE_ATMOSPHERE ) {
|
---|
| 969 | if ( swmode == NO_SWITCHING || swmode == POSITION_SWITCHING ) {
|
---|
| 970 | // position switching
|
---|
| 971 | // tentatively set NO_SWITCHING = POSITION_SWITCHING
|
---|
| 972 | if ( subIntent == ON_SOURCE ) {
|
---|
| 973 | srctype = SrcType::PONCAL ;
|
---|
| 974 | }
|
---|
| 975 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 976 | srctype = SrcType::POFFCAL ;
|
---|
| 977 | }
|
---|
| 978 | }
|
---|
| 979 | else if ( swmode == FREQUENCY_SWITCHING ) {
|
---|
| 980 | // frequency switching
|
---|
| 981 | if ( subIntent == ON_SOURCE ) {
|
---|
| 982 | srctype = SrcType::FONCAL ;
|
---|
| 983 | }
|
---|
| 984 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 985 | srctype = SrcType::FOFFCAL ;
|
---|
| 986 | }
|
---|
| 987 | }
|
---|
| 988 | else if ( swmode == NUTATOR_SWITCHING ) {
|
---|
| 989 | // nutator switching
|
---|
| 990 | if ( subIntent == ON_SOURCE ) {
|
---|
| 991 | srctype = SrcType::PONCAL ;
|
---|
| 992 | }
|
---|
| 993 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 994 | srctype = SrcType::POFFCAL ;
|
---|
| 995 | }
|
---|
| 996 | }
|
---|
| 997 | else {
|
---|
| 998 | // other switching mode
|
---|
| 999 | if ( subIntent == ON_SOURCE ) {
|
---|
| 1000 | srctype = SrcType::CAL ;
|
---|
| 1001 | }
|
---|
| 1002 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 1003 | srctype = SrcType::CAL ;
|
---|
| 1004 | }
|
---|
| 1005 | }
|
---|
| 1006 | }
|
---|
| 1007 | else {
|
---|
| 1008 | // off sky (e.g. calibrator device) scan
|
---|
| 1009 | if ( subIntent == ON_SOURCE ) {
|
---|
| 1010 | srctype = SrcType::SIG ;
|
---|
| 1011 | }
|
---|
| 1012 | else if ( subIntent == OFF_SOURCE ) {
|
---|
| 1013 | srctype = SrcType::REF ;
|
---|
| 1014 | }
|
---|
| 1015 | else if ( subIntent == HOT ) {
|
---|
| 1016 | srctype = SrcType::HOT ;
|
---|
| 1017 | }
|
---|
| 1018 | else if ( subIntent == AMBIENT ) {
|
---|
| 1019 | srctype = SrcType::SKY ;
|
---|
| 1020 | }
|
---|
| 1021 | else {
|
---|
| 1022 | srctype = SrcType::CAL ;
|
---|
| 1023 | }
|
---|
| 1024 | }
|
---|
| 1025 |
|
---|
| 1026 | return srctype ;
|
---|
| 1027 | }
|
---|
| 1028 |
|
---|
| 1029 | unsigned int OldASDMReader::getSubscanNo( unsigned int idx )
|
---|
| 1030 | {
|
---|
[2302] | 1031 | prepareData( idx ) ;
|
---|
| 1032 | return getSubscanNo() ;
|
---|
[2273] | 1033 | }
|
---|
| 1034 |
|
---|
[2302] | 1035 | unsigned int OldASDMReader::getSubscanNo()
|
---|
[2273] | 1036 | {
|
---|
[2302] | 1037 | //logsink_->postLocally( LogMessage("subscan"+String::toString(vmsData_->v_msState[dataIdList_[idx]].subscanNum)+": obsmode="+String::toString(vmsData_->v_msState[dataIdList_[idx]].obsMode),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1038 | return vmsData_->v_msState[dataIndex_].subscanNum ;
|
---|
[2273] | 1039 | }
|
---|
| 1040 |
|
---|
| 1041 | void OldASDMReader::getSourceDirection( vector<double> &dir, string &ref )
|
---|
| 1042 | {
|
---|
| 1043 | dir.resize( 2 ) ;
|
---|
| 1044 | ref = "J2000" ; // default is J2000
|
---|
| 1045 | SourceTable &tab = asdm_->getSource() ;
|
---|
| 1046 | SourceRow *row = tab.get()[0] ;
|
---|
| 1047 | vector<Angle> dirA = row->getDirection() ;
|
---|
| 1048 | dir[0] = dirA[0].get() ;
|
---|
| 1049 | dir[1] = dirA[1].get() ;
|
---|
| 1050 | if ( row->isDirectionCodeExists() ) {
|
---|
| 1051 | ref = CDirectionReferenceCode::toString( row->getDirectionCode() ) ;
|
---|
| 1052 | }
|
---|
| 1053 | }
|
---|
| 1054 |
|
---|
[2302] | 1055 | unsigned int OldASDMReader::getFlagRow( unsigned int idx )
|
---|
[2273] | 1056 | {
|
---|
[2302] | 1057 | prepareData( idx ) ;
|
---|
| 1058 | return getFlagRow() ;
|
---|
[2273] | 1059 | }
|
---|
| 1060 |
|
---|
[2302] | 1061 | unsigned int OldASDMReader::getFlagRow()
|
---|
[2273] | 1062 | {
|
---|
[2302] | 1063 | return vmsData_->v_flag[dataIndex_] ;
|
---|
[2273] | 1064 | }
|
---|
| 1065 |
|
---|
[2302] | 1066 | vector<unsigned int> OldASDMReader::getDataShape( unsigned int idx )
|
---|
[2273] | 1067 | {
|
---|
[2302] | 1068 | prepareData( idx ) ;
|
---|
| 1069 | return getDataShape() ;
|
---|
[2273] | 1070 | }
|
---|
| 1071 |
|
---|
[2302] | 1072 | vector<unsigned int> OldASDMReader::getDataShape()
|
---|
[2273] | 1073 | {
|
---|
[2302] | 1074 | return vmsData_->vv_dataShape[dataIndex_] ;
|
---|
[2273] | 1075 | }
|
---|
| 1076 |
|
---|
| 1077 | float * OldASDMReader::getSpectrum( unsigned int idx )
|
---|
| 1078 | {
|
---|
[2302] | 1079 | prepareData( idx ) ;
|
---|
| 1080 | return getSpectrum() ;
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|
| 1083 | float * OldASDMReader::getSpectrum()
|
---|
| 1084 | {
|
---|
| 1085 | map<AtmPhaseCorrection, float*> data = vmsData_->v_m_data[dataIndex_] ;
|
---|
[2273] | 1086 | //map<AtmPhaseCorrection, float*>::iterator iter = data.find(AP_UNCORRECTED) ;
|
---|
| 1087 | map<AtmPhaseCorrection, float*>::iterator iter = data.find(apc_) ;
|
---|
| 1088 | float *autoCorr = iter->second ;
|
---|
| 1089 | return autoCorr ;
|
---|
| 1090 | }
|
---|
| 1091 |
|
---|
| 1092 | vector< vector<float> > OldASDMReader::getTsys( unsigned int idx )
|
---|
| 1093 | {
|
---|
[2302] | 1094 | prepareData( idx ) ;
|
---|
| 1095 | return getTsys() ;
|
---|
| 1096 | }
|
---|
| 1097 |
|
---|
| 1098 | vector< vector<float> > OldASDMReader::getTsys()
|
---|
| 1099 | {
|
---|
[2273] | 1100 | vector< vector<float> > defaultTsys( 1, vector<float>( 1, 1.0 ) ) ;
|
---|
[2302] | 1101 | SysCalRow *scrow = getSysCalRow() ;
|
---|
[2273] | 1102 | if ( scrow != 0 && scrow->isTsysSpectrumExists() ) {
|
---|
| 1103 | vector< vector<Temperature> > tsysSpec = scrow->getTsysSpectrum() ;
|
---|
| 1104 | unsigned int numReceptor = tsysSpec.size() ;
|
---|
| 1105 | unsigned int numChan = tsysSpec[0].size() ;
|
---|
| 1106 | vector< vector<float> > tsys( numReceptor, vector<float>( numChan, 1.0 ) ) ;
|
---|
| 1107 | for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ ) {
|
---|
| 1108 | for ( unsigned int ic = 0 ; ic < numChan ; ic++ ) {
|
---|
| 1109 | tsys[ir][ic] = tsysSpec[ir][ic].get() ;
|
---|
| 1110 | }
|
---|
| 1111 | }
|
---|
| 1112 | return tsys ;
|
---|
| 1113 | }
|
---|
| 1114 | // else if ( scrow->isTsysExists() ) {
|
---|
| 1115 | // vector<Temperature> tsysScalar = scrow->getTsys() ;
|
---|
| 1116 | // unsigned int numReceptor = tsysScalar.size() ;
|
---|
| 1117 | // vector< vector<float> > tsys( numReceptor ) ;
|
---|
| 1118 | // for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ )
|
---|
| 1119 | // tsys[ir] = vector<float>( 1, tsysScalar[ir].get() ) ;
|
---|
| 1120 | // return tsys ;
|
---|
| 1121 | // }
|
---|
| 1122 | else {
|
---|
| 1123 | return defaultTsys ;
|
---|
| 1124 | }
|
---|
| 1125 | }
|
---|
| 1126 |
|
---|
| 1127 | vector< vector<float> > OldASDMReader::getTcal( unsigned int idx )
|
---|
| 1128 | {
|
---|
[2302] | 1129 | prepareData( idx ) ;
|
---|
| 1130 | return getTcal() ;
|
---|
| 1131 | }
|
---|
| 1132 |
|
---|
| 1133 | vector< vector<float> > OldASDMReader::getTcal()
|
---|
| 1134 | {
|
---|
[2273] | 1135 | vector< vector<float> > defaultTcal( 1, vector<float>( 1, 1.0 ) ) ;
|
---|
[2302] | 1136 | SysCalRow *scrow = getSysCalRow() ;
|
---|
[2273] | 1137 | if ( scrow != 0 && scrow->isTcalSpectrumExists() ) {
|
---|
| 1138 | vector< vector<Temperature> > tcalSpec = scrow->getTcalSpectrum() ;
|
---|
| 1139 | unsigned int numReceptor = tcalSpec.size() ;
|
---|
| 1140 | unsigned int numChan = tcalSpec[0].size() ;
|
---|
| 1141 | vector< vector<float> > tcal( numReceptor, vector<float>( numChan, 1.0 ) ) ;
|
---|
| 1142 | for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ ) {
|
---|
| 1143 | for ( unsigned int ic = 0 ; ic < numChan ; ic++ ) {
|
---|
| 1144 | tcal[ir][ic] = tcalSpec[ir][ic].get() ;
|
---|
| 1145 | }
|
---|
| 1146 | }
|
---|
| 1147 | return tcal ;
|
---|
| 1148 | }
|
---|
| 1149 | // else if ( scrow->isTcalExists() ) {
|
---|
| 1150 | // vector<Temperature> tcalScalar = scrow->getTcal() ;
|
---|
| 1151 | // unsigned int numReceptor = tcalScalar.size() ;
|
---|
| 1152 | // vector< vector<float> > tcal( numReceptor, vector<float>( 1, 1.0 ) ) ;
|
---|
| 1153 | // for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ )
|
---|
| 1154 | // tcal[ir][0] = tcalScalar[ir][0].get() ;
|
---|
| 1155 | // return tcal ;
|
---|
| 1156 | // }
|
---|
| 1157 | else {
|
---|
| 1158 | return defaultTcal ;
|
---|
| 1159 | }
|
---|
| 1160 | }
|
---|
| 1161 |
|
---|
| 1162 | void OldASDMReader::getTcalAndTsys( unsigned int idx,
|
---|
| 1163 | vector< vector<float> > &tcal,
|
---|
| 1164 | vector< vector<float> > &tsys )
|
---|
| 1165 | {
|
---|
[2302] | 1166 | prepareData( idx ) ;
|
---|
| 1167 | getTcalAndTsys( tcal, tsys ) ;
|
---|
| 1168 | }
|
---|
| 1169 |
|
---|
| 1170 | void OldASDMReader::getTcalAndTsys( vector< vector<float> > &tcal,
|
---|
| 1171 | vector< vector<float> > &tsys )
|
---|
| 1172 | {
|
---|
[2273] | 1173 | String funcName = "getTcalAndTsys" ;
|
---|
| 1174 |
|
---|
| 1175 | vector< vector<float> > defaultT( 1, vector<float>( 1, 1.0 ) ) ;
|
---|
[2302] | 1176 | SysCalRow *scrow = getSysCalRow() ;
|
---|
[2273] | 1177 | if ( scrow == 0 ) {
|
---|
| 1178 | tcal = defaultT ;
|
---|
| 1179 | tsys = defaultT ;
|
---|
| 1180 | }
|
---|
| 1181 | else {
|
---|
| 1182 | if ( scrow->isTsysSpectrumExists() ) {
|
---|
| 1183 | vector< vector<Temperature> > tsysSpec = scrow->getTsysSpectrum() ;
|
---|
| 1184 | unsigned int numReceptor = tsysSpec.size() ;
|
---|
| 1185 | unsigned int numChan = tsysSpec[0].size() ;
|
---|
| 1186 | tsys.resize( numReceptor ) ;
|
---|
| 1187 | for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ ) {
|
---|
| 1188 | tsys[ir].resize( numChan ) ;
|
---|
| 1189 | for ( unsigned int ic = 0 ; ic < numChan ; ic++ ) {
|
---|
| 1190 | tsys[ir][ic] = tsysSpec[ir][ic].get() ;
|
---|
| 1191 | }
|
---|
| 1192 | }
|
---|
| 1193 | }
|
---|
| 1194 | else {
|
---|
| 1195 | tsys = defaultT ;
|
---|
| 1196 | }
|
---|
| 1197 | if ( scrow->isTcalSpectrumExists() ) {
|
---|
| 1198 | vector< vector<Temperature> > tcalSpec = scrow->getTcalSpectrum() ;
|
---|
| 1199 | unsigned int numReceptor = tcalSpec.size() ;
|
---|
| 1200 | unsigned int numChan = tcalSpec[0].size() ;
|
---|
| 1201 | tcal.resize( numReceptor ) ;
|
---|
| 1202 | for ( unsigned int ir = 0 ; ir < numReceptor ; ir++ ) {
|
---|
| 1203 | tcal[ir].resize( numReceptor ) ;
|
---|
| 1204 | for ( unsigned int ic = 0 ; ic < numChan ; ic++ ) {
|
---|
| 1205 | tcal[ir][ic] = tcalSpec[ir][ic].get() ;
|
---|
| 1206 | }
|
---|
| 1207 | }
|
---|
| 1208 | }
|
---|
| 1209 | else {
|
---|
| 1210 | tcal = defaultT ;
|
---|
| 1211 | }
|
---|
| 1212 | }
|
---|
| 1213 | }
|
---|
| 1214 |
|
---|
| 1215 | vector<float> OldASDMReader::getOpacity( unsigned int idx )
|
---|
| 1216 | {
|
---|
[2302] | 1217 | prepareData( idx ) ;
|
---|
| 1218 | return getOpacity() ;
|
---|
| 1219 | }
|
---|
| 1220 |
|
---|
| 1221 | vector<float> OldASDMReader::getOpacity()
|
---|
| 1222 | {
|
---|
[2273] | 1223 | vector<float> tau(0) ;
|
---|
| 1224 | CalAtmosphereTable &atmtab = asdm_->getCalAtmosphere() ;
|
---|
| 1225 | unsigned int nrow = atmtab.size() ;
|
---|
| 1226 | if ( nrow > 0 ) {
|
---|
| 1227 | //int feedid = vmsData_->v_feedId1[index] ;
|
---|
| 1228 | //BasebandName bbname = spwrow->getBasebandName() ;
|
---|
| 1229 | //FeedRow *frow = asdm_->getFeed().getRowByKey( atag, spwtag, tint, feedid ) ;
|
---|
| 1230 | //int nfeed = frow->getNumReceptor() ;
|
---|
| 1231 | //vector<ReceiverRow *> rrows = frow->getReceivers() ;
|
---|
| 1232 | vector<CalAtmosphereRow *> atmrows = atmtab.get() ;
|
---|
| 1233 | //ReceiverBand rb = rrows[0]->getFrequencyBand() ;
|
---|
| 1234 | int row0 = -1 ;
|
---|
[2302] | 1235 | double eps = DBL_MAX ;
|
---|
[2273] | 1236 | for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 1237 | CalAtmosphereRow *atmrow = atmrows[irow] ;
|
---|
| 1238 | if ( casa::String(atmrow->getAntennaName()) != antennaName_
|
---|
| 1239 | //|| atmrow->getReceiverBand() != rb
|
---|
| 1240 | //|| atmrow->getBasebandName() != bbname
|
---|
| 1241 | || atmrow->getCalDataUsingCalDataId()->getCalType() != CAL_ATMOSPHERE )
|
---|
| 1242 | continue ;
|
---|
| 1243 | else {
|
---|
[2302] | 1244 | double dt = timeInterval_.getStart().getMJD() - atmrow->getEndValidTime().getMJD() ;
|
---|
[2273] | 1245 | if ( dt >= 0 && dt < eps ) {
|
---|
| 1246 | eps = dt ;
|
---|
| 1247 | row0 = (int)irow ;
|
---|
| 1248 | }
|
---|
| 1249 | }
|
---|
| 1250 | }
|
---|
| 1251 | if ( row0 != -1 ) {
|
---|
| 1252 | CalAtmosphereRow *atmrow = atmrows[row0] ;
|
---|
| 1253 | tau = atmrow->getTau() ;
|
---|
| 1254 | }
|
---|
| 1255 | }
|
---|
| 1256 | else {
|
---|
| 1257 | tau.resize( 1 ) ;
|
---|
| 1258 | tau[0] = 0.0 ;
|
---|
| 1259 | }
|
---|
| 1260 | return tau ;
|
---|
| 1261 | }
|
---|
| 1262 |
|
---|
| 1263 | void OldASDMReader::getWeatherInfo( unsigned int idx,
|
---|
| 1264 | float &temperature,
|
---|
| 1265 | float &pressure,
|
---|
| 1266 | float &humidity,
|
---|
| 1267 | float &windspeed,
|
---|
| 1268 | float &windaz )
|
---|
| 1269 | {
|
---|
[2302] | 1270 | prepareData( idx ) ;
|
---|
| 1271 | getWeatherInfo( temperature, pressure, humidity, windspeed, windaz ) ;
|
---|
| 1272 | }
|
---|
| 1273 |
|
---|
| 1274 | void OldASDMReader::getWeatherInfo( float &temperature,
|
---|
| 1275 | float &pressure,
|
---|
| 1276 | float &humidity,
|
---|
| 1277 | float &windspeed,
|
---|
| 1278 | float &windaz )
|
---|
| 1279 | {
|
---|
[2273] | 1280 | casa::String funcName = "getWeatherInfo" ;
|
---|
| 1281 |
|
---|
| 1282 | temperature = 0.0 ;
|
---|
| 1283 | pressure = 0.0 ;
|
---|
| 1284 | humidity = 0.0 ;
|
---|
| 1285 | windspeed = 0.0 ;
|
---|
| 1286 | windaz = 0.0 ;
|
---|
| 1287 |
|
---|
| 1288 | //logsink_->postLocally( LogMessage("weatherStationId_ = "+String::toString(weatherStationId_),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1289 |
|
---|
| 1290 | WeatherTable &wtab = asdm_->getWeather() ;
|
---|
| 1291 | if ( wtab.size() == 0 || weatherStationId_ == -1 )
|
---|
| 1292 | return ;
|
---|
| 1293 |
|
---|
| 1294 | Tag sttag( (unsigned int)weatherStationId_, TagType::Station ) ;
|
---|
| 1295 | //WeatherRow *wrow = wtab.getRowByKey( sttag, tint ) ;
|
---|
| 1296 | vector<WeatherRow *> *wrows = wtab.getByContext( sttag ) ;
|
---|
| 1297 | WeatherRow *wrow = (*wrows)[0] ;
|
---|
| 1298 | unsigned int nrow = wrows->size() ;
|
---|
| 1299 | //logsink_->postLocally( LogMessage("There are "+String::toString(nrow)+" rows for given context: stationId "+String::toString(weatherStationId_),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
[2302] | 1300 | ArrayTime startTime = getMidTime( timeInterval_ ) ;
|
---|
[2273] | 1301 | if ( startTime < (*wrows)[0]->getTimeInterval().getStart() ) {
|
---|
| 1302 | temperature = (*wrows)[0]->getTemperature().get() ;
|
---|
| 1303 | pressure = (*wrows)[0]->getPressure().get() ;
|
---|
| 1304 | humidity = (*wrows)[0]->getRelHumidity().get() ;
|
---|
| 1305 | windspeed = (*wrows)[0]->getWindSpeed().get() ;
|
---|
| 1306 | windaz = (*wrows)[0]->getWindDirection().get() ;
|
---|
| 1307 | }
|
---|
| 1308 | else if ( startTime > getEndTime( (*wrows)[nrow-1]->getTimeInterval() ) ) {
|
---|
| 1309 | temperature = (*wrows)[nrow-1]->getTemperature().get() ;
|
---|
| 1310 | pressure = (*wrows)[nrow-1]->getPressure().get() ;
|
---|
| 1311 | humidity = (*wrows)[nrow-1]->getRelHumidity().get() ;
|
---|
| 1312 | windspeed = (*wrows)[nrow-1]->getWindSpeed().get() ;
|
---|
| 1313 | windaz = (*wrows)[nrow-1]->getWindDirection().get() ;
|
---|
| 1314 | }
|
---|
| 1315 | else {
|
---|
| 1316 | for ( unsigned int irow = 1 ; irow < wrows->size() ; irow++ ) {
|
---|
| 1317 | wrow = (*wrows)[irow-1] ;
|
---|
| 1318 | ArrayTime tStart = wrow->getTimeInterval().getStart() ;
|
---|
| 1319 | ArrayTime tEnd = (*wrows)[irow]->getTimeInterval().getStart() ;
|
---|
| 1320 | if ( startTime >= tStart && startTime <= tEnd ) {
|
---|
| 1321 | temperature = wrow->getTemperature().get() ;
|
---|
| 1322 | pressure = wrow->getPressure().get() ;
|
---|
| 1323 | humidity = wrow->getRelHumidity().get() ;
|
---|
| 1324 | windspeed = wrow->getWindSpeed().get() ;
|
---|
| 1325 | windaz = wrow->getWindDirection().get() ;
|
---|
| 1326 | break ;
|
---|
| 1327 | }
|
---|
| 1328 | }
|
---|
| 1329 | }
|
---|
| 1330 |
|
---|
| 1331 | // Pa -> hPa
|
---|
| 1332 | pressure /= 100.0 ;
|
---|
| 1333 |
|
---|
| 1334 | return ;
|
---|
| 1335 | }
|
---|
| 1336 |
|
---|
| 1337 | void OldASDMReader::processStation()
|
---|
| 1338 | {
|
---|
| 1339 | antennaPad_.resize(0) ;
|
---|
| 1340 | weatherStation_.resize(0) ;
|
---|
| 1341 | StationTable &stab = asdm_->getStation() ;
|
---|
| 1342 | vector<StationRow *> srows = stab.get() ;
|
---|
| 1343 | for ( unsigned int irow = 0 ; irow < srows.size() ; irow++ ) {
|
---|
| 1344 | StationType stype = srows[irow]->getType() ;
|
---|
| 1345 | Tag stag = srows[irow]->getStationId() ;
|
---|
| 1346 | if ( stype == ANTENNA_PAD )
|
---|
| 1347 | antennaPad_.push_back( stag ) ;
|
---|
| 1348 | else if ( stype == WEATHER_STATION )
|
---|
| 1349 | weatherStation_.push_back( stag ) ;
|
---|
| 1350 | }
|
---|
| 1351 |
|
---|
| 1352 | weatherStationId_ = getClosestWeatherStation() ;
|
---|
| 1353 | }
|
---|
| 1354 |
|
---|
| 1355 | int OldASDMReader::getClosestWeatherStation()
|
---|
| 1356 | {
|
---|
| 1357 | if ( weatherStation_.size() == 0 )
|
---|
| 1358 | return -1 ;
|
---|
| 1359 |
|
---|
| 1360 | vector<double> apos( 3 ) ;
|
---|
| 1361 | StationTable &stab = asdm_->getStation() ;
|
---|
[2302] | 1362 | apos[0] = antennaPosition_[0].getValue( Unit("m") ) ;
|
---|
| 1363 | apos[1] = antennaPosition_[1].getValue( Unit("m") ) ;
|
---|
| 1364 | apos[2] = antennaPosition_[2].getValue( Unit("m") ) ;
|
---|
[2273] | 1365 |
|
---|
[2302] | 1366 | double eps = DBL_MAX ;
|
---|
[2273] | 1367 | int retval = -1 ;
|
---|
| 1368 | for ( unsigned int ir = 0 ; ir < weatherStation_.size() ; ir++ ) {
|
---|
[2302] | 1369 | StationRow *srow = stab.getRowByKey( weatherStation_[ir] ) ;
|
---|
[2273] | 1370 | vector<Length> wpos = srow->getPosition() ;
|
---|
| 1371 | double dist = (apos[0]-wpos[0].get())*(apos[0]-wpos[0].get())
|
---|
| 1372 | + (apos[1]-wpos[1].get())*(apos[1]-wpos[1].get())
|
---|
| 1373 | + (apos[2]-wpos[2].get())*(apos[2]-wpos[2].get()) ;
|
---|
| 1374 | if ( dist < eps ) {
|
---|
| 1375 | retval = (int)(weatherStation_[ir].getTagValue()) ;
|
---|
| 1376 | }
|
---|
| 1377 | }
|
---|
| 1378 |
|
---|
| 1379 | return retval ;
|
---|
| 1380 | }
|
---|
| 1381 |
|
---|
| 1382 | void OldASDMReader::getPointingInfo( unsigned int idx,
|
---|
| 1383 | vector<double> &dir,
|
---|
| 1384 | double &az,
|
---|
| 1385 | double &el,
|
---|
| 1386 | vector<double> &srate )
|
---|
| 1387 | {
|
---|
[2302] | 1388 | prepareData( idx ) ;
|
---|
| 1389 | getPointingInfo( dir, az, el, srate ) ;
|
---|
| 1390 | }
|
---|
| 1391 |
|
---|
| 1392 | void OldASDMReader::getPointingInfo( vector<double> &dir,
|
---|
| 1393 | double &az,
|
---|
| 1394 | double &el,
|
---|
| 1395 | vector<double> &srate )
|
---|
| 1396 | {
|
---|
[2273] | 1397 | String funcName = "getPointingInfo" ;
|
---|
| 1398 |
|
---|
| 1399 | dir.resize(0) ;
|
---|
| 1400 | az = -1.0 ;
|
---|
| 1401 | el = -1.0 ;
|
---|
| 1402 | srate.resize(0) ;
|
---|
| 1403 |
|
---|
[2302] | 1404 | //Tag atag( antennaId_, TagType::Antenna ) ;
|
---|
| 1405 | //unsigned int index = dataIdList_[idx] ;
|
---|
| 1406 | //vector<PointingRow *> *prows = asdm_->getPointing().getByContext( atag ) ;
|
---|
| 1407 | vector<PointingRow *> *prows = asdm_->getPointing().getByContext( antennaTag_ ) ;
|
---|
[2273] | 1408 |
|
---|
| 1409 | if ( prows == 0 )
|
---|
| 1410 | return ;
|
---|
| 1411 |
|
---|
| 1412 | PointingRow *prow ;
|
---|
| 1413 | PointingRow *qrow ;
|
---|
| 1414 | //ArrayTimeInterval tint( vmsData_->v_time[index]*s2d, vmsData_->v_interval[index]*s2d ) ;
|
---|
[2302] | 1415 | //double startSec = vmsData_->v_time[index] - 0.5 * vmsData_->v_interval[index] ;
|
---|
| 1416 | //ArrayTimeInterval tint( startSec*s2d, vmsData_->v_interval[index]*s2d ) ;
|
---|
[2273] | 1417 |
|
---|
| 1418 | unsigned int nrow = prows->size() ;
|
---|
| 1419 | //logsink_->postLocally( LogMessage("There are " << nrow << " rows for given context: antennaId "+String::toString(antennaId_),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1420 |
|
---|
| 1421 | // for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 1422 | // prow = (*prows)[irow] ;
|
---|
| 1423 | // ArrayTimeInterval ati = prow->getTimeInterval() ;
|
---|
| 1424 | // ArrayTime pst = ati.getStart() ;
|
---|
| 1425 | // ArrayTime pet( ati.getStartInMJD()+ati.getDurationInDays() ) ;
|
---|
| 1426 | // logsink_->postLocally( LogMessage("start: "+pst.toFITS(),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1427 | // logsink_->postLocally( LogMessage("end: "+pet.toFITS(),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1428 | // }
|
---|
| 1429 |
|
---|
| 1430 | srate.resize(2) ;
|
---|
| 1431 | srate[0] = 0.0 ;
|
---|
| 1432 | srate[1] = 0.0 ;
|
---|
| 1433 | az = 0.0 ;
|
---|
| 1434 | el = 0.0 ;
|
---|
| 1435 | //double tcen = 0.0 ;
|
---|
[2302] | 1436 | //double tcen = getMidTime( tint ).getMJD() ;
|
---|
| 1437 | double tcen = getMidTime( timeInterval_ ).getMJD() ;
|
---|
[2273] | 1438 |
|
---|
| 1439 | //
|
---|
| 1440 | // shape of pointingDirection is (numSample,2) if usePolynomial = False, while it is
|
---|
| 1441 | // (numTerm,2) if usePolynomial = True.
|
---|
| 1442 | //
|
---|
| 1443 | // In the former case, typical sampled time interval is 48msec, which is very small
|
---|
| 1444 | // compared with typical integration time (~a few sec).
|
---|
| 1445 | // Scan rate for this case is always [0,0] (or get slope?).
|
---|
| 1446 | //
|
---|
| 1447 | // In the later case, scan rate is (pointingDirection[1][0],pointingDirection[1][1])
|
---|
| 1448 | //
|
---|
| 1449 | // PointingDirection seems to store AZEL
|
---|
| 1450 | //
|
---|
| 1451 | ArrayTimeInterval pTime0 = (*prows)[0]->getTimeInterval() ;
|
---|
| 1452 | ArrayTimeInterval pTime1 = (*prows)[nrow-1]->getTimeInterval() ;
|
---|
| 1453 | //if ( tint.getStartInMJD()+tint.getDurationInDays() < pTime0.getStartInMJD() ) {
|
---|
[2302] | 1454 | //if ( getEndTime( tint ) < getStartTime( pTime0 ) ) {
|
---|
| 1455 | if ( getEndTime( timeInterval_ ) < getStartTime( pTime0 ) ) {
|
---|
[2273] | 1456 | logsink_->postLocally( LogMessage( "ArrayTimeInterval out of bounds: no data for given position (tint < ptime)", LogOrigin(className_,funcName,WHERE), LogMessage::WARN ) ) ;
|
---|
| 1457 | prow = (*prows)[0] ;
|
---|
| 1458 | vector< vector<double> > dirA = pointingDir( prow ) ;
|
---|
| 1459 | az = dirA[0][0] ;
|
---|
| 1460 | el = dirA[0][1] ;
|
---|
| 1461 | if ( prow->getUsePolynomials() && prow->getNumTerm() > 1 ) {
|
---|
| 1462 | srate[0] = dirA[1][0] ;
|
---|
| 1463 | srate[1] = dirA[1][1] ;
|
---|
| 1464 | }
|
---|
| 1465 | }
|
---|
| 1466 | //else if ( tint.getStartInMJD() > pTime1.getStartInMJD()+pTime1.getDurationInDays() ) {
|
---|
[2302] | 1467 | //else if ( getStartTime( tint ) > getEndTime( pTime1 ) ) {
|
---|
| 1468 | else if ( getStartTime( timeInterval_ ) > getEndTime( pTime1 ) ) {
|
---|
[2273] | 1469 | logsink_->postLocally( LogMessage( "ArrayTimeInterval out of bounds: no data for given position (tint > ptime)", LogOrigin(className_,funcName,WHERE), LogMessage::WARN ) ) ;
|
---|
| 1470 | prow = (*prows)[nrow-1] ;
|
---|
| 1471 | int numSample = prow->getNumSample() ;
|
---|
| 1472 | vector< vector<double> > dirA = pointingDir( prow ) ;
|
---|
| 1473 | if ( prow->getUsePolynomials() ) {
|
---|
| 1474 | az = dirA[0][0] ;
|
---|
| 1475 | el = dirA[0][1] ;
|
---|
| 1476 | if ( prow->getNumTerm() > 1 ) {
|
---|
| 1477 | srate[0] = dirA[1][0] ;
|
---|
| 1478 | srate[1] = dirA[1][1] ;
|
---|
| 1479 | }
|
---|
| 1480 | }
|
---|
| 1481 | else {
|
---|
| 1482 | az = dirA[numSample-1][0] ;
|
---|
| 1483 | el = dirA[numSample-1][1] ;
|
---|
| 1484 | }
|
---|
| 1485 | }
|
---|
| 1486 | else {
|
---|
[2302] | 1487 | //ArrayTime startTime = tint.getStart() ;
|
---|
| 1488 | //ArrayTime endTime = getEndTime( tint ) ;
|
---|
| 1489 | ArrayTime startTime = timeInterval_.getStart() ;
|
---|
| 1490 | ArrayTime endTime = getEndTime( timeInterval_ ) ;
|
---|
[2273] | 1491 | int row0 = -1 ;
|
---|
| 1492 | int row1 = -1 ;
|
---|
| 1493 | int row2 = -1 ;
|
---|
[2302] | 1494 | //double dt0 = getMidTime( tint ).getMJD() ;
|
---|
| 1495 | double dt0 = getMidTime( timeInterval_ ).getMJD() ;
|
---|
[2273] | 1496 | for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 1497 | prow = (*prows)[irow] ;
|
---|
[2302] | 1498 | //double dt = getMidTime( tint ).getMJD() - getMidTime( prow->getTimeInterval() ).getMJD() ;
|
---|
| 1499 | double dt = getMidTime( timeInterval_ ).getMJD() - getMidTime( prow->getTimeInterval() ).getMJD() ;
|
---|
[2273] | 1500 | if ( dt > 0 && dt < dt0 ) {
|
---|
| 1501 | dt0 = dt ;
|
---|
| 1502 | row2 = irow ;
|
---|
| 1503 | }
|
---|
| 1504 | if ( prow->getTimeInterval().contains( startTime ) )
|
---|
| 1505 | row0 = irow ;
|
---|
| 1506 | else if ( prow->getTimeInterval().contains( endTime ) )
|
---|
| 1507 | row1 = irow ;
|
---|
| 1508 | if ( row0 != -1 && row1 != -1 )
|
---|
| 1509 | break ;
|
---|
| 1510 | }
|
---|
| 1511 | //logsink_->postLocally( LogMessage("row0 = "+String::toString(row0)+", row1 = "+String::toString(row1)+", row2 = "+String::toString(row2),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1512 | if ( row0 == -1 && row1 == -1 ) {
|
---|
| 1513 | prow = (*prows)[row2] ;
|
---|
| 1514 | qrow = (*prows)[row2+1] ;
|
---|
| 1515 | double t0 = getEndTime( prow->getTimeInterval() ).getMJD() ;
|
---|
| 1516 | double t1 = qrow->getTimeInterval().getStartInMJD() ;
|
---|
| 1517 | vector< vector<double> > dirA = pointingDir( prow ) ;
|
---|
| 1518 | vector< vector<double> > dirB = pointingDir( qrow ) ;
|
---|
| 1519 | double da0 = dirA[0][0] ;
|
---|
| 1520 | double db0 = dirB[0][0] ;
|
---|
| 1521 | double da1 = dirA[0][1] ;
|
---|
| 1522 | double db1 = dirB[0][1] ;
|
---|
| 1523 | if ( prow->getUsePolynomials() && qrow->getUsePolynomials() ) {
|
---|
| 1524 | double dt = ( tcen - t0 ) / ( t1 - t0 ) ;
|
---|
| 1525 | az = da0 + ( db0 - da0 ) * dt ;
|
---|
| 1526 | el = da1 + ( db1 - da1 ) * dt ;
|
---|
| 1527 | if ( prow->getNumTerm() > 0 && qrow->getNumTerm() > 1 ) {
|
---|
| 1528 | double ra0 = dirA[1][0] ;
|
---|
| 1529 | double rb0 = dirB[1][0] ;
|
---|
| 1530 | double ra1 = dirA[1][1] ;
|
---|
| 1531 | double rb1 = dirB[1][1] ;
|
---|
| 1532 | srate[0] = ra0 + ( rb0 - ra0 ) * dt ;
|
---|
| 1533 | srate[1] = ra1 + ( rb1 - ra1 ) * dt ;
|
---|
| 1534 | }
|
---|
| 1535 | }
|
---|
| 1536 | else if ( !(qrow->getUsePolynomials()) ) {
|
---|
| 1537 | double dt = ( tcen - t0 ) / ( t1 - t0 ) ;
|
---|
| 1538 | az = da0 + ( db0 - da0 ) * dt ;
|
---|
| 1539 | el = da1 + ( db1 - da1 ) * dt ;
|
---|
| 1540 | }
|
---|
| 1541 | //else {
|
---|
| 1542 | // nothing to do
|
---|
| 1543 | //}
|
---|
| 1544 | }
|
---|
| 1545 | else {
|
---|
| 1546 | int ndir = 0 ;
|
---|
| 1547 | if ( row0 == -1 ) {
|
---|
| 1548 | row0 = row1 ;
|
---|
| 1549 | }
|
---|
| 1550 | else if ( row1 == -1 ) {
|
---|
| 1551 | row1 = row0 ;
|
---|
| 1552 | }
|
---|
| 1553 | prow = (*prows)[row0] ;
|
---|
| 1554 | qrow = (*prows)[row1] ;
|
---|
| 1555 | if ( prow->getUsePolynomials() && qrow->getUsePolynomials() ) {
|
---|
| 1556 | //logsink_->postLocally( LogMessage("usePolynomial = True",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1557 | if ( row0 == row1 ) {
|
---|
| 1558 | prow = (*prows)[row0] ;
|
---|
| 1559 | vector< vector<double> > dirA = pointingDir( prow ) ;
|
---|
| 1560 | az = dirA[0][0] ;
|
---|
| 1561 | el = dirA[0][1] ;
|
---|
| 1562 | if ( prow->getNumTerm() > 1 ) {
|
---|
| 1563 | srate[0] = dirA[1][0] ;
|
---|
| 1564 | srate[1] = dirA[1][1] ;
|
---|
| 1565 | }
|
---|
| 1566 | }
|
---|
| 1567 | else {
|
---|
| 1568 | prow = (*prows)[row0] ;
|
---|
| 1569 | qrow = (*prows)[row1] ;
|
---|
| 1570 | vector< vector<double> > dirA = pointingDir( prow ) ;
|
---|
| 1571 | vector< vector<double> > dirB = pointingDir( qrow ) ;
|
---|
| 1572 | double t0 = getMidTime( prow->getTimeInterval() ).getMJD() ;
|
---|
| 1573 | double t1 = getMidTime( qrow->getTimeInterval() ).getMJD() ;
|
---|
| 1574 | double dt = ( tcen - t0 ) / ( t1 - t0 ) ;
|
---|
| 1575 | double da0 = dirA[0][0] ;
|
---|
| 1576 | double db0 = dirB[0][0] ;
|
---|
| 1577 | double da1 = dirA[0][1] ;
|
---|
| 1578 | double db1 = dirB[0][1] ;
|
---|
| 1579 | az = da0 + ( db0 - da0 ) * dt ;
|
---|
| 1580 | el = da1 + ( db1 - db0 ) * dt ;
|
---|
| 1581 | if ( prow->getNumTerm() > 0 && qrow->getNumTerm() > 1 ) {
|
---|
| 1582 | double ra0 = dirA[1][0] ;
|
---|
| 1583 | double rb0 = dirB[1][0] ;
|
---|
| 1584 | double ra1 = dirA[1][1] ;
|
---|
| 1585 | double rb1 = dirB[1][1] ;
|
---|
| 1586 | srate[0] = ra0 + ( rb0 - ra0 ) * dt ;
|
---|
| 1587 | srate[1] = ra1 + ( rb1 - ra1 ) * dt ;
|
---|
| 1588 | }
|
---|
| 1589 | }
|
---|
| 1590 | }
|
---|
| 1591 | else if ( prow->getUsePolynomials() == qrow->getUsePolynomials() ) {
|
---|
| 1592 | //logsink_->postLocally( LogMessage("numSample == numTerm",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1593 | tcen = 0.0 ;
|
---|
| 1594 | for ( int irow = row0 ; irow <= row1 ; irow++ ) {
|
---|
| 1595 | prow = (*prows)[irow] ;
|
---|
| 1596 | int numSample = prow->getNumSample() ;
|
---|
| 1597 | //logsink_->postLocally( LogMessage("numSample = "+String::toString(numSample),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1598 | vector< vector<double> > dirA = pointingDir( prow ) ;
|
---|
| 1599 | if ( prow->isSampledTimeIntervalExists() ) {
|
---|
| 1600 | //logsink_->postLocally( LogMessage("sampledTimeIntervalExists",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1601 | vector<ArrayTimeInterval> stime = prow->getSampledTimeInterval() ;
|
---|
| 1602 | for ( int isam = 0 ; isam < numSample ; isam++ ) {
|
---|
| 1603 | //if ( tint.overlaps( stime[isam] ) ) {
|
---|
[2302] | 1604 | //if ( tint.contains( stime[isam] ) ) {
|
---|
| 1605 | if ( timeInterval_.contains( stime[isam] ) ) {
|
---|
[2273] | 1606 | az += dirA[isam][0] ;
|
---|
| 1607 | el += dirA[isam][1] ;
|
---|
| 1608 | tcen += getMidTime( stime[isam] ).getMJD() ;
|
---|
| 1609 | ndir++ ;
|
---|
| 1610 | }
|
---|
| 1611 | }
|
---|
| 1612 | }
|
---|
| 1613 | else {
|
---|
| 1614 | double sampleStart = prow->getTimeInterval().getStartInMJD() ;
|
---|
| 1615 | double sampleInterval = prow->getTimeInterval().getDurationInDays() / (double)numSample ;
|
---|
| 1616 | //logsink_->postLocally( LogMessage("sampleStart = "+String::toString(sampleStart),LogOrigin(className_,funcName,WHERE)) )
|
---|
| 1617 | //logsink_->postLocally( LogMessage("sampleInterval = "+String::toString(sampleInterval),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1618 | //logsink_->postLocally( LogMessage("tint = "+tint.toString(),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1619 | for ( int isam = 0 ; isam < numSample ; isam++ ) {
|
---|
| 1620 | ArrayTimeInterval stime( sampleStart+isam*sampleInterval, sampleInterval ) ;
|
---|
| 1621 | //if ( tint.overlaps( stime ) ) {
|
---|
[2302] | 1622 | //if ( tint.contains( stime ) ) {
|
---|
| 1623 | if ( timeInterval_.contains( stime ) ) {
|
---|
[2273] | 1624 | az += dirA[isam][0] ;
|
---|
| 1625 | el += dirA[isam][1] ;
|
---|
| 1626 | tcen += getMidTime( stime ).getMJD() ;
|
---|
| 1627 | ndir++ ;
|
---|
| 1628 | }
|
---|
| 1629 | }
|
---|
| 1630 | }
|
---|
| 1631 | }
|
---|
| 1632 | if ( ndir > 1 ) {
|
---|
| 1633 | az /= (double)ndir ;
|
---|
| 1634 | el /= (double)ndir ;
|
---|
| 1635 | tcen /= (double)ndir ;
|
---|
| 1636 | }
|
---|
| 1637 | }
|
---|
| 1638 | //else {
|
---|
| 1639 | // nothing to do
|
---|
| 1640 | //}
|
---|
| 1641 | }
|
---|
| 1642 |
|
---|
[2302] | 1643 | toJ2000( dir, az, el, tcen, antennaPosition_ ) ;
|
---|
[2273] | 1644 | }
|
---|
| 1645 |
|
---|
| 1646 | return ;
|
---|
| 1647 | }
|
---|
| 1648 |
|
---|
| 1649 | ArrayTime OldASDMReader::getMidTime( const ArrayTimeInterval &t )
|
---|
| 1650 | {
|
---|
| 1651 | return ArrayTime( t.getStartInMJD() + 0.5 * t.getDurationInDays() ) ;
|
---|
| 1652 | }
|
---|
| 1653 |
|
---|
| 1654 | ArrayTime OldASDMReader::getEndTime( const ArrayTimeInterval &t )
|
---|
| 1655 | {
|
---|
| 1656 | return ArrayTime( t.getStartInMJD() + t.getDurationInDays() ) ;
|
---|
| 1657 | }
|
---|
| 1658 |
|
---|
| 1659 | ArrayTime OldASDMReader::getStartTime( const ArrayTimeInterval &t )
|
---|
| 1660 | {
|
---|
| 1661 | return ArrayTime( t.getStartInMJD() ) ;
|
---|
| 1662 | }
|
---|
| 1663 |
|
---|
| 1664 | void OldASDMReader::toJ2000( vector<double> &dir,
|
---|
[2302] | 1665 | double &az,
|
---|
| 1666 | double &el,
|
---|
| 1667 | double &mjd,
|
---|
| 1668 | casa::Vector<casa::Quantity> &antpos )
|
---|
| 1669 | // casa::Vector<casa::Double> antpos )
|
---|
[2273] | 1670 | {
|
---|
| 1671 | String funcName = "toJ2000" ;
|
---|
| 1672 |
|
---|
[2302] | 1673 | String ref = "AZELGEO" ;
|
---|
[2273] | 1674 | vector<double> azel( 2 ) ;
|
---|
| 1675 | azel[0] = az ;
|
---|
| 1676 | azel[1] = el ;
|
---|
[2302] | 1677 | dir = toJ2000( azel, ref, mjd, antpos ) ;
|
---|
[2273] | 1678 | }
|
---|
| 1679 |
|
---|
[2302] | 1680 | vector<double> OldASDMReader::toJ2000( vector<double> &dir,
|
---|
| 1681 | casa::String &dirref,
|
---|
| 1682 | double &mjd,
|
---|
| 1683 | casa::Vector<casa::Quantity> &antpos )
|
---|
| 1684 | // casa::Vector<casa::Double> antpos )
|
---|
[2273] | 1685 | {
|
---|
| 1686 | casa::String funcName = "toJ2000" ;
|
---|
| 1687 |
|
---|
| 1688 | vector<double> newd( dir ) ;
|
---|
| 1689 | if ( dirref != "J2000" ) {
|
---|
| 1690 | casa::MEpoch me( casa::Quantity( (casa::Double)mjd, "d" ), casa::MEpoch::UTC ) ;
|
---|
[2302] | 1691 | casa::MPosition mp( casa::MVPosition( antpos ),
|
---|
[2273] | 1692 | casa::MPosition::ITRF ) ;
|
---|
| 1693 | //ostringstream oss ;
|
---|
| 1694 | //mp.print( oss ) ;
|
---|
| 1695 | //logsink_->postLocally( LogMessage(oss.str(),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1696 |
|
---|
| 1697 | casa::MeasFrame mf( me, mp ) ;
|
---|
| 1698 | casa::MDirection::Types dirtype ;
|
---|
| 1699 | casa::Bool b = casa::MDirection::getType( dirtype, dirref ) ;
|
---|
| 1700 | if ( b ) {
|
---|
| 1701 | casa::MDirection::Convert toj2000( dirtype,
|
---|
| 1702 | casa::MDirection::Ref( casa::MDirection::J2000, mf ) ) ;
|
---|
| 1703 | casa::Vector<casa::Double> cdir = toj2000( dir ).getAngle( "rad" ).getValue() ;
|
---|
| 1704 | //logsink_->postLocally( LogMessage("cdir = "+String::toString(cdir),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1705 | newd[0] = (double)(cdir[0]) ;
|
---|
| 1706 | newd[1] = (double)(cdir[1]) ;
|
---|
| 1707 | }
|
---|
| 1708 | }
|
---|
| 1709 | return newd ;
|
---|
| 1710 | }
|
---|
| 1711 |
|
---|
| 1712 | void OldASDMReader::setLogger( CountedPtr<LogSinkInterface> &logsink )
|
---|
| 1713 | {
|
---|
| 1714 | logsink_ = logsink ;
|
---|
| 1715 | }
|
---|
| 1716 |
|
---|
| 1717 | string OldASDMReader::getFrame()
|
---|
| 1718 | {
|
---|
| 1719 | casa::String funcName = "getFrame" ;
|
---|
| 1720 |
|
---|
| 1721 | // default is TOPO
|
---|
| 1722 | string frame = "TOPO" ;
|
---|
| 1723 |
|
---|
| 1724 | SpectralWindowTable &spwtab = asdm_->getSpectralWindow() ;
|
---|
| 1725 | vector<SpectralWindowRow *> rows = spwtab.get() ;
|
---|
| 1726 | vector<FrequencyReferenceCode> measFreqRef( rows.size() ) ;
|
---|
| 1727 | int nref = 0 ;
|
---|
| 1728 | for ( unsigned int irow = 0 ; irow < rows.size() ; irow++ ) {
|
---|
| 1729 | int nchan = rows[irow]->getNumChan() ;
|
---|
| 1730 | if ( nchan != 4 ) {
|
---|
| 1731 | if ( rows[irow]->isMeasFreqRefExists() ) {
|
---|
| 1732 | measFreqRef[nref] = rows[irow]->getMeasFreqRef() ;
|
---|
| 1733 | nref++ ;
|
---|
| 1734 | }
|
---|
| 1735 | }
|
---|
| 1736 | }
|
---|
| 1737 | if ( nref != 0 ) {
|
---|
| 1738 | frame = CFrequencyReferenceCode::toString( measFreqRef[0] ) ;
|
---|
| 1739 | }
|
---|
| 1740 |
|
---|
| 1741 | //logsink_->postLocally( LogMessage("frame = "+String::toString(frame),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1742 |
|
---|
| 1743 | return frame ;
|
---|
| 1744 | }
|
---|
| 1745 |
|
---|
| 1746 | int OldASDMReader::getNumIFs()
|
---|
| 1747 | {
|
---|
| 1748 | casa::String funcName = "getNumIFs" ;
|
---|
| 1749 |
|
---|
| 1750 | int nif = 0 ;
|
---|
| 1751 | vector<SpectralWindowRow *> rows = asdm_->getSpectralWindow().get() ;
|
---|
| 1752 | unsigned int nrow = rows.size() ;
|
---|
| 1753 | // check if all rows have freqGroup attribute
|
---|
| 1754 | bool freqGroupExists = true ;
|
---|
| 1755 | bool countedWvr = false ;
|
---|
| 1756 | for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 1757 | freqGroupExists &= rows[irow]->isFreqGroupExists() ;
|
---|
| 1758 | if ( rows[irow]->getNumChan() == 4 ) {
|
---|
| 1759 | if ( !countedWvr ) {
|
---|
| 1760 | countedWvr = true ;
|
---|
| 1761 | nif++ ;
|
---|
| 1762 | }
|
---|
| 1763 | }
|
---|
| 1764 | else {
|
---|
| 1765 | nif++ ;
|
---|
| 1766 | }
|
---|
| 1767 | }
|
---|
| 1768 |
|
---|
| 1769 | if ( freqGroupExists ) {
|
---|
| 1770 | vector<int> freqGroup(0) ;
|
---|
| 1771 | for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
|
---|
| 1772 | int fg = rows[irow]->getFreqGroup() ;
|
---|
| 1773 | if ( (int)count( freqGroup.begin(), freqGroup.end(), fg ) == 0 ) {
|
---|
| 1774 | freqGroup.push_back( fg ) ;
|
---|
| 1775 | }
|
---|
| 1776 | }
|
---|
| 1777 | nif = freqGroup.size() ;
|
---|
| 1778 | }
|
---|
| 1779 |
|
---|
| 1780 | //logsink_->postLocally( LogMessage("nif = "+String::toString(nif),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1781 |
|
---|
| 1782 | return nif ;
|
---|
| 1783 | }
|
---|
| 1784 |
|
---|
| 1785 | SysCalRow *OldASDMReader::getSysCalRow( unsigned int idx )
|
---|
| 1786 | {
|
---|
[2302] | 1787 | prepareData( idx ) ;
|
---|
| 1788 | return getSysCalRow() ;
|
---|
| 1789 | }
|
---|
| 1790 |
|
---|
| 1791 | SysCalRow *OldASDMReader::getSysCalRow()
|
---|
| 1792 | {
|
---|
[2273] | 1793 | String funcName = "getSysCalRow" ;
|
---|
| 1794 |
|
---|
| 1795 | SysCalRow *row = 0 ;
|
---|
[2302] | 1796 | int feedid = vmsData_->v_feedId1[dataIndex_] ;
|
---|
[2273] | 1797 | SysCalTable &sctab = asdm_->getSysCal() ;
|
---|
[2302] | 1798 | vector<SysCalRow *> *rows = sctab.getByContext( antennaTag_, specWinTag_, feedid ) ;
|
---|
[2273] | 1799 | //if ( nrow == 0 ) {
|
---|
| 1800 | if ( rows == 0 ) {
|
---|
| 1801 | //logsink_->postLocally( LogMessage("no rows in SysCal table",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1802 | row = 0 ;
|
---|
| 1803 | }
|
---|
| 1804 | else {
|
---|
| 1805 | unsigned int nrow = rows->size() ;
|
---|
| 1806 | //logsink_->postLocally( LogMessage("nrow = "+String::toString(nrow),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1807 | int scindex = -1 ;
|
---|
| 1808 | if ( nrow == 1 ) {
|
---|
| 1809 | scindex = 0 ;
|
---|
| 1810 | }
|
---|
[2302] | 1811 | else if ( getEndTime( timeInterval_ ) <= getStartTime( (*rows)[0]->getTimeInterval() ) )
|
---|
[2273] | 1812 | scindex = 0 ;
|
---|
| 1813 | else {
|
---|
| 1814 | for ( unsigned int irow = 0 ; irow < nrow-1 ; irow++ ) {
|
---|
[2302] | 1815 | ArrayTime t = getMidTime( timeInterval_ ) ;
|
---|
[2273] | 1816 | if ( t > getStartTime( (*rows)[irow]->getTimeInterval() )
|
---|
| 1817 | && t <= getStartTime( (*rows)[irow+1]->getTimeInterval() ) ) {
|
---|
| 1818 | scindex = irow ;
|
---|
| 1819 | break ;
|
---|
| 1820 | }
|
---|
| 1821 | }
|
---|
| 1822 | if ( scindex == -1 )
|
---|
| 1823 | scindex = nrow-1 ;
|
---|
| 1824 | }
|
---|
| 1825 | //logsink_->postLocally( LogMessage("irow = "+String::toString(scindex),LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
| 1826 | row = (*rows)[scindex] ;
|
---|
| 1827 | }
|
---|
| 1828 | return row ;
|
---|
| 1829 | }
|
---|
| 1830 |
|
---|
| 1831 | double OldASDMReader::limitedAngle( double angle )
|
---|
| 1832 | {
|
---|
| 1833 | if ( angle > C::pi )
|
---|
| 1834 | while ( angle > C::pi ) angle -= C::_2pi ;
|
---|
| 1835 | else if ( angle < -C::pi )
|
---|
| 1836 | while ( angle < -C::pi ) angle += C::_2pi ;
|
---|
| 1837 | return angle ;
|
---|
| 1838 | }
|
---|
| 1839 |
|
---|
| 1840 | vector< vector<double> > OldASDMReader::pointingDir( PointingRow *row )
|
---|
| 1841 | {
|
---|
[2302] | 1842 | //String funcName = "pointingDir" ;
|
---|
[2273] | 1843 | vector< vector<Angle> > aTar = row->getTarget() ;
|
---|
| 1844 | vector< vector<Angle> > aOff = row->getOffset() ;
|
---|
| 1845 | vector< vector<Angle> > aDir = row->getPointingDirection() ;
|
---|
| 1846 | vector< vector<Angle> > aEnc = row->getEncoder() ;
|
---|
| 1847 | unsigned int n = aTar.size() ;
|
---|
| 1848 | vector< vector<double> > dir( n ) ;
|
---|
| 1849 | double factor = 1.0 / cos( aTar[0][1].get() ) ;
|
---|
| 1850 | for ( unsigned int i = 0 ; i < n ; i++ ) {
|
---|
| 1851 | dir[i].resize( 2 ) ;
|
---|
| 1852 | /**
|
---|
| 1853 | * This is approximate way to add offset taking tracking error
|
---|
| 1854 | * into account
|
---|
| 1855 | *
|
---|
| 1856 | * az = dir[0][0] = target[0][0] + offset[0][0] / cos(el)
|
---|
| 1857 | * + encorder[0][0] - direction[0][0]
|
---|
| 1858 | * el = dir[0][1] = target[0][1] + offset[0][1]
|
---|
| 1859 | * + encorder[0][1] - direction[0][1]
|
---|
| 1860 | **/
|
---|
| 1861 | dir[i][0] = aTar[i][0].get() + factor * aOff[i][0].get()
|
---|
| 1862 | + aEnc[i][0].get() - aDir[i][0].get() ;
|
---|
| 1863 | dir[i][1] = aTar[i][1].get() + aOff[i][1].get()
|
---|
| 1864 | + aEnc[i][1].get() - aDir[i][1].get() ;
|
---|
[2302] | 1865 | //logsink_->postLocally( LogMessage("tracking offset: ["+String::toString(aEnc[i][0].get()-aDir[i][0].get())+","+String::toString(aEnc[i][0]-aDir[i][0].get())+"]",LogOrigin(className_,funcName,WHERE)) ) ;
|
---|
[2273] | 1866 | }
|
---|
| 1867 | return dir ;
|
---|
| 1868 | }
|
---|