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_TRANSFORM2_MULTITERMFTNEW_H
30 : #define SYNTHESIS_TRANSFORM2_MULTITERMFTNEW_H
31 :
32 : #include <synthesis/TransformMachines2/FTMachine.h>
33 : #include <casacore/casa/Arrays/Matrix.h>
34 : #include <casacore/scimath/Mathematics/FFTServer.h>
35 : #include <msvis/MSVis/VisBuffer2.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 : namespace vi{
56 : class VisibilityIterator2;
57 : }
58 :
59 : namespace refim { //# namespace refactor imaginging
60 : class MultiTermFTNew : public FTMachine {
61 : public:
62 :
63 : // Construct using an existing FT-Machine
64 : MultiTermFTNew(casacore::CountedPtr<FTMachine>& subftm, casacore::Int nterms=1, casacore::Bool forward=false);
65 :
66 : // Construct from a casacore::Record containing the MultiTermFTNew state
67 : MultiTermFTNew(const casacore::RecordInterface& stateRec);
68 :
69 : // Copy constructor.
70 : // This first calls the default "=" operator, and then instantiates objects for member pointers.
71 : MultiTermFTNew(const MultiTermFTNew &other);
72 :
73 : // Assignment operator --- leave it as the default
74 : MultiTermFTNew &operator=(const MultiTermFTNew &other);
75 :
76 : // Destructor
77 : ~MultiTermFTNew();
78 :
79 : // Called at the start of de-gridding : subftm->initializeToVis()
80 : // Note : Pre-de-gridding model-image divisions by PBs will go here.
81 :
82 0 : void initializeToVis(casacore::ImageInterface<casacore::Complex>& /*image*/,
83 0 : const vi::VisBuffer2& /*vb*/){throw(casacore::AipsError("not implemented"));};
84 : // Vectorized InitializeToVis
85 : // 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);
86 :
87 : virtual void initializeToVisNew(const vi::VisBuffer2& vb,
88 : casacore::CountedPtr<SIImageStore> imstore);
89 :
90 : // Called at the end of de-gridding : subftm->finalizeToVis()
91 : void finalizeToVis();
92 :
93 : // Called at the start of gridding : subftm->initializeToSky()
94 0 : void initializeToSky(casacore::ImageInterface<casacore::Complex>& /*image*/,
95 0 : casacore::Matrix<casacore::Float>& /*weight*/, const vi::VisBuffer2& /*vb*/){throw(casacore::AipsError("not implemented"));};
96 : // 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);
97 :
98 : virtual void initializeToSkyNew(const casacore::Bool dopsf,
99 : const vi::VisBuffer2& vb,
100 : casacore::CountedPtr<SIImageStore> imstore);
101 :
102 : virtual void initBriggsWeightor(vi::VisibilityIterator2& vi);
103 : // Called at the end of gridding : subftm->finalizeToSky()
104 0 : void finalizeToSky(){throw(casacore::AipsError("MultiTermFTNew::finalizeToSky() called without arguments!"));};
105 :
106 : //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);
107 :
108 : virtual void finalizeToSkyNew(casacore::Bool dopsf,
109 : const vi::VisBuffer2& vb,
110 : casacore::CountedPtr<SIImageStore> imstore );
111 :
112 : virtual void finalizeToWeightImage(const vi::VisBuffer2& vb,
113 : casacore::CountedPtr<SIImageStore> imstore );
114 : // 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)
115 : // {throw(casacore::AipsError("MultiTermFTNew::normalizeToSky should not get called !"));};
116 :
117 :
118 : // Do the degridding via subftm->get() and modify model-visibilities by Taylor-weights
119 : void get(vi::VisBuffer2& vb, casacore::Int row=-1);
120 : // Modify imaging weights with Taylor-weights and do gridding via subftm->put()
121 : void put(vi::VisBuffer2& vb, casacore::Int row=-1, casacore::Bool dopsf=false,
122 : refim::FTMachine::Type type=refim::FTMachine::OBSERVED);
123 : // Have a const version for compatibility with other FTMs.. Throw an exception if called.
124 0 : void put(const vi::VisBuffer2& /*vb*/, casacore::Int /*row=-1*/, casacore::Bool /*dopsf=false*/,
125 : refim::FTMachine::Type /*type=FTMachine::OBSERVED*/)
126 0 : {throw(casacore::AipsError("Internal error: called MultiTermFTNew::put(const VB2)"));};
127 :
128 : virtual void gridImgWeights(const vi::VisBuffer2& vb);
129 : // Calculate residual visibilities if possible.
130 : // The purpose is to allow rGridFT to make this multi-threaded
131 : virtual void ComputeResiduals(vi::VisBuffer2& vb, casacore::Bool useCorrected);
132 :
133 : // Make an image : subftm->makeImage()
134 : void makeImage(refim::FTMachine::Type type,
135 : vi::VisibilityIterator2& vs,
136 : casacore::ImageInterface<casacore::Complex>& image,
137 : casacore::Matrix<casacore::Float>& weight);
138 : ////Make the multi term images
139 : ////caller make sure vector is the size of nterms or npsfterms required
140 : void makeMTImages(refim::FTMachine::Type type,
141 : vi::VisibilityIterator2& vi,
142 : casacore::Vector<casacore::CountedPtr<casacore::ImageInterface<casacore::Complex> > >& image,
143 : casacore::Vector<casacore::CountedPtr<casacore::Matrix<casacore::Float> > >& weight);
144 : // Get the final image: do the Fourier transform grid-correct, then
145 : // optionally normalize by the summed weights
146 : // Note : Post-gridding residual-image divisions by PBs will go here.
147 : // For now, it just calls subftm->getImage()
148 : // casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& weights, casacore::Bool normalize=true)
149 : //{return getImage(weights,normalize,0);};
150 : //casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& weights, casacore::Bool normalize=true,
151 : // const casacore::Int taylorindex=0);
152 0 : casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& /*weights*/, casacore::Bool /*normalize*/=true)
153 0 : {throw(casacore::AipsError("MultiTermFTNew::getImage() should not be called"));}
154 :
155 0 : virtual casacore::Bool useWeightImage()
156 0 : {AlwaysAssert(subftms_p.nelements()>0,casacore::AipsError); return subftms_p[0]->useWeightImage(); };
157 :
158 0 : void getWeightImage(casacore::ImageInterface<casacore::Float>& weightImage, casacore::Matrix<casacore::Float>& weights)
159 0 : {AlwaysAssert(subftms_p.nelements()>0,casacore::AipsError);
160 0 : subftms_p[0]->getWeightImage(weightImage, weights);}
161 : // {throw(casacore::AipsError("MultiTermFTNew::getWeightImage() should not be called"));}
162 :
163 : // Save and restore the MultiTermFTNew to and from a record
164 : virtual casacore::Bool toRecord(casacore::String& error, casacore::RecordInterface& outRec, casacore::Bool withImage=false,
165 : const casacore::String diskimage="");
166 : virtual casacore::Bool fromRecord(casacore::String& error, const casacore::RecordInterface& inRec);
167 :
168 : // Various small inline functions
169 0 : virtual casacore::Bool isFourier() {return true;}
170 0 : virtual void setNoPadding(casacore::Bool nopad){subftms_p[0]->setNoPadding(nopad);};
171 0 : virtual casacore::String name()const {return machineName_p;};
172 0 : virtual void setMiscInfo(const casacore::Int qualifier){(void)qualifier;};
173 :
174 : void printFTTypes()
175 : {
176 : cout << "** Number of FTs : " << subftms_p.nelements() << " -- " ;
177 : for(casacore::uInt tix=0; tix<(subftms_p).nelements(); tix++)
178 : cout << tix << " : " << (subftms_p[tix])->name() << " " ;
179 : cout << endl;
180 : };
181 :
182 : FTMachine* cloneFTM();
183 0 : virtual void setDryRun(casacore::Bool val)
184 : {
185 0 : isDryRun=val;
186 : //cerr << "MTFTMN: " << isDryRun << endl;
187 0 : for (casacore::uInt i=0;i<subftms_p.nelements();i++)
188 0 : subftms_p[i]->setDryRun(val);
189 0 : };
190 0 : virtual casacore::Bool isUsingCFCache() {casacore::Bool v=false; if (subftms_p.nelements() > 0) v=subftms_p[0]->isUsingCFCache(); return v;};
191 0 : virtual const casacore::CountedPtr<refim::FTMachine>& getFTM2(const casacore::Bool ) {return subftms_p[0];}
192 : virtual void setCFCache(casacore::CountedPtr<CFCache>& cfc, const casacore::Bool resetCFC=true);
193 :
194 :
195 : ///return number of terms
196 :
197 0 : virtual casacore::Int nTerms(){ return nterms_p;};
198 0 : virtual casacore::Int psfNTerms(){ return psfnterms_p;};
199 :
200 : // set a moving source aka planets or comets => adjust phase center
201 : // on the fly for gridding
202 : virtual void setMovingSource(const casacore::String& sourcename, const casacore::String& ephemtable="");
203 : virtual void setMovingSource(const casacore::MDirection& mdir);
204 : // set and get the location used for frame
205 : virtual void setLocation(const casacore::MPosition& loc);
206 : ///estimate of memory necessary in kB
207 : virtual casacore::Long estimateRAM(const casacore::CountedPtr<SIImageStore>& imstore);
208 : protected:
209 : // have to call the initmaps of subftm
210 : virtual void initMaps(const vi::VisBuffer2& vb);
211 : // Instantiate a new sub FTM
212 : casacore::CountedPtr<FTMachine> getNewFTM(const casacore::CountedPtr<FTMachine>& ftm);
213 :
214 : // Multiply Imaging weights by Taylor-function weights - during "put"
215 : casacore::Bool modifyVisWeights(vi::VisBuffer2& vb, casacore::uInt thisterm);
216 : // Multiply model visibilities by Taylor-function weights - during "get"
217 : casacore::Bool modifyModelVis(vi::VisBuffer2 &vb, casacore::uInt thisterm);
218 : // Restore vb.imagingweights to the original
219 : void restoreImagingWeights(vi::VisBuffer2 &vb);
220 :
221 : // Helper function to write ImageInterfaces to disk
222 : casacore::Bool storeAsImg(casacore::String fileName, casacore::ImageInterface<casacore::Float> & theImg);
223 :
224 :
225 : casacore::Cube<casacore::Complex> modviscube_p;
226 :
227 : //// New MTFT specific internal parameters and functions
228 : casacore::uInt nterms_p, psfnterms_p;
229 : casacore::Double reffreq_p;
230 : casacore::Matrix<casacore::Float> imweights_p;
231 : casacore::String machineName_p;
232 :
233 : // casacore::Bool donePSF_p;
234 :
235 : casacore::Block< casacore::CountedPtr<FTMachine> > subftms_p;
236 :
237 : };
238 :
239 : } //end namespace refim
240 : } //# NAMESPACE CASA - END
241 :
242 : #endif
|