source: branches/hpc34/external-alma/asdm2ASAP/ASDMReader.h@ 3037

Last change on this file since 3037 was 2301, 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:

Test Programs: test_importasdm_sd

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Refactoring the code.


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