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, ATCA_C_RI, ATCA, ATCA_16, ATCA_K, ATCA_Q, ATCA_W,  EVLA, NONE
00142   };
00143 
00144   enum {
00145     NumberOfCommonPB=43  };
00146 
00147   // Default constructor, required for Block<PBMath>
00148   PBMath();
00149   
00150   // Make a PB of common type
00151   explicit PBMath(PBMath::CommonPB myPBType, Bool useSymmetricBeam=False);
00152 
00153   //Make a PB from a telescopename and frequency
00154 
00155   PBMath(String& telescopeName, Bool useSymmetricBeam=False, 
00156          Quantity freq=Quantity(0.0, "Hz"));
00157 
00158   //Make a PB by dish diameter
00159   PBMath(Double dishDiam, Bool useSymmetricBeam, Quantity freq);
00160 
00161   // Make a PB from a RecordInterface
00162   explicit PBMath(const RecordInterface& myrec);
00163 
00164   // Make a Gaussian Primary beam
00165   PBMath(PBMathInterface::PBClass theclass, Quantity halfWidth, 
00166          Quantity maxRad, Quantity refFreq, 
00167          Bool isThisVP=False,
00168          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00169                                                  Quantity(0.0, "deg"),
00170                                                  MDirection::Ref(MDirection::AZEL)), 
00171                                       Quantity(1.0, "GHz")),
00172          Bool useSymmetricBeam=False);
00173   
00174 
00175   // Make a Polynomial, Inverse Polynomial, or Numeric Primary beam
00176   // (These three have identical calling signatures, they can only be distinguished
00177   // by the PBClass enumeration)
00178   PBMath(PBMathInterface::PBClass theclass, const Vector<Double>& coeff, 
00179          Quantity maxRad, Quantity refFreq, 
00180          Bool isThisVP=False,
00181          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00182                                                  Quantity(0.0, "deg"),
00183                                                  MDirection::Ref(MDirection::AZEL)),
00184                                       Quantity(1.0, "GHz")),
00185          Bool useSymmetricBeam=False);
00186 
00187   
00188 
00189   // Make a Numeric Primary beam (FLOAT!)
00190   PBMath(PBMathInterface::PBClass theclass, const Vector<Float>& coeff, 
00191          Quantity maxRad, Quantity refFreq, 
00192          Bool isThisVP=False,
00193          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00194                                                  Quantity(0.0, "deg"),
00195                                                  MDirection::Ref(MDirection::AZEL)),
00196                                       Quantity(1.0, "GHz")),
00197          Bool useSymmetricBeam=False);
00198 
00199   
00200   // Make a CosPolynomial beam type
00201   PBMath(PBMathInterface::PBClass theclass, const Vector<Double>& coeff, 
00202          const Vector<Double>& scale, 
00203          Quantity maxRad, Quantity refFreq,
00204          Bool isThisVP=False,
00205          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00206                                                  Quantity(0.0, "deg"),
00207                                                  MDirection::Ref(MDirection::AZEL)),
00208                                       Quantity(1.0, "GHz")),
00209          Bool useSymmetricBeam=False);
00210   
00211   // Make an Airy beam type
00212   PBMath(PBMathInterface::PBClass theclass, Quantity dishDiam, Quantity blockageDiam,
00213          Quantity maxRad, Quantity refFreq,
00214          BeamSquint squint=BeamSquint(MDirection(Quantity(0.0, "deg"),
00215                                                  Quantity(0.0, "deg"),
00216                                                  MDirection::Ref(MDirection::AZEL)),
00217                                       Quantity(1.0, "GHz")),
00218          Bool useSymmetricBeam=False);
00219   
00220   // Make an Image-based beam
00221   PBMath(PBMathInterface::PBClass theclass,
00222          ImageInterface<Float>& reJones);
00223   PBMath(PBMathInterface::PBClass theclass,
00224          ImageInterface<Float>& reJones,
00225          ImageInterface<Float>& imJones);
00226   
00227   // Instantiate from a Table
00228   //  PBMath(const Table& theTable, Int row);
00229   
00230   
00231   // copy ctor: copies the reference counted pointer
00232   PBMath(const PBMath &other);
00233 
00234   // destructor
00235   ~PBMath();
00236   
00237   //operator=   returns a reference to the PBMath; reference counted pointer
00238   PBMath& operator=(const PBMath& other);
00239   
00240   // comparison operator: just checks that the objects are same
00241   // (could have two different objects with identical data, these are treated
00242   // as !=)
00243   Bool operator==(const PBMath& other) const;
00244   
00245   // comparison operator: just checks that the objects are different
00246   // (could have two different objects with identical data, these are treated
00247   // as !=)
00248   Bool operator!=(const PBMath& other) const;
00249   
00250   // copy()      returns a copy of the PBMath
00251   // PBMath copy() const;
00252   
00253 
00254   //  Apply Jones matrix to an image (and adjoint)
00255   // <group>
00256 
00257   ImageInterface<Complex>& applyVP(const ImageInterface<Complex>& in,
00258                                    ImageInterface<Complex>& out,
00259                                    const MDirection& sp,
00260                                    const Quantity parAngle = Quantity(0.0,"deg"),
00261                                    const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00262                                    Bool inverse = False,
00263                                    Bool conjugate = False,
00264                                    Float cutoff = 0.01,
00265                                    Bool forward=True);
00266 
00267   ImageInterface<Complex>& applyPB(const ImageInterface<Complex>& in,
00268                                    ImageInterface<Complex>& out,
00269                                    const MDirection& sp,
00270                                    const Quantity parAngle = Quantity(0.0,"deg"),
00271                                    const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00272                                    Bool inverse = False,
00273                                    Float cutoff = 0.01,
00274                                    Bool forward = True);
00275 
00276   ImageInterface<Float>& applyPB(const ImageInterface<Float>& in,
00277                                    ImageInterface<Float>& out,
00278                                    const MDirection& sp,
00279                                    const Quantity parAngle = Quantity(0.0,"deg"),
00280                                    const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00281                                    Float cutoff = 0.01);
00282 
00283 
00284   ImageInterface<Float>& applyPB2(const ImageInterface<Float>& in,
00285                                   ImageInterface<Float>& out,
00286                                   const MDirection& sp,
00287                                   const Quantity parAngle = Quantity(0.0,"deg"),
00288                                   const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00289                                   Float cutoff=0.01);
00290   // </group>
00291   
00292   // Apply Jones matrix to a sky component (and adjoint)
00293   // <group>
00294   SkyComponent& applyVP(SkyComponent& in,
00295                         SkyComponent& out,
00296                         const MDirection& sp,
00297                         const Quantity frequency,
00298                         const Quantity parAngle = Quantity(0.0,"deg"),
00299                         const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00300                         Bool inverse = False,
00301                         Bool conjugate = False,
00302                         Float cutoff = 0.01,
00303                         Bool forward = True);
00304 
00305   SkyComponent& applyPB(SkyComponent& in,
00306                         SkyComponent& out,
00307                         const MDirection& sp,
00308                         const Quantity frequency,
00309                         const Quantity parAngle = Quantity(0.0,"deg"),
00310                         const BeamSquint::SquintType doSquint = BeamSquint::NONE,
00311                         Bool inverse = False,
00312                         Float cutoff = 0.01,
00313                         Bool forward = True);
00314 
00315   SkyComponent& applyPB2(SkyComponent& in,
00316                          SkyComponent& out,
00317                          const MDirection& sp,
00318                          const Quantity frequency,
00319                          const Quantity parAngle = Quantity(0.0,"deg"),
00320                          const BeamSquint::SquintType doSquint = BeamSquint::NONE);
00321   // </group>
00322 
00323 
00324 
00325 
00326 
00327   
00328   // Fit an azimuthally symmetric beam to the squinted or otherwise 2-D beam
00329   // for Stokes I?
00330   void setUseSymmetric(Bool useSym=True) { pb_pointer_p->setUseSymmetric(useSym); }
00331 
00332   // Get value of useSymmetric
00333   Bool getUseSymmetric() { return pb_pointer_p->getUseSymmetric(); }
00334   
00335   // Get the type of PB this is
00336   PBMathInterface::PBClass whichPBClass() { return pb_pointer_p->whichPBClass(); }  
00337 
00338   // Summarize the Voltage Pattern;
00339   void summary(Int nValues=0);
00340 
00341   // Is the state of the PBMath OK?
00342   Bool ok() const;
00343 
00344   // Get the BLC, TRC of the primary beam on an Image for a given pointing
00345   // Note: BLC and TRC are not necesarily constrained to lie within the
00346   // image region (for example, if the pointing center is near the edge of the
00347   // image).  fPad: extra fractional padding above PB support
00348   // (note: we do not properly treat squint yet, this will cover it for now)
00349   // iChan: frequency channel to take: lowest frequency channel is safe for all
00350   ImageRegion* extent (const ImageInterface<Complex>& im, 
00351                        const MDirection& pointing,
00352                        const Int row,
00353                        const Float fPad,  
00354                        const Int iChan,  
00355                        const SkyJones::SizeType);
00356   ImageRegion* extent (const ImageInterface<Float>& im, 
00357                        const MDirection& pointing,
00358                        const Int row,
00359                        const Float fPad,  
00360                        const Int iChan,  
00361                        const SkyJones::SizeType);
00362 
00363   Int support (const CoordinateSystem& cs);
00364 
00365   // given the Telescope name and the frequency, guess the most approrpiate
00366   // CommonPB primary beam type and the band
00367   static void whichCommonPBtoUse (String &telescope, Quantity &freq, 
00368                                   String &band, PBMath::CommonPB &whichPB, 
00369                                   String &pbName);
00370 
00371   // converts the enumrated type into a string
00372   static void nameCommonPB(const PBMath::CommonPB iPB, String & str);
00373   
00374   // converts the PB String into an enumrated type
00375   static void enumerateCommonPB(const String & str, PBMath::CommonPB &ipb);
00376 
00377 
00378   // return a PBMathInteface for a commonPB ; caller needs to delete pointer
00379   static PBMathInterface* pbMathInterfaceForCommonPB(const PBMath::CommonPB ipb, Bool useSymmetricBeam);
00380 
00381   // gives the name of the PB Class that has been used
00382   void namePBClass(String & name) {  pb_pointer_p->namePBClass(name); }  
00383 
00384 
00385   // Gradient stuff: this needs more thought, as it is not
00386   // really connected with the stuff in VPSkyJones and all.
00387   // This will return the partial derivatives of chi^2 w.r.t
00388   // the beam model parameters, represented here as a vector.
00389   // Not implemented yet.  
00390   // void parameterGradient(Vector<Float> grad);
00391   
00392   // Flush the construction parameters to disk
00393   // This is a public method because this class doesn't know what Table
00394   // it is to be stored in
00395 
00396   //virtual Bool flushToTable(Table& beamSubTable, Int iRow);
00397 
00398   
00399 protected:
00400 
00401   // polymorphic lower level helping apply methods
00402   // <group>
00403   ImageInterface<Complex>& apply(const ImageInterface<Complex>& in,
00404                                  ImageInterface<Complex>& out,
00405                                  const MDirection& sp,
00406                                  const Quantity parAngle,             
00407                                  const BeamSquint::SquintType doSquint,
00408                                  Bool inverse,
00409                                  Bool conjugate,
00410                                  Int ipower,  // ie, 1=VP, 2=PB
00411                                  Float cutoff=0.01,
00412                                  Bool forward=True); 
00413 
00414   SkyComponent& apply(SkyComponent& in,
00415                       SkyComponent& out,
00416                       const MDirection& sp,
00417                       const Quantity frequency,       
00418                       const Quantity parAngle,        
00419                       const BeamSquint::SquintType doSquint,
00420                       Bool inverse,
00421                       Bool conjugate,
00422                       Int ipower,  // ie, 1=VP, 2=PB, 4=PB^2
00423                       Float cutoff=0.01,
00424                       Bool forward=True); 
00425   // </group>  
00426 
00427 
00428 private:    
00429   
00430   CountedPtr<PBMathInterface> pb_pointer_p;
00431   
00432 
00433   // These should probably move to RecordInterface when we are happy with their performance
00434   // <group>
00435 
00436   Bool getQuantity(const RecordInterface& rec, const String& item, 
00437                    Quantity& returnedQuantity) const;
00438   Bool getMDirection(const RecordInterface& rec, const String& item, 
00439                      MDirection& returnedMDirection) const;
00440   //Function to initialize the state of the tool
00441   void initByTelescope(PBMath::CommonPB myPBType, Bool useSymmetricBeam=False, 
00442                        Double frequency=0.0);
00443 
00444   //Function to initialize the by dish diameter 
00445   void initByDiameter(Double diam, Bool useSymmetricBeam, Double freq); 
00446 
00447   // </group>
00448 
00449 };
00450 
00451   
00452 
00453 } //# NAMESPACE CASA - END
00454 
00455 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1