casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDGrid.h
Go to the documentation of this file.
1 //# SDGrid.h: Definition for SDGrid
2 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
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: aips2-request@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_SDGRID_H
30 #define SYNTHESIS_SDGRID_H
31 
32 #include <casa/Arrays/Array.h>
33 #include <casa/Arrays/Matrix.h>
34 #include <casa/Arrays/Vector.h>
35 #include <casa/Containers/Block.h>
44 #include <msvis/MSVis/VisBuffer2.h>
50 
51 namespace casa { //# NAMESPACE CASA - BEGIN
52 
53 namespace refim { //# namespace for imaging refactor
54 
55 // <summary> An FTMachine for Gridding Single Dish data
56 // </summary>
57 
58 // <use visibility=export>
59 
60 // <reviewed reviewer="" date="" tests="" demos="">
61 
62 // <prerequisite>
63 // <li> <linkto class=FTMachine>FTMachine</linkto> module
64 // <li> <linkto class=SkyEquation>SkyEquation</linkto> module
65 // <li> <linkto class=VisBuffer>VisBuffer</linkto> module
66 // </prerequisite>
67 //
68 // <etymology>
69 // FTMachine is a Machine for Fourier Transforms. SDGrid does
70 // Single Dish gridding in a similar way
71 // </etymology>
72 //
73 // <synopsis>
74 // The <linkto class=SkyEquation>SkyEquation</linkto> needs to be able
75 // to perform Fourier transforms on visibility data and to grid
76 // single dish data.
77 // SDGrid allows efficient Single Dish processing using a
78 // <linkto class=VisBuffer>VisBuffer</linkto> which encapsulates
79 // a chunk of visibility (typically all baselines for one time)
80 // together with all the information needed for processing
81 // (e.g. direction coordinates).
82 //
83 // Gridding and degridding in SDGrid are performed using a
84 // novel sort-less algorithm. In this approach, the gridded plane is
85 // divided into small patches, a cache of which is maintained in memory
86 // using a general-purpose <linkto class=casacore::LatticeCache>LatticeCache</linkto> class. As the (time-sorted)
87 // visibility data move around slowly in the image plane, patches are
88 // swapped in and out as necessary. Thus, optimally, one would keep at
89 // least one patch per scan line of data.
90 //
91 // A grid cache is defined on construction. If the gridded image plane is smaller
92 // than this, it is kept entirely in memory and all gridding and
93 // degridding is done entirely in memory. Otherwise a cache of tiles is
94 // kept an paged in and out as necessary. Optimally the cache should be
95 // big enough to hold all polarizations and frequencies for one
96 // complete scan line.
97 // The paging rate will then be small. As the cache size is
98 // reduced below this critical value, paging increases. The algorithm will
99 // work for only one patch but it will be very slow!
100 //
101 // The gridding and degridding steps are implemented in Fortran
102 // for speed. In gridding, the visibilities are added onto the
103 // grid points in the neighborhood using a weighting function.
104 // In degridding, the value is derived by a weight summ of the
105 // same points, using the same weighting function.
106 // </synopsis>
107 //
108 // <example>
109 // See the example for <linkto class=SkyModel>SkyModel</linkto>.
110 // </example>
111 //
112 // <motivation>
113 // Define an interface to allow efficient processing of chunks of
114 // visibility data
115 // </motivation>
116 //
117 // <todo asof="97/10/01">
118 // <ul> Deal with large VLA spectral line case
119 // </todo>
120 
121 class SDGrid : public FTMachine {
122 public:
123 
124  // Constructor: cachesize is the size of the cache in words
125  // (e.g. a few million is a good number), tilesize is the
126  // size of the tile used in gridding (cannot be less than
127  // 12, 16 works in most cases), and convType is the type of
128  // gridding used (SF is prolate spheriodal wavefunction,
129  // and BOX is plain box-car summation). mLocation is
130  // the position to be used in some phase rotations. If
131  // mTangent is specified then the uvw rotation is done for
132  // that location iso the image center. userSupport is to allow
133  // larger support for the convolution if the user wants it ..-1 will
134  // use the default i.e 1 for BOX and 3 for others
135  // USEIMAGINGWEIGHT
136  // The parameter useImagingWeight in the constructors is to explicitly
137  // use vb.imagingweight while gridding,
138  // When doing just SD imaging then setting it to false is fine (in fact recommended as vb.imagingweight
139  // is set to zero if any pol is flagged this may change later .....today being 2014/08/06)
140  // when using it in conjuction with interferometer gridding then set useImagingWeight to true
141  // this is to allow for proper non natural weighting scheme while imaging
142  // <group>
144  casacore::String convType="BOX", casacore::Int userSupport=-1, casacore::Bool useImagingWeight=false);
145  SDGrid(casacore::MPosition& ml, SkyJones& sj, casacore::Int cachesize,
146  casacore::Int tilesize, casacore::String convType="BOX", casacore::Int userSupport=-1,
147  casacore::Float minweight=0., casacore::Bool clipminmax=false, casacore::Bool useImagingWeight=false);
148  SDGrid(casacore::Int cachesize, casacore::Int tilesize,
149  casacore::String convType="BOX", casacore::Int userSupport=-1, casacore::Bool useImagingWeight=false);
150  SDGrid(casacore::MPosition& ml, casacore::Int cachesize, casacore::Int tilesize,
151  casacore::String convType="BOX", casacore::Int userSupport=-1, casacore::Float minweight=0., casacore::Bool clipminmax=false,
152  casacore::Bool useImagingWeight=false);
153  SDGrid(casacore::MPosition& ml, casacore::Int cachesize, casacore::Int tilesize,
154  casacore::String convType="TGAUSS", casacore::Float truncate=-1.0,
155  casacore::Float gwidth=0.0, casacore::Float jwidth=0.0, casacore::Float minweight=0., casacore::Bool clipminmax=false,
156  casacore::Bool useImagingWeight=false);
157  // </group>
158 
159  // Copy constructor
160  SDGrid(const SDGrid &other);
161 
162  // Assignment operator
163  SDGrid &operator=(const SDGrid &other);
164 
165  ~SDGrid();
166 
167  // Initialize transform to Visibility plane using the image
168  // as a template. The image is loaded and Fourier transformed.
170  const vi::VisBuffer2& vb);
171 
172  // Finalize transform to Visibility plane: flushes the image
173  // cache and shows statistics if it is being used.
174  void finalizeToVis();
175 
176  // Initialize transform to Sky plane: initializes the image
178  const vi::VisBuffer2& vb);
179 
180  // Finalize transform to Sky plane: flushes the image
181  // cache and shows statistics if it is being used. DOES NOT
182  // DO THE FINAL TRANSFORM!
183  void finalizeToSky();
184 
185  // Get actual coherence from grid by degridding
186  void get(vi::VisBuffer2& vb, casacore::Int row=-1);
187 
188  // Put coherence to grid by gridding.
189  void put(const vi::VisBuffer2& vb, casacore::Int row=-1, casacore::Bool dopsf=false,
191 
192  // Make the entire image using a ROVisIter...
193  // This is an overload for FTMachine version as
194  //SDGrid now does everything in memory
195  // so for large cube ..proceed by slices that fit in memory here.
196  virtual void makeImage(FTMachine::Type type,
200 
201  // Get the final image:
202  // optionally normalize by the summed weights
205  const casacore::Matrix<casacore::Double>& /*sumOfWts*/,
206  casacore::Lattice<casacore::Float>& /*sensitivityImage*/,
207  casacore::Bool /*fftNorm*/)
208  {throw(casacore::AipsError("SDGrid::normalizeImage() called"));}
209 
210  // SDGrind needs to fill weightimage
211  virtual casacore::Bool useWeightImage(){return true;};
212 
213  // Get the final weights image
215 
216  // Has this operator changed since the last application?
217  virtual casacore::Bool changed(const vi::VisBuffer2& vb);
218  virtual void setMiscInfo(const casacore::Int qualifier){(void)qualifier;};
219  virtual void ComputeResiduals(vi::VisBuffer2& /*vb*/, casacore::Bool /*useCorrected*/) {};
220 
221  virtual casacore::String name() const;
222 
223 private:
224 
225  // Find the Primary beam and convert it into a convolution buffer
227  const vi::VisBuffer2& vb);
228 
230 
231  // Get the appropriate data pointer
234 
235  void ok();
236 
237  void init();
238 
239  // Image cache
242 
243  // Sizes
245 
246  // Is this tiled?
248 
249  // Storage for weights
251 
252  // casacore::Array lattice
255 
256  // Lattice. For non-tiled gridding, this will point to arrayLattice,
257  // whereas for tiled gridding, this points to the image
260 
262 
263  // Useful IPositions
265 
266  // casacore::Array for non-tiled gridding
268 
269 
271 
273 
275  //Original xypos of moving source
277 
279 
281 
287 
291 
293 
299 
302 
303  // for minmax clipping
310  void clipMinMax();
311 
313  const casacore::Double& interval=-1.0, const casacore::Int& antid=-1);
314 
316 
317  //get the casacore::MDirection from a chosen column of pointing table
321  const casacore::Int& index, const casacore::Int& index1, const casacore::Int& index2);
322 
324 
325  //for debugging
326  //FILE *pfile;
327 };
328 
329 } //End of namespace refim
330 } //# NAMESPACE CASA - END
331 
332 #endif
casacore::MDirection worldPosMeas
Definition: SDGrid.h:278
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
A Measure: astronomical direction.
Definition: MDirection.h:174
casacore::Bool useImagingWeight_p
Definition: SDGrid.h:296
virtual casacore::Bool useWeightImage()
SDGrind needs to fill weightimage.
Definition: SDGrid.h:211
A Measure: position on Earth.
Definition: MPosition.h:79
int Int
Definition: aipstype.h:50
virtual casacore::String name() const
Return the name of the machine.
casacore::Array< casacore::Complex > gmin_
Definition: SDGrid.h:305
casacore::ImageInterface< casacore::Complex > & getImage(casacore::Matrix< casacore::Float > &, casacore::Bool normalize=true)
Get the final image: optionally normalize by the summed weights.
casacore::String convType
Definition: SDGrid.h:261
defines interface for the Fourier Transform Machine
Definition: FTMachine.h:122
casacore::Int userSetSupport_p
Definition: SDGrid.h:286
VisibilityIterator2 iterates through one or more readonly MeasurementSets.
casacore::Vector< casacore::Double > xyPosMovingOrig_p
Original xypos of moving source.
Definition: SDGrid.h:276
casacore::LatticeCache< casacore::Complex > * imageCache
Image cache.
Definition: SDGrid.h:240
casacore::Int convSupport
Definition: SDGrid.h:285
casacore::MDirection interpolateDirectionMeas(const casacore::ROMSPointingColumns &mspc, const casacore::Double &time, const casacore::Int &index, const casacore::Int &index1, const casacore::Int &index2)
virtual Type type()
Return the type enum.
virtual void ComputeResiduals(vi::VisBuffer2 &, casacore::Bool)
Make the VB and VBStore interefaces for the interim re-factoring work.
Definition: SDGrid.h:219
casacore::Int tilesize
Definition: SDGrid.h:244
SDPosInterpolator * interpolator
Definition: SDGrid.h:301
ABSTRACT TOOL CLASSES A PlotTool is a higher level event handler for a PlotCanvas The idea is to take common tasks which may require multiple events and put them in one place PlotTools also provide additional functionality in that they can be active and blocking non blocking The PlotCanvas will only send events to active and will not send events to later tools or event handlers if the latest tool was blocking In this way a single tool can be used to handle ALL user interaction via the GUI at one time
Definition: PlotTool.h:43
casacore::DirectionCoordinate directionCoord
Definition: SDGrid.h:270
casacore::Lattice< casacore::Float > * wLattice
Definition: SDGrid.h:259
casacore::Bool getXYPos(const vi::VisBuffer2 &vb, casacore::Int row)
casacore::Int msId_p
Definition: SDGrid.h:298
casacore::Array< casacore::Float > wGriddedData
casacore::Array for non-tiled gridding
Definition: SDGrid.h:267
casacore::Lattice< casacore::Float > * wArrayLattice
Definition: SDGrid.h:254
casacore::Array< casacore::Complex > gmax_
Definition: SDGrid.h:306
casacore::Bool clipminmax_
for minmax clipping
Definition: SDGrid.h:304
casacore::Float truncate_p
Definition: SDGrid.h:288
casacore::Vector< casacore::Int > lastIndexPerAnt_p
Definition: SDGrid.h:295
SDGrid & operator=(const SDGrid &other)
Assignment operator.
casacore::ImageInterface< casacore::Float > * wImage
Storage for weights.
Definition: SDGrid.h:250
SkyJones * sj_p
Definition: SDGrid.h:229
void finalizeToSky()
Finalize transform to Sky plane: flushes the image cache and shows statistics if it is being used...
virtual void normalizeImage(casacore::Lattice< casacore::Complex > &, const casacore::Matrix< casacore::Double > &, casacore::Lattice< casacore::Float > &, casacore::Bool)
Definition: SDGrid.h:204
casacore::Cube< casacore::Int > flags
Definition: SDGrid.h:280
casacore::Array< casacore::Float > wmax_
Definition: SDGrid.h:308
casacore::Vector< casacore::Float > convFunc
Definition: SDGrid.h:282
casacore::Int lastIndex_p
Definition: SDGrid.h:294
casacore::Array< casacore::Int > npoints_
Definition: SDGrid.h:309
casacore::Int convSampling
Definition: SDGrid.h:283
casacore::Int convSize
Definition: SDGrid.h:284
A class to provide easy read-only access to MSPointing columns.
Interconvert pixel positions and directions (e.g. RA/DEC).
casacore::Bool isSplineInterpolationReady
Definition: SDGrid.h:300
double Double
Definition: aipstype.h:55
casacore::IPosition centerLoc
Useful IPositions.
Definition: SDGrid.h:264
casacore::MDirection directionMeas(const casacore::ROMSPointingColumns &mspc, const casacore::Int &index)
get the casacore::MDirection from a chosen column of pointing table
casacore::Array< casacore::Float > wmin_
Definition: SDGrid.h:307
casacore::Array< casacore::Float > * getWDataPointer(const casacore::IPosition &, casacore::Bool)
Type
Types of known Images that may be made using the makeImage method.
Definition: FTMachine.h:127
casacore::Int cachesize
Sizes.
Definition: SDGrid.h:244
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void initializeToSky(casacore::ImageInterface< casacore::Complex > &image, casacore::Matrix< casacore::Float > &weight, const vi::VisBuffer2 &vb)
Initialize transform to Sky plane: initializes the image.
casacore::LatticeCache< casacore::Float > * wImageCache
Definition: SDGrid.h:241
SDGrid(SkyJones &sj, casacore::Int cachesize, casacore::Int tilesize, casacore::String convType="BOX", casacore::Int userSupport=-1, casacore::Bool useImagingWeight=false)
Constructor: cachesize is the size of the cache in words (e.g.
casacore::MDirection::Convert * pointingToImage
Definition: SDGrid.h:272
virtual void setMiscInfo(const casacore::Int qualifier)
set the order of the Taylor term for MFS this is to tell A-casacore::Projection to qualify the accumu...
Definition: SDGrid.h:218
An FTMachine for Gridding Single Dish data.
Definition: SDGrid.h:121
float Float
Definition: aipstype.h:54
Sky Jones: Model sky-plane instrumental effects for the SkyEquation.
Definition: SkyJones.h:174
casacore::Lattice< casacore::Complex > * arrayLattice
casacore::Array lattice
Definition: SDGrid.h:253
void pickWeights(const vi::VisBuffer2 &vb, casacore::Matrix< casacore::Float > &weight)
void findPBAsConvFunction(const casacore::ImageInterface< casacore::Complex > &image, const vi::VisBuffer2 &vb)
Find the Primary beam and convert it into a convolution buffer.
void put(const vi::VisBuffer2 &vb, casacore::Int row=-1, casacore::Bool dopsf=false, FTMachine::Type type=FTMachine::OBSERVED)
Put coherence to grid by gridding.
casacore::Float minWeight_p
Definition: SDGrid.h:292
VisBuffer2s encapsulate one chunk of visibility data for processing.
Definition: VisBuffer2.h:141
Base class for all Casacore library errors.
Definition: Error.h:134
void initializeToVis(casacore::ImageInterface< casacore::Complex > &image, const vi::VisBuffer2 &vb)
Initialize transform to Visibility plane using the image as a template.
casacore::IPosition offsetLoc
Definition: SDGrid.h:264
void getWeightImage(casacore::ImageInterface< casacore::Float > &, casacore::Matrix< casacore::Float > &)
Get the final weights image.
void finalizeToVis()
Finalize transform to Visibility plane: flushes the image cache and shows statistics if it is being u...
casacore::Int lastAntID_p
Definition: SDGrid.h:297
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Int getIndex(const casacore::ROMSPointingColumns &mspc, const casacore::Double &time, const casacore::Double &interval=-1.0, const casacore::Int &antid=-1)
casacore::Array< casacore::Complex > * getDataPointer(const casacore::IPosition &, casacore::Bool)
Get the appropriate data pointer.
casacore::Float gwidth_p
Definition: SDGrid.h:289
casacore::Vector< casacore::Double > xyPos
Definition: SDGrid.h:274
casacore::Float jwidth_p
Definition: SDGrid.h:290
casacore::ImageInterface< casacore::Complex > * image
Definition: FTMachine.h:395
virtual void makeImage(FTMachine::Type type, vi::VisibilityIterator2 &vi, casacore::ImageInterface< casacore::Complex > &image, casacore::Matrix< casacore::Float > &weight)
Make the entire image using a ROVisIter...
virtual casacore::Bool changed(const vi::VisBuffer2 &vb)
Has this operator changed since the last application?
casacore::Lattice< casacore::Complex > * lattice
Lattice.
Definition: SDGrid.h:258
casacore::Bool isTiled
Is this tiled?
Definition: SDGrid.h:247