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

Last change on this file since 2228 was 2227, 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...

Frequency is stored as LSRK value although original frequency is
in an arbitrary frequency frame (e.g. TOPO). Conversion is done
in filler if necessary.


File size: 67.2 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 return tau ;
1229}
1230
1231void ASDMReader::getWeatherInfo( unsigned int idx,
1232 float &temperature,
1233 float &pressure,
1234 float &humidity,
1235 float &windspeed,
1236 float &windaz )
1237{
1238 temperature = 0.0 ;
1239 pressure = 0.0 ;
1240 humidity = 0.0 ;
1241 windspeed = 0.0 ;
1242 windaz = 0.0 ;
1243
1244 //logsink_->postLocally( LogMessage("weatherStationId_ = "+String::toString(weatherStationId_),LogOrigin(className_,funcName,WHERE)) ) ;
1245
1246 WeatherTable &wtab = asdm_->getWeather() ;
1247 if ( wtab.size() == 0 || weatherStationId_ == -1 )
1248 return ;
1249
1250 unsigned int index = dataIdList_[idx] ;
1251 //Tag anttag( antennaId_, TagType::Antenna ) ;
1252 //Tag sttag = (asdm_->getAntenna().getRowByKey( anttag ))->getStationId() ;
1253 Tag sttag( (unsigned int)weatherStationId_, TagType::Station ) ;
1254 //ArrayTimeInterval tint( vmsData_->v_time[index]*s2d, vmsData_->v_interval[index]*s2d ) ;
1255 double startSec = vmsData_->v_time[index] - 0.5 * vmsData_->v_interval[index] ;
1256 ArrayTimeInterval tint( startSec*s2d, vmsData_->v_interval[index]*s2d ) ;
1257 //WeatherRow *wrow = wtab.getRowByKey( sttag, tint ) ;
1258 vector<WeatherRow *> *wrows = wtab.getByContext( sttag ) ;
1259 WeatherRow *wrow = (*wrows)[0] ;
1260 unsigned int nrow = wrows->size() ;
1261 //logsink_->postLocally( LogMessage("There are "+String::toString(nrow)+" rows for given context: stationId "+String::toString(weatherStationId_),LogOrigin(className_,funcName,WHERE)) ) ;
1262 ArrayTime startTime = tint.getStart() ;
1263 if ( startTime < (*wrows)[0]->getTimeInterval().getStart() ) {
1264 temperature = (*wrows)[0]->getTemperature().get() ;
1265 pressure = (*wrows)[0]->getPressure().get() ;
1266 humidity = (*wrows)[0]->getRelHumidity().get() ;
1267 windspeed = (*wrows)[0]->getWindSpeed().get() ;
1268 windaz = (*wrows)[0]->getWindDirection().get() ;
1269 }
1270 else if ( startTime > (*wrows)[nrow-1]->getTimeInterval().getStart() ) {
1271 temperature = (*wrows)[nrow-1]->getTemperature().get() ;
1272 pressure = (*wrows)[nrow-1]->getPressure().get() ;
1273 humidity = (*wrows)[nrow-1]->getRelHumidity().get() ;
1274 windspeed = (*wrows)[nrow-1]->getWindSpeed().get() ;
1275 windaz = (*wrows)[nrow-1]->getWindDirection().get() ;
1276 }
1277 else {
1278 for ( unsigned int irow = 1 ; irow < wrows->size() ; irow++ ) {
1279 wrow = (*wrows)[irow-1] ;
1280 if ( startTime < (*wrows)[irow]->getTimeInterval().getStart() ) {
1281 temperature = wrow->getTemperature().get() ;
1282 pressure = wrow->getPressure().get() ;
1283 humidity = wrow->getRelHumidity().get() ;
1284 windspeed = wrow->getWindSpeed().get() ;
1285 windaz = wrow->getWindDirection().get() ;
1286 break ;
1287 }
1288 }
1289 }
1290
1291 return ;
1292}
1293
1294void ASDMReader::processStation()
1295{
1296 antennaPad_.resize(0) ;
1297 weatherStation_.resize(0) ;
1298 StationTable &stab = asdm_->getStation() ;
1299 vector<StationRow *> srows = stab.get() ;
1300 for ( unsigned int irow = 0 ; irow < srows.size() ; irow++ ) {
1301 StationType stype = srows[irow]->getType() ;
1302 Tag stag = srows[irow]->getStationId() ;
1303 if ( stype == ANTENNA_PAD )
1304 antennaPad_.push_back( stag ) ;
1305 else if ( stype == WEATHER_STATION )
1306 weatherStation_.push_back( stag ) ;
1307 }
1308
1309 weatherStationId_ = getClosestWeatherStation() ;
1310}
1311
1312int ASDMReader::getClosestWeatherStation()
1313{
1314 if ( weatherStation_.size() == 0 )
1315 return -1 ;
1316
1317 Tag atag( antennaId_, TagType::Antenna ) ;
1318 Tag stag = (asdm_->getAntenna().getRowByKey( atag ))->getStationId() ;
1319 vector<double> apos( 3 ) ;
1320 StationTable &stab = asdm_->getStation() ;
1321 StationRow *srow = stab.getRowByKey( stag ) ;
1322 vector<Length> pos = srow->getPosition() ;
1323 apos[0] = pos[0].get() ;
1324 apos[1] = pos[1].get() ;
1325 apos[2] = pos[2].get() ;
1326
1327 double eps = 1.0e20 ;
1328 int retval = -1 ;
1329 for ( unsigned int ir = 0 ; ir < weatherStation_.size() ; ir++ ) {
1330 srow = stab.getRowByKey( weatherStation_[ir] ) ;
1331 vector<Length> wpos = srow->getPosition() ;
1332 double dist = (apos[0]-wpos[0].get())*(apos[0]-wpos[0].get())
1333 + (apos[1]-wpos[1].get())*(apos[1]-wpos[1].get())
1334 + (apos[2]-wpos[2].get())*(apos[2]-wpos[2].get()) ;
1335 if ( dist < eps ) {
1336 retval = (int)(weatherStation_[ir].getTagValue()) ;
1337 }
1338 }
1339
1340 return retval ;
1341}
1342
1343void ASDMReader::getPointingInfo( unsigned int idx,
1344 vector<double> &dir,
1345 double &az,
1346 double &el,
1347 vector<double> &srate )
1348{
1349 String funcName = "getPointingInfo" ;
1350
1351 dir.resize(0) ;
1352 az = -1.0 ;
1353 el = -1.0 ;
1354 srate.resize(0) ;
1355
1356 Tag atag( antennaId_, TagType::Antenna ) ;
1357 unsigned int index = dataIdList_[idx] ;
1358 vector<PointingRow *> *prows = asdm_->getPointing().getByContext( atag ) ;
1359 PointingRow *prow ;
1360 PointingRow *qrow ;
1361 //ArrayTimeInterval tint( vmsData_->v_time[index]*s2d, vmsData_->v_interval[index]*s2d ) ;
1362 double startSec = vmsData_->v_time[index] - 0.5 * vmsData_->v_interval[index] ;
1363 ArrayTimeInterval tint( startSec*s2d, vmsData_->v_interval[index]*s2d ) ;
1364
1365 unsigned int nrow = prows->size() ;
1366 //logsink_->postLocally( LogMessage("There are " << nrow << " rows for given context: antennaId "+String::toString(antennaId_),LogOrigin(className_,funcName,WHERE)) ) ;
1367
1368// for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
1369// prow = (*prows)[irow] ;
1370// ArrayTimeInterval ati = prow->getTimeInterval() ;
1371// ArrayTime pst = ati.getStart() ;
1372// ArrayTime pet( ati.getStartInMJD()+ati.getDurationInDays() ) ;
1373// logsink_->postLocally( LogMessage("start: "+pst.toFITS(),LogOrigin(className_,funcName,WHERE)) ) ;
1374// logsink_->postLocally( LogMessage("end: "+pet.toFITS(),LogOrigin(className_,funcName,WHERE)) ) ;
1375// }
1376
1377 if ( nrow == 0 )
1378 return ;
1379
1380 srate.resize(2) ;
1381 srate[0] = 0.0 ;
1382 srate[1] = 0.0 ;
1383 az = 0.0 ;
1384 el = 0.0 ;
1385 double tcen = 0.0 ;
1386
1387 //
1388 // shape of pointingDirection is (numSample,2) if usePolynomial = False, while it is
1389 // (numTerm,2) if usePolynomial = True.
1390 //
1391 // In the former case, typical sampled time interval is 48msec, which is very small
1392 // compared with typical integration time (~a few sec).
1393 // Scan rate for this case is always [0,0] (or get slope?).
1394 //
1395 // In the later case, scan rate is (pointingDirection[1][0],pointingDirection[1][1])
1396 //
1397 // PointingDirection seems to store AZEL
1398 //
1399 ArrayTimeInterval pTime0 = (*prows)[0]->getTimeInterval() ;
1400 ArrayTimeInterval pTime1 = (*prows)[nrow-1]->getTimeInterval() ;
1401 if ( tint.getStartInMJD()+tint.getDurationInDays() < pTime0.getStartInMJD() ) {
1402 logsink_->postLocally( LogMessage( "ArrayTimeInterval out of bounds: no data for given position (tint < ptime)", LogOrigin(className_,funcName,WHERE), LogMessage::WARN ) ) ;
1403 prow = (*prows)[0] ;
1404 //vector< vector<Angle> > dirA = prow->getPointingDirection() ;
1405 vector< vector<Angle> > dirA = prow->getTarget() ;
1406 vector< vector<Angle> > offA = prow->getOffset() ;
1407 //az = dirA[0][0].get() ;
1408 //el = dirA[0][1].get() ;
1409 az = dirA[0][0].get() + offA[0][0].get() ;
1410 el = dirA[0][1].get() + offA[0][1].get() ;
1411 if ( prow->getUsePolynomials() && prow->getNumTerm() > 1 ) {
1412 //srate[0] = dirA[1][0].get() ;
1413 //srate[1] = dirA[1][1].get() ;
1414 srate[0] = dirA[1][0].get() + offA[1][0].get() ;
1415 srate[1] = dirA[1][1].get() + offA[1][1].get() ;
1416 }
1417 }
1418 else if ( tint.getStartInMJD() > pTime1.getStartInMJD()+pTime1.getDurationInDays() ) {
1419 logsink_->postLocally( LogMessage( "ArrayTimeInterval out of bounds: no data for given position (tint > ptime)", LogOrigin(className_,funcName,WHERE), LogMessage::WARN ) ) ;
1420 prow = (*prows)[nrow-1] ;
1421 int numSample = prow->getNumSample() ;
1422 //vector< vector<Angle> > dirA = prow->getPointingDirection() ;
1423 vector< vector<Angle> > dirA = prow->getTarget() ;
1424 vector< vector<Angle> > offA = prow->getOffset() ;
1425 if ( prow->getUsePolynomials() ) {
1426 //az = dirA[0][0].get() ;
1427 //el = dirA[0][1].get() ;
1428 az = dirA[0][0].get() + offA[0][0].get() ;
1429 el = dirA[0][1].get() + offA[0][1].get() ;
1430 if ( prow->getNumTerm() > 1 ) {
1431 //srate[0] = dirA[1][0].get() ;
1432 //srate[1] = dirA[1][1].get() ;
1433 srate[0] = dirA[1][0].get() + offA[1][0].get() ;
1434 srate[1] = dirA[1][1].get() + offA[1][0].get() ;
1435 }
1436 }
1437 else {
1438 //az = dirA[numSample-1][0].get() ;
1439 //el = dirA[numSample-1][1].get() ;
1440 az = dirA[numSample-1][0].get() + offA[numSample-1][0].get() ;
1441 el = dirA[numSample-1][1].get() + offA[numSample-1][1].get() ;
1442 }
1443 }
1444 else {
1445 ArrayTime startTime = tint.getStart() ;
1446 ArrayTime endTime( tint.getStartInMJD()+tint.getDurationInDays() ) ;
1447 int row0 = -1 ;
1448 int row1 = -1 ;
1449 int row2 = -1 ;
1450 double dt0 = getMidTime( tint ).getMJD() ;
1451 for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
1452 prow = (*prows)[irow] ;
1453 double dt = getMidTime( tint ).getMJD() - getMidTime( prow->getTimeInterval() ).getMJD() ;
1454 if ( dt > 0 && dt < dt0 ) {
1455 dt0 = dt ;
1456 row2 = irow ;
1457 }
1458 if ( prow->getTimeInterval().contains( startTime ) )
1459 row0 = irow ;
1460 else if ( prow->getTimeInterval().contains( endTime ) )
1461 row1 = irow ;
1462 if ( row0 != -1 && row1 != -1 )
1463 break ;
1464 }
1465 //logsink_->postLocally( LogMessage("row0 = "+String::toString(row0)+", row1 = "+String::toString(row1)+", row2 = "+String::toString(row2),LogOrigin(className_,funcName,WHERE)) ) ;
1466 if ( row0 == -1 && row1 == -1 ) {
1467 prow = (*prows)[row2] ;
1468 qrow = (*prows)[row2+1] ;
1469 double t0 = getEndTime( prow->getTimeInterval() ).getMJD() ;
1470 double t1 = qrow->getTimeInterval().getStartInMJD() ;
1471 double t = startTime.getMJD() ;
1472 //vector< vector<Angle> > dirA = prow->getPointingDirection() ;
1473 //vector< vector<Angle> > dirB = qrow->getPointingDirection() ;
1474 vector< vector<Angle> > dirA = prow->getTarget() ;
1475 vector< vector<Angle> > offA = prow->getOffset() ;
1476 vector< vector<Angle> > dirB = qrow->getTarget() ;
1477 vector< vector<Angle> > offB = qrow->getOffset() ;
1478 //double da0 = dirA[0][0].get() ;
1479 //double db0 = dirB[0][0].get() ;
1480 //double da1 = dirA[0][1].get() ;
1481 //double db1 = dirB[0][1].get() ;
1482 double da0 = dirA[0][0].get() + offA[0][0].get() ;
1483 double db0 = dirB[0][0].get() + offB[0][0].get() ;
1484 double da1 = dirA[0][1].get() + offA[0][1].get() ;
1485 double db1 = dirB[0][1].get() + offB[0][1].get() ;
1486 if ( prow->getUsePolynomials() && qrow->getUsePolynomials() ) {
1487 double dt = ( t - t0 ) / ( t1 - t0 ) ;
1488 az = da0 + ( db0 - da0 ) * dt ;
1489 el = da1 + ( db1 - da1 ) * dt ;
1490 if ( prow->getNumTerm() > 0 && qrow->getNumTerm() > 1 ) {
1491 //double ra0 = dirA[1][0].get() ;
1492 //double rb0 = dirB[1][0].get() ;
1493 //double ra1 = dirA[1][1].get() ;
1494 //double rb1 = dirB[1][1].get() ;
1495 double ra0 = dirA[1][0].get() + offA[1][0].get() ;
1496 double rb0 = dirB[1][0].get() + offB[1][0].get() ;
1497 double ra1 = dirA[1][1].get() + offA[1][1].get() ;
1498 double rb1 = dirB[1][1].get() + offB[1][1].get() ;
1499 srate[0] = ra0 + ( rb0 - ra0 ) * dt ;
1500 srate[1] = ra1 + ( rb1 - ra1 ) * dt ;
1501 }
1502 }
1503 else if ( !(qrow->getUsePolynomials()) ) {
1504 double dt = ( t - t0 ) / ( t1 - t0 ) ;
1505 az = da0 + ( db0 - da0 ) * dt ;
1506 el = da1 + ( db1 - da1 ) * dt ;
1507 }
1508 //else {
1509 // nothing to do
1510 //}
1511 }
1512 else {
1513 int ndir = 0 ;
1514 if ( row0 == -1 ) {
1515 row0 = row1 ;
1516 }
1517 else if ( row1 == -1 ) {
1518 row1 = row0 ;
1519 }
1520 prow = (*prows)[row0] ;
1521 qrow = (*prows)[row1] ;
1522 if ( prow->getUsePolynomials() && qrow->getUsePolynomials() ) {
1523 //logsink_->postLocally( LogMessage("usePolynomial = True",LogOrigin(className_,funcName,WHERE)) ) ;
1524 if ( row0 == row1 ) {
1525 prow = (*prows)[row0] ;
1526 //vector< vector<Angle> > dirA = prow->getPointingDirection() ;
1527 vector< vector<Angle> > dirA = prow->getTarget() ;
1528 vector< vector<Angle> > offA = prow->getOffset() ;
1529 //az = dirA[0][0].get() ;
1530 //el = dirA[0][1].get() ;
1531 az = dirA[0][0].get() + offA[0][0].get() ;
1532 el = dirA[0][1].get() + offA[0][1].get() ;
1533 if ( prow->getNumTerm() > 1 ) {
1534 //srate[0] = dirA[1][0].get() ;
1535 //srate[1] = dirA[1][1].get() ;
1536 srate[0] = dirA[1][0].get() + offA[1][0].get() ;
1537 srate[1] = dirA[1][1].get() + offA[1][0].get() ;
1538 }
1539 }
1540 else {
1541 prow = (*prows)[row0] ;
1542 qrow = (*prows)[row1] ;
1543 //vector< vector<Angle> > dirA = qrow->getPointingDirection() ;
1544 //vector< vector<Angle> > dirB = qrow->getPointingDirection() ;
1545 vector< vector<Angle> > dirA = qrow->getTarget() ;
1546 vector< vector<Angle> > offA = prow->getOffset() ;
1547 vector< vector<Angle> > dirB = qrow->getTarget() ;
1548 vector< vector<Angle> > offB = qrow->getOffset() ;
1549 double t0 = getMidTime( prow->getTimeInterval() ).getMJD() ;
1550 double t1 = getMidTime( qrow->getTimeInterval() ).getMJD() ;
1551 double t = startTime.getMJD() ;
1552 double dt = ( t - t0 ) / ( t1 - t0 ) ;
1553 //double da0 = dirA[0][0].get() ;
1554 //double db0 = dirB[0][0].get() ;
1555 //double da1 = dirA[0][1].get() ;
1556 //double db1 = dirB[0][1].get() ;
1557 double da0 = dirA[0][0].get() + offA[0][0].get() ;
1558 double db0 = dirB[0][0].get() + offB[0][0].get() ;
1559 double da1 = dirA[0][1].get() + offA[0][1].get() ;
1560 double db1 = dirB[0][1].get() + offB[0][1].get() ;
1561 az = da0 + ( db0 - da0 ) * dt ;
1562 el = da1 + ( db1 - db0 ) * dt ;
1563 if ( prow->getNumTerm() > 0 && qrow->getNumTerm() > 1 ) {
1564 //double ra0 = dirA[1][0].get() ;
1565 //double rb0 = dirB[1][0].get() ;
1566 //double ra1 = dirA[1][1].get() ;
1567 //double rb1 = dirB[1][1].get() ;
1568 double ra0 = dirA[1][0].get() + offA[1][0].get() ;
1569 double rb0 = dirB[1][0].get() + offB[1][0].get() ;
1570 double ra1 = dirA[1][1].get() + offA[1][1].get() ;
1571 double rb1 = dirB[1][1].get() + offB[1][1].get() ;
1572 srate[0] = ra0 + ( rb0 - ra0 ) * dt ;
1573 srate[1] = ra1 + ( rb1 - ra1 ) * dt ;
1574 }
1575 }
1576 }
1577 else if ( prow->getUsePolynomials() == qrow->getUsePolynomials() ) {
1578 //logsink_->postLocally( LogMessage("numSample == numTerm",LogOrigin(className_,funcName,WHERE)) ) ;
1579 for ( int irow = row0 ; irow <= row1 ; irow++ ) {
1580 prow = (*prows)[irow] ;
1581 int numSample = prow->getNumSample() ;
1582 //logsink_->postLocally( LogMessage("numSample = "+String::toString(numSample),LogOrigin(className_,funcName,WHERE)) ) ;
1583 //vector< vector<Angle> > dirA = prow->getPointingDirection() ;
1584 vector< vector<Angle> > dirA = prow->getTarget() ;
1585 vector< vector<Angle> > offA = prow->getOffset() ;
1586 if ( prow->isSampledTimeIntervalExists() ) {
1587 //logsink_->postLocally( LogMessage("sampledTimeIntervalExists",LogOrigin(className_,funcName,WHERE)) ) ;
1588 vector<ArrayTimeInterval> stime = prow->getSampledTimeInterval() ;
1589 for ( int isam = 0 ; isam < numSample ; isam++ ) {
1590 //if ( tint.overlaps( stime[isam] ) ) {
1591 if ( tint.contains( stime[isam] ) ) {
1592 //az += dirA[isam][0].get() ;
1593 //el += dirA[isam][1].get() ;
1594 az += dirA[isam][0].get() + offA[isam][0].get() ;
1595 el += dirA[isam][1].get() + offA[isam][1].get() ;
1596 ndir++ ;
1597 }
1598 }
1599 }
1600 else {
1601 double sampleStart = prow->getTimeInterval().getStartInMJD() ;
1602 double sampleInterval = prow->getTimeInterval().getDurationInDays() / (double)numSample ;
1603 //logsink_->postLocally( LogMessage("sampleStart = "+String::toString(sampleStart),LogOrigin(className_,funcName,WHERE)) )
1604 //logsink_->postLocally( LogMessage("sampleInterval = "+String::toString(sampleInterval),LogOrigin(className_,funcName,WHERE)) ) ;
1605 //logsink_->postLocally( LogMessage("tint = "+tint.toString(),LogOrigin(className_,funcName,WHERE)) ) ;
1606 for ( int isam = 0 ; isam < numSample ; isam++ ) {
1607 ArrayTimeInterval stime( sampleStart+isam*sampleInterval, sampleInterval ) ;
1608 //if ( tint.overlaps( stime ) ) {
1609 if ( tint.contains( stime ) ) {
1610 //az += dirA[isam][0].get() ;
1611 //el += dirA[isam][1].get() ;
1612 az += dirA[isam][0].get() + offA[isam][0].get() ;
1613 el += dirA[isam][1].get() + offA[isam][1].get() ;
1614 tcen += getMidTime( stime ).getMJD() ;
1615 ndir++ ;
1616 }
1617 }
1618 }
1619 }
1620 if ( ndir > 1 ) {
1621 az /= (double)ndir ;
1622 el /= (double)ndir ;
1623 tcen /= (double)ndir ;
1624 }
1625 }
1626 //else {
1627 // nothing to do
1628 //}
1629 }
1630
1631 AntennaRow *arow = asdm_->getAntenna().getRowByKey( Tag( antennaId_, TagType::Antenna ) ) ;
1632 StationRow *srow = arow->getStationUsingStationId() ;
1633 vector<Length> antposL = srow->getPosition() ;
1634 casa::Vector<casa::Double> antpos( 3 ) ;
1635 for ( int i = 0 ; i < 3 ; i++ )
1636 antpos[i] = antposL[i].get() ;
1637 //logsink_->postLocally( LogMessage("tcen = "+String::toString(tcen),LogOrigin(className_,funcName,WHERE)) ) ;
1638 //logsink_->postLocally( LogMessage("antpos = "+String::toString(antpos),LogOrigin(className_,funcName,WHERE)) ) ;
1639 toJ2000( dir, az, el, tcen, antpos ) ;
1640
1641 }
1642
1643 return ;
1644}
1645
1646ArrayTime ASDMReader::getMidTime( const ArrayTimeInterval &t )
1647{
1648 return ArrayTime( t.getStartInMJD() + 0.5 * t.getDurationInDays() ) ;
1649}
1650
1651ArrayTime ASDMReader::getEndTime( const ArrayTimeInterval &t )
1652{
1653 return ArrayTime( t.getStartInMJD() + t.getDurationInDays() ) ;
1654}
1655
1656ArrayTime ASDMReader::getStartTime( const ArrayTimeInterval &t )
1657{
1658 return ArrayTime( t.getStartInMJD() ) ;
1659}
1660
1661void ASDMReader::toJ2000( vector<double> &dir,
1662 double az,
1663 double el,
1664 double mjd,
1665 casa::Vector<casa::Double> antpos )
1666{
1667 String funcName = "toJ2000" ;
1668
1669// casa::Vector<casa::Double> azel( 2 ) ;
1670// azel[0] = az ;
1671// azel[1] = el ;
1672// casa::MEpoch me( casa::Quantity( (casa::Double)mjd, "d" ), casa::MEpoch::UTC ) ;
1673// casa::Vector<casa::Quantity> qantpos( 3 ) ;
1674// qantpos[0] = casa::Quantity( antpos[0], "m" ) ;
1675// qantpos[1] = casa::Quantity( antpos[1], "m" ) ;
1676// qantpos[2] = casa::Quantity( antpos[2], "m" ) ;
1677// casa::MPosition mp( casa::MVPosition( qantpos ),
1678// casa::MPosition::ITRF ) ;
1679// //ostringstream oss ;
1680// //mp.print( oss ) ;
1681// //logsink_->postLocally( LogMessage(oss.str(),LogOrigin(className_,funcName,WHERE)) ) ;
1682
1683// casa::MeasFrame mf( me, mp ) ;
1684// casa::MDirection::Convert toj2000( casa::MDirection::AZELGEO,
1685// casa::MDirection::Ref( casa::MDirection::J2000, mf ) ) ;
1686// casa::Vector<casa::Double> cdir = toj2000( azel ).getAngle( "rad" ).getValue() ;
1687// //logsink_->postLocally( LogMessage("cdir = "+String::toString(cdir),LogOrigin(className_,funcName,WHERE)) ) ;
1688// dir.resize(2) ;
1689// dir[0] = (double)(cdir[0]) ;
1690// dir[1] = (double)(cdir[1]) ;
1691 vector<double> azel( 2 ) ;
1692 azel[0] = az ;
1693 azel[1] = el ;
1694 dir = toJ2000( azel, "AZELGEO", mjd, antpos ) ;
1695}
1696
1697vector<double> ASDMReader::toJ2000( vector<double> dir,
1698 casa::String dirref,
1699 double mjd,
1700 casa::Vector<casa::Double> antpos )
1701{
1702 casa::String funcName = "toJ2000" ;
1703
1704 vector<double> newd( dir ) ;
1705 if ( dirref != "J2000" ) {
1706 casa::MEpoch me( casa::Quantity( (casa::Double)mjd, "d" ), casa::MEpoch::UTC ) ;
1707 casa::Vector<casa::Quantity> qantpos( 3 ) ;
1708 qantpos[0] = casa::Quantity( antpos[0], "m" ) ;
1709 qantpos[1] = casa::Quantity( antpos[1], "m" ) ;
1710 qantpos[2] = casa::Quantity( antpos[2], "m" ) ;
1711 casa::MPosition mp( casa::MVPosition( qantpos ),
1712 casa::MPosition::ITRF ) ;
1713 //ostringstream oss ;
1714 //mp.print( oss ) ;
1715 //logsink_->postLocally( LogMessage(oss.str(),LogOrigin(className_,funcName,WHERE)) ) ;
1716
1717 casa::MeasFrame mf( me, mp ) ;
1718 casa::MDirection::Types dirtype ;
1719 casa::Bool b = casa::MDirection::getType( dirtype, dirref ) ;
1720 if ( b ) {
1721 casa::MDirection::Convert toj2000( dirtype,
1722 casa::MDirection::Ref( casa::MDirection::J2000, mf ) ) ;
1723 casa::Vector<casa::Double> cdir = toj2000( dir ).getAngle( "rad" ).getValue() ;
1724 //logsink_->postLocally( LogMessage("cdir = "+String::toString(cdir),LogOrigin(className_,funcName,WHERE)) ) ;
1725 newd[0] = (double)(cdir[0]) ;
1726 newd[1] = (double)(cdir[1]) ;
1727 }
1728 }
1729 return newd ;
1730}
1731
1732void ASDMReader::setLogger( CountedPtr<LogSinkInterface> &logsink )
1733{
1734 logsink_ = logsink ;
1735}
1736
1737string ASDMReader::getFrame()
1738{
1739 casa::String funcName = "getFrame" ;
1740
1741 // default is TOPO
1742 string frame = "TOPO" ;
1743
1744 SpectralWindowTable &spwtab = asdm_->getSpectralWindow() ;
1745 vector<SpectralWindowRow *> rows = spwtab.get() ;
1746 vector<FrequencyReferenceCode> measFreqRef( rows.size() ) ;
1747 int nref = 0 ;
1748 for ( unsigned int irow = 0 ; irow < rows.size() ; irow++ ) {
1749 int nchan = rows[irow]->getNumChan() ;
1750 if ( nchan != 4 ) {
1751 if ( rows[irow]->isMeasFreqRefExists() ) {
1752 measFreqRef[nref] = rows[irow]->getMeasFreqRef() ;
1753 nref++ ;
1754 }
1755 }
1756 }
1757 if ( nref != 0 ) {
1758 frame = CFrequencyReferenceCode::toString( measFreqRef[0] ) ;
1759 }
1760
1761 //logsink_->postLocally( LogMessage("frame = "+String::toString(frame),LogOrigin(className_,funcName,WHERE)) ) ;
1762
1763 return frame ;
1764}
1765
1766int ASDMReader::getNumIFs()
1767{
1768 casa::String funcName = "getNumIFs" ;
1769
1770 int nif = 0 ;
1771 vector<SpectralWindowRow *> rows = asdm_->getSpectralWindow().get() ;
1772 unsigned int nrow = rows.size() ;
1773 // check if all rows have freqGroup attribute
1774 bool freqGroupExists = true ;
1775 bool countedWvr = false ;
1776 for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
1777 freqGroupExists &= rows[irow]->isFreqGroupExists() ;
1778 if ( rows[irow]->getNumChan() == 4 ) {
1779 if ( !countedWvr ) {
1780 countedWvr = true ;
1781 nif++ ;
1782 }
1783 }
1784 else {
1785 nif++ ;
1786 }
1787 }
1788
1789 if ( freqGroupExists ) {
1790 vector<int> freqGroup(0) ;
1791 for ( unsigned int irow = 0 ; irow < nrow ; irow++ ) {
1792 int fg = rows[irow]->getFreqGroup() ;
1793 if ( (int)count( freqGroup.begin(), freqGroup.end(), fg ) == 0 ) {
1794 freqGroup.push_back( fg ) ;
1795 }
1796 }
1797 nif = freqGroup.size() ;
1798 }
1799
1800 //logsink_->postLocally( LogMessage("nif = "+String::toString(nif),LogOrigin(className_,funcName,WHERE)) ) ;
1801
1802 return nif ;
1803}
Note: See TracBrowser for help on using the repository browser.