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_AWPROJECTFT_H
00030 #define SYNTHESIS_AWPROJECTFT_H
00031
00032 #include <synthesis/TransformMachines/VLACalcIlluminationConvFunc.h>
00033 #include <synthesis/TransformMachines/VLAIlluminationConvFunc.h>
00034 #include <synthesis/TransformMachines/AWVisResampler.h>
00035
00036 #include <synthesis/TransformMachines/EVLAConvFunc.h>
00037 #include <synthesis/MeasurementComponents/SolvableVisCal.h>
00038 #include <synthesis/TransformMachines/VPSkyJones.h>
00039 #include <synthesis/TransformMachines/FTMachine.h>
00040 #include <synthesis/TransformMachines/PolOuterProduct.h>
00041
00042 #include <synthesis/TransformMachines/Utils.h>
00043
00044 #include <scimath/Mathematics/FFTServer.h>
00045 #include <msvis/MSVis/VisBuffer.h>
00046
00047 #include <casa/Containers/Block.h>
00048 #include <casa/Arrays/Array.h>
00049 #include <casa/Arrays/Vector.h>
00050 #include <casa/Arrays/Matrix.h>
00051
00052 #include <scimath/Mathematics/ConvolveGridder.h>
00053 #include <lattices/Lattices/LatticeCache.h>
00054 #include <lattices/Lattices/ArrayLattice.h>
00055 #include <ms/MeasurementSets/MSColumns.h>
00056 #include <measures/Measures/Measure.h>
00057 #include <measures/Measures/MDirection.h>
00058 #include <measures/Measures/MPosition.h>
00059 #include <images/Images/ImageInterface.h>
00060 #include <coordinates/Coordinates/DirectionCoordinate.h>
00061
00062 #include <synthesis/TransformMachines/AWConvFunc.h>
00063 #include <synthesis/TransformMachines/AWConvFuncEPJones.h>
00064 #include <synthesis/TransformMachines/ATerm.h>
00065
00066 #include <casa/OS/Timer.h>
00067
00068 namespace casa {
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 class SolvableVisJones;
00147 class AWProjectFT : public FTMachine {
00148 public:
00149 static ATerm* createTelescopeATerm(const String& telescopeName,
00150 const Bool& isATermOn);
00151 static CountedPtr<ConvolutionFunction> makeCFObject(const String& telescopeName,
00152 const Bool aTermOn,
00153 const Bool psTermOn,
00154 const Bool wTermOn,
00155 const Bool mTermOn,
00156 const Bool wBAWP);
00157 AWProjectFT();
00158
00159
00160
00161
00162
00163
00164 AWProjectFT(Int nFacets, Long cachesize,
00165 CountedPtr<CFCache>& cfcache,
00166 CountedPtr<ConvolutionFunction>& cf,
00167 CountedPtr<VisibilityResamplerBase>& visResampler,
00168 Bool applyPointingOffset=True,
00169 Bool doPBCorr=True,
00170 Int tilesize=16,
00171 Float pbLimit=5e-4,
00172 Bool usezero=False,
00173 Bool conjBeams_p=True,
00174 Bool doublePrecGrid=False,
00175 PolOuterProduct::MuellerType muellerType=PolOuterProduct::FULL);
00176
00177
00178
00179 AWProjectFT(const RecordInterface& stateRec);
00180
00181
00182 AWProjectFT(const AWProjectFT &other);
00183
00184
00185 AWProjectFT &operator=(const AWProjectFT &other);
00186
00187 ~AWProjectFT();
00188
00189
00190 void setEPJones(SolvableVisJones* ep_j) {epJ_p = ep_j;}
00191
00192 virtual void setDOPBCorrection(Bool doit=True) {doPBCorrection=doit;};
00193 virtual Bool getDOPBCorrection() {return doPBCorrection;};
00194 virtual void setConjBeams(Bool useit=True) {conjBeams_p=useit;};
00195 virtual Bool getConjBeams() {return conjBeams_p;};
00196
00197 virtual Float getPBLimit() {return pbLimit_p;};
00198
00199
00200
00201 void setObservatoryLocation(const MPosition& mLocation) {mLocation_p=mLocation;};
00202
00203
00204
00205
00206
00207
00208
00209 virtual void initializeToVis(Block<CountedPtr<ImageInterface<Complex> > > & compImageVec,
00210 PtrBlock<SubImage<Float> *> & modelImageVec,
00211 PtrBlock<SubImage<Float> *>& weightImageVec,
00212 PtrBlock<SubImage<Float> *>& fluxScaleVec,
00213 Block<Matrix<Float> >& weightsVec,
00214 const VisBuffer& vb);
00215
00216 virtual void initializeToVis(ImageInterface<Complex>& image,
00217 const VisBuffer& vb);
00218
00219
00220 virtual void initializeToVis(ImageInterface<Complex>& image,
00221 const VisBuffer& vb, Array<Complex>& griddedVis,
00222 Vector<Double>& uvscale);
00223
00224
00225
00226 virtual void finalizeToVis();
00227
00228
00229 virtual void initializeToSky(ImageInterface<Complex>& image, Matrix<Float>& weight,
00230 const VisBuffer& vb);
00231
00232
00233
00234
00235 virtual void finalizeToSky();
00236
00237 virtual void initVisBuffer(VisBuffer& vb, Type whichVBColumn);
00238 void initVisBuffer(VisBuffer& vb, Type whichVBColumn, Int row);
00239
00240
00241 void get(VisBuffer& vb, Int row=-1);
00242
00243
00244
00245
00246 void get(VisBuffer& vb, Cube<Complex>& degrid,
00247 Array<Complex>& griddedVis, Vector<Double>& scale,
00248 Int row=-1);
00249
00250 void get(VisBuffer& vb, Cube<Float>& pointingOffsets, Int row=-1,
00251 Type whichVBColumn=FTMachine::MODEL,Int Conj=0)
00252 {
00253 get(vb,vb,vb,pointingOffsets,row,whichVBColumn,whichVBColumn,Conj,0);
00254 }
00255
00256 void get(VisBuffer& vb, VisBuffer& gradAzVB,VisBuffer& gradElVB,
00257 Cube<Float>& pointingOffsets,Int row=-1,
00258 Type whichVBColumn=FTMachine::MODEL,
00259 Type whichGradVBColumn=FTMachine::MODEL,
00260 Int Conj=0, Int doGrad=1) ;
00261 void nget(VisBuffer& vb,
00262
00263 Array<Float>& l_off, Array<Float>& m_off,
00264 Cube<Complex>& Mout,
00265 Cube<Complex>& dMout1,
00266 Cube<Complex>& dMout2,
00267 Int Conj=0, Int doGrad=1);
00268
00269
00270
00271 void get(VisBuffer& vb, Cube<Complex>& degrid,
00272 Array<Complex>& griddedVis, Vector<Double>& scale,
00273 Cube<Float>& pointingOffsets,Int row=-1);
00274
00275
00276
00277 void put(const VisBuffer&,
00278 TempImage<Complex>&, Vector<Double>&, int,
00279 UVWMachine*, Bool)
00280 {
00281
00282 }
00283 void put(const VisBuffer& vb, Int row=-1, Bool dopsf=False,
00284 FTMachine::Type type=FTMachine::OBSERVED);
00285
00286
00287 virtual void makeImage(FTMachine::Type,
00288 ROVisibilityIterator&,
00289 ImageInterface<Complex>&,
00290 Matrix<Float>&) {};
00291
00292
00293 void makeImage(FTMachine::Type type,
00294 VisSet& vs,
00295 ImageInterface<Complex>& image,
00296 Matrix<Float>& weight);
00297
00298
00299
00300 virtual ImageInterface<Complex>& getImage(Matrix<Float>&, Bool normalize=True);
00301
00302
00303 void getWeightImage(ImageInterface<Float>&, Matrix<Float>&);
00304
00305
00306 Bool toRecord(RecordInterface& outRec, Bool withImage=False);
00307 Bool fromRecord(const RecordInterface& inRec);
00308
00309
00310 Bool isFourier() {return True;}
00311
00312
00313
00314
00315 virtual Int findPointingOffsets(const VisBuffer&, Array<Float>&, Array<Float>&,
00316 Bool Evaluate=True);
00317 virtual Int findPointingOffsets(const VisBuffer&, Cube<Float>&,
00318 Array<Float>&, Array<Float>&,
00319 Bool Evaluate=True);
00320 virtual Double getVBPA(const VisBuffer& vb)
00321 {
00322
00323
00324 return getPA(vb);
00325 };
00326 MDirection::Convert makeCoordinateMachine(const VisBuffer&,
00327 const MDirection::Types&,
00328 const MDirection::Types&,
00329 MEpoch& last);
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 virtual void makeSensitivityImage(Lattice<Complex>&,
00340 ImageInterface<Float>&,
00341 const Matrix<Float>&,
00342 const Bool& ) {};
00343 virtual void makeSensitivityImage(const VisBuffer& vb, const ImageInterface<Complex>& imageTemplate,
00344 ImageInterface<Float>& sensitivityImage);
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 virtual ImageInterface<Float>& getSensitivityImage() {return *avgPB_p;}
00369 virtual Matrix<Double>& getSumOfWeights() {return sumWeight;};
00370 virtual Matrix<Double>& getSumOfCFWeights() {return sumCFWeight;};
00371
00372 void makeConjPolMap(const VisBuffer& vb, const Vector<Int> cfPolMap, Vector<Int>& conjPolMap);
00373
00374 void makeCFPolMap(const VisBuffer& vb, const Vector<Int>& cfstokes, Vector<Int>& polM);
00375
00376 void reset() {paChangeDetector.reset();}
00377
00378 void setPAIncrement(const Quantity &computePAIncr, const Quantity &rotateOTFPAIncr);
00379
00380 Vector<Int>& getPolMap() {return polMap;};
00381 virtual String name() const { return "AWProjectFT";};
00382 virtual Bool verifyAvgPB(ImageInterface<Float>& pb, ImageInterface<Float>& sky)
00383 {return verifyShapes(pb.shape(),sky.shape());}
00384
00385 virtual Bool verifyAvgPB(ImageInterface<Float>& pb, ImageInterface<Complex>& sky)
00386 {return verifyShapes(pb.shape(),sky.shape());}
00387
00388 virtual Bool verifyShapes(IPosition shape0, IPosition shape1);
00389
00390 inline virtual Float pbFunc(const Float& a, const Float& limit)
00391 {Float tt=sqrt(a);return (abs(tt) >= limit)?tt:1.0;};
00392
00393
00394 inline virtual Complex pbFunc(const Complex& a, const Float& limit)
00395 {if (abs(a)>=limit) return (a); else return Complex(1.0,0.0);};
00396
00397 virtual void setMiscInfo(const Int qualifier)
00398 {
00399 sensitivityPatternQualifier_p=qualifier;
00400 sensitivityPatternQualifierStr_p = ".tt"+String::toString(sensitivityPatternQualifier_p);
00401 }
00402 virtual void ComputeResiduals(VisBuffer&vb, Bool useCorrected);
00403 void makeWBCFWt(CFStore2& cfs,const Double imRefFreq);
00404
00405 CFBStruct cfbst_pub;
00406
00407 Vector<Double> uvScale, uvOffset;
00408 protected:
00409
00410 Int nint(Double val) {return Int(floor(val+0.5));};
00411
00412
00413
00414
00415 void findConvFunction(const ImageInterface<Complex>& image,
00416 const VisBuffer& vb);
00417
00418
00419 Array<Complex>* getDataPointer(const IPosition&, Bool);
00420
00421 void ok();
00422
00423 void init();
00424
00425
00426
00427 Bool recordOnGrid(const VisBuffer& vb, Int rownr) const;
00428
00429
00430 Float padding_p;
00431
00432 Int nWPlanes_p;
00433
00434 LatticeCache<Complex> * imageCache;
00435
00436
00437 Long cachesize;
00438 Int tilesize;
00439
00440
00441 ConvolveGridder<Double, Complex>* gridder;
00442
00443
00444 Bool isTiled;
00445
00446
00447 CountedPtr<Lattice<Complex> > arrayLattice;
00448
00449
00450
00451 CountedPtr<Lattice<Complex> > lattice;
00452
00453 Float maxAbsData;
00454
00455
00456 IPosition centerLoc, offsetLoc;
00457
00458
00459
00460
00461
00462
00463 MDirection::Convert* pointingToImage;
00464
00465
00466 Bool usezero_p;
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476 Int
00477 convSampling, wConvSize, lastIndex_p;
00478
00479
00480
00481
00482 CountedPtr<ImageInterface<Float> > avgPB_p;
00483 CountedPtr<ImageInterface<Complex> > avgPBSq_p;
00484
00485
00486
00487
00488 Int maxConvSupport;
00489
00490
00491
00492
00493 CountedPtr<SolvableVisJones> epJ_p;
00494 Double sigma;
00495 Int Nant_p, doPointing;
00496 Bool doPBCorrection, makingPSF, conjBeams_p;
00497
00498
00499 ParAngleChangeDetector paChangeDetector;
00500 Double rotateOTFPAIncr_p, computePAIncr_p;
00501
00502 Unit Second, Radian, Day;
00503 Array<Float> l_offsets,m_offsets;
00504 Vector<Float> pbPeaks, paList;
00505
00506 Double currentCFPA, cfRefFreq_p, imRefFreq_p;
00507 Float lastPAUsedForWtImg;
00508 Bool pbNormalized_p;
00509 Vector<Bool> paNdxProcessed_p;
00510
00511
00512
00513 virtual void normalizeAvgPB();
00514 virtual void normalizeAvgPB(ImageInterface<Complex>& inImage,
00515 ImageInterface<Float>& outImage);
00516 virtual void resampleDataToGrid(Array<Complex>& griddedData, VBStore& vbs,
00517 const VisBuffer& vb, Bool& dopsf);
00518 virtual void resampleDataToGrid(Array<DComplex>& griddedData, VBStore& vbs,
00519 const VisBuffer& vb, Bool& dopsf);
00520 virtual void resampleGridToData(VBStore& vbs, Array<Complex>& griddedData,
00521 const VisBuffer& vb);
00522
00523 virtual void makeThGridCoords(VBStore& vbs, const Vector<Int>& gridShape);
00524 virtual void setupVBStore(VBStore& vbs,
00525 const VisBuffer& vb,
00526 const Matrix<Float>& imagingweight,
00527 const Cube<Complex>& visData,
00528 const Matrix<Double>& uvw,
00529 const Cube<Int>& flagCube,
00530 const Vector<Double>& dphase,
00531 const Bool& doPSF,
00532 const Vector<Int> &gridShape);
00533
00534
00535 CountedPtr<VisibilityResamplerBase> visResampler_p;
00536 Int sensitivityPatternQualifier_p;
00537 String sensitivityPatternQualifierStr_p;
00538 CFStore rotatedConvFunc_p;
00539
00540 Vector<Int> ConjCFMap_p, CFMap_p;
00541
00542 Timer timer_p;
00543 Double runTime1_p;
00544
00545 PolOuterProduct::MuellerType muellerType_p;
00546
00547 #include "AWProjectFT.FORTRANSTUFF.INC"
00548 };
00549 }
00550
00551 #endif