Line data Source code
1 : //# NewMultiTermFT.h: Definition for NewMultiTermFT
2 : //# Copyright (C) 1996,1997,1998,1999,2000,2002
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //#
5 : //# This library is free software; you can redistribute it and/or modify it
6 : //# under the terms of the GNU Library General Public License as published by
7 : //# the Free Software Foundation; either version 2 of the License, or (at your
8 : //# option) any later version.
9 : //#
10 : //# This library is distributed in the hope that it will be useful, but WITHOUT
11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 : //# License for more details.
14 : //#
15 : //# You should have received a copy of the GNU Library General Public License
16 : //# along with this library; if not, write to the Free Software Foundation,
17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 : //#
19 : //# Correspondence concerning AIPS++ should be adressed as follows:
20 : //# Internet email: casa-feedback@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //# Charlottesville, VA 22903-2475 USA
25 : //#
26 : //#
27 : //# $Id$
28 :
29 : #ifndef SYNTHESIS_MULTITERMFTNEW_H
30 : #define SYNTHESIS_MULTITERMFTNEW_H
31 :
32 : #include <synthesis/TransformMachines/FTMachine.h>
33 : #include <casacore/casa/Arrays/Matrix.h>
34 : #include <casacore/scimath/Mathematics/FFTServer.h>
35 : #include <msvis/MSVis/VisBuffer.h>
36 : #include <casacore/images/Images/ImageInterface.h>
37 : #include <casacore/images/Images/ImageInterface.h>
38 : #include <casacore/casa/Containers/Block.h>
39 : #include <casacore/casa/Arrays/Array.h>
40 : #include <casacore/casa/Arrays/Vector.h>
41 : #include <casacore/casa/Arrays/Matrix.h>
42 : #include <casacore/scimath/Mathematics/ConvolveGridder.h>
43 : #include <casacore/lattices/Lattices/LatticeCache.h>
44 : #include <casacore/lattices/Lattices/ArrayLattice.h>
45 : //#include <synthesis/MeasurementComponents/SynthesisPeek.h>
46 : #include <casacore/casa/OS/Timer.h>
47 :
48 : namespace casacore{
49 :
50 : class UVWMachine;
51 : }
52 :
53 : namespace casa { //# NAMESPACE CASA - BEGIN
54 :
55 :
56 : class MultiTermFTNew : public FTMachine {
57 : public:
58 :
59 : // Construct using an existing FT-Machine
60 : MultiTermFTNew(casacore::CountedPtr<FTMachine>& subftm, casacore::Int nterms=1, casacore::Bool forward=false);
61 :
62 : // Construct from a casacore::Record containing the MultiTermFTNew state
63 : MultiTermFTNew(const casacore::RecordInterface& stateRec);
64 :
65 : // Copy constructor.
66 : // This first calls the default "=" operator, and then instantiates objects for member pointers.
67 : MultiTermFTNew(const MultiTermFTNew &other);
68 :
69 : // Assignment operator --- leave it as the default
70 : MultiTermFTNew &operator=(const MultiTermFTNew &other);
71 :
72 : // Destructor
73 : ~MultiTermFTNew();
74 :
75 : // Called at the start of de-gridding : subftm->initializeToVis()
76 : // Note : Pre-de-gridding model-image divisions by PBs will go here.
77 0 : void initializeToVis(casacore::ImageInterface<casacore::Complex>& /*image*/,
78 : const VisBuffer& /*vb*/)
79 0 : {throw(casacore::AipsError("MultiTermFTNew::initializeToVis called without vectors !"));};
80 :
81 : // Vectorized InitializeToVis
82 : // void initializeToVis(casacore::Block<casacore::CountedPtr<casacore::ImageInterface<casacore::Complex> > > & compImageVec,casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & modelImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& weightImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& fluxScaleVec, casacore::Block<casacore::Matrix<casacore::Float> >& weightsVec, const VisBuffer& vb);
83 :
84 : virtual void initializeToVisNew(const VisBuffer& vb,
85 : casacore::CountedPtr<SIImageStore> imstore);
86 :
87 : // Called at the end of de-gridding : subftm->finalizeToVis()
88 : void finalizeToVis();
89 :
90 : // Called at the start of gridding : subftm->initializeToSky()
91 0 : void initializeToSky(casacore::ImageInterface<casacore::Complex>& /*image*/,
92 : casacore::Matrix<casacore::Float>& /*weight*/, const VisBuffer& /*vb*/)
93 0 : {throw(casacore::AipsError("MultiTermFTNew::initializeToSky() called without vectors!"));};
94 :
95 : // void initializeToSky(casacore::Block<casacore::CountedPtr<casacore::ImageInterface<casacore::Complex> > > & compImageVec, casacore::Block<casacore::Matrix<casacore::Float> >& weightsVec, const VisBuffer& vb, const casacore::Bool dopsf);
96 :
97 : virtual void initializeToSkyNew(const casacore::Bool dopsf,
98 : const VisBuffer& vb,
99 : casacore::CountedPtr<SIImageStore> imstore);
100 :
101 :
102 : // Called at the end of gridding : subftm->finalizeToSky()
103 0 : void finalizeToSky(){throw(casacore::AipsError("MultiTermFTNew::finalizeToSky() called without arguments!"));};
104 :
105 : //void finalizeToSky(casacore::Block<casacore::CountedPtr<casacore::ImageInterface<casacore::Complex> > > & compImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & resImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& weightImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& fluxScaleVec, casacore::Bool dopsf, casacore::Block<casacore::Matrix<casacore::Float> >& weightsVec, const VisBuffer& vb);
106 :
107 : virtual void finalizeToSkyNew(casacore::Bool dopsf,
108 : const VisBuffer& vb,
109 : casacore::CountedPtr<SIImageStore> imstore );
110 :
111 : // void normalizeToSky(casacore::ImageInterface<casacore::Complex>& compImage, casacore::ImageInterface<casacore::Float>& resImage, casacore::ImageInterface<casacore::Float>& weightImage, casacore::Bool dopsf, casacore::Matrix<casacore::Float>& weights)
112 : // {throw(casacore::AipsError("MultiTermFTNew::normalizeToSky should not get called !"));};
113 :
114 :
115 : // Do the degridding via subftm->get() and modify model-visibilities by Taylor-weights
116 : void get(VisBuffer& vb, casacore::Int row=-1);
117 :
118 : // Modify imaging weights with Taylor-weights and do gridding via subftm->put()
119 : void put(VisBuffer& vb, casacore::Int row=-1, casacore::Bool dopsf=false,
120 : FTMachine::Type type=FTMachine::OBSERVED);
121 :
122 : // Have a const version for compatibility with other FTMs.. Throw an exception if called.
123 0 : void put(const VisBuffer& /*vb*/, casacore::Int /*row*/=-1, casacore::Bool /*dopsf*/=false,
124 : FTMachine::Type /*type*/=FTMachine::OBSERVED)
125 0 : {throw(casacore::AipsError("MultiTermFTNew::put called with a const vb. This FTM needs to modify the vb."));};
126 :
127 : // Calculate residual visibilities if possible.
128 : // The purpose is to allow rGridFT to make this multi-threaded
129 : virtual void ComputeResiduals(VisBuffer&vb, casacore::Bool useCorrected);
130 :
131 : // Make an image : subftm->makeImage()
132 : void makeImage(FTMachine::Type type,
133 : VisSet& vs,
134 : casacore::ImageInterface<casacore::Complex>& image,
135 : casacore::Matrix<casacore::Float>& weight);
136 :
137 : // Get the final image: do the Fourier transform grid-correct, then
138 : // optionally normalize by the summed weights
139 : // Note : Post-gridding residual-image divisions by PBs will go here.
140 : // For now, it just calls subftm->getImage()
141 : // casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& weights, casacore::Bool normalize=true)
142 : //{return getImage(weights,normalize,0);};
143 : //casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& weights, casacore::Bool normalize=true,
144 : // const casacore::Int taylorindex=0);
145 0 : casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& /*weights*/, casacore::Bool /*normalize*/=true)
146 0 : {throw(casacore::AipsError("MultiTermFTNew::getImage() should not be called"));}
147 :
148 0 : virtual casacore::Bool useWeightImage()
149 0 : {AlwaysAssert(subftms_p.nelements()>0,casacore::AipsError); return subftms_p[0]->useWeightImage(); };
150 :
151 0 : void getWeightImage(casacore::ImageInterface<casacore::Float>& weightImage, casacore::Matrix<casacore::Float>& weights)
152 0 : {AlwaysAssert(subftms_p.nelements()>0,casacore::AipsError);
153 0 : subftms_p[0]->getWeightImage(weightImage, weights);}
154 : // {throw(casacore::AipsError("MultiTermFTNew::getWeightImage() should not be called"));}
155 :
156 : // Save and restore the MultiTermFTNew to and from a record
157 : virtual casacore::Bool toRecord(casacore::String& error, casacore::RecordInterface& outRec, casacore::Bool withImage=false,
158 : const casacore::String diskimage="");
159 : virtual casacore::Bool fromRecord(casacore::String& error, const casacore::RecordInterface& inRec);
160 :
161 : // Various small inline functions
162 0 : virtual casacore::Bool isFourier() {return true;}
163 0 : virtual void setNoPadding(casacore::Bool nopad){subftms_p[0]->setNoPadding(nopad);};
164 0 : virtual casacore::String name()const {return machineName_p;};
165 0 : virtual void setMiscInfo(const casacore::Int qualifier){(void)qualifier;};
166 :
167 : void printFTTypes()
168 : {
169 : cout << "** Number of FTs : " << subftms_p.nelements() << " -- " ;
170 : for(casacore::uInt tix=0; tix<(subftms_p).nelements(); tix++)
171 : cout << tix << " : " << (subftms_p[tix])->name() << " " ;
172 : cout << endl;
173 : };
174 :
175 : FTMachine* cloneFTM();
176 0 : virtual void setDryRun(casacore::Bool val)
177 : {
178 0 : isDryRun=val;
179 : //cerr << "MTFTMN: " << isDryRun << endl;
180 0 : for (casacore::uInt i=0;i<subftms_p.nelements();i++)
181 0 : subftms_p[i]->setDryRun(val);
182 0 : };
183 0 : virtual casacore::Bool isUsingCFCache() {casacore::Bool v=false; if (subftms_p.nelements() > 0) v=subftms_p[0]->isUsingCFCache(); return v;};
184 :
185 : protected:
186 : // have to call the initmaps of subftm
187 : virtual void initMaps(const VisBuffer& vb);
188 : // Instantiate a new sub FTM
189 : casacore::CountedPtr<FTMachine> getNewFTM(const casacore::CountedPtr<FTMachine>& ftm);
190 :
191 : // Multiply Imaging weights by Taylor-function weights - during "put"
192 : casacore::Bool modifyVisWeights(VisBuffer& vb, casacore::uInt thisterm);
193 : // Multiply model visibilities by Taylor-function weights - during "get"
194 : casacore::Bool modifyModelVis(VisBuffer &vb, casacore::uInt thisterm);
195 : // Restore vb.imagingweights to the original
196 : void restoreImagingWeights(VisBuffer &vb);
197 :
198 : // Helper function to write ImageInterfaces to disk
199 : casacore::Bool storeAsImg(casacore::String fileName, casacore::ImageInterface<casacore::Float> & theImg);
200 :
201 :
202 : casacore::Cube<casacore::Complex> modviscube_p;
203 :
204 : //// New MTFT specific internal parameters and functions
205 : casacore::uInt nterms_p, psfnterms_p;
206 : casacore::Double reffreq_p;
207 : casacore::Matrix<casacore::Float> imweights_p;
208 : casacore::String machineName_p;
209 :
210 : // casacore::Bool donePSF_p;
211 :
212 : casacore::Block< casacore::CountedPtr<FTMachine> > subftms_p;
213 :
214 : };
215 :
216 : } //# NAMESPACE CASA - END
217 :
218 : #endif
|