Line data Source code
1 : // -*- C++ -*-
2 : //# VisibilityResampler.h: Definition of the VisibilityResampler class
3 : //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
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_VISIBILITYRESAMPLER_H
30 : #define SYNTHESIS_TRANSFORM2_VISIBILITYRESAMPLER_H
31 :
32 : #include <synthesis/TransformMachines2/CFStore.h>
33 : #include <synthesis/TransformMachines2/Utils.h>
34 : #include <synthesis/TransformMachines2/VBStore.h>
35 : #include <synthesis/TransformMachines2/AWConvFuncHolder.h>
36 : #include <synthesis/TransformMachines2/VisibilityResamplerBase.h>
37 : #include <msvis/MSVis/VisBuffer2.h>
38 : #include <casacore/casa/Arrays/Array.h>
39 : #include <casacore/casa/Arrays/Vector.h>
40 : //#include <msvis/MSVis/AsynchronousTools.h>
41 :
42 : #include <casacore/casa/Logging/LogIO.h>
43 : #include <casacore/casa/Logging/LogSink.h>
44 : #include <casacore/casa/Logging/LogMessage.h>
45 :
46 : namespace casa { //# NAMESPACE CASA - BEGIN
47 : namespace refim{
48 : class VisibilityResampler: public VisibilityResamplerBase
49 : {
50 : public:
51 0 : VisibilityResampler(): VisibilityResamplerBase() {nVBs_p=nVisGridded_p=0;};
52 : // VisibilityResampler(const CFStore& cfs): VisibilityResamplerBase(cfs) {};
53 0 : VisibilityResampler(const VisibilityResampler& other):VisibilityResamplerBase()
54 0 : {copy(other);}
55 :
56 : // {setConvFunc(cfs);};
57 0 : virtual ~VisibilityResampler()
58 0 : {
59 : // cerr << "~VisibilityResampler:: "
60 : // << "No. of VBs processed: " << nVBs_p << endl
61 : // << "No. of vis. processed: " << nVisGridded_p << endl;
62 0 : };
63 :
64 : // VisibilityResampler& operator=(const VisibilityResampler& other);
65 :
66 0 : void copy(const VisibilityResamplerBase& other)
67 0 : {VisibilityResamplerBase::copy(other);}
68 :
69 0 : virtual Bool needCFPhaseScreen() {return true;};
70 0 : virtual VisibilityResamplerBase* clone()
71 0 : {return new VisibilityResampler(*this);}
72 :
73 0 : virtual void getParams(casacore::Vector<casacore::Double>& uvwScale, casacore::Vector<casacore::Double>& offset, casacore::Vector<casacore::Double>& dphase)
74 0 : {uvwScale.assign(uvwScale_p); offset.assign(offset_p); dphase.assign(dphase_p);};
75 0 : virtual void setParams(const casacore::Vector<casacore::Double>& uvwScale, const casacore::Vector<casacore::Double>& offset,
76 : const casacore::Vector<casacore::Double>& dphase)
77 : {
78 : // SynthesisUtils::SETVEC(uvwScale_p, uvwScale);
79 : // SynthesisUtils::SETVEC(offset_p, offset);
80 : // SynthesisUtils::SETVEC(dphase_p, dphase);
81 0 : uvwScale_p.reference(uvwScale);
82 0 : offset_p.reference(offset);
83 0 : dphase_p.reference(dphase);
84 0 : };
85 :
86 0 : virtual void setMaps(const casacore::Vector<casacore::Int>& chanMap, const casacore::Vector<casacore::Int>& polMap)
87 : {
88 : // SynthesisUtils::SETVEC(chanMap_p,chanMap);
89 : // SynthesisUtils::SETVEC(polMap_p,polMap);
90 0 : chanMap_p.reference(chanMap);
91 0 : polMap_p.reference(polMap);
92 0 : }
93 :
94 0 : virtual void setFreqMaps(const casacore::Matrix<casacore::Double>& spwChanFreqs, const casacore::Matrix<casacore::Double>& spwChanConjFreqs)
95 : {
96 0 : spwChanFreq_p.assign(spwChanFreqs);
97 0 : spwChanConjFreq_p.assign(spwChanConjFreqs);
98 0 : }
99 :
100 0 : virtual void setConvFunc(const CFStore& cfs)
101 : {
102 0 : convFuncStore_p = cfs;
103 0 : };
104 0 : virtual void setConvFunc(std::shared_ptr<AWConvFuncHolder>& awh)
105 0 : {awConvHolder_p=awh;};
106 :
107 0 : virtual void setCFMaps(const casacore::Vector<casacore::Int>& cfMap, const casacore::Vector<casacore::Int>& conjCFMap) {(void)cfMap;(void)conjCFMap;};
108 0 : virtual void setPATolerance(const double& dPA) {paTolerance_p = dPA;};
109 : //
110 : //------------------------------------------------------------------------------
111 : //
112 : // Re-sample the griddedData on the VisBuffer (a.k.a gridding).
113 : //
114 : // In this class, these just call the private templated version.
115 : // The first variant grids onto a double precision grid while the
116 : // second one does it on a single precision grid.
117 : //
118 0 : virtual void DataToGrid(casacore::Array<casacore::DComplex>& griddedData, VBStore& vbs,
119 : casacore::Matrix<casacore::Double>& sumwt, const casacore::Bool& dopsf,
120 : casacore::Bool /*useConjFreqCF*/=false)
121 0 : {DataToGridImpl_p(griddedData, vbs, dopsf, sumwt);}
122 :
123 0 : virtual void DataToGrid(casacore::Array<casacore::Complex>& griddedData, VBStore& vbs,
124 : casacore::Matrix<casacore::Double>& sumwt, const casacore::Bool& dopsf,
125 : casacore::Bool /*useConjFreqCF*/=false)
126 0 : {DataToGridImpl_p(griddedData, vbs, dopsf, sumwt);}
127 :
128 : //
129 : //------------------------------------------------------------------------------
130 : //
131 : // Re-sample VisBuffer to a regular grid (griddedData) (a.k.a. de-gridding)
132 : //
133 : virtual void GridToData(VBStore& vbs,const casacore::Array<casacore::Complex>& griddedData);
134 : // virtual void GridToData(VBStore& vbs, casacore::Array<casacore::Complex>& griddedData);
135 :
136 : virtual void ComputeResiduals(VBStore& vbs);
137 0 : virtual void setMutex(async::Mutex *mu) {myMutex_p = mu;};
138 :
139 : // Genealogical baggage -- required for the
140 : // MultiThreadedVisibilityResampler -- that everyone else has to
141 : // carray around.
142 : //
143 : // These are no-ops for unithreaded samplers.
144 : //
145 0 : virtual void init(const casacore::Bool& doublePrecision) {(void)doublePrecision;};
146 0 : virtual void GatherGrids(casacore::Array<casacore::DComplex>& griddedData, casacore::Matrix<casacore::Double>& sumwt) {(void)griddedData;(void)sumwt;};
147 0 : virtual void GatherGrids(casacore::Array<casacore::Complex>& griddedData, casacore::Matrix<casacore::Double>& sumwt) {(void)griddedData;(void)sumwt;};
148 0 : virtual void initializePutBuffers(const casacore::Array<casacore::DComplex>& griddedData,
149 0 : const casacore::Matrix<casacore::Double>& sumwt) {(void)griddedData;(void)sumwt;};
150 0 : virtual void initializePutBuffers(const casacore::Array<casacore::Complex>& griddedData,
151 0 : const casacore::Matrix<casacore::Double>& sumwt) {(void)griddedData;(void)sumwt;};
152 0 : virtual void initializeDataBuffers(VBStore& vbs) {(void)vbs;};
153 :
154 0 : virtual void releaseBuffers() {};
155 : //
156 : //------------------------------------------------------------------------------
157 : //----------------------------Private parts-------------------------------------
158 : //------------------------------------------------------------------------------
159 : //
160 : protected:
161 : async::Mutex *myMutex_p;
162 : double nVBs_p, nVisGridded_p;
163 : // casacore::Vector<casacore::Double> uvwScale_p, offset_p, dphase_p;
164 : // casacore::Vector<casacore::Int> chanMap_p, polMap_p;
165 : // CFStore convFuncStore_p;
166 : // casacore::Int inc0_p, inc1_p, inc2_p, inc3_p;
167 : //
168 : // Re-sample the griddedData on the VisBuffer (a.k.a de-gridding).
169 : //
170 : template <class T>
171 : void DataToGridImpl_p(casacore::Array<T>& griddedData, VBStore& vb,
172 : const casacore::Bool& dopsf, casacore::Matrix<casacore::Double>& sumwt,casacore::Bool useConjFreqCF=false);
173 :
174 :
175 : std::shared_ptr<AWConvFuncHolder> awConvHolder_p;
176 : // void sgrid(casacore::Vector<casacore::Double>& pos, casacore::Vector<casacore::Int>& loc, casacore::Vector<casacore::Int>& off,
177 : // casacore::Complex& phasor, const casacore::Int& irow, const casacore::Matrix<casacore::Double>& uvw,
178 : // const casacore::Double& dphase, const casacore::Double& freq,
179 : // const casacore::Vector<casacore::Double>& scale, const casacore::Vector<casacore::Double>& offset,
180 : // const casacore::Vector<casacore::Float>& sampling);
181 :
182 : /*
183 : void sgrid(casacore::Int& ndim, casacore::Double* pos, casacore::Int* loc, casacore::Int* off,
184 : casacore::Complex& phasor, const casacore::Int& irow, const casacore::Double* uvw,
185 : const casacore::Double& dphase, const casacore::Double& freq,
186 : const casacore::Double* scale, const casacore::Double* offset,
187 : const casacore::Float* sampling);
188 :
189 : inline casacore::Bool onGrid (const casacore::Int& nx, const casacore::Int& ny,
190 : const casacore::Vector<casacore::Int>& __restrict__ loc,
191 : const casacore::Vector<casacore::Int>& __restrict__ support) __restrict__
192 : {
193 : return (((loc(0)-support[0]) >= 0 ) && ((loc(0)+support[0]) < nx) &&
194 : ((loc(1)-support[1]) >= 0 ) && ((loc(1)+support[1]) < ny));
195 : };
196 : inline casacore::Bool onGrid (const casacore::Int& nx, const casacore::Int& ny,
197 : const casacore::Int& loc0, const casacore::Int& loc1,
198 : const casacore::Int& support) __restrict__
199 : {
200 : return (((loc0-support) >= 0 ) && ((loc0+support) < nx) &&
201 : ((loc1-support) >= 0 ) && ((loc1+support) < ny));
202 : };
203 :
204 : // casacore::Array assignment operator in CASACore requires lhs.nelements()
205 : // == 0 or lhs.nelements()=rhs.nelements()
206 : // template <class T>
207 : // inline void SETVEC(casacore::Vector<T>& lhs, const casacore::Vector<T>& rhs)
208 : // {lhs.resize(rhs.shape()); lhs = rhs;};
209 :
210 :
211 : //
212 : // Internal methods to address a 4D array. These should ulimately
213 : // moved to a Array4D class in CASACore
214 : //
215 :
216 : // This is called less frequently. Currently once per VisBuffer
217 : inline void cacheAxisIncrements(casacore::Int& n0, casacore::Int& n1, casacore::Int& n2, casacore::Int& n3)
218 : {inc0_p=1, inc1_p=inc0_p*n0, inc2_p=inc1_p*n1, inc3_p=inc2_p*n2;(void)n3;}
219 :
220 :
221 : // The following two methods are called in the innermost loop.
222 : inline casacore::Complex getFrom4DArray(const casacore::Complex* __restrict__ store,
223 : const casacore::Int* __restrict__ iPos) __restrict__
224 : {return store[iPos[0] + iPos[1]*inc1_p + iPos[2]*inc2_p +iPos[3]*inc3_p];};
225 :
226 : template <class T>
227 : void addTo4DArray(T* __restrict__ store,
228 : const casacore::Int* __restrict__ iPos,
229 : casacore::Complex& nvalue, casacore::Double& wt) __restrict__
230 : {store[iPos[0] + iPos[1]*inc1_p + iPos[2]*inc2_p +iPos[3]*inc3_p] += (nvalue*wt);}
231 : */
232 : };
233 : }; //# NAMESPACE CASA - END
234 : };
235 : #endif //
|