00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef SYNTHESIS_VISCAL_H
00030 #define SYNTHESIS_VISCAL_H
00031
00032 #include <casa/aips.h>
00033 #include <casa/Containers/Record.h>
00034 #include <casa/BasicSL/Complex.h>
00035 #include <casa/BasicSL/Constants.h>
00036 #include <synthesis/MeasurementComponents/Mueller.h>
00037 #include <synthesis/MeasurementComponents/Jones.h>
00038 #include <synthesis/CalTables/VisCalEnum.h>
00039 #include <synthesis/MeasurementComponents/VisVector.h>
00040 #include <msvis/MSVis/VisSet.h>
00041 #include <msvis/MSVis/VisBuffer2.h>
00042
00043 #include <msvis/MSVis/VisBuffGroupAcc.h>
00044
00045 namespace casa {
00046
00047 class MSMetaInfoForCal;
00048
00049
00050
00051
00052
00053 class VisCal {
00054
00055 friend class SolvableVisJones;
00056
00057 public:
00058
00059
00060
00061 enum Type{Test=0,ANoise,M,KAntPos,K,B,G,J,D,X,C,P,E,T,F,A,ALL};
00062
00063
00064 enum ParType{Co,Re,CoRe};
00065
00066 static String nameOfType(Type type) {
00067 switch (type) {
00068 case ANoise: return "ANoise";
00069 case M: return "M";
00070 case K: return "K";
00071 case B: return "B";
00072 case J: return "J";
00073 case D: return "D";
00074 case X: return "X";
00075 case C: return "C";
00076 case P: return "P";
00077 case E: return "E";
00078 case T: return "T";
00079 case F: return "F";
00080 case A: return "A";
00081 default: return "0";
00082 }
00083 }
00084
00085 VisCal(VisSet& vs);
00086
00087 VisCal(String msname,Int MSnAnt,Int MSnSpw);
00088
00089 VisCal(const MSMetaInfoForCal& msmc);
00090
00091 VisCal(const Int& nAnt);
00092
00093 virtual ~VisCal();
00094
00095
00096
00097 virtual Type type()=0;
00098
00099
00100 virtual String typeName() { return "Unknown VisCal"; };
00101 virtual String longTypeName() { return "Unknown VisCal"; };
00102
00103
00104 virtual VisCalEnum::MatrixType matrixType() { return VisCalEnum::GLOBAL; };
00105
00106
00107 virtual VisCalEnum::VCParType parType() { return VisCalEnum::COMPLEX; };
00108
00109
00110
00111 virtual Int nPar()=0;
00112
00113
00114
00115 virtual Vector<Bool> spwOK() { return Vector<Bool>(nSpw(),True); };
00116 virtual Bool spwOK(Int) { return True; };
00117
00118
00119 virtual Bool freqDepPar() { return False; };
00120
00121
00122 inline const Int& nChanPar() const { return nChanPar_[currSpw_]; };
00123
00124
00125 virtual Bool freqDepMat() { return freqDepPar(); };
00126
00127
00128 virtual Bool freqDepCalWt() { return False; };
00129
00130
00131 virtual Bool timeDepMat() { return False; };
00132
00133
00134 inline Bool isApplied() {return applied_;};
00135
00136
00137 virtual Bool isSolvable() {return False;};
00138
00139
00140 inline virtual Double& interval() {return interval_;}
00141
00142
00143 virtual void setApply();
00144 virtual void setApply(const Record& apply);
00145 virtual void setCallib(const Record& callib,const MeasurementSet& selms);
00146
00147
00148 virtual String applyinfo();
00149
00150
00151
00152 inline virtual String siminfo() { return applyinfo(); };
00153
00154
00155 inline Bool& calWt() { return calWt_; };
00156
00157
00158
00159 virtual void correct(VisBuffer& vb, Bool trial=False);
00160 virtual void correct2(vi::VisBuffer2& vb, Bool trial=False, Bool doWtSp=False);
00161 virtual void corrupt(VisBuffer& vb);
00162 virtual void corrupt2(vi::VisBuffer2& vb);
00163
00164
00165
00166 virtual void correct(VisBuffer& vb, Cube<Complex>& Vout,Bool trial=False);
00167 virtual void corrupt(VisBuffer& vb, Cube<Complex>& Mout);
00168 virtual void corrupt2(vi::VisBuffer2& vb, Cube<Complex>& Mout);
00169
00170
00171 virtual void initCalFlagCount();
00172 virtual Record actionRec();
00173
00174
00175 virtual void state();
00176
00177 virtual void currMetaNote();
00178
00179
00180 inline void setPrtlev(const Int& prtlev) { prtlev_=prtlev; };
00181
00182
00183 inline Int blnidx(const Int& a1,
00184 const Int& a2) { return a1*nAnt() - a1*(a1+1)/2 + a2; };
00185
00186 inline String& extraTag() { return extratag_; };
00187
00188
00189
00190
00191
00192 virtual void setMeta(Int obs, Int scan, Double time,
00193 Int spw, const Vector<Double>& freq,
00194 Int fld);
00195
00196
00197
00198 virtual void sizeApplyParCurrSpw(Int nVisChan);
00199
00200
00201
00202 virtual void setDefApplyParCurrSpw(Bool sync=False, Bool doInv=False);
00203
00204
00205 protected:
00206
00207
00208 inline void setApplied(const Bool& flag) {applied_=flag;};
00209
00210 inline String& msName() { return msName_; };
00211
00212
00213 inline Int& nSpw() { return nSpw_; };
00214 inline Int& nAnt() { return nAnt_; };
00215 inline Int& nBln() { return nBln_; };
00216
00217
00218 virtual Int& nElem()=0;
00219
00220
00221 virtual Int nCalMat()=0;
00222
00223
00224 inline Int& currSpw() { return currSpw_; };
00225
00226
00227 inline Double& lastTime() { return lastTime_(currSpw()); };
00228 inline Double& currTime() { return currTime_(currSpw()); };
00229 inline Int& currScan() { return currScan_(currSpw()); };
00230 inline Int& currObs() { return currObs_(currSpw()); };
00231 inline Int& currField() { return currField_(currSpw()); };
00232 inline Vector<Double>& currFreq() { return currFreq_; };
00233
00234 inline Double& refTime() { return refTime_; };
00235 inline Double& refFreq() { return refFreq_; };
00236
00237
00238 inline Int& nChanPar() { return nChanPar_[currSpw_]; };
00239 inline Int& nChanMat() { return nChanMat_[currSpw_]; };
00240 inline Int& startChan() { return startChan_[currSpw_];};
00241 inline Vector<Int>& nChanParList() { return nChanPar_; };
00242 inline Vector<Int>& nChanMatList() { return nChanMat_; };
00243 inline Vector<Int>& startChanList() { return startChan_;};
00244
00245
00246 inline VisVector& V() { return (*V_[currSpw()]); };
00247
00248
00249 inline virtual Cube<Complex>& currCPar() {return (*currCPar_[currSpw()]);};
00250 inline virtual Cube<Float>& currRPar() {return (*currRPar_[currSpw()]);};
00251 inline virtual Cube<Bool>& currParOK() {return (*currParOK_[currSpw()]);};
00252
00253
00254 inline void invalidateP() {PValid_(currSpw())=False;};
00255 inline void validateP() {PValid_(currSpw())=True;};
00256 inline Bool PValid() {return PValid_(currSpw());};
00257
00258
00259 virtual void invalidateCalMat()=0;
00260
00261
00262 inline Cube<Float>& currWtScale() { return (*currWtScale_[currSpw()]); };
00263
00264
00265 virtual void countInFlag(const VisBuffer& vb);
00266 virtual void countInFlag2(const vi::VisBuffer2& vb);
00267 virtual void countOutFlag(const VisBuffer& vb);
00268 virtual void countOutFlag2(const vi::VisBuffer2& vb);
00269
00270
00271 virtual void applyCal(VisBuffer& vb, Cube<Complex>& Vout,Bool trial=False)=0;
00272 virtual void applyCal2(vi::VisBuffer2& vb,
00273 Cube<Complex>& Vout,Cube<Float>& Wout,
00274 Bool trial=False)=0;
00275
00276
00277 virtual void syncCal(const VisBuffer& vb,
00278 const Bool& doInv=False);
00279 virtual void syncCal2(const vi::VisBuffer2& vb,
00280 const Bool& doInv=False);
00281 virtual void syncCal(VisCal& vc);
00282
00283
00284 virtual void syncMeta(const VisBuffer& vb);
00285 virtual void syncMeta2(const vi::VisBuffer2& vb);
00286 void syncMeta(VisCal& vc);
00287
00288 void syncMeta(const Int& spw,
00289 const Double& time,
00290 const Int& field,
00291 const Vector<Double>& freq,
00292 const Int& nchan);
00293
00294
00295 void setCalChannelization(const Int& nChanDat);
00296
00297
00298 void checkCurrCal();
00299
00300
00301 virtual void syncCal(const Bool& doInv=False);
00302
00303
00304 virtual void syncPar();
00305
00306
00307 virtual void calcPar();
00308
00309
00310 virtual void syncCalMat(const Bool& doInv=False)=0;
00311
00312
00313 inline Int& prtlev() { return prtlev_; };
00314
00315
00316 void setCurrField(const Int& ifld);
00317
00318
00319 const MSMetaInfoForCal& msmc() const { if (msmc_) return *msmc_; else throw(AipsError("VisCal::msmc(): No MSMetaInfoForCal object!")); };
00320
00321 private:
00322
00323
00324 VisCal();
00325
00326
00327 void initVisCal();
00328
00329
00330 void deleteVisCal();
00331
00332
00333 String msName_;
00334
00335
00336 const MSMetaInfoForCal* msmc_;
00337 const Bool delmsmc_;
00338
00339
00340 Int nSpw_;
00341
00342
00343 Int nAnt_;
00344
00345
00346 Int nBln_;
00347
00348
00349 Int currSpw_;
00350
00351
00352 Vector<Double> currTime_;
00353 Vector<Int> currScan_;
00354 Vector<Int> currObs_;
00355 Vector<Int> currField_;
00356 Vector<Double> currFreq_;
00357 Vector<Double> lastTime_;
00358 Double refTime_;
00359 Double refFreq_;
00360
00361
00362 Vector<Int> nChanPar_, nChanMat_;
00363 Vector<Int> startChan_;
00364
00365
00366 Double interval_;
00367
00368
00369 Bool applied_;
00370
00371
00372 Int focusChan_;
00373
00374
00375 PtrBlock<VisVector*> V_;
00376
00377
00378 PtrBlock<Cube<Complex>*> currCPar_;
00379 PtrBlock<Cube<Float>*> currRPar_;
00380 PtrBlock<Cube<Bool>*> currParOK_;
00381
00382
00383 Vector<Bool> PValid_;
00384
00385
00386 Bool calWt_;
00387
00388
00389 PtrBlock<Cube<Float>*> currWtScale_;
00390
00391
00392 Int64 ndataIn_, nflagIn_, nflagOut_;
00393
00394
00395 Int prtlev_;
00396
00397 String extratag_;
00398
00399
00400 };
00401
00402
00403
00404
00405
00406
00407 class VisMueller : virtual public VisCal {
00408
00409 public:
00410
00411
00412 VisMueller(VisSet& vs);
00413
00414 VisMueller(String msname,Int MSnAnt,Int MSnSpw);
00415
00416 VisMueller(const MSMetaInfoForCal& msmc);
00417
00418 VisMueller(const Int& nAnt);
00419
00420 virtual ~VisMueller();
00421
00422
00423 virtual VisCalEnum::MatrixType matrixType() { return VisCalEnum::MUELLER; };
00424
00425
00426 virtual Mueller::MuellerType muellerType()=0;
00427
00428
00429 virtual void state();
00430
00431 protected:
00432
00433
00434 virtual Int& nElem() { return nBln(); };
00435
00436
00437
00438 virtual Int nCalMat() { return nBln(); };
00439
00440
00441
00442
00443 virtual Bool trivialMuellerElem()=0;
00444
00445
00446
00447 virtual Bool applyByMueller() { return True; };
00448
00449
00450 inline Mueller& M() { return (*M_[currSpw()]); };
00451
00452
00453 inline Cube<Complex>& currMElem() {return (*currMElem_[currSpw()]);};
00454 inline Cube<Bool>& currMElemOK() {return (*currMElemOK_[currSpw()]);};
00455
00456
00457 inline virtual void invalidateCalMat() { invalidateM(); };
00458
00459
00460 inline void invalidateM() {MValid_(currSpw())=False;};
00461 inline void validateM() {MValid_(currSpw())=True;};
00462 inline Bool MValid() {return MValid_(currSpw());};
00463
00464
00465 virtual void applyCal(VisBuffer& vb, Cube<Complex>& Vout,Bool trial=False);
00466 virtual void applyCal2(vi::VisBuffer2& vb,
00467 Cube<Complex>& Vout,Cube<Float>& Wout,
00468 Bool trial=False);
00469
00470
00471
00472 virtual void syncCalMat(const Bool& doInv=False);
00473
00474
00475 virtual void syncMueller(const Bool& doInv=False);
00476
00477
00478 virtual void calcAllMueller();
00479
00480
00481 virtual void calcOneMueller(Vector<Complex>& mat, Vector<Bool>& mOk,
00482 const Vector<Complex>& par, const Vector<Bool>& pOk);
00483
00484
00485 virtual void invMueller();
00486
00487
00488
00489
00490 virtual void setMatByOk();
00491
00492
00493 void createMueller();
00494
00495
00496 virtual void syncWtScale();
00497
00498
00499 virtual void calcWtScale();
00500
00501
00502 virtual void updateWt(Vector<Float>& wt,const Int& a1,const Int& a2);
00503
00504
00505 private:
00506
00507
00508 VisMueller();
00509
00510
00511 void initVisMueller();
00512
00513
00514 void deleteVisMueller();
00515
00516
00517 PtrBlock<Mueller*> M_;
00518
00519
00520 PtrBlock<Cube<Complex>*> currMElem_;
00521 PtrBlock<Cube<Bool>*> currMElemOK_;
00522
00523
00524 Vector<Bool> MValid_;
00525
00526 };
00527
00528
00529
00530
00531
00532
00533 class VisJones : virtual public VisMueller {
00534
00535 friend class SolvableVisJones;
00536
00537 public:
00538
00539
00540 VisJones(VisSet& vs);
00541
00542 VisJones(String msname,Int MSnAnt,Int MSnSpw);
00543
00544 VisJones(const MSMetaInfoForCal& msmc);
00545
00546 VisJones(const Int& nAnt);
00547
00548 virtual ~VisJones();
00549
00550
00551 virtual VisCalEnum::MatrixType matrixType() { return VisCalEnum::JONES; };
00552
00553
00554
00555 virtual Mueller::MuellerType muellerType();
00556
00557
00558
00559 virtual Jones::JonesType jonesType()=0;
00560
00561
00562 virtual void state();
00563
00564 protected:
00565
00566
00567 inline virtual Int& nElem() { return nAnt(); };
00568
00569
00570
00571 virtual Int nCalMat() { return nAnt(); };
00572
00573
00574 virtual Bool trivialMuellerElem() { return False; };
00575
00576
00577
00578
00579 virtual Bool trivialJonesElem()=0;
00580
00581
00582
00583 virtual Bool applyByMueller() { return False; };
00584 virtual Bool applyByJones() { return True; };
00585
00586
00587 inline Jones& J1() { return *J1_[currSpw()]; };
00588 inline Jones& J2() { return *J2_[currSpw()]; };
00589
00590
00591 inline Cube<Complex>& currJElem() {return (*currJElem_[currSpw()]);};
00592 inline Cube<Bool>& currJElemOK() {return (*currJElemOK_[currSpw()]);};
00593
00594
00595 inline virtual void invalidateCalMat() { invalidateM(); invalidateJ(); };
00596
00597
00598 inline void invalidateJ() {JValid_(currSpw())=False;};
00599 inline void validateJ() {JValid_(currSpw())=True;};
00600 inline Bool JValid() {return JValid_(currSpw());};
00601
00602
00603 virtual void applyCal(VisBuffer& vb, Cube<Complex>& Vout,Bool trial=False);
00604 virtual void applyCal2(vi::VisBuffer2& vb,
00605 Cube<Complex>& Vout,Cube<Float>& Wout,
00606 Bool trial=False);
00607
00608
00609 virtual void syncCalMat(const Bool& doInv=False);
00610
00611
00612
00613 virtual void calcAllMueller();
00614
00615
00616 virtual void syncJones(const Bool& doInv=False);
00617
00618
00619 virtual void calcAllJones();
00620
00621
00622 virtual void calcOneJones(Vector<Complex>& mat, Vector<Bool>& mOk,
00623 const Vector<Complex>& par, const Vector<Bool>& pOk );
00624
00625
00626 virtual void invJones();
00627
00628
00629
00630
00631 virtual void setMatByOk();
00632
00633
00634 void createJones();
00635
00636
00637 virtual void syncWtScale();
00638
00639
00640 virtual void calcWtScale();
00641
00642
00643 virtual void updateWt(Vector<Float>& wt,const Int& a1,const Int& a2);
00644 virtual void updateWt2(Matrix<Float>& wt,const Int& a1,const Int& a2);
00645
00646 private:
00647
00648
00649 VisJones();
00650
00651
00652 void initVisJones();
00653
00654
00655 void deleteVisJones();
00656
00657
00658 PtrBlock<Jones*> J1_;
00659 PtrBlock<Jones*> J2_;
00660
00661
00662 PtrBlock<Cube<Complex>*> currJElem_;
00663 PtrBlock<Cube<Bool>*> currJElemOK_;
00664
00665
00666 Vector<Bool> JValid_;
00667
00668
00669 };
00670
00671 }
00672
00673 #endif