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