source: trunk/external-alma/asdm2ASAP/ASDMReader.h@ 2977

Last change on this file since 2977 was 2755, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: No

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...

Speed up asdm2ASAP by reusing MDirection::Convert object.


File size: 16.5 KB
Line 
1#ifndef ASAP_ASDM_READER_H
2#define ASAP_ASDM_READER_H
3
4#include <string>
5#include <map>
6
7#include <casa/Utilities/CountedPtr.h>
8#include <casa/Containers/Record.h>
9#include <casa/Logging/LogSinkInterface.h>
10#include <ASDMAll.h>
11#include <SDMBinData.h>
12
13class casa::MDirection;
14class casa::MeasFrame;
15class casa::MPosition;
16class casa::MEpoch;
17
18class ASDMReader
19{
20public:
21 /**
22 * constructor
23 **/
24 ASDMReader() ;
25
26 /**
27 * destructor
28 **/
29 ~ASDMReader() ;
30
31 /**
32 * open data
33 *
34 * @param filename input ASDM name
35 * @param processing options as casa record
36 * @return boolean status (true or false)
37 **/
38 bool open( const std::string &filename, const casa::Record &rec ) ;
39
40 /**
41 * fill data
42 **/
43// void fill() ;
44
45 /**
46 * close data
47 **/
48 void close() ;
49
50 /**
51 * get antenna id
52 **/
53 casa::Int getAntennaId() { return antennaId_ ; } ;
54
55 /**
56 * get antenna name
57 **/
58 casa::String getAntennaName() { return antennaName_ ; } ;
59
60 /**
61 * fill header
62 *
63 * @param nchan (maximum) number of channel
64 * @param npol (maximum) number of polarization
65 * @param nif number of IFs
66 * @param nbeam number of beam
67 * @param observer observer name
68 * @param project name
69 * @param obstype observation type
70 * @param antennaname antenna name
71 * @param antennaposition antenna position
72 * @param equinox equinox (numerical value)
73 * @param freqref frequency frame
74 * @param reffreq reference frequency
75 * @param bandwidth (maximum) bandwidth
76 * @param utc start time of observation
77 * @param fluxunit flux unit (K or Jy)
78 * @param epoch epoch (UTC)
79 * @param poltype polarization type
80 **/
81 void fillHeader( casa::Int &nchan,
82 casa::Int &npol,
83 casa::Int &nif,
84 casa::Int &nbeam,
85 casa::String &observer,
86 casa::String &project,
87 casa::String &obstype,
88 casa::String &antennaname,
89 casa::Vector<casa::Double> &antennaposition,
90 casa::Float &equinox,
91 casa::String &freqref,
92 casa::Double &reffreq,
93 casa::Double &bandwidth,
94 casa::Double &utc,
95 casa::String &fluxunit,
96 casa::String &epoch,
97 casa::String &poltype ) ;
98
99 /**
100 * get list of valid configDescriptionId
101 *
102 * only return list of configDescriptionId with correlationMode of
103 * AUTO_ONLY or CROSS_AND_AUTO.
104 *
105 * @return list of valid configDescriptionId
106 **/
107 casa::Vector<casa::uInt> getConfigDescriptionIdList() { return configDescIdList_ ; } ;
108
109 /**
110 * get list of fieldId
111 *
112 * @return list of fieldId as casa::uInt
113 **/
114 casa::Vector<casa::uInt> getFieldIdList() ;
115
116 /**
117 * get number of rows in Main table
118 *
119 * @return number of rows in Main table
120 **/
121 casa::uInt getNumMainRow() ;
122
123 /**
124 * binary data selection
125 **/
126 void select() ;
127
128 /**
129 * set Main rows that matches given context (configDescId and fieldId)
130 * to mainRow_
131 *
132 * @param configDescId
133 * @param fieldId
134 **/
135 casa::Bool setMainRow( casa::uInt configDescId, casa::uInt fieldId ) ;
136
137 /**
138 * set Main row to SDMBinData object
139 *
140 * @param irow row index
141 * @return boolean indicating the row is valid or not
142 **/
143 casa::Bool setMainRow( casa::uInt irow ) ;
144
145 /**
146 * get scan number of current row
147 *
148 * @return scan number
149 **/
150 unsigned int getScanNoOfCurrentRow() { return (unsigned int)(mainRow_[row_]->getScanNumber()) ; } ;
151
152 /**
153 * get subscan number of current row
154 *
155 * @return subscan number
156 **/
157 unsigned int getSubscanNoOfCurrentRow() { return (unsigned int)(mainRow_[row_]->getSubscanNumber()) ; } ;
158
159 /**
160 * set data index
161 *
162 * @param idx for vmsData_
163 **/
164 void prepareData( unsigned int idx ) ;
165
166 /**
167 * get subscan number for given index
168 *
169 * @param idx for vmsData_
170 * @return subscan number
171 **/
172 unsigned int getSubscanNo( unsigned int idx ) ;
173 unsigned int getSubscanNo() ;
174
175 /**
176 * get IF number for given index
177 *
178 * @param idx for vmsData_
179 * @return IF number
180 **/
181 casa::uInt getIFNo( unsigned int idx ) ;
182 casa::uInt getIFNo() ;
183
184 /**
185 * get number of polarization for given index
186 *
187 * @param idx for vmsData_
188 * @return number of polarizations
189 **/
190 int getNumPol( unsigned int idx ) ;
191 int getNumPol() ;
192
193 /**
194 * get REFPIX, REFVAL, INCREMENT for given index
195 *
196 * @param idx for vmsData_
197 * @param refpix REFPIX
198 * @param refval REFVAL
199 * @param incr INCREMENT
200 * @param freqref frequency reference
201 **/
202 void getFrequency( unsigned int idx,
203 double &refpix,
204 double &refval,
205 double &incr,
206 std::string &freqref ) ;
207 void getFrequency( double &refpix,
208 double &refval,
209 double &incr,
210 std::string &freqref ) ;
211
212 /**
213 * get MJD time in day for given index
214 *
215 * @param idx for vmsData_
216 * @return MJD time in day
217 **/
218 double getTime( unsigned int idx ) ;
219 double getTime() ;
220
221 /**
222 * get integration time in sec for given index
223 *
224 * @param idx for vmsData_
225 * @return integration time in sec
226 **/
227 double getInterval( unsigned int idx ) ;
228 double getInterval() ;
229
230 /**
231 * get source direction with reference
232 *
233 * @param dir source direction
234 * @param reference frame
235 * @param idx for Source table
236 **/
237 void getSourceDirection( std::vector<double> &dir, std::string &ref ) ;
238
239 /**
240 * get row-based flag for given index
241 *
242 * @param idx for vmsData_
243 * @return row-based flag
244 **/
245 unsigned int getFlagRow( unsigned int idx ) ;
246 unsigned int getFlagRow() ;
247
248 /**
249 * get data shape (nPol, nChan, nApc=1) for given index
250 *
251 * @param idx for vmsData_
252 * @return data shape
253 **/
254 std::vector<unsigned int> getDataShape( unsigned int idx ) ;
255 std::vector<unsigned int> getDataShape() ;
256
257 /**
258 * get spectral data for given index
259 *
260 * @param idx for vmsData_
261 * @return spectral data
262 **/
263 float *getSpectrum( unsigned int idx ) ;
264 float *getSpectrum() ;
265
266 /**
267 * get Tsys for given index
268 *
269 * @param idx for vmsData_
270 * @return Tsys
271 **/
272 std::vector< std::vector<float> > getTsys( unsigned int idx ) ;
273 std::vector< std::vector<float> > getTsys() ;
274
275 /**
276 * get Tcal for given index
277 *
278 * @param idx for vmsData_
279 * @return Tcal
280 **/
281 std::vector< std::vector<float> > getTcal( unsigned int idx ) ;
282 std::vector< std::vector<float> > getTcal() ;
283
284 /**
285 * get Tcal and Tsys for given index
286 *
287 * @param idx for vmsData_
288 * @param tcal Tcal
289 * @param tsys Tsys
290 **/
291 void getTcalAndTsys( unsigned int idx,
292 std::vector< std::vector<float> > &tcal,
293 std::vector< std::vector<float> > &tsys ) ;
294 void getTcalAndTsys( std::vector< std::vector<float> > &tcal,
295 std::vector< std::vector<float> > &tsys ) ;
296
297 /**
298 * get opacity for given index
299 *
300 * @param idx for vmsData_
301 * @return opacity
302 **/
303 std::vector<float> getOpacity( unsigned int idx ) ;
304 std::vector<float> getOpacity() ;
305
306 /**
307 * get weather information for given index
308 *
309 * @param idx for vmsData_
310 * @param temperature
311 * @param pressure
312 * @param humidity
313 * @param windspeed
314 * @param windaz
315 **/
316 void getWeatherInfo( unsigned int idx,
317 float &temperature,
318 float &pressure,
319 float &humidity,
320 float &windspeed,
321 float &windaz ) ;
322 void getWeatherInfo( float &temperature,
323 float &pressure,
324 float &humidity,
325 float &windspeed,
326 float &windaz ) ;
327
328 /**
329 * get pointing information for given index
330 *
331 * @param idx for vmsData_
332 * @param dir direction
333 * @param az azimuth
334 * @param el elevation
335 * @param srate scan rate
336 **/
337 void getPointingInfo( unsigned int idx,
338 std::vector<double> &dir,
339 double &az,
340 double &el,
341 std::vector<double> &srate ) ;
342 void getPointingInfo( std::vector<double> &dir,
343 double &az,
344 double &el,
345 std::vector<double> &srate ) ;
346
347 /**
348 * get source type enum (int) for given scan and subscan
349 *
350 * @param scan scan No.
351 * @param subscan subscan No.
352 * @return source type as int
353 **/
354 int getSrcType( unsigned int scan,
355 unsigned int subscan ) ;
356
357 /**
358 * get source properties
359 *
360 * @param idx for vmsData_
361 * @param srcname source name
362 * @param fieldname field name
363 * @param srcdir source direction
364 * @param srcpm source proper motion
365 * @param sysvel systemic velocity of the source
366 * @param restfreq rest frequency
367 **/
368 void getSourceProperty( unsigned int idx,
369 std::string &srcname,
370 std::string &fieldname,
371 std::vector<double> &srcdir,
372 std::vector<double> &srcpm,
373 double &sysvel,
374 std::vector<double> &restfreq ) ;
375 void getSourceProperty( std::string &srcname,
376 std::string &fieldname,
377 std::vector<double> &srcdir,
378 std::vector<double> &srcpm,
379 double &sysvel,
380 std::vector<double> &restfreq ) ;
381
382 /**
383 * set binary data to MSData object
384 *
385 * @return boolean status
386 **/
387 casa::Bool setData() ;
388
389 /**
390 * get number of data in the current row
391 *
392 * @return number of data
393 **/
394 unsigned int getNumData() { return numData_ ; } ;
395
396 /**
397 * get frequency frame
398 *
399 * @return string representating frequency frame
400 **/
401 std::string getFrame() ;
402
403 /**
404 * set Logger
405 *
406 * @param logger (LogSinkInterface)
407 **/
408 void setLogger( casa::CountedPtr<casa::LogSinkInterface> &logsink ) ;
409
410
411private:
412
413 /**
414 * pick up valid configDescriptionId
415 *
416 * only retrieve configDescriptionId with correlationMode of
417 * AUTO_ONLY or CROSS_AND_AUTO.
418 **/
419 void selectConfigDescription() ;
420
421 /**
422 * pick up valid feedId
423 *
424 * only retrieve feedId that has corresponding row for antennaId_
425 **/
426 void selectFeed() ;
427
428 /**
429 * clear mainRow_
430 **/
431 void clearMainRow() ;
432
433 /**
434 * determine IFNO for each SpectralWindow rows
435 *
436 * SpectralWindow row is identified as WVR when basebandName is "NOBB" and numChan is 4.
437 * All WVR SpectralWindow is merged into one IFNO.
438 **/
439 void setupIFNO() ;
440
441 /**
442 * check if given SpectralWindow is WVR or not
443 **/
444 bool isWVR( asdm::SpectralWindowRow *row ) ;
445
446 /**
447 * process Station table
448 *
449 * classify station Ids by its type
450 **/
451 void processStation() ;
452
453 /**
454 * get the closest weather station for given antenna pad
455 *
456 * @return stationId for weather station
457 **/
458 int getClosestWeatherStation() ;
459
460 /**
461 * get mid-point of ArrayTimeInterval
462 *
463 * @param time interval as ArrayTimeInterval
464 * @return time of mid-point as ArrayTime
465 **/
466 asdm::ArrayTime getMidTime( const asdm::ArrayTimeInterval &t ) ;
467
468 /**
469 * get start-point of ArrayTimeInterval
470 *
471 * @param time interval as ArrayTimeInterval
472 * @return time of start-point as ArrayTime
473 **/
474 asdm::ArrayTime getStartTime( const asdm::ArrayTimeInterval &t ) ;
475
476 /**
477 * get end-point of ArrayTimeInterval
478 *
479 * @param time interval as ArrayTimeInterval
480 * @return time of end-point as ArrayTime
481 **/
482 asdm::ArrayTime getEndTime( const asdm::ArrayTimeInterval &t ) ;
483
484 /**
485 * AZEL to J2000
486 *
487 * @param dir pointing direction
488 * @param az azimuth
489 * @param el elevation
490 * @param mjd reference time
491 * @param antpos antenna position vector
492 **/
493 void toJ2000( std::vector<double> &dir,
494 double &az,
495 double &el,
496 double &mjd ) ;
497 /**
498 * to J2000
499 *
500 * @param dir pointing direction
501 * @param dirref direction reference
502 * @param mjd reference time
503 * @param antpos antenna position vector
504 * @return new direction
505 **/
506 std::vector<double> toJ2000( std::vector<double> &dir,
507 casa::String &dirref,
508 double &mjd ) ;
509
510 /**
511 * get nIF
512 *
513 * @return number of IFs
514 **/
515 int getNumIFs() ;
516
517 /**
518 * get appropriate row from SysCal table
519 *
520 * @param idx for vmsData_
521 * @return pointer to SysCalRow object (0 when no appropriate row)
522 **/
523 asdm::SysCalRow *getSysCalRow( unsigned int idx ) ;
524 asdm::SysCalRow *getSysCalRow() ;
525
526 /**
527 * limit angule in radian within [-pi,pi]
528 *
529 * @param any angule in radian
530 * @return equivalent angle that satisfies [-pi,pi]
531 **/
532 double limitedAngle( double angle ) ;
533
534 /**
535 * retrieve pointing direction from pointingDirection column
536 * or from target+offset
537 *
538 * @param row pointer to PointingRow object
539 * @return pointing direction vector (matrix)
540 **/
541 std::vector< std::vector<double> > pointingDir( asdm::PointingRow *row ) ;
542
543 /**
544 * initialize conversion engine
545 **/
546 void initConvert() ;
547
548 asdm::ASDM *asdm_ ; // pointer to ASDM object
549 sdmbin::SDMBinData *sdmBin_ ; // pointer to ASDM binary data
550 /**
551 * vmsData_ is a pointer to binary data
552 *
553 * VMSData contents
554 *
555 * int processorId
556 * vector< double > v_time MJD time in sec
557 * vector< int > v_fieldId
558 * vector< double > v_interval interval in sec
559 * vector< AtmPhaseCorrection > v_atmPhaseCorrection
560 * int binNum
561 * vector< unsigned int > v_projectPath
562 * vector< int > v_antennaId1 antennaId in int
563 * vector< int > v_antennaId2 antennaId in int
564 * vector< int > v_feedId1 feedId in int
565 * vector< int > v_feedId2 feedId in int
566 * vector< int > v_dataDescId dataDescriptionId in int
567 * vector< double > v_timeCentroid
568 * vector< double > exposure
569 * vector< int > v_numData
570 * vector< vector< unsigned int > > vv_dataShape (nPol,nChan,nApc=1)
571 * vector< map< AtmPhaseCorrection, float *> > v_m_data actual data
572 * vector< vector< vector< Angle > > > v_pahseDir direction
573 * vector< int > v_stateId
574 * vector< MSState > v_msState
575 * vector< unsigned int > v_flag
576 **/
577 const sdmbin::VMSData *vmsData_ ;
578
579 casa::Int antennaId_ ; // antenna id
580 casa::String antennaName_ ; // antenna name
581 casa::String stationName_ ; // station name
582 casa::Vector<casa::Quantity> antennaPosition_ ; // antenna position
583 casa::Vector<casa::uInt> configDescIdList_ ; // list of valid configDescriptionId
584 casa::Vector<casa::uInt> feedIdList_ ; // list of valid feedId
585 casa::Vector<casa::uInt> fieldIdList_ ; // list of fieldId
586 casa::Int row_ ; // current row index
587 map<asdm::Tag,casa::uInt> ifno_ ; // list of IFNO for each SpectralWindow rows
588 unsigned int numData_ ; // number of valid data in vmsData_ where v_antennaId equals antennaId_
589 vector<unsigned int> dataIdList_ ; // list of valid data indexes in vmsData_
590 vector<asdm::Tag> antennaPad_ ; // list of Station Tags for ANTENNA_PAD
591 vector<asdm::Tag> weatherStation_ ; // list of Station Tags for WEATHER_STATION
592 int weatherStationId_ ; // closest weather station for antennaId_
593 AtmPhaseCorrectionMod::AtmPhaseCorrection apc_ ; // ATM phase correction
594 EnumSet<CorrelationModeMod::CorrelationMode> corrMode_ ; // input correlation mode
595 EnumSet<TimeSamplingMod::TimeSampling> timeSampling_ ; // time sampling
596 EnumSet<SpectralResolutionTypeMod::SpectralResolutionType> resolutionType_ ; // spectral resolution type
597 casa::CountedPtr<casa::LogSinkInterface> logsink_ ; // Logger
598 casa::String className_ ;
599 unsigned int dataIndex_ ;
600
601 // Tables/Rows for ASDM
602 casa::Vector<asdm::MainRow *> mainRow_ ; // list of pointers to all Main rows
603 //asdm::AntennaRow *antennaRow_p ; // pointer to target Antenna row
604 //asdm::StationRow *stationRow_p ; // pointer to target Station row that target antenna is located
605 asdm::SpectralWindowRow *specWinRow_p ; // pointer to SpectralWindow row
606 asdm::PolarizationRow *polarizationRow_p ; // pointer to Polarization row
607 asdm::FieldRow *fieldRow_p ; // pointer to Field row
608
609 // Tags
610 asdm::Tag antennaTag_ ;
611 asdm::Tag specWinTag_ ;
612 asdm::Tag execBlockTag_ ;
613
614 // time
615 asdm::ArrayTimeInterval timeInterval_ ;
616
617 casa::MDirection::Convert toj2000_ ;
618 casa::MeasFrame mf_ ;
619 casa::MPosition mp_ ;
620 casa::MEpoch me_ ;
621} ;
622#endif // ASAP_ASDM_READER_H
Note: See TracBrowser for help on using the repository browser.