casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Go to the documentation of this file.
1 //# Copyright (C) 1998,1999,2000,2001,2003
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This program is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU General Public License as published by the Free
6 //# Software Foundation; either version 2 of the License, or (at your option)
7 //# any later version.
8 //#
9 //# This program is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 //# more details.
13 //#
14 //# You should have received a copy of the GNU General Public License along
15 //# with this program; if not, write to the Free Software Foundation, Inc.,
16 //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email:
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
36 namespace casa {
38 template <class T> class ImageFitter : public ImageTask<T> {
39  // <summary>
40  // Top level interface to ImageAnalysis::fitsky to handle inputs, bookkeeping etc and
41  // ultimately call fitsky to do fitting
42  // </summary>
44  // <reviewed reviewer="" date="" tests="" demos="">
45  // </reviewed>
47  // <prerequisite>
48  // </prerequisite>
50  // <etymology>
51  // Fits components to sources in images (ImageSourceComponentFitter was deemed to be to long
52  // of a name)
53  // </etymology>
55  // <synopsis>
56  // ImageFitter is the top level interface for fitting image source components. It handles most
57  // of the inputs, bookkeeping etc. It can be instantiated and its one public method, fit,
58  // run from either a C++ app or python.
59  // </synopsis>
61  // <example>
62  // <srcblock>
63  // ImageFitter fitter(...)
64  //
65  // </srcblock>
66  // </example>
68 public:
70  ImageFitter() = delete;
72  // constructor appropriate for API calls.
73  // Parameters:
74  // <ul>
75  // <li>imagename - the name of the input image in which to fit the models</li>
76  // <li>box - A 2-D rectangular box in which to use pixels for the fitting, eg box=100,120,200,230
77  // In cases where both box and region are specified, box, not region, is used.</li>
78  // <li>region - Named region to use for fitting</li>
79  // <li>regionPtr - A pointer to a region. Note there are unfortunately several different types of
80  // region records throughout CASA. In this case, it must be a casacore::Record produced by creating a
81  // region via a casacore::RegionManager method.
82  // <li>chanInp - Zero-based channel number on which to do the fit. Only a single channel can be
83  // specified.</li>
84  // <li>stokes - casacore::Stokes plane on which to do the fit. Only a single casacore::Stokes parameter can be
85  // specified.</li>
86  // <li> maskInp - Mask (as LEL) to use as a way to specify which pixels to use </li>
87  // <li> includepix - Pixel value range to include in the fit. includepix and excludepix
88  // cannot be specified simultaneously. </li>
89  // <li> excludepix - Pixel value range to exclude from fit</li>
90  // <li> residualInp - Name of residual image to save. Blank means do not save residual image</li>
91  // <li> modelInp - Name of the model image to save. Blank means do not save model image</li>
93  // use these constructors when you already have a pointer to a valid casacore::ImageInterface object
97  const SPCIIT image, const casacore::String& region,
98  const casacore::Record *const &regionRec,
99  const casacore::String& box="", const casacore::String& chanInp="",
100  const casacore::String& stokes="", const casacore::String& maskInp="",
101  const casacore::String& estiamtesFilename="",
102  const casacore::String& newEstimatesInp="",
103  const casacore::String& compListName=""
104  );
106  ImageFitter(const ImageFitter& other) = delete;
108  // destructor
109  virtual ~ImageFitter();
111  // Do the fit. If componentList is specified, store the fitted components in
112  // that object. The first list in the returned pair represents the convolved components.
113  // The second list represents the deconvolved components. If the image has no beam,
114  // the two lists will be the same.
115  std::pair<ComponentList, ComponentList> fit();
118  _writeControl = x;
119  }
121  inline casacore::String getClass() const {return _class;}
123  // Did the fit converge for the specified channel?
124  // Throw casacore::AipsError if the fit has not yet been done.
125  // <src>plane</src> is relative to the first plane in the image chosen to be fit.
128  // Did the fit converge?
129  // Throw casacore::AipsError if the fit has not yet been done.
130  // <src>plane</src> is relative to the first plane in the image chosen to be fit.
133  // set the zero level estimate. Implies fitting of zero level should be done. Must be
134  // called before fit() to have an effect.
136  casacore::Double estimate, casacore::Bool isFixed
137  );
139  // Unset zero level (resets to zero). Implies fitting of zero level should not be done.
140  // Call prior to fit().
141  void unsetZeroLevelEstimate();
143  // get the fitted result and error. Throws
144  // an exception if the zero level was not fit for.
146  std::vector<casacore::Double>& solution, std::vector<casacore::Double>& error
147  );
149  // set rms level for calculating uncertainties. If not positive, an exception is thrown.
150  void setRMS(const casacore::Quantity& rms);
152  void setIncludePixelRange(const std::pair<T, T>& r) {
153  _includePixelRange.reset(new std::pair<T, T>(r));
154  }
156  void setExcludePixelRange(const std::pair<T, T>& r) {
157  _excludePixelRange.reset(new std::pair<T, T>(r));
158  }
160  // set the output model image name
161  void setModel(const casacore::String& m) { _model = m; }
163  // set the output residual image name
164  void setResidual(const casacore::String& r) { _residual = r; }
166  // set noise correlation beam FWHM
167  void setNoiseFWHM(const casacore::Quantity& q);
169  // in pixel widths
172  // clear noise FWHM, if the image has no beam, use the uncorrelated noise equations.
173  // If the image has a beam(s) use the correlated noise equations with theta_N =
174  // the geometric mean of the beam major and minor axes.
175  void clearNoiseFWHM();
177  // The casacore::Record holding all the output info
180  // Set The summary text file name.
181  void setSummaryFile(const casacore::String& f) { _summary = f; }
183 protected:
185  virtual casacore::Bool _hasLogfileSupport() const { return true; }
187  virtual inline casacore::Bool _supportsMultipleRegions() const {
188  return true;
189  }
191 private:
198  std::shared_ptr<std::pair<T, T>> _includePixelRange{}, _excludePixelRange{};
201  casacore::Bool _fitDone{false}, _noBeam{false}, _doZeroLevel{false},
204  std::vector<casacore::Quantity> _peakIntensities{}, _peakIntensityErrors{},
208  std::vector<casacore::Quantity> _allConvolvedPeakIntensities{},
211  std::vector<std::shared_ptr<casacore::Vector<casacore::Double>>>
213  std::vector<casacore::GaussianBeam> _allBeams;
214  std::vector<casacore::Double> _allBeamsPix, _allBeamsSter;
215  std::vector<casacore::uInt> _allChanNums;
216  std::vector<casacore::Bool> _isPoint;
222  };
226  std::vector<casacore::Double> _zeroLevelOffsetSolution,
230  std::unique_ptr<casacore::Quantity> _noiseFWHM{};
233  const static casacore::String _class;
235  void _fitLoop(
236  casacore::Bool& anyConverged, ComponentList& convolvedList,
237  ComponentList& deconvolvedList, SPIIT templateImage,
238  SPIIT residualImage, SPIIT modelImage, casacore::String& resultsString
239  );
241  std::vector<OutputDestinationChecker::OutputStruct> _getOutputStruct();
243  std::vector<casacore::Coordinate::Type> _getNecessaryCoordinates() const;
247  void _finishConstruction(const casacore::String& estimatesFilename);
249  // summarize the results in a nicely formatted string
252  //summarize the size details in a nicely formatted string
253  casacore::String _sizeToString(const casacore::uInt compNumber) const;
257  void _setDeconvolvedSizes();
260  casacore::Double& inputStdDev, casacore::Double& residStdDev
261  ) const;
263  void _getRMSs(casacore::Double& inputRMS, casacore::Double& residRMS) const;
266  const casacore::String& type, const casacore::uInt index,
267  const casacore::Record& stats
268  ) const;
272  SPIIT _createImageTemplate() const;
274  void _writeCompList(ComponentList& list) const;
276  void _setIncludeExclude(casacore::Fit2D& fitter) const;
278  void _fitsky(
279  casacore::Fit2D& fitter, casacore::Array<T>& pixels,
281  casacore::Double& zeroLevelOffsetSolution,
282  casacore::Double& zeroLevelOffsetError,
283  std::pair<casacore::Int, casacore::Int>& pixelOffsets,
285  casacore::Bool deconvolveIt,
286  casacore::Double zeroLevelEstimate
287  );
291  const casacore::MaskedArray<T>& pixels, T minVal, T maxVal,
292  const casacore::IPosition& minPos, const casacore::IPosition& maxPos
293  ) const;
297  void _fitskyExtractBeam(
299  const casacore::ImageInfo& imageInfo, const casacore::Bool xIsLong,
300  const casacore::CoordinateSystem& cSys
301  ) const;
304  SkyComponent& sky, casacore::Double facToJy,
305  const casacore::CoordinateSystem& csys,
306  const casacore::Vector<casacore::Double>& parameters,
309  ) const;
311  void _doConverged(
312  ComponentList& convolvedList, ComponentList& deconvolvedList,
313  casacore::Double& zeroLevelOffsetEstimate,
314  std::pair<casacore::Int, casacore::Int>& pixelOffsets,
315  SPIIT& residualImage, SPIIT& modelImage,
316  std::shared_ptr<casacore::TempImage<T>>& tImage,
317  std::shared_ptr<casacore::ArrayLattice<casacore::Bool> >& initMask,
318  casacore::Double zeroLevelOffsetSolution,
319  casacore::Double zeroLevelOffsetError, casacore::Bool hasSpectralAxis,
320  casacore::Int spectralAxisNumber, casacore::Bool outputImages,
321  const casacore::IPosition& planeShape,
322  const casacore::Array<T>& pixels,
323  const casacore::Array<casacore::Bool>& pixelMask,
324  const casacore::Fit2D& fitter
325  );
329  void _calculateErrors();
331  casacore::Double _getRMS() const;
335  casacore::Double signalToNoise
336  ) const;
340  void _createOutputRecord(
341  const ComponentList& convolved, const ComponentList& decon
342  );
344  void _setSum(
345  const SkyComponent& comp, const casacore::SubImage<T>& im,
346  casacore::uInt compNum
347  );
349  void _setBeam(casacore::GaussianBeam& beam, casacore::uInt ngauss);
350 };
352 }
355 #include <imageanalysis/ImageAnalysis/ImageFitter.tcc>
356 #endif
358 #endif
casacore::String _bUnit
Definition: ImageFitter.h:197
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
casacore::String _regionString
Definition: ImageFitter.h:195
std::vector< casacore::Double > _zeroLevelOffsetSolution
Definition: ImageFitter.h:226
int Int
Definition: aipstype.h:50
std::vector< casacore::Double > _allBeamsSter
Definition: ImageFitter.h:214
casacore::Vector< casacore::Double > _singleParameterEstimate(casacore::Fit2D &fitter, casacore::Fit2D::Types model, const casacore::MaskedArray< T > &pixels, T minVal, T maxVal, const casacore::IPosition &minPos, const casacore::IPosition &maxPos) const
casacore::Double _getStatistic(const casacore::String &type, const casacore::uInt index, const casacore::Record &stats) const
std::vector< casacore::Quantity > _minorAxisErrors
Definition: ImageFitter.h:206
std::vector< casacore::Bool > _isPoint
Definition: ImageFitter.h:216
Temporary astronomical images.
ComponentList _curConvolvedList
Definition: ImageFitter.h:199
std::vector< casacore::Quantity > _allConvolvedPeakIntensities
Definition: ImageFitter.h:208
std::vector< casacore::Quantity > _fluxDensities
Definition: ImageFitter.h:205
std::vector< casacore::Quantity > _majorAxisErrors
Definition: ImageFitter.h:206
casacore::Int _chanPixNumber
Definition: ImageFitter.h:228
static const casacore::String _class
Definition: ImageFitter.h:233
Top level interface to ImageAnalysis::fitsky to handle inputs, bookkeeping etc and ultimately call fi...
void getZeroLevelSolution(std::vector< casacore::Double > &solution, std::vector< casacore::Double > &error)
get the fitted result and error.
std::vector< casacore::Quantity > _allConvolvedPeakIntensityErrors
Definition: ImageFitter.h:209
void setModel(const casacore::String &m)
set the output model image name
Definition: ImageFitter.h:161
The shapes of all the components.
casacore::Bool _fitDone
Definition: ImageFitter.h:201
casacore::String _newEstimatesFileName
Definition: ImageFitter.h:197
casacore::String _sizeToString(const casacore::uInt compNumber) const
summarize the size details in a nicely formatted string
virtual Type type()
Return the type enum.
casacore::Double _getRMS() const
std::vector< casacore::Quantity > _peakIntensityErrors
Definition: ImageFitter.h:204
void _getStandardDeviations(casacore::Double &inputStdDev, casacore::Double &residStdDev) const
casacore::Bool _zeroLevelIsFixed
Definition: ImageFitter.h:202
casacore::String _spectrumToString(casacore::uInt compNumber) const
ComponentList _curDeconvolvedList
Definition: ImageFitter.h:199
casacore::String _resultsToString(casacore::uInt nPixels)
summarize the results in a nicely formatted string
void _getRMSs(casacore::Double &inputRMS, casacore::Double &residRMS) const
void _fitsky(casacore::Fit2D &fitter, casacore::Array< T > &pixels, casacore::Array< casacore::Bool > &pixelMask, casacore::Bool &converged, casacore::Double &zeroLevelOffsetSolution, casacore::Double &zeroLevelOffsetError, std::pair< casacore::Int, casacore::Int > &pixelOffsets, const casacore::Vector< casacore::String > &models, casacore::Bool fitIt, casacore::Bool deconvolveIt, casacore::Double zeroLevelEstimate)
casacore::Bool _doZeroLevel
Definition: ImageFitter.h:201
void setSummaryFile(const casacore::String &f)
Set The summary text file name.
Definition: ImageFitter.h:181
std::shared_ptr< std::pair< T, T > > _excludePixelRange
Definition: ImageFitter.h:198
casacore::String _kludgedStokes
Definition: ImageFitter.h:219
casacore::Vector< casacore::String > _deconvolvedMessages
Definition: ImageFitter.h:200
virtual casacore::Bool _supportsMultipleRegions() const
Definition: ImageFitter.h:187
casacore::Vector< casacore::String > _fixed
Definition: ImageFitter.h:200
ComponentType::Shape _convertModelType(casacore::Fit2D::Types typeIn) const
std::vector< casacore::Quantity > _fluxDensityErrors
Definition: ImageFitter.h:205
std::vector< casacore::Quantity > _minorAxes
Definition: ImageFitter.h:206
Represents a Gaussian restoring beam associated with an image.
Definition: GaussianBeam.h:68
casacore::Vector< casacore::Bool > _fitConverged
Definition: ImageFitter.h:203
The Stokes types are defined by this enum.
Definition: Stokes.h:66
std::vector< casacore::Quantity > _allSums
Definition: ImageFitter.h:209
virtual ~ImageFitter()
casacore::Vector< casacore::uInt > _chanVec
Definition: ImageFitter.h:223
Class for masking an Array for operations on that Array.
void _setSum(const SkyComponent &comp, const casacore::SubImage< T > &im, casacore::uInt compNum)
casacore::GaussianBeam _getCurrentBeam() const
std::vector< casacore::Coordinate::Type > _getNecessaryCoordinates() const
Represents the minimum set of coordinates necessary for the task to function.
void setExcludePixelRange(const std::pair< T, T > &r)
Definition: ImageFitter.h:156
casacore::String _model
Definition: ImageFitter.h:196
void _fitLoop(casacore::Bool &anyConverged, ComponentList &convolvedList, ComponentList &deconvolvedList, SPIIT templateImage, SPIIT residualImage, SPIIT modelImage, casacore::String &resultsString)
#define SPIIT
Definition: ImageTypedefs.h:34
casacore::String _statisticsToString() const
void _finishConstruction(const casacore::String &estimatesFilename)
double Double
Definition: aipstype.h:55
std::vector< casacore::Double > _zeroLevelOffsetError
Definition: ImageFitter.h:226
std::vector< std::shared_ptr< casacore::Vector< casacore::Double > > > _pixelCoords
Definition: ImageFitter.h:212
void setRMS(const casacore::Quantity &rms)
set rms level for calculating uncertainties.
void _setBeam(casacore::GaussianBeam &beam, casacore::uInt ngauss)
std::vector< casacore::Quantity > _peakIntensities
Definition: ImageFitter.h:204
casacore::Record getOutputRecord() const
The casacore::Record holding all the output info.
Definition: ImageFitter.h:178
Enum describing the different models you can fit.
Definition: Fit2D.h:106
std::vector< casacore::Quantity > _allFluxDensityErrors
Definition: ImageFitter.h:210
casacore::String _summary
Definition: ImageFitter.h:196
void setIncludePixelRange(const std::pair< T, T > &r)
Definition: ImageFitter.h:152
casacore::Record _residStats
Definition: ImageFitter.h:217
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Quantity _pixelWidth()
std::vector< casacore::Quantity > _allFluxDensities
Definition: ImageFitter.h:209
void _encodeSkyComponentError(SkyComponent &sky, casacore::Double facToJy, const casacore::CoordinateSystem &csys, const casacore::Vector< casacore::Double > &parameters, const casacore::Vector< casacore::Double > &errors, casacore::Stokes::StokesTypes stokes, casacore::Bool xIsLong) const
void setZeroLevelEstimate(casacore::Double estimate, casacore::Bool isFixed)
set the zero level estimate.
void _doConverged(ComponentList &convolvedList, ComponentList &deconvolvedList, casacore::Double &zeroLevelOffsetEstimate, std::pair< casacore::Int, casacore::Int > &pixelOffsets, SPIIT &residualImage, SPIIT &modelImage, std::shared_ptr< casacore::TempImage< T >> &tImage, std::shared_ptr< casacore::ArrayLattice< casacore::Bool > > &initMask, casacore::Double zeroLevelOffsetSolution, casacore::Double zeroLevelOffsetError, casacore::Bool hasSpectralAxis, casacore::Int spectralAxisNumber, casacore::Bool outputImages, const casacore::IPosition &planeShape, const casacore::Array< T > &pixels, const casacore::Array< casacore::Bool > &pixelMask, const casacore::Fit2D &fitter)
std::shared_ptr< std::pair< T, T > > _includePixelRange
Definition: ImageFitter.h:198
std::pair< ComponentList, ComponentList > fit()
Do the fit.
void setResidual(const casacore::String &r)
set the output residual image name
Definition: ImageFitter.h:164
casacore::Record inputStats
Definition: ImageFitter.h:217
void _fitskyExtractBeam(casacore::Vector< casacore::Double > &parameters, const casacore::ImageInfo &imageInfo, const casacore::Bool xIsLong, const casacore::CoordinateSystem &cSys) const
casacore::Vector< casacore::Bool > converged() const
Did the fit converge? Throw casacore::AipsError if the fit has not yet been done. ...
std::vector< casacore::uInt > _allChanNums
Definition: ImageFitter.h:215
A (masked) subset of an ImageInterface object.
#define SPCIIT
Definition: ImageTypedefs.h:35
ImageFitterResults< T > _results
Definition: ImageFitter.h:229
virtual casacore::Bool _hasLogfileSupport() const
by default, derived classes are configured to have no log file support.
Definition: ImageFitter.h:185
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
casacore::String _estimatesString
Definition: ImageFitter.h:196
casacore::Record _output
Definition: ImageFitter.h:217
Fit 2-D objects to 2-D Lattices or Arrays.
Definition: Fit2D.h:101
casacore::Double _correlatedOverallSNR(casacore::uInt comp, casacore::Double a, casacore::Double b, casacore::Double signalToNoise) const
std::unique_ptr< casacore::Quantity > _noiseFWHM
Definition: ImageFitter.h:230
casacore::String getClass() const
Definition: ImageFitter.h:121
std::vector< OutputDestinationChecker::OutputStruct > _getOutputStruct()
void setWriteControl(typename ImageFitterResults< T >::CompListWriteControl x)
Definition: ImageFitter.h:117
void _writeCompList(ComponentList &list) const
A class for manipulating groups of components.
std::vector< casacore::Quantity > _majorAxes
Definition: ImageFitter.h:205
TableExprNode rms(const TableExprNode &array)
Definition: ExprNode.h:1637
casacore::Bool _useBeamForNoise
Definition: ImageFitter.h:202
void setNoiseFWHM(const casacore::Quantity &q)
set noise correlation beam FWHM
A component of a model of the sky.
Definition: SkyComponent.h:130
ComponentList _estimates
Definition: ImageFitter.h:199
void unsetZeroLevelEstimate()
Unset zero level (resets to zero).
casacore::String _compListName
Definition: ImageFitter.h:197
casacore::Bool _correlatedNoise
Definition: ImageFitter.h:202
ImageFitterResults< T >::CompListWriteControl _writeControl
Definition: ImageFitter.h:220
void _setDeconvolvedSizes()
String: the storage and methods of handling collections of characters.
Definition: String.h:223
std::vector< casacore::GaussianBeam > _allBeams
Definition: ImageFitter.h:213
casacore::Quantity _pixWidth
Definition: ImageFitter.h:231
casacore::Double _rms
Definition: ImageFitter.h:218
casacore::String _residual
Definition: ImageFitter.h:196
std::vector< casacore::Double > _allBeamsPix
Definition: ImageFitter.h:214
casacore::Int _stokesPixNumber
Definition: ImageFitter.h:228
casacore::uInt _curChan
Definition: ImageFitter.h:224
A memory resident Lattice.
Definition: ImageTask.h:16
std::vector< casacore::Quantity > _positionAngles
Definition: ImageFitter.h:206
Miscellaneous information related to an image.
Definition: ImageInfo.h:92
casacore::Double _zeroLevelOffsetEstimate
Definition: ImageFitter.h:225
std::vector< casacore::Quantity > _positionAngleErrors
Definition: ImageFitter.h:207
void clearNoiseFWHM()
clear noise FWHM, if the image has no beam, use the uncorrelated noise equations. ...
void _setIncludeExclude(casacore::Fit2D &fitter) const
SPIIT _createImageTemplate() const
Interconvert pixel and world coordinates.
unsigned int uInt
Definition: aipstype.h:51
CasacRegionManager::StokesControl _getStokesControl() const
void _createOutputRecord(const ComponentList &convolved, const ComponentList &decon)
Used exclusively by ImageFitter. Unless you are modifying that class, you should have no reason to us...
casacore::Bool _noBeam
Definition: ImageFitter.h:201