source: trunk/external-alma/asdm2ASAP/ASDMReader.cc@ 2243

Last change on this file since 2243 was 2235, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: Yes CAS-1913

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Updated a way to search appropriate weather information based on time.
Also, pressure should be diveded by 100.0 since ASDM stores pressure
in Pa while MS stores pressure in hPa.


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