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
41template <class T>
42class TempLattice;
43
44// <summary>Lists the different types of Convolutions that can be done</summary>
45// <synopsis>This enumerator is brought out as a separate class because g++
46// currently cannot handle enumerators in a templated class. When it can this
47// class will go away and this enumerator moved into the Cleaner
48// class</synopsis>
49class CleanEnums {
50 public:
51 enum CleanType {
52 // Hogbom
53 HOGBOM,
54 // Multi-scale
56 // Clark
57 CLARK
58 };
59};
60
61// <summary>A class for doing multi-dimensional cleaning</summary>
62
63// <use visibility=export>
64
65// <reviewed reviewer="" date="yyyy/mm/dd" tests="tLatticeCleaner">
66// </reviewed>
67
68// <prerequisite>
69// <li> The mathematical concept of deconvolution
70// </prerequisite>
71//
72// <etymology>
73
74// The LatticeCleaner class will deconvolve Lattices.
75
76// </etymology>
77//
78// <synopsis>
79// This class will perform various types of Clean deconvolution
80// on Lattices.
81//
82// </synopsis>
83//
84// <example>
85// <srcblock>
86// </srcblock>
87// </example>
88//
89// <motivation>
90// </motivation>
91//
92// <thrown>
93// <li> AipsError: if psf has more dimensions than the model.
94// </thrown>
95//
96// <todo asof="yyyy/mm/dd">
97// <li> Allow the psf to be specified with a
98// <linkto class=Function>Function</linkto>.
99// </todo>
100
101template <class T>
103 public:
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
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, const Float gain,
141 const Quantity& aThreshold, const Quantity& fThreshold, const Bool choose = True);
142
143 // This version of the method disables stopping on fractional threshold
144 Bool setcontrol(CleanEnums::CleanType cleanType, const Int niter, const Float gain,
145 const Quantity& threshold, const Bool choose = True);
146
147 // return how many iterations we did do
148 Int iteration() const { return itsIteration; }
150
151 // what iteration number to start on
152 void startingIteration(const Int starting = 0) { itsStartingIter = starting; }
153
154 // Clean an image.
155 // return value gives you a hint of what's happening
156 // 1 = converged
157 // 0 = not converged but behaving normally
158 // -1 = not converged and stopped on cleaning consecutive smallest scale
159 // -2 = not converged and either large scale hit negative or diverging
160 // -3 = clean is diverging rather than converging
161 Int clean(Lattice<T>& model, LatticeCleanProgress* progress = 0);
162
163 // Set the mask
164 // mask - input mask lattice
165 // maskThreshold - if positive, the value is treated as a threshold value to determine
166 // whether a pixel is good (mask value is greater than the threshold) or has to be
167 // masked (mask value is below the threshold). Negative threshold switches mask clipping
168 // off. The mask value is used to weight the flux during cleaning. This mode is used
169 // to implement cleaning based on the signal-to-noise as opposed to the standard cleaning
170 // based on the flux. The default threshold value is 0.9, which ensures the behavior of the
171 // code is exactly the same as before this parameter has been introduced.
172 void setMask(const Lattice<T>& mask, const T& maskThreshold = T(0.9));
173
174 // Tell the algorithm to NOT clean just the inner quarter
175 // (This is useful when multiscale clean is being used
176 // inside a major cycle for MF or WF algorithms)
177 // if True, the full image deconvolution will be attempted
179
180 // Consider the case of a point source:
181 // the flux on all scales is the same, and the first scale will be chosen.
182 // Now, consider the case of a point source with a *little* bit of extended structure:
183 // thats right, the largest scale will be chosen. In this case, we should provide some
184 // bias towards the small scales, or against the large scales. We do this in
185 // an ad hoc manner, multiplying the maxima found at each scale by
186 // 1.0 - itsSmallScaleBias * itsScaleSizes(scale)/itsScaleSizes(nScalesToClean-1);
187 // Typical bias values range from 0.2 to 1.0.
188 void setSmallScaleBias(const Float x = 0.5) { itsSmallScaleBias = x; }
189
190 // During early iterations of a cycled MS Clean in mosaicing, it common
191 // to come across an ocsilatory pattern going between positive and
192 // negative in the large scale. If this is set, we stop at the first
193 // negative in the largest scale.
195
196 // Some algorithms require that the cycles be terminated when the image
197 // is dominated by point sources; if we get nStopPointMode of the
198 // smallest scale components in a row, we terminate the cycles
199 void stopPointMode(Int nStopPointMode) { itsStopPointMode = nStopPointMode; }
200
201 // After completion of cycle, querry this to find out if we stopped because
202 // of stopPointMode
204
205 // speedup() will speed the clean iteration by raising the
206 // threshold. This may be required if the threshold is
207 // accidentally set too low (ie, lower than can be achieved
208 // given errors in the approximate PSF).
209 //
210 // threshold(iteration) = threshold(0)
211 // * ( exp( (iteration - startingiteration)/Ndouble )/ 2.718 )
212 // If speedup() is NOT invoked, no effect on threshold
213 void speedup(const Float Ndouble);
214
215 // Look at what WE think the residuals look like
216 // Assumes the first scale is zero-sized
218
219 // Method to return threshold, including any speedup factors
221
222 // Method to return the strength optimum achieved at the last clean iteration
223 // The output of this method makes sense only if it is called after clean
225
226 // Helper function to optimize adding
227 static void addTo(Lattice<T>& to, const Lattice<T>& add);
228
229 protected:
230 // Make sure that the peak of the Psf is within the image
232
233 // Make an lattice of the specified scale
234 void makeScale(Lattice<T>& scale, const Float& scaleSize);
235
236 // Make Spheroidal function for scale images
238
239 // Find the Peak of the Lattice
240 static Bool findMaxAbsLattice(const Lattice<T>& lattice, T& maxAbs, IPosition& posMax);
241
242 // Find the Peak of the lattice, applying a mask
243 Bool findMaxAbsMaskLattice(const Lattice<T>& lattice, const Lattice<T>& mask, T& maxAbs,
244 IPosition& posMax);
245
246 // Helper function to reduce the box sizes until the have the same
247 // size keeping the centers intact
248 static void makeBoxesSameSize(IPosition& blc1, IPosition& trc1, IPosition& blc2, IPosition& trc2);
249
252 Int itsMaxNiter; // maximum possible number of iterations
256
257 private:
258 // # The following functions are used in various places in the code and are
259 // # documented in the .cc file. Static functions are used when the functions
260 // # do not modify the object state. They ensure that implicit assumptions
261 // # about the current state and implicit side-effects are not possible
262 // # because all information must be supplied in the input arguments
263
266
269
275
277
278 Int itsIteration; // what iteration did we get to?
279 Int itsStartingIter; // what iteration did we get to?
281
284
287
288 // Memory to be allocated per TempLattice
290
291 // Let the user choose whether to stop
293
294 // Threshold speedup factors:
295 Bool itsDoSpeedup; // if false, threshold does not change with iteration
297
298 // # Stop now?
299 // #// Bool stopnow(); Removed on 8-Apr-2004 by GvD
300
301 // Calculate index into PsfConvScales
302 Int index(const Int scale, const Int otherscale);
303
306
314
315 // threshold for masks. If negative, mask values are used as weights and no pixels are
316 // discarded (although effectively they would be discarded if the mask value is 0.)
318};
319
320} // namespace casacore
321
322#ifndef CASACORE_NO_AUTO_TEMPLATES
323#include <casacore/lattices/LatticeMath/LatticeCleaner.tcc>
324#endif // # CASACORE_NO_AUTO_TEMPLATES
325#endif
@ MULTISCALE
Multi-scale.
Bool findMaxAbsMaskLattice(const Lattice< T > &lattice, const Lattice< T > &mask, T &maxAbs, IPosition &posMax)
Find the Peak of the lattice, applying a mask.
T itsMaskThreshold
threshold for masks.
Vector< Float > itsScaleSizes
~LatticeCleaner()
The destructor does nothing special.
Block< TempLattice< T > * > itsScaleMasks
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.
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.
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.
Block< TempLattice< Complex > * > itsScaleXfrs
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
Block< TempLattice< T > * > itsPsfConvScales
T strengthOptimum() const
Method to return the strength optimum achieved at the last clean iteration The output of this method ...
Block< TempLattice< T > * > itsScales
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
Block< TempLattice< T > * > itsDirtyConvScales
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
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...
For temporary backward namespace compatibility, use casa as alias for casacore.
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
Quantum< Double > Quantity
Definition Quantum.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53