Line data Source code
1 : // -*- C++ -*-
2 : //# AWConvFunc.h: Definition of the AWConvFunc class
3 : //# Copyright (C) 1997-2023
4 : //# Associated Universities, Inc. Washington DC, USA.
5 : //#
6 : //# This library is free software; you can redistribute it and/or modify it
7 : //# under the terms of the GNU Library General Public License as published by
8 : //# the Free Software Foundation; either version 2 of the License, or (at your
9 : //# option) any later version.
10 : //#
11 : //# This library is distributed in the hope that it will be useful, but WITHOUT
12 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 : //# License for more details.
15 : //#
16 : //# You should have received a copy of the GNU Library General Public License
17 : //# along with this library; if not, write to the Free Software Foundation,
18 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 : //#
20 : //# Correspondence concerning AIPS++ should be addressed as follows:
21 : //# Internet email: casa-feedback@nrao.edu.
22 : //# Postal address: AIPS++ Project Office
23 : //# National Radio Astronomy Observatory
24 : //# 520 Edgemont Road
25 : //# Charlottesville, VA 22903-2475 USA
26 : //#
27 : //# $Id$
28 : //
29 : #ifndef SYNTHESIS_TRANSFORM2_AWCONVFUNC_H
30 : #define SYNTHESIS_TRANSFORM2_AWCONVFUNC_H
31 :
32 : #include <synthesis/TransformMachines2/ConvolutionFunction.h>
33 : #include <synthesis/TransformMachines2/PolOuterProduct.h>
34 : #include <casacore/coordinates/Coordinates/DirectionCoordinate.h>
35 : #include <synthesis/TransformMachines2/CFStore.h>
36 : #include <synthesis/TransformMachines2/CFStore2.h>
37 : #include <synthesis/TransformMachines2/CFBuffer.h>
38 : #include <synthesis/TransformMachines2/VB2CFBMap.h>
39 : #include <synthesis/TransformMachines2/PSTerm.h>
40 : #include <synthesis/TransformMachines2/WTerm.h>
41 : #include <synthesis/TransformMachines2/ATerm.h>
42 : #include <casacore/images/Images/ImageInterface.h>
43 : #include <casacore/images/Images/TempImage.h>
44 : #include <casacore/casa/Logging/LogIO.h>
45 : #include <casacore/casa/Logging/LogSink.h>
46 : #include <casacore/casa/Logging/LogOrigin.h>
47 : #include <casacore/casa/Arrays/ArrayFwd.h>
48 : #include <msvis/MSVis/VisBuffer2.h>
49 : namespace casacore{
50 :
51 : template<class T> class ImageInterface;
52 :
53 : }
54 :
55 : namespace casa { //# NAMESPACE CASA - BEGIN
56 : using namespace vi;
57 : // class VisBuffer2;
58 : //
59 : //-------------------------------------------------------------------------------------------
60 : //
61 : namespace refim{
62 : //forward decs
63 : class WPConvFunc;
64 : class EVLAAperture;
65 : class AWConvFunc : public ConvolutionFunction
66 : {
67 : public:
68 : AWConvFunc(const casacore::CountedPtr<ATerm> ATerm,
69 : const casacore::CountedPtr<PSTerm> psTerm,
70 : const casacore::CountedPtr<WTerm> wTerm,
71 : const casacore::Bool wbAWP=false,
72 : const casacore::Bool conjPB=casacore::True);
73 :
74 : //this constructor is from 2023 to generate aw convfunc on the fly
75 : //For now noot using generic Aterm but specificall ELVA/VLA specialization
76 : AWConvFunc(std::shared_ptr<EVLAAperture> aterm, std::shared_ptr<WPConvFunc> wterm);
77 :
78 :
79 :
80 :
81 :
82 0 : ~AWConvFunc() {};
83 : //Makes the FT of PB (should be replicated to apply product of 2 different VP for
84 : //heterogenous array
85 : // No oversampling at this stage
86 : // return conv function RR, RL, LR LL and freq axis as long a freq vector,
87 : // supports are freqlist long
88 : // if dosquint=false pa ignored and a average RR, LL beam is made
89 : // The shape of convFunc is [convSize, convSize, 4, len(freqlist)]
90 : // npix will be support on which the beam will be calculated
91 : // this can be used to rescale the beam along with the csys to the grid it is being
92 : //applied
93 : void makeAConvFunc(casacore::Array<casacore::Complex> &convFunc,
94 : casacore::Array<casacore::Complex> &wtconv,
95 : casacore::CoordinateSystem &csys,
96 : casacore::Vector<casacore::Int> &asupport,
97 : casacore::Int &npix,
98 : const casacore::Vector<casacore::Double> &freqlist,
99 : const casacore::Bool dosquint = False,
100 : const casacore::Double &pa = 0.0, const bool isSingleField=false);
101 : // same as above except used for squint so reduce fov
102 : void makeSmallAConvFunc(casacore::Array<casacore::Complex> &convFunc,
103 : casacore::Array<casacore::Complex> &wtconv,
104 : casacore::CoordinateSystem &csys,
105 : casacore::Vector<casacore::Int> &asupport,
106 : casacore::Int &npix,
107 : const casacore::Vector<casacore::Double> &freqlist,
108 : const casacore::Double &pa = 0.0);
109 :
110 : //Makes the combination of wvals along A terms freqScale
111 : //return shapes of convFunc as [convSize, convSize, 4, len(freq), len(Wvals)]
112 : //returned matrix support is of shape [len(freq], len(wVals)]
113 : void makeAWConvFunc(casacore::Array<casacore::Complex>& convFunc,
114 : casacore::Array<casacore::Complex>& wtconv,
115 : casacore::CoordinateSystem& csys,
116 : casacore::Matrix<casacore::Int>& awsupport,
117 : casacore::Int& npix,
118 : const casacore::Vector<casacore::Double>& freqlist,
119 : const casacore::Vector<casacore::Double>& wVals,
120 : const casacore::Bool dosquint=False,
121 : const casacore::Double& pa=0.0, const bool isSingleField=false);
122 :
123 :
124 :
125 :
126 : AWConvFunc& operator=(const AWConvFunc& other);
127 : virtual void makeConvFunction(const casacore::ImageInterface<casacore::Complex>& image,
128 : const VisBuffer2& vb,
129 : const casacore::Int wConvSize,
130 : const casacore::CountedPtr<PolOuterProduct>& pop,
131 : const casacore::Float pa,
132 : const casacore::Float dpa,
133 : const casacore::Vector<casacore::Double>& uvScale, const casacore::Vector<casacore::Double>& uvOffset,
134 : const casacore::Matrix<casacore::Double>& vbFreqSelection,
135 : CFStore2& cfs,
136 : CFStore2& cfwts,
137 : casacore::Bool fillCF=true);
138 : virtual void fillConvFuncBuffer(CFBuffer& cfb, CFBuffer& cfWtb,
139 : const casacore::Int& skyNX, const casacore::Int& skyNY,
140 : const casacore::Vector<casacore::Double>& skyIncr,
141 : const casacore::Int& nx, const casacore::Int& ny,
142 : const casacore::Vector<casacore::Double>& freqValues,
143 : const casacore::Vector<casacore::Double>& wValues,
144 : const casacore::Double& wScale,
145 : const casacore::Double& vbPA, const casacore::Double& freqHi,
146 : const PolMapType& muellerElements,
147 : const PolMapType& muellerElementsIndex,
148 : const VisBuffer2& vb, const casacore::Float& psScale,
149 : PSTerm& psTerm, WTerm& wTerm, ATerm& aTerm,
150 : casacore::Bool isDryRun=false);
151 : static void makeConvFunction2(const casacore::String& uvGridDiskimage,
152 : const casacore::Vector<casacore::Double>& uvScale, const casacore::Vector<casacore::Double>& uvOffset,
153 : const casacore::Matrix<casacore::Double>& vbFreqSelection,
154 : CFStore2& cfs,
155 : CFStore2& cfwts,
156 : const casacore::Bool psTermOn,
157 : const casacore::Bool aTermOn,
158 : const casacore::Bool conjBeams);
159 : static void fillConvFuncBuffer2(CFBuffer& cfb, CFBuffer& cfWtb,
160 : const casacore::Int& nx, const casacore::Int& ny,
161 : const casacore::ImageInterface<casacore::Complex>& skyImage,
162 : const CFCStruct& miscInfo,
163 : PSTerm& psTerm, WTerm& wTerm, ATerm& aTerm,
164 : casacore::Bool conjBeams);
165 :
166 : virtual casacore::Bool makeAverageResponse(const VisBuffer2& vb,
167 : const casacore::ImageInterface<casacore::Complex>& image,
168 : casacore::ImageInterface<casacore::Float>& theavgPB,
169 : casacore::Bool reset=true);
170 : virtual casacore::Bool makeAverageResponse(const VisBuffer2& vb,
171 : const casacore::ImageInterface<casacore::Complex>& image,
172 : casacore::ImageInterface<casacore::Complex>& theavgPB,
173 : casacore::Bool reset=true);
174 0 : virtual int getVisParams(const VisBuffer2& vb,const casacore::CoordinateSystem& skyCoord=casacore::CoordinateSystem())
175 0 : {return aTerm_p->getVisParams(vb,skyCoord);};
176 0 : virtual void setPolMap(const casacore::Vector<casacore::Int>& polMap) {aTerm_p->setPolMap(polMap);};
177 : // virtual void setFeedStokes(const casacore::Vector<casacore::Int>& feedStokes) {aTerm_p->setFeedStokes(feedStokes);};
178 : virtual casacore::Bool findSupport(casacore::Array<casacore::Complex>& func, casacore::Float& threshold,casacore::Int& origin, casacore::Int& R);
179 0 : virtual casacore::Vector<casacore::Double> findPointingOffset(const casacore::ImageInterface<casacore::Complex>& /*image*/,
180 0 : const VisBuffer2& /*vb*/) {casacore::Vector<casacore::Double> tt(2); tt=0;return tt;};
181 : //virtual void prepareConvFunction(const VisBuffer2& vb, VBRow2CFBMapType& cfs);
182 : virtual void prepareConvFunction(const VisBuffer2& vb, VB2CFBMap& cfs);
183 0 : casacore::Int mapAntIDToAntType(const casacore::Int& ant) {return aTerm_p->mapAntIDToAntType(ant);};
184 :
185 : virtual casacore::Vector<casacore::Double> makeFreqValList(casacore::Double& freqScale,
186 : const VisBuffer2& vb,
187 : const casacore::ImageInterface<casacore::Complex>& uvGrid,
188 : casacore::Vector<casacore::String>& bandNames);
189 : virtual casacore::Vector<casacore::Double> makeWValList(const casacore::Double &dW, const casacore::Int &nW);
190 :
191 : virtual void setMiscInfo(const casacore::RecordInterface& params);
192 : virtual casacore::Matrix<casacore::Double> getFreqRangePerSpw(const VisBuffer2& vb);
193 :
194 :
195 :
196 : //
197 : // Global methods (services)
198 : //
199 : static void makeConjPolAxis(casacore::CoordinateSystem& cs, casacore::Int conjStokes_in=-1);
200 : static casacore::Complex cfArea(casacore::Matrix<casacore::Complex>& cf, const casacore::Int& xSupport, const casacore::Int& ySupport, const casacore::Float& sampling);
201 : static casacore::Bool awFindSupport(casacore::Array<casacore::Complex>& func, casacore::Float& threshold, casacore::Int& origin, casacore::Int& radius);
202 : static casacore::Bool setUpCFSupport(casacore::Array<casacore::Complex>& func, casacore::Int& xSupport, casacore::Int& ySupport,
203 : const casacore::Float& sampling, const casacore::Complex& peak);
204 : static casacore::Bool resizeCF(casacore::Array<casacore::Complex>& func, casacore::Int& xSupport, casacore::Int& ySupport,
205 : const casacore::Int& supportBuffer, const casacore::Float& sampling, const casacore::Complex& peak);
206 : static int getOversampling(PSTerm& psTerm, WTerm& wTerm, ATerm& aTerm);
207 0 : int getOversampling(){return getOversampling(*psTerm_p, *wTerm_p, *aTerm_p);}
208 :
209 0 : virtual casacore::CountedPtr<CFTerms> getTerm(const casacore::String& name)
210 0 : {if (name=="ATerm") return aTerm_p; else return NULL;}
211 :
212 0 : virtual bool isWBAWP() {return wbAWP_p;};
213 :
214 : // virtual casacore::Vector<casacore::Vector<casacore::Double> >findPointingOffset(const casacore::ImageInterface<casacore::Complex>& /*image*/,
215 : // const VisBuffer2& /*vb*/, const casacore::Bool& doPointing);
216 :
217 :
218 :
219 : casacore::CountedPtr<ATerm> aTerm_p;
220 : casacore::CountedPtr<PSTerm> psTerm_p;
221 : casacore::CountedPtr<WTerm> wTerm_p;
222 :
223 : protected:
224 : void normalizeAvgPB(casacore::ImageInterface<casacore::Complex>& inImage,
225 : casacore::ImageInterface<casacore::Float>& outImage);
226 : // void makePBSq(casacore::ImageInterface<casacore::Complex>& inImage);
227 :
228 : //for now this will support EVLA and VLA defined bands in evla L to Q
229 : //and VLA L to Q
230 : // return optimal cellsize and npix to calculate beam on
231 : std::pair<casacore::Quantity, int> getBeamCellSize(const String& bandName="EVLA_L");
232 : //find support and normalize convfunc for A Term only
233 : casacore::Bool supportAndNormalizeAFunc(casacore::Int& sup,
234 : casacore::Array<casacore::Complex>& conv,
235 : casacore::Array<casacore::Complex>& wtconv, const bool widefield=false);
236 : //support returned is row is freq axis, col is w axis
237 : //It will reduce the array XY size to match largest support found
238 : // aTermsup is just to make sure any support found is not smaller than support for
239 : // just a Aterm conv
240 : casacore::Bool supportResizeAWConv(casacore::Matrix<casacore::Int>& sup, casacore::Array<casacore::Complex>& conv, const casacore::Vector<casacore::Int>& aTermSup);
241 :
242 :
243 :
244 :
245 : casacore::Vector<casacore::Double> thePix_p;
246 : casacore::Vector<casacore::Vector<casacore::Double> >pixFieldGrad_p;
247 : casacore::Double imRefFreq_p;
248 : casacore::Bool wbAWP_p, conjPB_p;
249 : casacore::CountedPtr<CFBuffer> baseCFB_p;
250 : ///These are the object that generates image/and UV domains A and W term
251 : std::shared_ptr<EVLAAperture> atermMaker_p;
252 : std::shared_ptr<WPConvFunc> wtermMaker_p;
253 : refim::MathUtils mutils_p;
254 : casacore::CoordinateSystem csys_p;
255 : };
256 : //
257 : //-------------------------------------------------------------------------------------------
258 : //
259 : };
260 : };
261 : #endif
|