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 IMAGEANALYSIS_IMAGEPROFILEFITTERRESULTS_H
00029 #define IMAGEANALYSIS_IMAGEPROFILEFITTERRESULTS_H
00030
00031 #include <components/SpectralComponents/GaussianMultipletSpectralElement.h>
00032 #include <imageanalysis/ImageAnalysis/ImageFit1D.h>
00033 #include <images/Images/TempImage.h>
00034
00035 #include <casa/namespace.h>
00036
00037 namespace casa {
00038
00039 class LogFile;
00040 class ProfileFitResults;
00041
00042 class ImageProfileFitterResults {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 public:
00067 ImageProfileFitterResults(
00068 const SHARED_PTR<LogIO> log, const CoordinateSystem& csysIm,
00069 const Array<SHARED_PTR<ProfileFitResults> >* const &fitters,
00070 const SpectralList& nonPolyEstimates,
00071 const SHARED_PTR<const SubImage<Float> > subImage, Int fitAxis, Int polyOrder,
00072 uInt nGaussSinglets, uInt nGaussMultiplets, uInt nLorentzSinglets,
00073 uInt nPLPCoeffs, uInt nLTPCoeffs, Bool logResults, Bool multiFit,
00074 const SHARED_PTR<LogFile> logfile, const String& xUnit,
00075 const String& summaryHeader
00076 );
00077
00078 ~ImageProfileFitterResults();
00079
00080
00081 void createResults();
00082
00083
00084 Record getResults() const;
00085
00086 inline String getClass() const { return _class; };
00087
00088
00089 inline void setLogResults(const Bool logResults) { _logResults = logResults; }
00090
00091
00092
00093 inline void setAmpName(const String& s) { _ampName = s; }
00094
00095 inline void setAmpErrName(const String& s) { _ampErrName = s; }
00096
00097 inline void setCenterName(const String& s) { _centerName = s; }
00098
00099 inline void setCenterErrName(const String& s) { _centerErrName = s; }
00100
00101 inline void setFWHMName(const String& s) { _fwhmName = s; }
00102
00103 inline void setFWHMErrName(const String& s) { _fwhmErrName = s; }
00104
00105 inline void setIntegralName(const String& s) { _integralName = s; }
00106
00107 inline void setIntegralErrName(const String& s) { _integralErrName = s; }
00108
00109
00110
00111 inline void setPLPName(const String& s) { _plpName = s; }
00112
00113
00114 inline void setPLPErrName(const String& s) { _plpErrName = s; }
00115
00116
00117 inline void setLTPName(const String& s) { _ltpName = s; }
00118
00119
00120 inline void setLTPErrName(const String& s) { _ltpErrName = s; }
00121
00122
00123
00124
00125
00126
00127 const static String _CONVERGED;
00128 const static String _SUCCEEDED;
00129 const static String _VALID;
00130
00131 const Array<ImageFit1D<Float> >& getFitters() const;
00132
00133 const Vector<Double> getPixelCenter( uint index ) const;
00134
00135
00136 Double getWorldValue(
00137 double pixelVal, const IPosition& imPos, const String& units,
00138 bool velocity, bool wavelength
00139 ) const;
00140
00141 void setPLPDivisor(const String& x) { _plpDivisor = x; }
00142
00143 void logSummary(
00144 uInt nProfiles, uInt nAttempted, uInt nSucceeded,
00145 uInt nConverged, uInt nValid
00146 );
00147
00148 void writeImages(Bool someConverged) const;
00149
00150 private:
00151 enum gaussSols {
00152 AMP, CENTER, FWHM, INTEGRAL, AMPERR, CENTERERR,
00153 FWHMERR, INTEGRALERR, NGSOLMATRICES
00154 };
00155
00156 enum spxSols {
00157 SPXSOL, SPXERR, NSPXSOLMATRICES
00158 };
00159
00160 enum axisType {
00161 LONGITUDE, LATITUDE, FREQUENCY, POLARIZATION, NAXISTYPES
00162 };
00163
00164 const static String _class;
00165 Bool _logResults, _multiFit, _doVelocity;
00166 String _xUnit, _centerName, _centerErrName, _fwhmName,
00167 _fwhmErrName, _ampName, _ampErrName,
00168 _integralName, _integralErrName, _plpName, _plpErrName,
00169 _ltpName, _ltpErrName, _summaryHeader;
00170 uInt _nGaussSinglets, _nGaussMultiplets, _nLorentzSinglets,
00171 _nPLPCoeffs, _nLTPCoeffs;
00172 const Array<SHARED_PTR<ProfileFitResults> >* const _fitters;
00173 SpectralList _nonPolyEstimates;
00174
00175
00176 const SHARED_PTR<const SubImage<Float> > _subImage;
00177 Int _polyOrder, _fitAxis;
00178 vector<axisType> _axisTypes;
00179 Array<String> _worldCoords;
00180 Record _results;
00181 const static uInt _nOthers, _gsPlane, _lsPlane;
00182 SHARED_PTR<LogFile> _logfile;
00183 SHARED_PTR<LogIO> _log;
00184 Vector<Double> _goodAmpRange, _goodCenterRange, _goodFWHMRange;
00185 const CoordinateSystem _csysIm;
00186 String _plpDivisor;
00187
00188 void _setResults();
00189
00190 void _resultsToLog();
00191
00192 String _getTag(const uInt i) const;
00193
00194 std::unique_ptr<vector<vector<Array<Double> > > > _createPCFArrays() const;
00195
00196 String _elementToString(
00197 const Double value, const Double error,
00198 const String& unit, Bool isFixed
00199 ) const;
00200
00201 String _pcfToString(
00202 const PCFSpectralElement *const &pcf, const CoordinateSystem& csys,
00203 const Vector<Double>& world, const IPosition& imPos, Bool showTypeString=True,
00204 const String& indent=""
00205 ) const;
00206
00207 String _gaussianMultipletToString(
00208 const GaussianMultipletSpectralElement& gm,
00209 const CoordinateSystem& csys, const Vector<Double>& world,
00210 const IPosition& imPos
00211 ) const;
00212
00213 Bool _setAxisTypes();
00214
00215 String _polynomialToString(
00216 const PolynomialSpectralElement& poly, const CoordinateSystem& csys,
00217 const Vector<Double>& imPix, const Vector<Double>& world
00218 ) const;
00219
00220 String _powerLogPolyToString(
00221 const PowerLogPolynomialSpectralElement& plp
00222 ) const;
00223
00224 String _logTransPolyToString(
00225 const LogTransformedPolynomialSpectralElement& ltp
00226 ) const;
00227
00228 void _marshalFitResults(
00229 Array<Bool>& attemptedArr, Array<Bool>& successArr,
00230 Array<Bool>& convergedArr, Array<Bool>& validArr,
00231 Array<String>& typeMat, Array<Int>& niterArr,
00232 Array<Int>& nCompArr, std::unique_ptr<vector<vector<Array<Double> > > >& pcfArrays,
00233 vector<Array<Double> >& plpArrayss, vector<Array<Double> >& ltpArrays, Bool returnDirection,
00234 Array<String>& directionInfo
00235 );
00236
00237 static void _makeSolutionImages(
00238 const String& name, const CoordinateSystem& csys,
00239 const Array<Double>& values, const String& unit,
00240 const Array<Bool>& mask
00241 );
00242
00243 void _insertPCF(
00244 vector<vector<Array<Double> > >& pcfArrays,
00245 const IPosition& pixel, const PCFSpectralElement& pcf,
00246 const uInt row, const uInt col,
00247 const Double increment
00248 ) const;
00249
00250 void _writeImages(
00251 const CoordinateSystem& csys,
00252 const Array<Bool>& mask, const String& yUnit
00253 ) const;
00254
00255 Double _fitAxisIncrement() const;
00256
00257 Double _centerWorld(
00258 const PCFSpectralElement& solution, const IPosition& imPos
00259 ) const;
00260
00261
00262
00263 Vector< Vector<Double> > _pixelPositions;
00264
00265 void _writeLogfile(const String& str, Bool open, Bool close);
00266
00267
00268
00269 static Array<Bool> _replicateMask(const Array<Bool>& array, Int n);
00270
00271 void _doWorldCoords(
00272 Array<String>& directionInfo, const CoordinateSystem& csysSub,
00273 const IPosition& pixel, const DirectionCoordinate* const &dcoord,
00274 const SpectralCoordinate* const &spcoord, const StokesCoordinate* const &polcoord,
00275 Bool returnDirection, const String& directionType
00276 );
00277
00278 void _processSolutions(
00279 Array<String>& typeMat, Array<Int>& niterArr,
00280 Array<Int>& nCompArr, const IPosition& pixel,
00281 SHARED_PTR<const ProfileFitResults> fitter,
00282
00283 std::unique_ptr<vector<vector<Array<Double> > > >& pcfArrays,
00284 vector<Array<Double> >& plpArrays, vector<Array<Double> >& ltpArrays,
00285 Double increment
00286 );
00287 };
00288 }
00289
00290 #endif