casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SkyCompRep.h
Go to the documentation of this file.
00001 //# SkyCompRep.h: A model component of the sky brightness
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002
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: SkyCompRep.h 21292 2012-11-28 14:58:19Z gervandiepen $
00028 
00029 #ifndef COMPONENTS_SKYCOMPREP_H
00030 #define COMPONENTS_SKYCOMPREP_H
00031 
00032 #include <casa/aips.h>
00033 #include <components/ComponentModels/ComponentType.h>
00034 #include <components/ComponentModels/Flux.h>
00035 #include <components/ComponentModels/SkyCompBase.h>
00036 #include <casa/Utilities/CountedPtr.h>
00037 #include <casa/BasicSL/String.h>
00038 #include <measures/Measures/Stokes.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 class ComponentShape;
00043 class CoordinateSystem;
00044 class DirectionCoordinate;
00045 class LogIO;
00046 class MDirection;
00047 class MFrequency;
00048 class MVAngle;
00049 class MVDirection;
00050 class MVFrequency;
00051 class RecordInterface;
00052 class SpectralModel;
00053 class TwoSidedShape;
00054 class Unit;
00055 class GaussianBeam;
00056 template <class Ms> class MeasRef;
00057 template <class T> class Cube;
00058 template <class T> class Vector;
00059 template <class T> class Quantum;
00060 
00061 
00062 
00063 // <summary>A model component of the sky brightness</summary>
00064 
00065 // <use visibility=export>
00066 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSkyCompRep" demos="">
00067 // </reviewed>
00068 
00069 // <prerequisite> 
00070 // <li> <linkto class=Flux>Flux</linkto>
00071 // <li> <linkto class=ComponentShape>ComponentShape</linkto>
00072 // <li> <linkto class=SpectralModel>SpectralModel</linkto>
00073 // </prerequisite>
00074 //
00075 // <synopsis> 
00076 
00077 // This class is concrete implementation of a class that represents a component
00078 // of a model of the sky brightness. 
00079 
00080 // The base class (<linkto class="SkyCompBase">SkyCompBase</linkto>) contains a
00081 // description of components and all the member functions used to manipulate
00082 // them and hence will not be discussed here. But the base class does not
00083 // include any constructors or a description of the copy semantics. This will
00084 // be discussed below.
00085 
00086 // A SkyCompRep is an "envelope" class in the sense that it can contain one of
00087 // a variety of different component shapes and spectral models. It is necessary
00088 // to specify the which shape and spectral model you want at construction
00089 // time. This can be done either with enumerators or by constructing the
00090 // classes derived from ComponentShape & SpectralModel and supplying them as
00091 // construction arguments.
00092 
00093 // This class uses copy semantics for both the copy constructor and the
00094 // assignment operator. 
00095 
00096 // </synopsis>
00097 
00098 // <example>
00099 // These examples are coded in the tSkyCompRep.h file.
00100 // <h4>Example 1:</h4>
00101 // In this example a SkyCompRep object is created and used to calculate the
00102 // ...
00103 // <srcblock>
00104 // </srcblock>
00105 // </example>
00106 //
00107 // <motivation>
00108 // Model fitting is an important part of astronomical data
00109 // reduction/interpretation. This class defines a model component. Many
00110 // components can be strung together (using the ComponentList class) to
00111 // construct a model. It is expected that this class will eventually allow you
00112 // to solve for parameters of the model.
00113 // </motivation>
00114 
00115 // <thrown>
00116 // <li> AipsError - If an internal inconsistancy is detected, when compiled in 
00117 // debug mode only.
00118 // </thrown>
00119 //
00120 // <todo asof="1998/05/22">
00121 //   <li> Add time variability
00122 //   <li> Add the ability to solve for component parameters.
00123 // </todo>
00124 
00125 // <linkfrom anchor="SkyCompRep" classes="SkyComponent SkyCompBase">
00126 //  <here>SkyCompRep</here> - Models the sky brightness (copy semantics)
00127 // </linkfrom>
00128  
00129 class SkyCompRep: public SkyCompBase
00130 {
00131 public:
00132   // The default SkyCompRep is a point source with a constant spectrum. See
00133   // the default constructors in the PointShape, ConstantSpectrum and Flux
00134   // classes for the default values for the flux, shape and spectrum.
00135   SkyCompRep();
00136   
00137   // Construct a SkyCompRep of the specified shape. The resultant component
00138   // has a constant spectrum and a shape given by the default constructor of
00139   // the specified ComponentShape class.
00140   // <thrown>
00141   // <li> AipsError - if the shape is UNKNOWN_SHAPE or NUMBER_SHAPES
00142   // </thrown>
00143   SkyCompRep(const ComponentType::Shape& shape);
00144   
00145   // Construct a SkyCompRep with the user specified model for the shape and
00146   // spectrum. The resultant component has a shape given by the default
00147   // constructor of the specified ComponentShape class and a spectrum given by
00148   // the default constructor of the specified SpectralModel class
00149   // <thrown>
00150   // <li> AipsError - if the shape is UNKNOWN_SHAPE or NUMBER_SHAPES
00151   // <li> AipsError - if the spectrum is UNKNOWN_SPECTRAL_SHAPE or
00152   //                  NUMBER_SPECTRAL_SHAPES
00153   // </thrown>
00154   SkyCompRep(const ComponentType::Shape& shape,
00155              const ComponentType::SpectralShape& spectrum);
00156 
00157   // Construct a SkyCompRep with a fully specified model for the shape, 
00158   // spectrum and flux.
00159   SkyCompRep(const Flux<Double>& flux,
00160              const ComponentShape& shape, 
00161              const SpectralModel& spectrum);
00162   
00163   // The copy constructor uses copy semantics
00164   SkyCompRep(const SkyCompRep& other);
00165   
00166   // The destructor does not appear to do much
00167   virtual ~SkyCompRep();
00168 
00169   // The assignment operator uses copy semantics.
00170   SkyCompRep& operator=(const SkyCompRep& other);
00171 
00172   // See the corresponding functions in the
00173   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00174   // class for a description of these functions.
00175   // <group>
00176   virtual const Flux<Double>& flux() const;
00177   virtual Flux<Double>& flux();
00178   // </group>
00179 
00180   // See the corresponding functions in the
00181   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00182   // class for a description of these functions.
00183   // <group>
00184   virtual const ComponentShape& shape() const;
00185   virtual ComponentShape& shape();
00186   virtual void setShape(const ComponentShape& newShape);
00187   // </group>
00188   
00189   // See the corresponding functions in the
00190   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00191   // class for a description of these functions.
00192   // <group>
00193   virtual const SpectralModel& spectrum() const;
00194   virtual SpectralModel& spectrum();
00195   virtual void setSpectrum(const SpectralModel& newSpectrum);
00196   // </group>
00197   
00198   // See the corresponding functions in the
00199   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00200   // class for a description of these functions.
00201   // <group>
00202   virtual String& label();
00203   virtual const String& label() const;
00204   // </group>
00205 
00206   // See the corresponding functions in the
00207   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00208   // class for a description of these functions.
00209   // <group>
00210   virtual Vector<Double>& optionalParameters();
00211   virtual const Vector<Double>& optionalParameters() const;
00212   // </group>
00213 
00214   // See the corresponding function in the
00215   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00216   // class for a description of this function.
00217   virtual Bool isPhysical() const;
00218   
00219   // See the corresponding function in the
00220   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00221   // class for a description of this function.
00222   virtual Flux<Double> sample(const MDirection& direction, 
00223                               const MVAngle& pixelLatSize,
00224                               const MVAngle& pixelLongSize,
00225                               const MFrequency& centerFrequency) const;
00226 
00227   // See the corresponding function in the
00228   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00229   // class for a description of this function.
00230   virtual void sample(Cube<Double>& samples,
00231                       const Unit& reqUnit,
00232                       const Vector<MVDirection>& directions, 
00233                       const MeasRef<MDirection>& dirRef, 
00234                       const MVAngle& pixelLatSize, 
00235                       const MVAngle& pixelLongSize, 
00236                       const Vector<MVFrequency>& frequencies,
00237                       const MeasRef<MFrequency>& freqRef) const;
00238 
00239   // See the corresponding function in the
00240   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00241   // class for a description of this function.
00242   virtual Flux<Double> visibility(const Vector<Double>& uvw,
00243                                   const Double& frequency) const;
00244 
00245   // See the corresponding function in the
00246   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00247   // class for a description of this function.
00248   virtual void visibility(Cube<DComplex>& visibilities,
00249                           const Matrix<Double>& uvws,
00250                           const Vector<Double>& frequencies) const;
00251 
00252   // See the corresponding functions in the
00253   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00254   // class for a description of these functions.
00255   // <group>
00256   virtual Bool fromRecord(String& errorMessage, 
00257                           const RecordInterface& record);
00258   virtual Bool toRecord(String& errorMessage, 
00259                         RecordInterface& record) const;
00260   // </group>
00261 
00262   // Convert the SkyComponent to a vector of Doubles 
00263   // for the specified Stokes type (others are lost).
00264   // The first three elements of the returned vector are : flux for given 
00265   // Stokes (in the units you specify), longitude location (absolute pixels), and
00266   // latitude location (absolute pixels).  For DISK and GAUSSIAN shapes,
00267   // the next three elements are major axis (absolute pixels)
00268   // minor axis (absolute pixels), and position angle (N->E; radians).
00269   // You must specify the brightness units to which the integral flux stored
00270   // in the SkyComponent should be converted.  So as to be able to handle
00271   // /beam units, the restoring beam must also be suppluied.  It can be obtained 
00272   // from the ImageInfo class.  It should be of length 3 or 0 (no beam).  
00273   //  A constant spectrum is used so any spectral index information in
00274   // the component is lost.
00275   Vector<Double> toPixel (
00276                   const Unit& brightnessUnitOut,
00277           const GaussianBeam& restoringBeam,
00278           const CoordinateSystem& cSys,
00279           Stokes::StokesTypes stokes
00280   ) const;
00281 
00282   // Take a vector Doubles and fill the SkyComponent from the values.
00283   // The first three elements of the given vector are : flux for given 
00284   // Stokes (in the units you specify), longitude location (absolute pixels), and
00285   // latitude location (absolute pixels).  For DISK and GAUSSIAN shapes,
00286   // the next three elements are major axis (absolute pixels)
00287   // minor axis (absolute pixels), and position angle (N->E; radians).
00288   // You must specify the brightness units in which the flux is stored
00289   // in the vector.  It will be converted to an integral reprentation
00290   // internally for the SkyComponent.  So as to be able to handle
00291   // /beam units, the restoring beam must also be supplied.  It can be obtained 
00292   // from the ImageInfo class.  It should be of length 3 or 0 (no beam).  
00293   // Multiplying by fluxRatio converts the brightness units to Jy/whatever (e.g. mJy/beam
00294   // to Jy/beam). You must specify the type of shape to convert to.
00295   // The SkyComponent is given a  constant spectrum.
00296   void fromPixel (Double& fluxRatio, const Vector<Double>& parameters,
00297                   const Unit& brightnessUnitIn,
00298                   const GaussianBeam& restoringBeam,
00299                   const CoordinateSystem& cSys,
00300                   ComponentType::Shape componentShape,
00301                   Stokes::StokesTypes stokes);
00302 
00303   // See the corresponding function in the
00304   // <linkto class="SkyCompBase">SkyCompBase</linkto>
00305   // class for a description of this function.
00306   virtual Bool ok() const;
00307 
00308 
00309 // Find the factor that converts whatever per whatevers (e.g. mJy per beam)
00310 // to Jy per whatevers (e.g. Jy per beam)
00311    static Double convertToJy (const Unit& brightnessUnit);
00312 
00313    // Convert a peak flux density to integral flux density
00314         static Quantity peakToIntegralFlux (
00315                 const DirectionCoordinate& dirCoord,
00316                 const ComponentType::Shape componentShape,
00317                 const Quantum<Double>& peakFlux,
00318                 const Quantum<Double>& majorAxis,
00319                 const Quantum<Double>& minorAxis,
00320                 const GaussianBeam& restoringBeam
00321         );
00322 
00323         // Convert an integral flux density to peak flux density.  The brightness unit
00324         // of the output quantum (e.g. mJy/beam) is specified by <src>brightnessUnit</src>
00325         // Throws an exception if the units of <src>integralFlux</src> do not conform to Jy.
00326         static Quantity integralToPeakFlux (
00327                 const DirectionCoordinate& dirCoord,
00328                 const ComponentType::Shape componentShape,
00329                 const Quantity& integralFlux,
00330                 const Unit& brightnessUnit,
00331                 const Quantity& majorAxis,
00332                 const Quantity& minorAxis,
00333                 const GaussianBeam& restoringBeam
00334         );
00335 
00336 private:
00337   CountedPtr<ComponentShape> itsShapePtr;
00338   CountedPtr<SpectralModel> itsSpectrumPtr;
00339   Flux<Double> itsFlux;
00340   String itsLabel;
00341   Vector<Double> itsOptParms;
00342 
00343 
00344   // Make definitions to handle "/beam" and "/pixel" units.   The restoring beam
00345   // is provided in a vector of quanta (major, minor, position angle).  Should
00346   // be length 0 or 3. It can be obtained from class ImageInfo
00347   static Unit defineBrightnessUnits (
00348                   LogIO& os, const Unit& brightnessUnitIn,
00349                   const DirectionCoordinate& dirCoord,
00350                   const GaussianBeam& restoringBeam,
00351                   const Bool integralIsJy
00352   );
00353 
00354   // Remove the user defined "/beam" and "/pixel" definitions
00355      static void undefineBrightnessUnits();
00356 
00357 };
00358 
00359 } //# NAMESPACE CASA - END
00360 
00361 #endif