casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MatrixNACleaner.h
Go to the documentation of this file.
1 //# MatrixNACleaner.h: this defines Cleaner a class for doing deconvolution
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 General Public License as published by
7 //# the Free Software Foundation; either version 3 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 
28 
29 #ifndef SYNTHESIS_MATRIXNACLEANER_H
30 #define SYNTHESIS_MATRIXNACLEANER_H
31 
32 //# Includes
33 #include <casa/aips.h>
34 #include <casa/Quanta/Quantum.h>
35 #include <casa/Arrays/IPosition.h>
36 #include <casa/Arrays/Vector.h>
37 #include <casa/Containers/Block.h>
38 
39 namespace casacore{
40 
41 template <class T> class Matrix;
42 }
43 
44 namespace casa { //# NAMESPACE CASA - BEGIN
45 
46 //# Forward Declarations
47 
48 // <summary>A simple deconvolver that masks by memory of previous peaks</summary>
49 // <synopsis> Evolution of a simple cleaner
50 //
51 // </synopsis>
52 
53 // <summary>A class for doing multi-dimensional cleaning</summary>
54 
55 // <use visibility=export>
56 
57 // <reviewed reviewer="" date="yyyy/mm/dd" tests="Mulouktanee">
58 // </reviewed>
59 
60 // <prerequisite>
61 // <li> The mathematical concept of deconvolution
62 // </prerequisite>
63 //
64 // <etymology>
65 
66 // The MatrixNACleaner Uses the matrix class and cleaner is for deconvolver by CLEAN
67 // NA stands for Non Amnesiac...i.e remember where past peaks were to search in these region preferentially ...i.e no need to mask
68 
69 // </etymology>
70 //
71 // <synopsis>
72 // This class will perform various types of Clean deconvolution
73 // on Lattices.
74 //
75 // </synopsis>
76 //
77 // <example>
78 // <srcblock>
79 // </srcblock>
80 // </example>
81 //
82 // <motivation>
83 // </motivation>
84 //
85 // <thrown>
86 // <li> casacore::AipsError: if psf has more dimensions than the model.
87 // </thrown>
88 //
89 // <todo asof="yyyy/mm/dd">
90 // </todo>
91 
93 {
94 public:
95 
96  // Create a cleaner : default constructor
98 
99  // Create a cleaner for a specific dirty image and PSF
100  MatrixNACleaner(const casacore::Matrix<casacore::Float> & psf, const casacore::Matrix<casacore::Float> & dirty, const casacore::Int memtype=2, const casacore::Float numSigma=5.0);
101 
102  // The copy constructor uses reference semantics
103  MatrixNACleaner(const MatrixNACleaner& other);
104 
105  // The assignment operator also uses reference semantics
106  MatrixNACleaner & operator=(const MatrixNACleaner & other);
107 
108  // The destructor does nothing special.
110 
111 
112 
113  //Set the dirty image without calculating convolutions..
114  //can be done by calling makeDirtyScales or setscales if one want to redo the
115  //psfscales too.
116  void setDirty(const casacore::Matrix<casacore::Float>& dirty);
117 
118 
119 
120  //change the psf
121  //don't forget to redo the setscales or run makePsfScales,
122  //followed by makeDirtyScales
123  void setPsf(const casacore::Matrix<casacore::Float>& psf);
124 
125 
126 
127  // niter - number of iterations
128  // gain - loop gain used in cleaning (a fraction of the maximum
129  // subtracted at every iteration)
130  // aThreshold - absolute threshold to stop iterations
131 
132  void setcontrol(const casacore::Int niter,
133  const casacore::Float gain, const casacore::Quantity& aThresho, const casacore::Int masksupport=3 , const casacore::Int memType=2, const casacore::Float numsigma=5.0);
134 
135 
136 
137  // return how many iterations we did do
139 
140 
141 
142  //Total flux accumulated so far
144 
145 
146  // Clean an image.
147 
149 
150  // Set the mask
151  // mask - input mask lattice
152 
154 
155 
156  void setPixFlag(const casacore::Matrix<casacore::Bool>& bitpix);
157 
158  // remove the mask;
159  // useful when keeping object and sending a new dirty image to clean
160  // one can set another mask then
161  void unsetMask();
162 
164 
165 
166 
167  // Look at what WE think the residuals look like
169 
170  // Method to return threshold
171  casacore::Float threshold() const;
172 
173 
175  // Helper function to optimize adding
176  //static void addTo(casacore::Matrix<casacore::Float>& to, const casacore::Matrix<casacore::Float> & add);
177 
178 protected:
179  // Make sure that the peak of the Psf is within the image
181 
182 
183  // Find the Peak of the lattice, applying a mask
185  casacore::Float& maxAbs, casacore::IPosition& posMax, const casacore::Int support=5);
186 
187  // Helper function to reduce the box sizes until the have the same
188  // size keeping the centers intact
191 
192 
194  casacore::Int itsMaxNiter; // maximum possible number of iterations
196 
197 
198 private:
199 
200  //# The following functions are used in various places in the code and are
201  //# documented in the .cc file. Static functions are used when the functions
202  //# do not modify the object state. They ensure that implicit assumptions
203  //# about the current state and implicit side-effects are not possible
204  //# because all information must be supplied in the input arguments
205 
206  std::shared_ptr<casacore::Matrix<casacore::Float> > itsMask;
207  std::shared_ptr<casacore::Matrix<casacore::Float> > itsDirty;
208  std::shared_ptr<casacore::Matrix<casacore::Float> > itsPsf;
209  std::shared_ptr<casacore::Matrix<casacore::Float> >itsResidual;
210  std::shared_ptr<casacore::Matrix<casacore::Bool> > itsBitPix;
211 
216 
218  casacore::Int itsIteration; // what iteration did we get to?
219  casacore::Int itsStartingIter; // what iteration did we get to?
225  casacore::Int typeOfMemory_p; //0 nomemory, 1 weak, 2 medium, 3 strong
227  std::function<casacore::Float(const casacore::Float&)> f_p;
228 };
229 
230 } //# NAMESPACE CASA - END
231 
232 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
int Int
Definition: aipstype.h:50
static void makeBoxesSameSize(casacore::IPosition &blc1, casacore::IPosition &trc1, casacore::IPosition &blc2, casacore::IPosition &trc2)
Helper function to reduce the box sizes until the have the same size keeping the centers intact...
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
casacore::Int iteration() const
return how many iterations we did do
casacore::Float medium(const casacore::Float &v)
std::shared_ptr< casacore::Matrix< casacore::Float > > itsPsf
casacore::Float itsMaximumResidual
void setDirty(const casacore::Matrix< casacore::Float > &dirty)
Set the dirty image without calculating convolutions.
std::function< casacore::Float(const casacore::Float &)> f_p
casacore::Int itsStartingIter
casacore::Float itsGain
MatrixNACleaner()
Create a cleaner : default constructor.
casacore::Int typeOfMemory_p
casacore::Float itsRms
casacore::Quantum< casacore::Double > itsThreshold
casacore::Float weak(const casacore::Float &v)
casacore::Bool findMaxAbsMask(const casacore::Matrix< casacore::Float > &lattice, casacore::Matrix< casacore::Float > &mask, casacore::Float &maxAbs, casacore::IPosition &posMax, const casacore::Int support=5)
Find the Peak of the lattice, applying a mask.
std::shared_ptr< casacore::Matrix< casacore::Float > > itsMask
casacore::Int itsIteration
std::shared_ptr< casacore::Matrix< casacore::Float > > itsResidual
void setPsf(const casacore::Matrix< casacore::Float > &psf)
change the psf don&#39;t forget to redo the setscales or run makePsfScales, followed by makeDirtyScales ...
void setMask(casacore::Matrix< casacore::Float > &mask)
Set the mask mask - input mask lattice.
casacore::Float itsTotalFlux
casacore::Bool validatePsf(const casacore::Matrix< casacore::Float > &psf)
Helper function to optimize adding static void addTo(casacore::Matrix&lt;casacore::Float&gt;&amp; to...
~MatrixNACleaner()
The destructor does nothing special.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Float numSigma_p
std::shared_ptr< casacore::Matrix< casacore::Bool > > itsBitPix
float Float
Definition: aipstype.h:54
void unsetMask()
remove the mask; useful when keeping object and sending a new dirty image to clean one can set anothe...
casacore::IPosition itsPositionPeakPsf
A simple deconvolver that masks by memory of previous peaks.
casacore::Float threshold() const
Method to return threshold.
void getMask(casacore::Matrix< casacore::Float > &mask)
casacore::IPosition psfShape_p
void setPixFlag(const casacore::Matrix< casacore::Bool > &bitpix)
casacore::Matrix< casacore::Float > getResidual()
Look at what WE think the residuals look like.
casacore::Int itsSupport
casacore::Int itsMaxNiter
void setcontrol(const casacore::Int niter, const casacore::Float gain, const casacore::Quantity &aThresho, const casacore::Int masksupport=3, const casacore::Int memType=2, const casacore::Float numsigma=5.0)
niter - number of iterations gain - loop gain used in cleaning (a fraction of the maximum subtracted ...
casacore::Float amnesiac(const casacore::Float &val)
casacore::Float strong(const casacore::Float &v)
casacore::Float totalFlux() const
Total flux accumulated so far.
casacore::Int clean(casacore::Matrix< casacore::Float > &model)
Clean an image.
casacore::Float maxResidual()
std::shared_ptr< casacore::Matrix< casacore::Float > > itsDirty
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
MatrixNACleaner & operator=(const MatrixNACleaner &other)
The assignment operator also uses reference semantics.