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_FTMACHINE_H
00030 #define SYNTHESIS_TRANSFORM2_FTMACHINE_H
00031
00032 #include <measures/Measures/Measure.h>
00033 #include <measures/Measures/MDirection.h>
00034 #include <measures/Measures/MPosition.h>
00035 #include <casa/Arrays/Array.h>
00036 #include <casa/Arrays/Vector.h>
00037 #include <casa/Arrays/Matrix.h>
00038 #include <casa/Logging/LogIO.h>
00039 #include <casa/Logging/LogSink.h>
00040 #include <casa/Logging/LogMessage.h>
00041 #include <casa/Containers/RecordInterface.h>
00042 #include <casa/Containers/Block.h>
00043 #include <images/Images/TempImage.h>
00044 #include <coordinates/Coordinates/SpectralCoordinate.h>
00045 #include <scimath/Mathematics/InterpolateArray1D.h>
00046 #include <synthesis/TransformMachines2/CFCache.h>
00047 #include <synthesis/TransformMachines2/CFStore2.h>
00048
00049 #include <synthesis/TransformMachines2/ConvolutionFunction.h>
00050 #include <synthesis/TransformMachines2/PolOuterProduct.h>
00051
00052 #include <images/Images/ImageInterface.h>
00053 #include <images/Images/SubImage.h>
00054 #include <synthesis/TransformMachines/StokesImageUtil.h>
00055
00056 #include <synthesis/ImagerObjects/SIImageStore.h>
00057 #include <synthesis/ImagerObjects/SIImageStoreMultiTerm.h>
00058
00059 #include <synthesis/TransformMachines2/SkyJones.h>
00060
00061 namespace casa{
00062
00063 class UVWMachine;
00064 class VisModelData;
00065 namespace vi{ class VisBuffer2;
00066 class VisibilityIterator2;
00067 }
00068 namespace refim{
00069
00070 class SkyJones;
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 class FTMachine {
00119 public:
00120
00121
00122
00123 enum Type {
00124 OBSERVED=0,
00125 MODEL,
00126 CORRECTED,
00127 RESIDUAL,
00128 PSF,
00129 COVERAGE,
00130 N_types,
00131 DEFAULT=OBSERVED
00132 };
00133
00134 FTMachine();
00135
00136
00137 FTMachine(CountedPtr<CFCache>& cfcache,CountedPtr<ConvolutionFunction>& cfctor);
00138
00139 FTMachine(const FTMachine& other);
00140
00141 FTMachine& operator=(const FTMachine& other);
00142
00143 void setBasePrivates(const FTMachine& other){FTMachine::operator=(other);}
00144
00145 virtual ~FTMachine();
00146
00147
00148
00149
00150 virtual FTMachine* cloneFTM(){return NULL;};
00151
00152 virtual void initializeToVis(ImageInterface<Complex>& image, const vi::VisBuffer2& vb) = 0;
00153
00154 virtual void initializeToVisNew(const vi::VisBuffer2& vb,
00155 CountedPtr<SIImageStore> imstore);
00156
00157
00158
00159
00160 virtual void finalizeToVis() = 0;
00161
00162
00163
00164
00165
00166
00167 virtual void initializeToSky(ImageInterface<Complex>& image,
00168 Matrix<Float>& weight, const vi::VisBuffer2& vb) = 0;
00169
00170
00171 virtual void initializeToSkyNew(const Bool dopsf,
00172 const vi::VisBuffer2& vb,
00173 CountedPtr<SIImageStore> imstore);
00174
00175
00176
00177 virtual void finalizeToSky() = 0;
00178
00179 virtual void finalizeToSky(ImageInterface<Complex>& iimage){(void)iimage;};
00180
00181
00182 virtual void finalizeToSkyNew(Bool dopsf,
00183 const vi::VisBuffer2& vb,
00184 CountedPtr<SIImageStore> imstore );
00185
00186
00187
00188
00189 virtual void get(vi::VisBuffer2& vb, Int row=-1) = 0;
00190
00191
00192 virtual void put(const vi::VisBuffer2& vb, Int row=-1, Bool dopsf=False,
00193 refim::FTMachine::Type type= refim::FTMachine::OBSERVED)=0;
00194
00195
00196
00197 virtual void put(vi::VisBuffer2& vb, Int row=-1, Bool dopsf=False,
00198 refim::FTMachine::Type type= refim::FTMachine::OBSERVED)
00199 {put((const vi::VisBuffer2&)vb,row,dopsf,type);};
00200
00201
00202 virtual void correlationToStokes(ImageInterface<Complex>& compImage,
00203 ImageInterface<Float>& resImage,
00204 const Bool dopsf);
00205
00206 virtual void stokesToCorrelation(ImageInterface<Float>& modelImage,
00207 ImageInterface<Complex>& compImage);
00208
00209
00210
00211
00212
00213
00214
00215 virtual void normalizeImage(Lattice<Complex>&,
00216 const Matrix<Double>&,
00217 Lattice<Float>&,
00218 Bool ){return;};
00219
00220 virtual void normalizeImage(ImageInterface<Float>& skyImage,
00221 Matrix<Float>& sumOfWts,
00222 ImageInterface<Float>& sensitivityImage,
00223 Bool dopsf, Float pblimit, Int normtype);
00224
00225
00226
00227
00228 virtual Bool useWeightImage(){return False;};
00229 virtual Bool isSkyJonesSet(){return (sj_p.nelements()>0) && !( sj_p[0]).null() ;}
00230 virtual Bool isSkyJonesChanged(vi::VisBuffer2& vb, Int row){if(sj_p.nelements()>0){return sj_p[0]->changed(vb,row);} else {return False;} };
00231
00232
00233
00234
00235
00236 virtual void setSkyJones(Vector<CountedPtr<SkyJones> >& sj);
00237
00238 Bool changedSkyJonesLogic(const vi::VisBuffer2& vb, Bool& firstRow, Bool& internalRow);
00239
00240
00241
00242
00243
00244 template <typename T> void getGrid(Array<T>& thegrid);
00245
00246 virtual ImageInterface<Complex>& getImage(Matrix<Float>&, Bool normalize=True) = 0;
00247 virtual const CountedPtr<refim::ConvolutionFunction>& getAWConvFunc() {return convFuncCtor_p;};
00248
00249 virtual void findConvFunction(const ImageInterface<Complex>&,
00250 const vi::VisBuffer2& ) {};
00251
00252 virtual void getWeightImage(ImageInterface<Float>& weightImage, Matrix<Float>& weights) = 0;
00253
00254
00255
00256 virtual void getFluxImage(ImageInterface<Float>& image){(void)image;};
00257
00258
00259
00260 virtual void makeImage(FTMachine::Type type,
00261 vi::VisibilityIterator2& vi,
00262 ImageInterface<Complex>& image,
00263 Matrix<Float>& weight);
00264
00265
00266
00267
00268
00269 void rotateUVW(Matrix<Double>& uvw, Vector<Double>& dphase,
00270 const vi::VisBuffer2& vb);
00271
00272 void refocus(Matrix<Double>& uvw, const Vector<Int>& ant1,
00273 const Vector<Int>& ant2,
00274 Vector<Double>& dphase, const vi::VisBuffer2& vb);
00275
00276 static void locateuvw(const Double*& uvw, const Double*&dphase, const Double*& freq, const Int& nchan, const Double*& scale, const Double*& offset, const Int& sampling, Int*& loc,Int*& off, Complex*& phasor, const Int& row, const Bool& doW=False);
00277
00278
00279
00280 virtual Bool toRecord(String& error, RecordInterface& outRecord,
00281 Bool withImage=False, const String diskimagename="");
00282 virtual Bool fromRecord(String& error, const RecordInterface& inRecord);
00283
00284
00285 virtual Bool changed(const vi::VisBuffer2& vb);
00286
00287 virtual Bool isFourier() {return False;}
00288
00289
00290 Bool setFrameValidity(Bool validFrame);
00291
00292
00293 virtual Bool doublePrecGrid();
00294
00295
00296 virtual void setNoPadding(Bool nopad){(void)nopad;};
00297
00298
00299
00300 virtual String name() const =0;
00301
00302
00303 void setLocation(const MPosition& loc);
00304 MPosition& getLocation();
00305
00306
00307
00308 virtual void setMovingSource(const String& sourcename);
00309 virtual void setMovingSource(const MDirection& mdir);
00310
00311
00312 virtual void reset(){};
00313
00314
00315 virtual void setFreqInterpolation(const String& method);
00316
00317
00318
00319 virtual void setPointingDirColumn(const String& column="DIRECTION");
00320
00321 virtual String getPointingDirColumnInUse();
00322
00323 virtual void setSpwChanSelection(const Cube<Int>& spwchansels);
00324 virtual void setSpwFreqSelection(const Matrix<Double>& spwfreqs);
00325
00326
00327
00328
00329 virtual void setMiscInfo(const Int qualifier)=0;
00330
00331 virtual void setCanComputeResiduals(Bool& b) {canComputeResiduals_p=b;};
00332 virtual Bool canComputeResiduals() {return canComputeResiduals_p;};
00333
00334
00335
00336 virtual void ComputeResiduals(vi::VisBuffer2&vb, Bool useCorrected) = 0;
00337 virtual Float getPBLimit() {return pbLimit_p;};
00338
00339
00340 void setnumthreads(Int n);
00341 Int getnumthreads();
00342
00343 virtual void setCFCache(CountedPtr<CFCache>& cfc, const Bool resetCFC=True);
00344 CountedPtr<CFCache> getCFCache() {return cfCache_p;};
00345 String getCacheDir() { return cfCache_p->getCacheDir(); };
00346
00347 virtual void setDryRun(Bool val)
00348 {
00349 isDryRun=val;
00350
00351 };
00352 virtual Bool dryRun() {return isDryRun;}
00353 virtual Bool isUsingCFCache()
00354 {
00355
00356 return (cfCache_p.nrefs()!=0);
00357 }
00358 Bool isDryRun;
00359
00360 protected:
00361
00362 friend class VisModelData;
00363 friend class MultiTermFT;
00364 friend class MultiTermFTNew;
00365 LogIO logIO_p;
00366
00367 LogIO& logIO();
00368
00369 ImageInterface<Complex>* image;
00370
00371 casa::UVWMachine* uvwMachine_p;
00372
00373 MeasFrame mFrame_p;
00374
00375
00376 Bool tangentSpecified_p;
00377 MDirection mTangent_p;
00378
00379 MDirection mImage_p;
00380
00381
00382 MDirection movingDir_p;
00383 Bool fixMovingSource_p;
00384 MDirection firstMovingDir_p;
00385
00386
00387 Double distance_p;
00388
00389 uInt nAntenna_p;
00390
00391 Int lastFieldId_p;
00392 Int lastMSId_p;
00393
00394 Bool useDoubleGrid_p;
00395
00396 virtual void initMaps(const vi::VisBuffer2& vb);
00397 virtual void initPolInfo(const vi::VisBuffer2& vb);
00398
00399
00400 Matrix<Double> sumWeight, sumCFWeight;
00401
00402
00403 Int nx, ny, npol, nchan, nvischan, nvispol;
00404
00405
00406 Vector<Int> chanMap, polMap;
00407
00408
00409 Bool isIOnly;
00410
00411
00412 MPosition mLocation_p;
00413
00414
00415
00416 Bool doUVWRotation_p;
00417 virtual void ok();
00418
00419
00420
00421 virtual void gridOk (Int gridsupport);
00422
00423
00424
00425
00426
00427 Vector<Int> nVisChan_p;
00428 Bool matchChannel(const Int& spw,
00429 const VisBuffer& vb);
00430 Bool matchChannel(const vi::VisBuffer2& vb);
00431
00432 Bool matchAllSpwChans(const VisBuffer& vb);
00433
00434
00435
00436
00437
00438 virtual Bool interpolateFrequencyTogrid(const vi::VisBuffer2& vb,
00439 const Matrix<Float>& wt,
00440 Cube<Complex>& data,
00441 Cube<Int>& flag,
00442 Matrix<Float>& weight,
00443 FTMachine::Type type=FTMachine::OBSERVED );
00444
00445
00446 virtual Bool interpolateFrequencyFromgrid(vi::VisBuffer2& vb,
00447 Cube<Complex>& data,
00448 FTMachine::Type type=FTMachine::MODEL );
00449
00450
00451
00452 virtual void getInterpolateArrays(const vi::VisBuffer2& vb,
00453 Cube<Complex>& data, Cube<Int>& flag);
00454
00455
00456 void setSpectralFlag(const vi::VisBuffer2& vb, Cube<Bool>& modflagcube);
00457
00458 Bool saveMeasure(RecordInterface& rec, const String& name, String& error, const Measure& ms);
00459
00460 Matrix<Double> negateUV(const vi::VisBuffer2& vb);
00461
00462
00463 SpectralCoordinate spectralCoord_p;
00464
00465 Bool freqFrameValid_p;
00466 Vector<Double> imageFreq_p;
00467
00468 Vector<Double> lsrFreq_p;
00469 Vector<Double> interpVisFreq_p;
00470 InterpolateArray1D<Double,Complex>::InterpolationMethod freqInterpMethod_p;
00471 String pointingDirCol_p;
00472 Cube<Int> spwChanSelFlag_p;
00473 Matrix<Double> spwFreqSel_p, expandedSpwFreqSel_p,expandedSpwConjFreqSel_p;
00474 Vector<Int> cfStokes_p;
00475 Int polInUse_p;
00476 CountedPtr<CFCache> cfCache_p;
00477 CFStore cfs_p, cfwts_p;
00478 CountedPtr<CFStore2> cfs2_p, cfwts2_p;
00479
00480 CountedPtr<ConvolutionFunction> convFuncCtor_p;
00481 CountedPtr<PolOuterProduct> pop_p;
00482
00483 Bool canComputeResiduals_p;
00484 Bool toVis_p;
00485 Int numthreads_p;
00486
00487
00488
00489 Array<Complex> griddedData;
00490 Array<DComplex> griddedData2;
00491
00492
00493 Float pbLimit_p;
00494
00495 Vector<CountedPtr<SkyJones> > sj_p;
00496
00497 CountedPtr<ImageInterface<Complex> > cmplxImage_p;
00498
00499 private:
00500
00501
00502
00503
00504 void swapyz(Cube<Complex>& out, const Cube<Complex>& in);
00505 void swapyz(Cube<Complex>& out, const Cube<Bool>& outFlag, const Cube<Complex>& in);
00506 void swapyz(Cube<Bool>& out, const Cube<Bool>& in);
00507 void convUVW(Double& dphase, Vector<Double>& thisrow);
00508
00509 };
00510
00511 #include <synthesis/TransformMachines/FTMachine.tcc>
00512
00513 }
00514 }
00515 #endif
00516
00517
00518