ImageProfileFitterResults.h

Go to the documentation of this file.
00001 //# tSubImage.cc: Test program for class SubImage
00002 //# Copyright (C) 1998,1999,2000,2001,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This program is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU General Public License as published by the Free
00007 //# Software Foundation; either version 2 of the License, or (at your option)
00008 //# any later version.
00009 //#
00010 //# This program 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 General Public License for
00013 //# more details.
00014 //#
00015 //# You should have received a copy of the GNU General Public License along
00016 //# with this program; if not, write to the Free Software Foundation, Inc.,
00017 //# 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 
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         // <summary>
00044         // </summary>
00045 
00046         // <reviewed reviewer="" date="" tests="" demos="">
00047         // </reviewed>
00048 
00049         // <prerequisite>
00050         // </prerequisite>
00051 
00052         // <etymology>
00053         // </etymology>
00054 
00055         // <synopsis>
00056         // This class is the encapsulated IO portion of ImageProfileFitter. It is meant to be
00057         // used only by that class. It is seperate from ImageProfileFitter for maintenence
00058         // and compile convenience.
00059         // </synopsis>
00060 
00061         // <example>
00062         // <srcblock>
00063         // </srcblock>
00064         // </example>
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         // create all the products. Should be run after the object has been entirely configured
00081         void createResults();
00082 
00083     // get the result Record
00084         Record getResults() const;
00085 
00086     inline String getClass() const { return _class; };
00087 
00088     // stream results to logger? This can be a lot of output.
00089     inline void setLogResults(const Bool logResults) { _logResults = logResults; }
00090 
00091     // <group>
00092     // gaussian amplitude image name
00093     inline void setAmpName(const String& s) { _ampName = s; }
00094     // gaussian amplitude error image name
00095     inline void setAmpErrName(const String& s) { _ampErrName = s; }
00096     // gaussian center image name
00097     inline void setCenterName(const String& s) { _centerName = s; }
00098     // gaussian center error image name
00099     inline void setCenterErrName(const String& s) { _centerErrName = s; }
00100     // gaussian fwhm image name
00101     inline void setFWHMName(const String& s) { _fwhmName = s; }
00102     // gaussian fwhm error image name
00103     inline void setFWHMErrName(const String& s) { _fwhmErrName = s; }
00104     // gaussian integral image name
00105     inline void setIntegralName(const String& s) { _integralName = s; }
00106     // gaussian integral error image name
00107     inline void setIntegralErrName(const String& s) { _integralErrName = s; }
00108     // </group>
00109 
00110     // set the name of the power logarithmic polynomial image.
00111     inline void setPLPName(const String& s) { _plpName = s; }
00112 
00113     // set the name of the power logarithmic polynomial image.
00114     inline void setPLPErrName(const String& s) { _plpErrName = s; }
00115 
00116     // set the name of the power logarithmic polynomial image.
00117     inline void setLTPName(const String& s) { _ltpName = s; }
00118 
00119     // set the name of the power logarithmic polynomial image.
00120     inline void setLTPErrName(const String& s) { _ltpErrName = s; }
00121 
00122 
00123     //inline void setOutputSigmaImage(const String& s) { _sigmaName = s; }
00124     // </group>
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     // Returns the center, in pixels of the indexth fit.
00133     const Vector<Double> getPixelCenter( uint index ) const;
00134     //Converts a pixel value into a world value either in velocity, wavelength, or
00135     //frequency units.
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, /*_sigmaName, */ _summaryHeader;
00170     uInt _nGaussSinglets, _nGaussMultiplets, _nLorentzSinglets,
00171                 _nPLPCoeffs, _nLTPCoeffs;
00172     const Array<SHARED_PTR<ProfileFitResults> >* const  _fitters;
00173         SpectralList _nonPolyEstimates;
00174         // subimage contains the region of the original image
00175         // on which the fit is performed.
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 /*, Array<Bool>& mask */
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, /*Bool& isSolutionSane,*/
00245         const IPosition& pixel, const PCFSpectralElement& pcf, 
00246         const uInt row, const uInt col, 
00247         const Double increment/*, const uInt npix*/
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     //Bool _inVelocitySpace() const;
00262 
00263     Vector< Vector<Double> > _pixelPositions;
00264 
00265     void _writeLogfile(const String& str, Bool open, Bool close);
00266 
00267     // the input array must have a degenerate last axis. It will be replicated
00268     // along this axis n times to form an array with a last axis laength of n.
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<Bool>& mask, */ Array<String>& typeMat, Array<Int>& niterArr,
00280         Array<Int>& nCompArr, const IPosition& pixel,
00281         SHARED_PTR<const ProfileFitResults> fitter,
00282         /* const RO_MaskedLatticeIterator<Float>& inIter, */
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1