casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClarkCleanLatModel.h
Go to the documentation of this file.
1 //# ClarkCleanLatModel.h: this defines ClarkCleanLatModel
2 //# Copyright (C) 1996,1997,1998,1999,2000,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: 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_CLARKCLEANLATMODEL_H
30 #define SYNTHESIS_CLARKCLEANLATMODEL_H
31 
32 #include <casa/aips.h>
36 #include <casa/Arrays/IPosition.h>
38 #include <casa/Logging/LogIO.h>
39 
40 namespace casacore{
41 
42 template <class T> class Matrix;
43 template <class T> class Vector;
44 }
45 
46 namespace casa { //# NAMESPACE CASA - BEGIN
47 
48 class ClarkCleanProgress;
49 class LatConvEquation;
50 class CCList;
51 
52 // <summary>
53 // A Class for performing the Clark Clean Algorithm on Arrays
54 // </summary>
55 
56 // <use visibility=export>
57 
58 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
59 // </reviewed>
60 
61 // <prerequisite>
62 // <li> ResidualEquation/LatConvEquation
63 // <li> LinearModel/LinearEquation Paradigm
64 // </prerequisite>
65 //
66 // <etymology>
67 // This class is called ClarkCleanLatModel because thats the algorithm it uses
68 // deconvolve the lattice-based model.
69 // </etymology>
70 //
71 // <synopsis>
72 // This class is used to perform the Clark Clean Algorithm on an
73 // Array. Only the deconvolved model of the sky are directly stored by this
74 // class. The point spread function (psf) and convolved (dirty) image are
75 // stored in a companion class which is must be derived from
76 // ResidualEquation.
77 //
78 // The cleaning works like this. The user constructs a ClarkCleanLatModel by
79 // specifying an initial model of the sky. This can by be
80 // one,two,three... dimensional depending on the dimension of the psf (see
81 // below). The user then constructs a class which implements the forward
82 // equation between the model and the dirty image. Typically this will be
83 // the ConvolutionEquation class, although any class which has a
84 // ResidualEquation interface will be work (but perhaps very slowly, as the
85 // ConvolutionEquation class has member functions optimised for cleaning)
86 //
87 // The user then calls the solve() function (with the appropriate equation
88 // class as an arguement), and this class will perform the Clark clean.
89 // The various clean parameters are set (prior to calling solve) using the
90 // functions derived from the Iterate class, in particular setGain(),
91 // setNumberIterations() & setThreshold() (to set a flux limit).
92 //
93 // The solve() function does not return either the deconvolved model or the
94 // residuals. The solved model can be obtained using the getModel() function
95 // (derived from ArrayModel()) and the residual can be obtained using the
96 // residual() member function of the Convolution/Residual Equation Class.
97 //
98 // The size and shape of the model used in this class MUST be the same as
99 // the convolved data (Dirty Image), stored in the companion
100 // ResidualEquation Class. However the model (and convolved data) can have
101 // more dimensions than the psf, as well as a different size (either larger
102 // or smaller). When the dimensionality is different the cleaning is done
103 // independendtly in each "plane" of the model. (Note this has not
104 // been implemented yet but is relatively simple to do if necessary).
105 //
106 // This multi-dimensionalty is exploited when cleaning arrays of
107 // StokesVectors. Here the casacore::Array of StokesVectors is decomposed into a stack
108 // of 4 Floating point arrays and the cleaning is done on all the the arrays
109 // simultaneosly. The criterion for choosing the brightest pixel has been
110 // generalised by using the "length" of the Stokesvector in 4 dimensional
111 // space.
112 //
113 // A companion class to this one is MaskedClarkCleanLatModel. This provides
114 // the same functionality but is used with MaskedArrays which indicate which
115 // regions of the model to search for clean components.
116 //
117 // </synopsis>
118 //
119 // <example>
120 // <srcblock>
121 // casacore::Matrix<casacore::Float> psf(12,12), dirty(10,10), initialModel(10,10);
122 // ...put appropriate values into psf, dirty, & initialModel....
123 // ClarkCleanLatModel<casacore::Float> deconvolvedModel(initialModel);
124 // ConvolutionEquation convEqn(psf, dirty);
125 // deconvolvedModel.setGain(0.2);
126 // deconvolvedModel.setNumberIterations(1000);
127 // casacore::Bool convWorked = deconvolvedModel.solve(convEqn);
128 // if (convWorked)
129 // ConvEqn.residual(deconvolvedModel, finalResidual);
130 // </srcblock>
131 // </example>
132 //
133 // <motivation>
134 // This class is needed to deconvolve images.
135 // </motivation>
136 //
137 // <templating arg=T>
138 // I have tested this class with Arrays of
139 // <li> Float
140 // <li> StokesVector
141 // </templating>
142 //
143 // <todo asof="1996/05/02">
144 // <li> Make changes so that multidimensions work as advertised
145 // <li> compare timing with other clean implementations (ie, Mark's
146 // CleanTools, SDE, AIPS & miriad)
147 // </todo>
148 
150  public LinearModel< casacore::Lattice<casacore::Float> >,
151  public Iterate
152 {
153 public:
154  // The default constructor does nothing more than initialise a zero length
155  // array to hold the deconvolved model. If this constructor is used then
156  // the actual model must be set using the setModel() function of the
157  // LatticeModel class.
159 
160  // Construct the ClarkCleanLatModel object and initialise the model.
162 
163  // Construct the ClarkCleanLatModel object and initialise the model ans mask
165 
166  // Construct the ClarkCleanLatModel object and initialise the model ans mask
169  // Destroy!
170  virtual ~ClarkCleanLatModel();
171 
172  virtual const casacore::Lattice<casacore::Float> & getModel() const { return *itsModelPtr; }
173  virtual void setModel(const casacore::Lattice<casacore::Float> & model);
174  virtual void setModel(casacore::Lattice<casacore::Float> & model);
175 
177  void setMask(const casacore::Lattice<casacore::Float> & mask);
178 
180  virtual const casacore::Lattice<casacore::Float> & getResidual() const { return *itsResidualPtr; }
181 
183 
185  // Using a Clark clean deconvolution proceedure solve for an improved
186  // estimate of the deconvolved object. The convolution/residual equation
187  // contains the psf and dirty image. When called with a ResidualEquation
188  // arguement a quite general interface is used that is slow. The
189  // convolution equation contains functions that speed things up. The
190  // functions return false if the deconvolution could not be done.
191  // <group>
194  // </group>
195 
196  // The user can be asked whether to stop after every minor cycle
197  // <group>
198  virtual void setChoose(const casacore::Bool askForChoice);
199  virtual casacore::Bool getChoose();
200  // </group>
201 
202  // These remaining functions set various "knobs" that the user can tweak and
203  // are specific to the Clark clean algorithm. The more generic parameters
204  // ie. clean gain, and maximum residual fluxlimit, are set using functions in
205  // the Iterate base class. The get functions return the value that was
206  // actually used after the cleaning was done.
207 
208  // set the size of the PSF used in the minor iterations. If not set it
209  // defaults to the largest useful Psf (ie. min(modelSize*2, psfSize))
210  // <group>
211  virtual void setPsfPatchSize(const casacore::IPosition & psfPatchSize);
213  // </group>
214 
215  // Set the size of the histogram used to determine how many pixels are
216  // "active" in a minor iteration. Default value of 1000 is OK for
217  // everything except very small cleans.
218  // <group>
219  virtual void setHistLength(const casacore::uInt histBins);
220  virtual casacore::uInt getHistLength();
221  // </group>
222 
223  // Set the maximum number of minor iterations to perform for each major
224  // cycle.
225  // <group>
226  virtual void setMaxNumberMinorIterations(const casacore::uInt maxNumMinorIterations);
228  // </group>
229 
230  // Set and get the initial number of iterations
231  // <group>
232  virtual void setInitialNumberIterations(const casacore::uInt initialNumberIterations);
234  // </group>
235 
236  // Set the maximum number of major cycles to perform
237  // <group>
238  virtual void setMaxNumberMajorCycles(const casacore::uInt maxNumMajorCycles);
240  // </group>
241 
242  // Set the maximum number of active pixels to use in the minor
243  // iterations. The specified number can be exceeded if the topmost bin of
244  // the histogram contains more pixels than specified here. The default is
245  // 10,000 which is suitable for images of 512by512 pixels. Reduce this for
246  // smaller images and increase it for larger ones.
247  // <group>
248  virtual void setMaxNumPix(const casacore::uInt maxNumPix );
249  virtual casacore::uInt getMaxNumPix();
250  // </group>
251 
252 
253  // Set the maximum exterior psf value. This is used to determine when to
254  // stop the minor itartions. This is normally determined from the psf and
255  // the number set here is only used if this cannot be determined. The
256  // default is zero.
257  // <group>
258  virtual void setMaxExtPsf(const casacore::Float maxExtPsf );
259  virtual casacore::Float getMaxExtPsf();
260  // </group>
261 
262  // The total flux density in the model.
264 
265  // An exponent on the F(m,n) factor (see Clark[1980]) which influences how
266  // quickly active pixels are treated as unreliable. Larger values mean
267  // more major iterations. The default is zero. I have no experience on
268  // when to use this factor.
269  // <group>
270  virtual void setSpeedup(const casacore::Float speedup);
271  virtual casacore::Float getSpeedup();
272  // </group>
273  //Set the cycle factor....the larger this is the shallower is the minor
274  //cycle
275  virtual void setCycleFactor(const casacore::Float factor);
276 
277 
278  // Set/get the progress display
279  // <group>
280  virtual void setProgress(ClarkCleanProgress& ccp) { itsProgressPtr = &ccp; }
282  // </group>
283 
284 private:
285 // Do all the minor iterations for one major cycle. Cleaning stops
286 // when the flux or iteration limit is reached.
287  void doMinorIterations(CCList & activePixels,
289  casacore::Float fluxLimit,
291  casacore::Float Fmn,
292  const casacore::uInt totalIterations,
293  casacore::Float& totalFlux);
294 
295  void cacheActivePixels(CCList & activePixels,
296  const casacore::Lattice<casacore::Float> & residual, casacore::Float fluxLimit);
297 
298  // make histogram of absolute values in array
301 
302  // Determine the flux limit if we only select the maxNumPix biggest
303  // residuals. Flux limit is not exact due to quantising by the histogram
305  const casacore::Float fluxLimit,
306  const casacore::Lattice<casacore::Float> & residual);
307 
308 // Work out the size of the Psf patch to use.
310 
311 // The maximum residual is the absolute maximum.
313  void maxVect(casacore::Block<casacore::Float> & maxVal, casacore::Float & absVal, casacore::Int & offset,
314  const CCList & activePixels);
315  void subtractComponent(CCList & activePixels, const casacore::Block<casacore::Float> & maxVal,
320  casacore::Int getbig(casacore::Float const * pixValPtr, casacore::Int const * pixPosPtr, const casacore::Int nPix,
321  const casacore::Float fluxLimit,
322  const casacore::Float * const residualPtr, const casacore::Float * const maskPtr,
323  const casacore::uInt npol, const casacore::Int nx, const casacore::Int ny);
324 
325  void updateModel(CCList & cleanComponents);
326 
345 
347 
348 };
349 
350 
351 } //# NAMESPACE CASA - END
352 
353 #endif
casacore::Lattice< casacore::Float > * itsModelPtr
virtual const casacore::Lattice< casacore::Float > & getModel() const
Return the current model.
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
casacore::Int getbig(casacore::Float const *pixValPtr, casacore::Int const *pixPosPtr, const casacore::Int nPix, const casacore::Float fluxLimit, const casacore::Float *const residualPtr, const casacore::Float *const maskPtr, const casacore::uInt npol, const casacore::Int nx, const casacore::Int ny)
virtual casacore::uInt getInitialNumberIterations()
casacore::uInt itsInitialNumberIterations
int Int
Definition: aipstype.h:50
casacore::Bool stopnow()
std::vector< double > Vector
Definition: ds9context.h:24
virtual casacore::Bool getChoose()
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
virtual void setSpeedup(const casacore::Float speedup)
An exponent on the F(m,n) factor (see Clark[1980]) which influences how quickly active pixels are tre...
virtual void setMaxExtPsf(const casacore::Float maxExtPsf)
Set the maximum exterior psf value.
Implements the convolution equation.
casacore::IPosition itsPsfPatchSize
casacore::Bool singleSolve(LatConvEquation &eqn, casacore::Lattice< casacore::Float > &residual)
casacore::Lattice< casacore::Float > * itsResidualPtr
virtual void setCycleFactor(const casacore::Float factor)
Set the cycle factor....the larger this is the shallower is the minor cycle.
A Class for performing the Clark Clean Algorithm on Arrays.
void maxVect(casacore::Block< casacore::Float > &maxVal, casacore::Float &absVal, casacore::Int &offset, const CCList &activePixels)
const casacore::Lattice< casacore::Float > * itsSoftMaskPtr
virtual void setChoose(const casacore::Bool askForChoice)
The user can be asked whether to stop after every minor cycle.
ostream-like interface to creating log messages.
Definition: LogIO.h:167
virtual casacore::uInt getMaxNumberMinorIterations()
virtual casacore::IPosition getPsfPatchSize()
virtual ~ClarkCleanLatModel()
Destroy!
ClarkCleanLatModel()
The default constructor does nothing more than initialise a zero length array to hold the deconvolved...
virtual void setInitialNumberIterations(const casacore::uInt initialNumberIterations)
Set and get the initial number of iterations.
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
casacore::Float absMaxBeyondDist(const casacore::IPosition &maxDist, const casacore::IPosition &centre, const casacore::Lattice< casacore::Float > &psf)
virtual const casacore::Lattice< casacore::Float > & getResidual() const
virtual void setProgress(ClarkCleanProgress &ccp)
Set/get the progress display.
casacore::Float biggestResiduals(casacore::Float &maxRes, const casacore::uInt maxNumPix, const casacore::Float fluxLimit, const casacore::Lattice< casacore::Float > &residual)
Determine the flux limit if we only select the maxNumPix biggest residuals.
casacore::Int getNumberIterations()
virtual void setHistLength(const casacore::uInt histBins)
Set the size of the histogram used to determine how many pixels are &quot;active&quot; in a minor iteration...
virtual void setMaxNumberMajorCycles(const casacore::uInt maxNumMajorCycles)
Set the maximum number of major cycles to perform.
void cacheActivePixels(CCList &activePixels, const casacore::Lattice< casacore::Float > &residual, casacore::Float fluxLimit)
casacore::Float modelFlux()
The total flux density in the model.
Abstract base class to monitor progress in lattice operations.
casacore::Float getPsfPatch(casacore::Matrix< casacore::Float > &psfPatch, LatConvEquation &eqn)
Work out the size of the Psf patch to use.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Float maxResidual(const casacore::Lattice< casacore::Float > &residual)
The maximum residual is the absolute maximum.
void doMinorIterations(CCList &activePixels, casacore::Matrix< casacore::Float > &psfPatch, casacore::Float fluxLimit, casacore::uInt &numberIterations, casacore::Float Fmn, const casacore::uInt totalIterations, casacore::Float &totalFlux)
Do all the minor iterations for one major cycle.
void absHistogram(casacore::Vector< casacore::Int > &hist, casacore::Float &minVal, casacore::Float &maxVal, const casacore::Lattice< casacore::Float > &data)
make histogram of absolute values in array
virtual casacore::Float getSpeedup()
casacore::uInt itsMaxNumberMinorIterations
float Float
Definition: aipstype.h:54
casacore::Float getMaxResidual()
virtual casacore::uInt getHistLength()
virtual ClarkCleanProgress & getProgress()
virtual void setModel(const casacore::Lattice< casacore::Float > &model)
Set the current model.
casacore::Int numberIterations()
Definition: Iterate.h:62
void updateModel(CCList &cleanComponents)
void setResidual(casacore::Lattice< casacore::Float > &residual)
casacore::Int itsMaxNumberMajorCycles
virtual void setMaxNumberMinorIterations(const casacore::uInt maxNumMinorIterations)
Set the maximum number of minor iterations to perform for each major cycle.
virtual casacore::uInt getMaxNumberMajorCycles()
Base class for Iteration.
Definition: Iterate.h:40
virtual casacore::uInt getMaxNumPix()
virtual void setMaxNumPix(const casacore::uInt maxNumPix)
Set the maximum number of active pixels to use in the minor iterations.
virtual void setPsfPatchSize(const casacore::IPosition &psfPatchSize)
These remaining functions set various &quot;knobs&quot; that the user can tweak and are specific to the Clark c...
virtual casacore::Float getMaxExtPsf()
casacore::Bool solve(LatConvEquation &eqn)
Using a Clark clean deconvolution proceedure solve for an improved estimate of the deconvolved object...
void subtractComponent(CCList &activePixels, const casacore::Block< casacore::Float > &maxVal, const casacore::Block< casacore::Int > &maxPos, const casacore::Matrix< casacore::Float > &psf)
unsigned int uInt
Definition: aipstype.h:51
ClarkCleanProgress * itsProgressPtr
void setMask(const casacore::Lattice< casacore::Float > &mask)
const casacore::Lattice< casacore::Float > & getMask() const
Provides a model for use in model fitting applications.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42