casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LatConvEquation.h
Go to the documentation of this file.
00001 //# LatConvEquation.h: this defines LatConvEquation
00002 //# Copyright (C) 1996,1997,1998,1999,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id$
00028 
00029 #ifndef SYNTHESIS_LATCONVEQUATION_H
00030 #define SYNTHESIS_LATCONVEQUATION_H
00031 
00032 
00033 #include <casa/aips.h>
00034 #include <synthesis/MeasurementEquations/LinearEquation.h>
00035 #include <lattices/Lattices/LatticeConvolver.h>
00036 #include <lattices/Lattices/Lattice.h>
00037 #include <casa/Arrays/IPosition.h>
00038 #include <casa/Arrays/Array.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 template <class Domain> class LinearModel;
00043 
00044 
00045 // <summary> Implements the convolution equation </summary>
00046 
00047 // <use visibility=local>
00048 
00049 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00050 // </reviewed>
00051 
00052 // <prerequisite> 
00053 // <li> <linkto class="HogbomCleanModel">HogbomCleanModel</linkto> 
00054 //       (or similar classes) 
00055 // <li> LinearModel/LinearEquation Paradigm 
00056 // </prerequisite>
00057 //
00058 // <etymology>
00059 // This class implements convolution within the LinearEquation framework.
00060 // </etymology>
00061 //
00062 // <synopsis>
00063 // This class is used in conjunction with classes like HogbomCleanModel to
00064 // implement deconvolution algorithms. This class contains the point spread
00065 // function (psf) and the convolved data (dirty image), and is able to
00066 // convolve a supplied model with the psf to produce a predicted output
00067 // (using the evaluate() function), or to subtract the convolved data and
00068 // produce a residual (using the residual() function).
00069 //
00070 // See the documentation for 
00071 // <linkto class=HogbomCleanModel>HogbomCleanModel</linkto> 
00072 // for an example of how this class can be used to perform deconvolution.
00073 //
00074 // This class also contains specialised functions (like the version of
00075 // evaluate() for a point source model) that speed up the calculation of the
00076 // convolution. This specialised version of evaluate() does not need to
00077 // actually perform the convolution and instead returns a suitable part of
00078 // the psf (zero padded if necessary). When this function is called this
00079 // class will get the psf from the convolver and cache it, on the assumption
00080 // that many evaluations of this function will be requested (as occurs in
00081 // Clean algorithms). 
00082 // 
00083 // The size and shape of the psf and the supplied model may be different. The
00084 // only restriction is that the dimension of the psf must be less than or
00085 // equal to the dimension of the model. If the dimension of the
00086 // model is larger than the dimension of the psf then the convolution
00087 // will be repeated along the slowest moving (last) axis. The dirty image
00088 // and the supplied model must be the same size and shape. 
00089 //
00090 //
00091 // </synopsis>
00092 //
00093 // <example>
00094 // <srcblock>
00095 // PagedArray<Float> psf(2,4,4), dirty(2,20,20), model(2,20,20);
00096 // .... put some meaningful values into these Lattices....
00097 // // create a convolution equation, and a PagedArray model
00098 // LatConvEquation convEqn(psf, dirty);
00099 // LinearModel< Lattice<Float> > myModel(model);
00100 // // now calculate the convolution of the model and the psf
00101 // PagedArray<Float> prediction;
00102 // convEqn.evaluate(myModel, prediction);
00103 // // and calculate the difference between the predicted and actual convolution
00104 // PagedArray<Float> residual;
00105 // convEqn.residual(mymodel, residual)
00106 // </srcblock>
00107 // </example>
00108 //
00109 // <motivation>
00110 // This class was designed with deconvolution in mind. 
00111 // </motivation>
00112 //
00113 // <todo asof="1990/05/03">
00114 //   <li> Reinstate the  evaluate() method with position argument.
00115 //   <li> Fix up copies and references with Ralph Marson's help
00116 //   <li> This class is not templated. If necessary I would use templating
00117 //        to produce a Double Precision Version.
00118 // </todo>
00119 
00120 class LatConvEquation: 
00121   public LinearEquation< Lattice<Float>, Lattice<Float> >
00122 {
00123 public:
00124 
00125   // Construct the LatConvEquation setting the psf and measured data
00126   LatConvEquation(Lattice<Float> & psf, 
00127                   Lattice<Float> & dirtyImage);
00128 
00129   // destroy
00130   virtual ~LatConvEquation();
00131   
00132   // Do the convolution of the model supplied by the LinearModel class with
00133   // the internal psf. Return the answer in result .
00134   virtual Bool evaluate(Lattice<Float> & result, 
00135                         const LinearModel< Lattice<Float> > & model);
00136 
00137   // Do the convolution of the a point source model at position 'position'
00138   // with amplitude 'amplitude' and the internal psf. Return the answer in
00139   // result. 
00140   Lattice<Float> * evaluate(const IPosition & position, 
00141                             const Float amplitude, 
00142                             const IPosition & modelShape);
00143 
00144   // Do the convolution of the a point source model at position 'position'
00145   // with amplitude 'amplitude' and the internal psf. Return the answer in
00146   // result, which is an array
00147   // Calling this will result in throwing away creating a new PSF owned by
00148   // this object;
00149   Bool evaluate(Array<Float> & result, const IPosition & position, 
00150                 const Float amplitude, 
00151                 const IPosition & modelShape);
00152 
00153   // Calculate the convolution of the model (supplied by the LinearModel
00154   // class) and the psf and the difference between this and the supplied
00155   // (presumably measured) convolution.  
00156   virtual Bool residual(Lattice<Float> & result, 
00157                         const LinearModel< Lattice<Float> > & model);
00158 
00159   // Calculate the convolution of the model (supplied by the LinearModel
00160   // class) and the psf and the difference between this and the supplied
00161   // (presumably measured) convolution.   Also return chisq.
00162   virtual Bool residual(Lattice<Float> & result, Float & chisq, 
00163                         const LinearModel< Lattice<Float> > & model);
00164 
00165   // Calculate the convolution of the model (supplied by the LinearModel
00166   // class) and the psf and the difference between this and the supplied
00167   // (presumably measured) convolution.   Also return chisq, considering mask
00168   virtual Bool residual(Lattice<Float> & result, Float & chisq, 
00169                         Lattice<Float> & mask,
00170                         const LinearModel< Lattice<Float> > & model);
00171 
00172   // return the psf size used in the convolution. The returned size does not
00173   // include any zero padding  
00174   IPosition psfSize();
00175 
00176 protected:
00177 
00178   // Don't use this one, due to the Lattice<Float> &
00179   LatConvEquation();
00180   Lattice<Float> * itsMeas;
00181   Lattice<Float> * itsPsf;
00182   LatticeConvolver<Float> itsConv;
00183   IPosition itsPsfOrigin;
00184   IPosition itsRealPsfSize;
00185   Bool itsVirgin;
00186 };
00187 
00188 
00189 } //# NAMESPACE CASA - END
00190 
00191 #endif