casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
BeamCalc.h
Go to the documentation of this file.
00001 //# VLAIlluminationConvFunc.h: Definition for VLAIlluminationConvFunc
00002 //# Copyright (C) 1996,1997,1998,1999,2000,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 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_BEAMCALC_H
00030 #define SYNTHESIS_BEAMCALC_H
00031 
00032 //#include <casa/complex.h>
00033 #include <images/Images/TempImage.h>
00034 #include <casa/Exceptions.h>
00035 #include <casa/Logging/LogIO.h>
00036 
00037 namespace casa
00038 {
00039 
00040 #define MAXGEOM 2000
00041 
00042   typedef struct        /* all dimensions in meters, GHz */
00043   {
00044     char name[16];      /* name of antenna, e.g., VLA */
00045     Double sub_h;       /* subreflector vertex height above primary vertex */
00046     Double feedpos[3];  /* position of feed */
00047     Double subangle;    /* angle subtended by the subreflector */
00048     Double legwidth;    /* strut width */
00049     Double legfoot;             /* distance from optic axis of leg foot */
00050     Double legapex;             /* hight of leg intersection */
00051     Double Rhole;               /* radius of central hole */
00052     Double Rant;                /* antenna radius */
00053     Double reffreq;             /* a reference frequency */
00054     Double taperpoly[5];        /* polynomial expanded about reffreq */
00055     Int ntaperpoly;             /* number of terms in polynomial */
00056     
00057     Double astigm_0;     /* astigmatism: coefficient of Zernike Polyn. Z6 a.k.a. 0-90 */
00058     Double astigm_45;    /* astigmatism: coefficient of Zernike Polyn. Z5 a.k.a. 45-135 */
00059 
00060     /* to be added later
00061        Double focus;
00062        Double dfeedpos[3];
00063        Double dsub_z;
00064     */
00065   } BeamCalcGeometry;
00066   
00067   typedef struct 
00068   {
00069     Int oversamp;                       /* average this many points per cell */
00070     TempImage<Complex> *aperture;       /* Jones planes [Nx,Ny,NStokes,NFreq]*/
00071     Double x0, y0;                      /* center of cell 0, 0, meters */
00072     Double dx, dy;                      /* increment in meters */
00073     Int nx, ny;                 /* calculation plane size in cells */
00074     /* last cell is at coordinates:
00075        X = x0 + (nx-1)*dx
00076        Y = y0 + (ny-1)*dy
00077     */
00078     Double pa;                  /* Parallactic angle, radians */
00079     Double freq;                        /* GHz */
00080     Int band;
00081   } ApertureCalcParams;
00082 
00083   /*
00084    * calcAntenna parameters
00085    */
00086   typedef struct
00087   {
00088     Double sub_h;               /* height of subreflector (on axis) */
00089     Double feed[3];             /* position of the feed */
00090     Double feeddir[3];          /* unit vector pointing along feed */
00091     Double pfeeddir[3];         /* same as above after pathology applied */
00092     Double radius;              /* antenna radius (m) */
00093     Double K;
00094     Double deltar;
00095     Double zedge;               /* height at the edge of the dish */
00096     Double bestparabola;        /* best fit parabola quadratic coef */
00097     Double ftaper;              /* taper of feed */
00098     Double thmax;               /* maximum angle of feed */
00099     Double fa2pi;
00100     Double legwidth;
00101     Double legfoot, legfootz;
00102     Double legapex;
00103     Double legthick;
00104     Double hole_radius;
00105     Double freq, lambda;
00106     Double astigm_0;     /* astigmatism: coefficient of Zernike Polyn. Z6 a.k.a. 0-90 */
00107     Double astigm_45;    /* astigmatism: coefficient of Zernike Polyn. Z5 a.k.a. 45-135 */
00108     Double dir[3];
00109     Double hhat[3], vhat[3];   /* unit vectors orthogonal to dir */
00110     Double z[MAXGEOM];
00111     Double m[MAXGEOM];
00112     Double k[3];
00113     Int ngeom;
00114     char name[16];
00115     Int gridsize;
00116   } calcAntenna;
00117   
00118   typedef struct
00119   {
00120     Double subrot[3][3];        /* 3x3 matrix rotating x,y,z or nx,ny,nz */
00121     Double feedrot[3][3];       /* 3x3 matrix rotating x,y,z or nx,ny,nz */
00122     Double subshift[3];         /* 3 length vector */
00123     Double feedshift[3];        /* 3 length vector */
00124     Double subrotpoint[3];      /* 3 vector describing point to rotate sub. */
00125     Double az_offset;           /* azimuth pointing offset (radians) */
00126     Double el_offset;           /* elevation pointing offset (radians) */
00127     Double phase_offset;        /* DC offset in phase (radians) */
00128     Double focus;               /* meters out of focus toward subreflector */
00129   } Pathology;
00130   
00131   typedef struct
00132   {
00133     Double aper[6];             /* aperture x, y, z, nx, ny, nz */
00134     Double dish[6];             /* dish x, y, z, nx, ny, nz */
00135     Double sub[6];              /* subreflector x, y, z, nx, ny, nz */
00136     Double feed[3];             /* feed x, y, z */
00137   } Ray;
00138 
00139 
00140   enum VLABeamCalcBandCode{
00141     BeamCalc_VLA_L = 0,
00142     BeamCalc_VLA_C,
00143     BeamCalc_VLA_X,
00144     BeamCalc_VLA_U,
00145     BeamCalc_VLA_K,
00146     BeamCalc_VLA_Q,
00147     BeamCalc_VLA_4,
00148     
00149     VLABeamCalc_NumBandCodes    /* this line last */
00150   };
00151 
00152   enum EVLABeamCalcBandCode{
00153     BeamCalc_EVLA_L = 0,
00154     BeamCalc_EVLA_S,
00155     BeamCalc_EVLA_C,
00156     BeamCalc_EVLA_X,
00157     BeamCalc_EVLA_U,
00158     BeamCalc_EVLA_K,
00159     BeamCalc_EVLA_A,
00160     BeamCalc_EVLA_Q,
00161     BeamCalc_EVLA_4,
00162     
00163     EVLABeamCalc_NumBandCodes   /* this line last */
00164   };
00165 
00166   enum ALMABeamCalcBandCode{
00167     BeamCalc_ALMA_1 = 0,
00168     BeamCalc_ALMA_2,
00169     BeamCalc_ALMA_3,
00170     BeamCalc_ALMA_4,
00171     BeamCalc_ALMA_5,
00172     BeamCalc_ALMA_6,
00173     BeamCalc_ALMA_7,
00174     BeamCalc_ALMA_8,
00175     BeamCalc_ALMA_9,
00176     BeamCalc_ALMA_10,
00177     
00178     ALMABeamCalc_NumBandCodes   /* this line last */
00179   };
00180 
00181   extern Double VLABandMinFreqDefaults[VLABeamCalc_NumBandCodes];
00182   extern Double VLABandMaxFreqDefaults[VLABeamCalc_NumBandCodes];
00183   extern BeamCalcGeometry VLABeamCalcGeometryDefaults[VLABeamCalc_NumBandCodes];
00184   extern Double EVLABandMinFreqDefaults[EVLABeamCalc_NumBandCodes];
00185   extern Double EVLABandMaxFreqDefaults[EVLABeamCalc_NumBandCodes];
00186   extern BeamCalcGeometry EVLABeamCalcGeometryDefaults[EVLABeamCalc_NumBandCodes];
00187   extern Double ALMABandMinFreqDefaults[ALMABeamCalc_NumBandCodes];
00188   extern Double ALMABandMaxFreqDefaults[ALMABeamCalc_NumBandCodes];
00189   extern BeamCalcGeometry ALMABeamCalcGeometryDefaults[ALMABeamCalc_NumBandCodes];
00190 
00191   class BeamCalc
00192   {
00193   public:
00194 
00195     // This is a SINGLETON class
00196     static BeamCalc* Instance();
00197 
00198     void setBeamCalcGeometries(const String& obsName, // (the observatory name, e.g. "ALMA" or "ACA")
00199                                const String& antennaType = "STANDARD",
00200                                const MEpoch& obsTime = MEpoch(Quantity(50000., "d")),
00201                                const String& otherAntRayPath=""); // override the AntennaResponses Table in Observatories
00202 
00203     Int getBandID(const Double freq, // in Hz 
00204                   const String& obsname,
00205                   const String& antennaType="STANDARD",
00206                   const MEpoch& obsTime = MEpoch(Quantity(50000., "d")),
00207                   const String& otherAntRayPath=""); // override the AntennaResponses Table in Observatories 
00208 
00209     Int calculateAperture(ApertureCalcParams *ap);
00210 
00211   protected:
00212     BeamCalc();
00213     
00214   private:
00215 
00216   void computePixelValues(const ApertureCalcParams *ap, const calcAntenna *a, const Pathology *p,
00217                           const Double &L0, Complex *Er, Complex *El, 
00218                           const Int &i, const Int &j);
00219     //normalizes a "vector" of 3 Doubles in the vector sense
00220     inline void norm3(Double *v)
00221     {
00222       Double s;
00223       s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00224       v[0] /= s;
00225       v[1] /= s;
00226       v[2] /= s;
00227     }
00228 
00229     calcAntenna *newAntenna(Double sub_h, Double feed_x, Double feed_y, Double feed_z,
00230                             Double ftaper, Double thmax, const char *geomfile);
00231 
00232     void deleteAntenna(calcAntenna *a);
00233 
00234     void Antennasetfreq(calcAntenna *a, Double freq);
00235 
00236     void Antennasetdir(calcAntenna *a, const Double *dir);
00237 
00238     // sets feeddir after pathology is considered 
00239     void alignfeed(calcAntenna *a, const Pathology *p);
00240 
00241     void getfeedbasis(const calcAntenna *a, Double B[3][3]);
00242 
00243     void Efield(const calcAntenna *a, const Complex *pol, Complex *E);
00244 
00245     Int Antennasetfeedpattern(calcAntenna *a, const char *filename, Double scale);
00246 
00247     calcAntenna *newAntennafromApertureCalcParams(ApertureCalcParams *ap);
00248 
00249     Int dishvalue(const calcAntenna *a, Double r, Double *z, Double *m);
00250 
00251     Int astigdishvalue(const calcAntenna *a, Double x, Double y, Double *z, Double *m); 
00252 
00253     // Returns position of subreflector piece (x, y, z) and
00254     // its normal (u, v, w)
00255     Int subfromdish(const calcAntenna *a, Double x, Double y, Double *subpoint);
00256 
00257     Int dishfromsub(const calcAntenna *a, Double x, Double y, Double *dishpoint);
00258 
00259     void printAntenna(const calcAntenna *a);
00260 
00261     Ray* newRay(const Double *sub);
00262 
00263     void deleteRay(Ray *ray);
00264 
00265     Pathology* newPathology();
00266 
00267     Pathology* newPathologyfromApertureCalcParams(ApertureCalcParams *ap);
00268 
00269     void deletePathology(Pathology *P);
00270 
00271     void normvec(const Double *a, const Double *b, Double *c);
00272 
00273     Double dAdOmega(const calcAntenna *a, const Ray *ray1, const Ray *ray2,
00274                     const Ray *ray3, const Pathology *p);
00275 
00276     Double dOmega(const calcAntenna *a, const Ray *ray1, const Ray *ray2,
00277                   const Ray *ray3, const Pathology *p);
00278 
00279     Double Raylen(const Ray *ray);
00280 
00281     void Pathologize(Double *sub, const Pathology *p);
00282 
00283     void applyPathology(Pathology *P, calcAntenna *a);
00284 
00285     void intersectdish(const calcAntenna *a, const Double *sub, const Double *unitdir,
00286                        Double *dish, Int niter);
00287 
00288     void intersectaperture(const calcAntenna *a, const Double *dish, 
00289                            const Double *unitdir, Double *aper);
00290 
00291     Double feedfunc(const calcAntenna *a, Double theta);
00292 
00293     Double feedgain(const calcAntenna *a, const Ray *ray, const Pathology *p);
00294 
00295     Ray* trace(const calcAntenna *a, Double x, Double y, const Pathology *p);
00296 
00297     void tracepol(Complex *E0, const Ray *ray, Complex *E1);
00298 
00299     Int legplanewaveblock(const calcAntenna *a, Double x, Double y);
00300 
00301     Int legplanewaveblock2(const calcAntenna *a, const Ray *ray);
00302 
00303     Int legsphericalwaveblock(const calcAntenna *a, const Ray *ray);
00304 
00305     void copyBeamCalcGeometry(BeamCalcGeometry* to, BeamCalcGeometry* from);
00306 
00307     static BeamCalc* instance_p;
00308 
00309     String obsName_p;
00310     String antType_p;
00311     MEpoch obsTime_p;
00312     uInt BeamCalc_NumBandCodes_p;
00313     Vector<BeamCalcGeometry> BeamCalcGeometries_p;
00314     Vector<Double> bandMinFreq_p; // in Hz
00315     Vector<Double> bandMaxFreq_p; // in Hz
00316     String antRespPath_p;
00317 
00318     static const Double METER_INCH;
00319     static const Double INCH_METER;
00320     static const Double NS_METER;
00321     static const Double METER_NS;
00322     static const Double DEG_RAD;
00323     static const Double RAD_DEG;
00324 
00325   };
00326   
00327 };
00328 
00329 #endif