casacore
Loading...
Searching...
No Matches
LatticeCleaner.h
Go to the documentation of this file.
1//# Cleaner.h: this defines Cleaner a class for doing convolution
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 addressed 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#ifndef LATTICES_LATTICECLEANER_H
27#define LATTICES_LATTICECLEANER_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Quanta/Quantum.h>
32#include <casacore/lattices/Lattices/TempLattice.h>
33#include <casacore/casa/Arrays/IPosition.h>
34#include <casacore/casa/Arrays/Vector.h>
35#include <casacore/casa/Containers/Block.h>
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39//# Forward Declarations
40class LatticeCleanProgress;
41template <class T> class TempLattice;
42
43// <summary>Lists the different types of Convolutions that can be done</summary>
44// <synopsis>This enumerator is brought out as a separate class because g++
45// currently cannot handle enumerators in a templated class. When it can this
46// class will go away and this enumerator moved into the Cleaner
47// class</synopsis>
48class CleanEnums {
49public:
50 enum CleanType {
51 // Hogbom
52 HOGBOM,
53 // Multi-scale
55 // Clark
56 CLARK
57 };
58};
59
60// <summary>A class for doing multi-dimensional cleaning</summary>
61
62// <use visibility=export>
63
64// <reviewed reviewer="" date="yyyy/mm/dd" tests="tLatticeCleaner">
65// </reviewed>
66
67// <prerequisite>
68// <li> The mathematical concept of deconvolution
69// </prerequisite>
70//
71// <etymology>
72
73// The LatticeCleaner class will deconvolve Lattices.
74
75// </etymology>
76//
77// <synopsis>
78// This class will perform various types of Clean deconvolution
79// on Lattices.
80//
81// </synopsis>
82//
83// <example>
84// <srcblock>
85// </srcblock>
86// </example>
87//
88// <motivation>
89// </motivation>
90//
91// <thrown>
92// <li> AipsError: if psf has more dimensions than the model.
93// </thrown>
94//
95// <todo asof="yyyy/mm/dd">
96// <li> Allow the psf to be specified with a
97// <linkto class=Function>Function</linkto>.
98// </todo>
99
100template<class T> class LatticeCleaner
101{
102public:
103
104 // Create a cleaner : default constructor
106
107 // Create a cleaner for a specific dirty image and PSF
108 LatticeCleaner(const Lattice<T> & psf, const Lattice<T> & dirty);
109
110 // The copy constructor uses reference semantics
112
113 // The assignment operator also uses reference semantics
115
116 // The destructor does nothing special.
118
119 // Update the dirty image only
120 void update(const Lattice<T> & dirty);
121
122 // Set a number of scale sizes. The units of the scale are pixels.
123 Bool setscales(const Int nscales, const Float scaleInc=1.0);
124
125 // Set a specific set of scales
126 Bool setscales(const Vector<Float> & scales);
127
128 // Set up control parameters
129 // cleanType - type of the cleaning algorithm to use (HOGBOM, MULTISCALE)
130 // niter - number of iterations
131 // gain - loop gain used in cleaning (a fraction of the maximum
132 // subtracted at every iteration)
133 // aThreshold - absolute threshold to stop iterations
134 // fThreshold - fractional threshold (i.e. given w.r.t. maximum residual)
135 // to stop iterations. This parameter is specified as
136 // Quantity so it can be given in per cents.
137 // choose - unused at the moment, specify False. Original meaning is
138 // to allow interactive decision on whether to continue iterations.
139 // This method always returns True.
140 Bool setcontrol(CleanEnums::CleanType cleanType, const Int niter,
141 const Float gain, const Quantity& aThreshold,
142 const Quantity& fThreshold,
143 const Bool choose=True);
144
145 // This version of the method disables stopping on fractional threshold
146 Bool setcontrol(CleanEnums::CleanType cleanType, const Int niter,
147 const Float gain, const Quantity& threshold,
148 const Bool choose=True);
149
150 // return how many iterations we did do
151 Int iteration() const { return itsIteration; }
153
154 // what iteration number to start on
155 void startingIteration(const Int starting = 0) {itsStartingIter = starting; }
156
157 // Clean an image.
158 //return value gives you a hint of what's happening
159 // 1 = converged
160 // 0 = not converged but behaving normally
161 // -1 = not converged and stopped on cleaning consecutive smallest scale
162 // -2 = not converged and either large scale hit negative or diverging
163 // -3 = clean is diverging rather than converging
165
166 // Set the mask
167 // mask - input mask lattice
168 // maskThreshold - if positive, the value is treated as a threshold value to determine
169 // whether a pixel is good (mask value is greater than the threshold) or has to be
170 // masked (mask value is below the threshold). Negative threshold switches mask clipping
171 // off. The mask value is used to weight the flux during cleaning. This mode is used
172 // to implement cleaning based on the signal-to-noise as opposed to the standard cleaning
173 // based on the flux. The default threshold value is 0.9, which ensures the behavior of the
174 // code is exactly the same as before this parameter has been introduced.
175 void setMask(const Lattice<T> & mask, const T& maskThreshold = T(0.9));
176
177 // Tell the algorithm to NOT clean just the inner quarter
178 // (This is useful when multiscale clean is being used
179 // inside a major cycle for MF or WF algorithms)
180 // if True, the full image deconvolution will be attempted
182
183 // Consider the case of a point source:
184 // the flux on all scales is the same, and the first scale will be chosen.
185 // Now, consider the case of a point source with a *little* bit of extended structure:
186 // thats right, the largest scale will be chosen. In this case, we should provide some
187 // bias towards the small scales, or against the large scales. We do this in
188 // an ad hoc manner, multiplying the maxima found at each scale by
189 // 1.0 - itsSmallScaleBias * itsScaleSizes(scale)/itsScaleSizes(nScalesToClean-1);
190 // Typical bias values range from 0.2 to 1.0.
191 void setSmallScaleBias(const Float x=0.5) { itsSmallScaleBias = x; }
192
193 // During early iterations of a cycled MS Clean in mosaicing, it common
194 // to come across an ocsilatory pattern going between positive and
195 // negative in the large scale. If this is set, we stop at the first
196 // negative in the largest scale.
198
199 // Some algorithms require that the cycles be terminated when the image
200 // is dominated by point sources; if we get nStopPointMode of the
201 // smallest scale components in a row, we terminate the cycles
202 void stopPointMode(Int nStopPointMode) {itsStopPointMode = nStopPointMode; }
203
204 // After completion of cycle, querry this to find out if we stopped because
205 // of stopPointMode
207
208 // speedup() will speed the clean iteration by raising the
209 // threshold. This may be required if the threshold is
210 // accidentally set too low (ie, lower than can be achieved
211 // given errors in the approximate PSF).
212 //
213 // threshold(iteration) = threshold(0)
214 // * ( exp( (iteration - startingiteration)/Ndouble )/ 2.718 )
215 // If speedup() is NOT invoked, no effect on threshold
216 void speedup(const Float Ndouble);
217
218 // Look at what WE think the residuals look like
219 // Assumes the first scale is zero-sized
221
222 // Method to return threshold, including any speedup factors
224
225 // Method to return the strength optimum achieved at the last clean iteration
226 // The output of this method makes sense only if it is called after clean
228
229 // Helper function to optimize adding
230 static void addTo(Lattice<T>& to, const Lattice<T>& add);
231
232protected:
233 // Make sure that the peak of the Psf is within the image
235
236 // Make an lattice of the specified scale
237 void makeScale(Lattice<T>& scale, const Float& scaleSize);
238
239 // Make Spheroidal function for scale images
241
242 // Find the Peak of the Lattice
243 static Bool findMaxAbsLattice(const Lattice<T>& lattice,
244 T& maxAbs, IPosition& posMax);
245
246 // Find the Peak of the lattice, applying a mask
248 T& maxAbs, IPosition& posMax);
249
250 // Helper function to reduce the box sizes until the have the same
251 // size keeping the centers intact
252 static void makeBoxesSameSize(IPosition& blc1, IPosition& trc1,
253 IPosition &blc2, IPosition& trc2);
254
255
258 Int itsMaxNiter; // maximum possible number of iterations
262private:
263
264 //# The following functions are used in various places in the code and are
265 //# documented in the .cc file. Static functions are used when the functions
266 //# do not modify the object state. They ensure that implicit assumptions
267 //# about the current state and implicit side-effects are not possible
268 //# because all information must be supplied in the input arguments
269
270
273
276
282
284
285 Int itsIteration; // what iteration did we get to?
286 Int itsStartingIter; // what iteration did we get to?
288
291
292
295
296 // Memory to be allocated per TempLattice
298
299 // Let the user choose whether to stop
301
302 // Threshold speedup factors:
303 Bool itsDoSpeedup; // if false, threshold does not change with iteration
305
306 //# Stop now?
307 //#// Bool stopnow(); Removed on 8-Apr-2004 by GvD
308
309 // Calculate index into PsfConvScales
310 Int index(const Int scale, const Int otherscale);
311
314
315
323
324 // threshold for masks. If negative, mask values are used as weights and no pixels are
325 // discarded (although effectively they would be discarded if the mask value is 0.)
327
328};
329
330} //# NAMESPACE CASACORE - END
331
332#ifndef CASACORE_NO_AUTO_TEMPLATES
333#include <casacore/lattices/LatticeMath/LatticeCleaner.tcc>
334#endif //# CASACORE_NO_AUTO_TEMPLATES
335#endif
@ MULTISCALE
Multi-scale.
A class for doing multi-dimensional cleaning.
Bool findMaxAbsMaskLattice(const Lattice< T > &lattice, const Lattice< T > &mask, T &maxAbs, IPosition &posMax)
Find the Peak of the lattice, applying a mask.
PtrBlock< TempLattice< T > * > itsScales
T itsMaskThreshold
threshold for masks.
Vector< Float > itsScaleSizes
~LatticeCleaner()
The destructor does nothing special.
Bool itsChoose
Let the user choose whether to stop.
void stopPointMode(Int nStopPointMode)
Some algorithms require that the cycles be terminated when the image is dominated by point sources; i...
Int clean(Lattice< T > &model, LatticeCleanProgress *progress=0)
Clean an image.
Bool setscales(const Vector< Float > &scales)
Set a specific set of scales.
LatticeCleaner(const Lattice< T > &psf, const Lattice< T > &dirty)
Create a cleaner for a specific dirty image and PSF.
Double itsMemoryMB
Memory to be allocated per TempLattice.
Bool setcontrol(CleanEnums::CleanType cleanType, const Int niter, const Float gain, const Quantity &aThreshold, const Quantity &fThreshold, const Bool choose=True)
Set up control parameters cleanType - type of the cleaning algorithm to use (HOGBOM,...
static void addTo(Lattice< T > &to, const Lattice< T > &add)
Helper function to optimize adding.
void makeScale(Lattice< T > &scale, const Float &scaleSize)
Make an lattice of the specified scale.
PtrBlock< TempLattice< T > * > itsDirtyConvScales
Quantum< Double > itsFracThreshold
Bool setcontrol(CleanEnums::CleanType cleanType, const Int niter, const Float gain, const Quantity &threshold, const Bool choose=True)
This version of the method disables stopping on fractional threshold.
static Bool findMaxAbsLattice(const Lattice< T > &lattice, T &maxAbs, IPosition &posMax)
Find the Peak of the Lattice.
Bool setscales(const Int nscales, const Float scaleInc=1.0)
Set a number of scale sizes.
Bool validatePsf(const Lattice< T > &psf)
Make sure that the peak of the Psf is within the image.
void speedup(const Float Ndouble)
speedup() will speed the clean iteration by raising the threshold.
PtrBlock< TempLattice< Complex > * > itsScaleXfrs
void ignoreCenterBox(Bool huh)
Tell the algorithm to NOT clean just the inner quarter (This is useful when multiscale clean is being...
Float threshold() const
Method to return threshold, including any speedup factors.
LatticeCleaner< T > & operator=(const LatticeCleaner< T > &other)
The assignment operator also uses reference semantics.
void startingIteration(const Int starting=0)
what iteration number to start on
void setMask(const Lattice< T > &mask, const T &maskThreshold=T(0.9))
Set the mask mask - input mask lattice maskThreshold - if positive, the value is treated as a thresho...
TempLattice< T > * itsMask
void setSmallScaleBias(const Float x=0.5)
Consider the case of a point source: the flux on all scales is the same, and the first scale will be ...
LatticeCleaner()
Create a cleaner : default constructor.
CleanEnums::CleanType itsCleanType
void update(const Lattice< T > &dirty)
Update the dirty image only.
Lattice< T > * residual()
Look at what WE think the residuals look like Assumes the first scale is zero-sized.
Bool itsDoSpeedup
Threshold speedup factors:
Vector< Float > itsTotalFluxScale
T strengthOptimum() const
Method to return the strength optimum achieved at the last clean iteration The output of this method ...
Int index(const Int scale, const Int otherscale)
Calculate index into PsfConvScales.
Bool queryStopPointMode() const
After completion of cycle, querry this to find out if we stopped because of stopPointMode.
static void makeBoxesSameSize(IPosition &blc1, IPosition &trc1, IPosition &blc2, IPosition &trc2)
Helper function to reduce the box sizes until the have the same size keeping the centers intact
TempLattice< Complex > * itsXfr
Float spheroidal(Float nu)
Make Spheroidal function for scale images.
Int iteration() const
return how many iterations we did do
Quantum< Double > itsThreshold
TempLattice< T > * itsDirty
PtrBlock< TempLattice< T > * > itsPsfConvScales
PtrBlock< TempLattice< T > * > itsScaleMasks
LatticeCleaner(const LatticeCleaner< T > &other)
The copy constructor uses reference semantics.
void stopAtLargeScaleNegative()
During early iterations of a cycled MS Clean in mosaicing, it common to come across an ocsilatory pat...
A drop-in replacement for Block<T*>.
Definition Block.h:812
this file contains all the compiler specific defines
Definition mainpage.dox:28
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53