00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef IMAGES_IMAGEPROFILEFITTER_H
00029 #define IMAGES_IMAGEPROFILEFITTER_H
00030
00031 #include <imageanalysis/ImageAnalysis/ImageTask.h>
00032
00033 #include <components/SpectralComponents/GaussianMultipletSpectralElement.h>
00034 #include <imageanalysis/ImageAnalysis/ImageFit1D.h>
00035 #include <images/Images/TempImage.h>
00036
00037 #include <casa/namespace.h>
00038
00039 namespace casa {
00040
00041 class ProfileFitResults;
00042
00043 class ImageProfileFitter : public ImageTask<Float> {
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 public:
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 ImageProfileFitter(
00095 const SPCIIF image, const String& region,
00096 const Record *const ®ionPtr, const String& box,
00097 const String& chans, const String& stokes, const String& mask,
00098 const Int axis, const uInt ngauss, Bool overwrite=False
00099 );
00100
00101
00102
00103 ImageProfileFitter(
00104 const SPCIIF image, const String& region,
00105 const Record *const ®ionPtr, const String& box,
00106 const String& chans, const String& stokes, const String& mask,
00107 const Int axis, const String& estimatesFilename,
00108 Bool overwrite=False
00109 );
00110
00111
00112
00113
00114 ImageProfileFitter(
00115 const SPCIIF image, const String& region,
00116 const Record *const ®ionPtr, const String& box,
00117 const String& chans, const String& stokes, const String& mask,
00118 const Int axis, const SpectralList& spectralList, Bool overwrite=False
00119 );
00120
00121
00122 ~ImageProfileFitter();
00123
00124
00125 Record fit(Bool doDetailedResults=True);
00126
00127
00128 Record getResults() const;
00129
00130 inline String getClass() const { return _class; };
00131
00132
00133 void setPolyOrder(Int p);
00134
00135
00136 inline void setDoMultiFit(const Bool m) { _multiFit = m; }
00137
00138
00139 inline void setLogResults(const Bool logResults) { _logResults = logResults; }
00140
00141
00142 inline void setMinGoodPoints(const uInt mgp) {
00143 ThrowIf(mgp == 0, "Number of good points has to be > 0");
00144 _minGoodPoints = mgp;
00145 }
00146
00147
00148
00149
00150 inline void setModel(const String& model) { _model = model; }
00151
00152 inline void setResidual(const String& residual) { _residual = residual; }
00153
00154 inline void setAmpName(const String& s) { _ampName = s; }
00155
00156 inline void setAmpErrName(const String& s) { _ampErrName = s; }
00157
00158 inline void setCenterName(const String& s) { _centerName = s; }
00159
00160 inline void setCenterErrName(const String& s) { _centerErrName = s; }
00161
00162 inline void setFWHMName(const String& s) { _fwhmName = s; }
00163
00164 inline void setFWHMErrName(const String& s) { _fwhmErrName = s; }
00165
00166 inline void setIntegralName(const String& s) { _integralName = s; }
00167
00168 inline void setIntegralErrName(const String& s) { _integralErrName = s; }
00169
00170
00171
00172 inline void setPLPName(const String& s) { _plpName = s; }
00173
00174
00175 inline void setPLPErrName(const String& s) { _plpErrName = s; }
00176
00177
00178 inline void setLTPName(const String& s) { _ltpName = s; }
00179
00180
00181 inline void setLTPErrName(const String& s) { _ltpErrName = s; }
00182
00183
00184 void setGoodAmpRange(const Double min, const Double max);
00185
00186
00187 void setGoodCenterRange(const Double min, const Double max);
00188
00189
00190 void setGoodFWHMRange(const Double min, const Double max);
00191
00192
00193
00194 void setSigma(const Array<Float>& sigma);
00195
00196 void setSigma(const ImageInterface<Float> *const &sigma);
00197
00198 inline void setOutputSigmaImage(const String& s) { _sigmaName = s; }
00199
00200
00201 const Array<SHARED_PTR<ProfileFitResults> >& getFitters() const;
00202
00203
00204
00205
00206
00207 Double getWorldValue(
00208 Double pixelVal, const IPosition& imPos, const String& units,
00209 Bool velocity, Bool wavelength, Int tabularIndex=-1,
00210 MFrequency::Types type=MFrequency::DEFAULT
00211 ) const;
00212
00213 void setAbscissaDivisor(Double d);
00214
00215 void setAbscissaDivisor(const Quantity& q);
00216
00217
00218
00219 void createResidualImage(Bool b) { _createResid = b; }
00220
00221 SPIIF getResidual() const {
00222 return _residImage;
00223 }
00224
00225
00226
00227 void setGoodPlanes(const std::set<uInt>& planes) { _goodPlanes = planes; }
00228
00229 protected:
00230
00231 inline CasacRegionManager::StokesControl _getStokesControl() const {
00232 return CasacRegionManager::USE_FIRST_STOKES;
00233 }
00234
00235 inline vector<Coordinate::Type> _getNecessaryCoordinates() const {
00236 return vector<Coordinate::Type>(0);
00237 }
00238
00239 Bool _hasLogfileSupport() const { return True; }
00240
00241 inline Bool _supportsMultipleRegions() const {return True;}
00242
00243 private:
00244 String _residual, _model, _xUnit,
00245 _centerName, _centerErrName, _fwhmName,
00246 _fwhmErrName, _ampName, _ampErrName,
00247 _integralName, _integralErrName, _plpName, _plpErrName,
00248 _ltpName, _ltpErrName, _sigmaName, _abscissaDivisorForDisplay;
00249 Bool _multiFit, _logResults, _isSpectralIndex,
00250 _createResid, _overwrite, _storeFits;
00251 Int _polyOrder, _fitAxis;
00252 uInt _nGaussSinglets, _nGaussMultiplets, _nLorentzSinglets,
00253 _nPLPCoeffs, _nLTPCoeffs, _minGoodPoints, _nProfiles, _nAttempted,
00254 _nSucceeded, _nConverged, _nValid;
00255 Array<SHARED_PTR<ProfileFitResults> > _fitters;
00256
00257
00258 SHARED_PTR<const SubImage<Float> > _subImage;
00259 Record _results;
00260 SpectralList _nonPolyEstimates;
00261 PtrHolder<std::pair<Double, Double> > _goodAmpRange, _goodCenterRange, _goodFWHMRange;
00262 Matrix<String> _worldCoords;
00263 SHARED_PTR<TempImage<Float> > _sigma;
00264 Double _abscissaDivisor;
00265 SPIIF _modelImage, _residImage;
00266
00267
00268 std::set<uInt> _goodPlanes;
00269
00270 const static String _class;
00271
00272 mutable Bool _haveWarnedAboutGuessingGaussians = False;
00273
00274 std::vector<OutputDestinationChecker::OutputStruct> _getOutputStruct();
00275
00276 void _checkNGaussAndPolyOrder() const;
00277
00278 void _finishConstruction();
00279
00280
00281 void _fitallprofiles();
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 void _fitProfiles(const Bool showProgress);
00299
00300
00301
00302 void _flagFitterIfNecessary(ImageFit1D<Float>& fitter) const;
00303
00304 Bool _isPCFSolutionOK(const PCFSpectralElement *const &pcf) const;
00305
00306 void _loopOverFits(
00307 SPCIIF fitData, Bool showProgress,
00308 SHARED_PTR<ProgressMeter> progressMeter, Bool checkMinPts,
00309 const Array<Bool>& fitMask, ImageFit1D<Float>::AbcissaType abcissaType,
00310 const IPosition& fitterShape, const IPosition& sliceShape,
00311 const std::set<uInt> goodPlanes
00312 );
00313
00314 void _setAbscissaDivisorIfNecessary(const Vector<Double>& abscissaValues);
00315
00316 Bool _setFitterElements(
00317 ImageFit1D<Float>& fitter, SpectralList& newEstimates,
00318 const PtrHolder<const PolynomialSpectralElement>& polyEl,
00319 const vector<IPosition>& goodPos,
00320 const IPosition& fitterShape, const IPosition& curPos,
00321 uInt nOrigComps
00322 ) const;
00323
00324 void _updateModelAndResidual(
00325 Bool fitOK, const ImageFit1D<Float>& fitter,
00326 const IPosition& sliceShape, const IPosition& curPos,
00327 Lattice<Bool>* const &pFitMask, Lattice<Bool>* const &pResidMask
00328 ) const;
00329
00330
00331 uInt _nUnknowns() const;
00332
00333 };
00334 }
00335
00336 #endif