casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PBMath.h
Go to the documentation of this file.
00001 //# PBMath.h: Envelope class for PBMath1D and PBMath2D types
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2002,2003
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 adressed 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$
00028 
00029 #ifndef SYNTHESIS_PBMATH_H
00030 #define SYNTHESIS_PBMATH_H
00031 
00032 #include <casa/aips.h>
00033 #include <synthesis/TransformMachines/PBMathInterface.h>
00034 #include <synthesis/TransformMachines/PBMath1DGauss.h>
00035 #include <synthesis/TransformMachines/PBMath1DNumeric.h>
00036 #include <synthesis/TransformMachines/PBMath1DAiry.h>
00037 #include <synthesis/TransformMachines/PBMath1DPoly.h>
00038 #include <synthesis/TransformMachines/PBMath1DIPoly.h>
00039 #include <synthesis/TransformMachines/PBMath1DCosPoly.h>
00040 #include <synthesis/TransformMachines/PBMath2DImage.h>
00041 #include <synthesis/TransformMachines/BeamSquint.h>
00042 #include <images/Images/ImageInterface.h>
00043 #include <measures/Measures.h>
00044 #include <casa/Utilities/CountedPtr.h>
00045 
00046 namespace casa { //# NAMESPACE CASA - BEGIN
00047 
00048 //#forward
00049 class Table;
00050 class ImageRegion;
00051 class RecordInterface;
00052 class CoordinateSystem;
00053 // <summary> Primary beam envelope class, derived from PBMathInterface </summary>
00054 
00055 // <use visibility=export>
00056 
00057 // <reviewed reviewer="" date="" tests="" demos="">
00058 
00059 // <prerequisite>
00060 // <li> <linkto class="SkyJones">SkyJones</linkto> class
00061 // <li> <linkto class="BeamSkyJones">BeamSkyJones</linkto> class
00062 // <li> <linkto class="PBMathInterface">PBMathInterface</linkto> class
00063 // </prerequisite>
00064 //
00065 // <etymology>
00066 // PBMath types do the mathematical operations of the Primary Beamss or
00067 // Voltage patterns.  This envelope class's name was designed for simplicity.
00068 // </etymology>
00069 //
00070 // <synopsis> 
00071 // PBMath is an envelope class for the various types of 1D and 2D primary
00072 // beam/voltage pattern objects.  They all have a common interface defined
00073 // by PBMathInterface.  The PBMath object has a counted pointer to the
00074 // actual PB type; hence, the PBMath object is lightweight and can
00075 // be passed around by value in other classes.
00076 //
00077 // Construct a PBMath via PBMath's enumerated CommonPB type.
00078 // <example>
00079 // <srcblock>
00080 // PBMath wsrtPB(PBMath::WSRT);
00081 // PBMath vla_LPB(PBMath::VLA_L);  // has L band squint built in
00082 // </srcblock>
00083 // </example>
00084 //
00085 // A PBMath can also be constructed by the complete argument list for
00086 // the type of PB it holds.  Since different PB types can have the same
00087 // argument list (PBMath1DPoly and PBMath1DIPoly, for example), the exact
00088 // type also needs to be specified via the PBMathInterface::PBClass.
00089 //
00090 // The main thing you want to do with a primary beam or voltage pattern is
00091 // to apply it to an image.  The PBMath object forwards its low level
00092 // "apply" calls to the letter class's "apply" calls.
00093 // <example>
00094 // <srcblock>
00095 //
00096 //    PagedImage<Float> in;
00097 //    PagedImage<Complex> out;
00098 //    MDirection pointingDir(Quantity(135.0, "deg"), Quantity(60.0, "deg"), 
00099 //                           MDirection::Ref(MDirection::J2000));
00100 //    Quantity parallacticAngle(26.5, "deg");
00101 //    PBMath wsrtPB(PBMath::WSRT_LOW);
00102 //    wsrtPB.applyPB(in, out, pointingDir);   // multiply by primary beam
00103 //    wsrtPB.applyPB(in, out, pointingDir, parallacticAngle, BeamSquint::GOFIGURE, 
00104 //                   True, 0.02); // divide by primary beam
00105 //    wsrtPB.applyVP(in, out, pointingDir);   // multiply by voltage pattern
00106 // </srcblock>
00107 // </example>
00108 // 
00109 // </synopsis> 
00110 //
00111 //
00112 // <motivation>
00113 // This Envelope class allows the user to create a PBMath object which
00114 // can display all the polymorphic traits of PBMath1D classes or
00115 // PBMath2D classes.
00116 // </motivation>
00117 //
00118 // <todo asof="98/010/21">
00119 // </todo>
00120 
00121  
00122 class PBMath {
00123 public:
00124 
00125   // This enumeration provides a simple way to instantiate the
00126   // common primary beam models.  They are each represented by one of
00127   // the more fundamental PBMath1D types
00128   //
00129   // New CommonPB Types must go to the end
00130   enum CommonPB {UNKNOWN, DEFAULT,
00131                  ATCA_L1, ATCA_L2, ATCA_L3, ATCA_S, ATCA_C, ATCA_X, 
00132                  GBT, 
00133                  GMRT,
00134                  HATCREEK,
00135                  NRAO12M,
00136                  NRAO140FT,
00137                  OVRO,
00138                  VLA, VLA_INVERSE, VLA_NVSS, VLA_2NULL, 
00139                  VLA_4, VLA_P, VLA_L, VLA_C, VLA_X, VLA_U, VLA_K, VLA_Q, 
00140                  WSRT, WSRT_LOW, ALMA, ALMASD, ACA, IRAMPDB, IRAM30M, SMA, 
00141                  ATA, NONE, ATCA_C_RI
00142   };
00143 
00144   enum {
00145     NumberOfCommonPB=36
00146   };
00147 
00148   // Default constructor, required for Block<PBMath>
00149   PBMath();
00150   
00151   // Make a PB of common type
00152   explicit PBMath(PBMath::CommonPB myPBType, Bool useSymmetricBeam=False);
00153 
00154   //Make a PB from a telescopename and frequency
00155 
00156   PBMath(String& telescopeName, Bool useSymmetricBeam=False, 
00157          Quantity freq=Quantity(0.0, "Hz"));
00158 
00159   //Make a PB by dish diameter
00160   PBMath(Double dishDiam, Bool useSymmetricBeam, Quantity freq);
00161 
00162   // Make a PB from a RecordInterface
00163   explicit PBMath(const RecordInterface& myrec);
00164 
00165   // Make a Gaussian Primary beam
00166   PBMath(PBMathInterface::PBClass theclass, Quantity halfWidth, 
00167          Quantity maxRad, Quantity refFreq, 
00168          Bool isThisVP=False,
00169          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00170                                                  Quantity(0.0, "deg"),
00171                                                  MDirection::Ref(MDirection::AZEL)), 
00172                                       Quantity(1.0, "GHz")),
00173          Bool useSymmetricBeam=False);
00174   
00175 
00176   // Make a Polynomial, Inverse Polynomial, or Numeric Primary beam
00177   // (These three have identical calling signatures, they can only be distinguished
00178   // by the PBClass enumeration)
00179   PBMath(PBMathInterface::PBClass theclass, const Vector<Double>& coeff, 
00180          Quantity maxRad, Quantity refFreq, 
00181          Bool isThisVP=False,
00182          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00183                                                  Quantity(0.0, "deg"),
00184                                                  MDirection::Ref(MDirection::AZEL)),
00185                                       Quantity(1.0, "GHz")),
00186          Bool useSymmetricBeam=False);
00187 
00188   
00189 
00190   // Make a Numeric Primary beam (FLOAT!)
00191   PBMath(PBMathInterface::PBClass theclass, const Vector<Float>& coeff, 
00192          Quantity maxRad, Quantity refFreq, 
00193          Bool isThisVP=False,
00194          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00195                                                  Quantity(0.0, "deg"),
00196                                                  MDirection::Ref(MDirection::AZEL)),
00197                                       Quantity(1.0, "GHz")),
00198          Bool useSymmetricBeam=False);
00199 
00200   
00201   // Make a CosPolynomial beam type
00202   PBMath(PBMathInterface::PBClass theclass, const Vector<Double>& coeff, 
00203          const Vector<Double>& scale, 
00204          Quantity maxRad, Quantity refFreq,
00205          Bool isThisVP=False,
00206          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00207                                                  Quantity(0.0, "deg"),
00208                                                  MDirection::Ref(MDirection::AZEL)),
00209                                       Quantity(1.0, "GHz")),
00210          Bool useSymmetricBeam=False);
00211   
00212   // Make an Airy beam type
00213   PBMath(PBMathInterface::PBClass theclass, Quantity dishDiam, Quantity blockageDiam,
00214          Quantity maxRad, Quantity refFreq,
00215          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00216                                                  Quantity(0.0, "deg"),
00217                                                  MDirection::Ref(MDirection::AZEL)),
00218                                       Quantity(1.0, "GHz")),
00219          Bool useSymmetricBeam=False);
00220   
00221   // Make an Image-based beam
00222   PBMath(PBMathInterface::PBClass theclass,
00223          ImageInterface<Float>& reJones);
00224   PBMath(PBMathInterface::PBClass theclass,
00225          ImageInterface<Float>& reJones,
00226          ImageInterface<Float>& imJones);
00227   
00228   // Instantiate from a Table
00229   //  PBMath(const Table& theTable, Int row);
00230   
00231   
00232   // copy ctor: copies the reference counted pointer
00233   PBMath(const PBMath &other);
00234 
00235   // destructor
00236   ~PBMath();
00237   
00238   //operator=   returns a reference to the PBMath; reference counted pointer
00239   PBMath& operator=(const PBMath& other);
00240   
00241   // comparison operator: just checks that the objects are same
00242   // (could have two different objects with identical data, these are treated
00243   // as !=)
00244   Bool operator==(const PBMath& other) const;
00245   
00246   // comparison operator: just checks that the objects are different
00247   // (could have two different objects with identical data, these are treated
00248   // as !=)
00249   Bool operator!=(const PBMath& other) const;
00250   
00251   // copy()      returns a copy of the PBMath
00252   // PBMath copy() const;
00253   
00254 
00255   //  Apply Jones matrix to an image (and adjoint)
00256   // <group>
00257 
00258   ImageInterface<Complex>& applyVP(const ImageInterface<Complex>& in,
00259                                    ImageInterface<Complex>& out,
00260                                    const MDirection& sp,
00261                                    const Quantity parAngle = Quantity(0.0,"deg"),
00262                                    const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00263                                    Bool inverse = False,
00264                                    Bool conjugate = False,
00265                                    Float cutoff = 0.01,
00266                                    Bool forward=True);
00267 
00268   ImageInterface<Complex>& applyPB(const ImageInterface<Complex>& in,
00269                                    ImageInterface<Complex>& out,
00270                                    const MDirection& sp,
00271                                    const Quantity parAngle = Quantity(0.0,"deg"),
00272                                    const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00273                                    Bool inverse = False,
00274                                    Float cutoff = 0.01,
00275                                    Bool forward = True);
00276 
00277   ImageInterface<Float>& applyPB(const ImageInterface<Float>& in,
00278                                    ImageInterface<Float>& out,
00279                                    const MDirection& sp,
00280                                    const Quantity parAngle = Quantity(0.0,"deg"),
00281                                    const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00282                                    Float cutoff = 0.01);
00283 
00284 
00285   ImageInterface<Float>& applyPB2(const ImageInterface<Float>& in,
00286                                   ImageInterface<Float>& out,
00287                                   const MDirection& sp,
00288                                   const Quantity parAngle = Quantity(0.0,"deg"),
00289                                   const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00290                                   Float cutoff=0.01);
00291   // </group>
00292   
00293   // Apply Jones matrix to a sky component (and adjoint)
00294   // <group>
00295   SkyComponent& applyVP(SkyComponent& in,
00296                         SkyComponent& out,
00297                         const MDirection& sp,
00298                         const Quantity frequency,
00299                         const Quantity parAngle = Quantity(0.0,"deg"),
00300                         const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00301                         Bool inverse = False,
00302                         Bool conjugate = False,
00303                         Float cutoff = 0.01,
00304                         Bool forward = True);
00305 
00306   SkyComponent& applyPB(SkyComponent& in,
00307                         SkyComponent& out,
00308                         const MDirection& sp,
00309                         const Quantity frequency,
00310                         const Quantity parAngle = Quantity(0.0,"deg"),
00311                         const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00312                         Bool inverse = False,
00313                         Float cutoff = 0.01,
00314                         Bool forward = True);
00315 
00316   SkyComponent& applyPB2(SkyComponent& in,
00317                          SkyComponent& out,
00318                          const MDirection& sp,
00319                          const Quantity frequency,
00320                          const Quantity parAngle = Quantity(0.0,"deg"),
00321                          const BeamSquint::SquintType doSquint = BeamSquint::NONE);
00322   // </group>
00323 
00324 
00325 
00326 
00327 
00328   
00329   // Fit an azimuthally symmetric beam to the squinted or otherwise 2-D beam
00330   // for Stokes I?
00331   void setUseSymmetric(Bool useSym=True) { pb_pointer_p->setUseSymmetric(useSym); }
00332 
00333   // Get value of useSymmetric
00334   Bool getUseSymmetric() { return pb_pointer_p->getUseSymmetric(); }
00335   
00336   // Get the type of PB this is
00337   PBMathInterface::PBClass whichPBClass() { return pb_pointer_p->whichPBClass(); }  
00338 
00339   // Summarize the Voltage Pattern;
00340   void summary(Int nValues=0);
00341 
00342   // Is the state of the PBMath OK?
00343   Bool ok() const;
00344 
00345   // Get the BLC, TRC of the primary beam on an Image for a given pointing
00346   // Note: BLC and TRC are not necesarily constrained to lie within the
00347   // image region (for example, if the pointing center is near the edge of the
00348   // image).  fPad: extra fractional padding above PB support
00349   // (note: we do not properly treat squint yet, this will cover it for now)
00350   // iChan: frequency channel to take: lowest frequency channel is safe for all
00351   ImageRegion* extent (const ImageInterface<Complex>& im, 
00352                        const MDirection& pointing,
00353                        const Int row,
00354                        const Float fPad,  
00355                        const Int iChan,  
00356                        const SkyJones::SizeType);
00357   ImageRegion* extent (const ImageInterface<Float>& im, 
00358                        const MDirection& pointing,
00359                        const Int row,
00360                        const Float fPad,  
00361                        const Int iChan,  
00362                        const SkyJones::SizeType);
00363 
00364   Int support (const CoordinateSystem& cs);
00365 
00366   // given the Telescope name and the frequency, guess the most approrpiate
00367   // CommonPB primary beam type and the band
00368   static void whichCommonPBtoUse (String &telescope, Quantity &freq, 
00369                                   String &band, PBMath::CommonPB &whichPB, 
00370                                   String &pbName);
00371 
00372   // converts the enumrated type into a string
00373   static void nameCommonPB(const PBMath::CommonPB iPB, String & str);
00374   
00375   // converts the PB String into an enumrated type
00376   static void enumerateCommonPB(const String & str, PBMath::CommonPB &ipb);
00377 
00378   // gives the name of the PB Class that has been used
00379   void namePBClass(String & name) {  pb_pointer_p->namePBClass(name); }  
00380 
00381 
00382   // Gradient stuff: this needs more thought, as it is not
00383   // really connected with the stuff in VPSkyJones and all.
00384   // This will return the partial derivatives of chi^2 w.r.t
00385   // the beam model parameters, represented here as a vector.
00386   // Not implemented yet.  
00387   // void parameterGradient(Vector<Float> grad);
00388   
00389   // Flush the construction parameters to disk
00390   // This is a public method because this class doesn't know what Table
00391   // it is to be stored in
00392 
00393   //virtual Bool flushToTable(Table& beamSubTable, Int iRow);
00394 
00395   
00396 protected:
00397 
00398   // polymorphic lower level helping apply methods
00399   // <group>
00400   ImageInterface<Complex>& apply(const ImageInterface<Complex>& in,
00401                                  ImageInterface<Complex>& out,
00402                                  const MDirection& sp,
00403                                  const Quantity parAngle,             
00404                                  const BeamSquint::SquintType doSquint,
00405                                  Bool inverse,
00406                                  Bool conjugate,
00407                                  Int ipower,  // ie, 1=VP, 2=PB
00408                                  Float cutoff=0.01,
00409                                  Bool forward=True); 
00410 
00411   SkyComponent& apply(SkyComponent& in,
00412                       SkyComponent& out,
00413                       const MDirection& sp,
00414                       const Quantity frequency,       
00415                       const Quantity parAngle,        
00416                       const BeamSquint::SquintType doSquint,
00417                       Bool inverse,
00418                       Bool conjugate,
00419                       Int ipower,  // ie, 1=VP, 2=PB, 4=PB^2
00420                       Float cutoff=0.01,
00421                       Bool forward=True); 
00422   // </group>  
00423 
00424 
00425 private:    
00426   
00427   CountedPtr<PBMathInterface> pb_pointer_p;
00428   
00429 
00430   // These should probably move to RecordInterface when we are happy with their performance
00431   // <group>
00432 
00433   Bool getQuantity(const RecordInterface& rec, const String& item, 
00434                    Quantity& returnedQuantity) const;
00435   Bool getMDirection(const RecordInterface& rec, const String& item, 
00436                      MDirection& returnedMDirection) const;
00437   //Function to initialize the state of the tool
00438   void initByTelescope(PBMath::CommonPB myPBType, Bool useSymmetricBeam=False, 
00439                        Double frequency=0.0);
00440 
00441   //Function to initialize the by dish diameter 
00442   void initByDiameter(Double diam, Bool useSymmetricBeam, Double freq); 
00443 
00444   // </group>
00445 
00446 };
00447 
00448   
00449 
00450 } //# NAMESPACE CASA - END
00451 
00452 #endif