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

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

Default opacity value is 0.0


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