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