casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FluxCalc_SS_JPL_Butler.h
Go to the documentation of this file.
00001 //# FluxCalc_SS_JPL_Butler.h: class for getting the fluxes and angular
00002 //# diameters of various Solar System objects.
00003 //# Copyright (C) 2010
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 
00028 #ifndef COMPONENTS_FLUXCALC_SS_JPL_BUTLER_H
00029 #define COMPONENTS_FLUXCALC_SS_JPL_BUTLER_H
00030 
00031 //# include directives
00032 #include <casa/aips.h>
00033 #include <casa/BasicSL/String.h>
00034 #include <measures/Measures/MEpoch.h>
00035 //#include <measures/Measures/MFrequency.h>
00036 #include <measures/Measures/MDirection.h>
00037 #include <components/ComponentModels/Flux.h>
00038 #include <tables/Tables/ScalarColumn.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 class MFrequency;
00043 //class ROScalarColumn<Double>;  There doesn't seem to be a way to forward
00044 //declare a template.
00045 
00046 // <summary> 
00047 // FluxCalc_SS_JPL_Butler: Compute flux densities and get angular diameters 
00048 // for standard Solar System reference sources.
00049 // </summary>
00050 
00051 // <use visibility=export>
00052 
00053 // <reviewed reviewer="" date="" tests="" demos="">
00054 
00055 // <prerequisite>
00056 // <li><linkto class="FluxStandard">FluxStandard</linkto> module
00057 // </prerequisite>
00058 //
00059 // <etymology>
00060 // From "flux density",
00061 //      "Solar System",
00062 //      "JPL" (ephemeris provides position and angular diameter),
00063 //      and (Bryan) "Butler" (provides model to convert the above to a flux density).
00064 // </etymology>
00065 //
00066 // <synopsis>
00067 // This class organizes a set of functions to compute expected flux densities
00068 // and angular diameters for several Solar System sources commonly used for
00069 // flux calibration in (sub)mm astronomy.
00070 // </synopsis>
00071 //
00072 // <example>
00073 // <srcblock>
00074 // </srcblock>
00075 // </example>
00076 //
00077 // <motivation>
00078 // Make available and encapsulate the Butler Solar System flux density models.
00079 // </motivation>
00080 //
00081 // <todo asof="10/07/07">
00082 // <li> Support more complicated (image) models.
00083 // <li> Support a choice of models for a given object.
00084 // <li> Refine the error estimate by looking at the extremes of the time and
00085 //      frequency intervals.
00086 // </todo>
00087 
00088 class FluxCalc_SS_JPL_Butler
00089 {
00090  public:
00091   // Default constructor; provided mainly so an array of these can be made more
00092   // easily.  (Not that there appears to be an immediate need for that.)
00093   FluxCalc_SS_JPL_Butler();
00094 
00095   // The more useful constructor.
00096   FluxCalc_SS_JPL_Butler(const String& objname, const MEpoch& time);
00097   
00098   ~FluxCalc_SS_JPL_Butler();
00099 
00100   // Chooses an object, and returns whether was successful.  It ignores the
00101   // case of objname.
00102   Bool setObj(const String& objname);
00103   
00104   void setTime(const MEpoch& time);
00105   //void setFreq(const MFrequency& freq);
00106 
00107   // These return whether or not the item has been set, and if has, copy their
00108   // item to the arg.
00109   Bool getName(String& output) const;
00110   Bool getTime(MEpoch& output) const;
00111   //Bool getFreq(MFrequency& output) const;
00112 
00113   // Returns the default direction (N. Pole) on failure.
00114   MDirection getDirection();
00115 
00116   // Sets angdiam to the source's angular diameter in radians and returns the
00117   // object's component type (i.e. DISK), or UNKNOWN_SHAPE on failure.
00118   ComponentType::Shape getShape(Double& angdiam);
00119 
00120   // Returns the distance from the object to the Sun in AU, or -1 if unknown.
00121   Double getHeliocentricDist();
00122 
00123   // returns the number of objects supported by this class.
00124   uInt n_known() const;
00125   
00126   // Compute the flux densities, their uncertainties, and the angular diameter
00127   // of the calibration source for a set of frequencies.  It will try to read
00128   // the right table in data/ephemerides/JPL-Horizons/.
00129   //
00130   // Return value:
00131   //    the model's shape, or UNKNOWN_SHAPE on failure.
00132   // Inputs:
00133   //    must be already set, or it returns UNKNOWN_SHAPE.
00134   //    report: If False, suppress logger messages like e.g. references for the
00135   //            temperature.  Intended for use in a loop, i.e. print the
00136   //            messages for the 1st spw but do not repeat them for the others.
00137   // Output args:
00138   //    value: the calculated flux.
00139   //    error: the estimated uncertainty of value.
00140   //    angdiam: angular diameter in radians
00141   ComponentType::Shape compute(Vector<Flux<Double> >& values,
00142                                Vector<Flux<Double> >& errors, Double& angdiam,
00143                                const Vector<MFrequency>& mfreqs,
00144                                const Bool report=True);
00145 
00146   // Same as the above, but for a set of sets of frequencies, i.e.
00147   // mfreqs[spw] is a set of frequencies for channels in spectral window spw.
00148   ComponentType::Shape compute(Vector<Vector<Flux<Double> > >& values,
00149                                Vector<Vector<Flux<Double> > >& errors,
00150                                Double& angdiam,
00151                                const Vector<Vector<MFrequency> >& mfreqs);
00152  private:
00153   enum KnownObjects {
00154     Mercury = 0,
00155     Venus,
00156     // Earth, // Too highly resolved
00157     Mars,
00158     Jupiter,
00159     Io,
00160     Ganymede,
00161     Europa,
00162     Callisto,
00163     // Saturn, // Modeling the rings is too complicated.
00164     Titan,
00165     Uranus,
00166     Neptune,
00167     Triton,
00168     Pluto,
00169     Ceres,
00170     Pallas,
00171     Vesta,
00172     Juno,
00173     Victoria,
00174     Davida,
00175     N_KNOWN
00176   };
00177 
00178   // Tries to set objnum_p to the KnownObject matching name_p.
00179   // Returns whether or not it found a match.
00180   Bool setObjNum();
00181 
00182   // Reads a JPL-Horizons ephemeris table to get temperature_p,
00183   // r_p (heliocentric distance), delta_p (geocentric distance),
00184   // and phang_p (phase angle).
00185   // Returns whether or not it was able to get the info.
00186   Bool readEphem();
00187   
00188   // Compute the flux densities assuming a uniform disk blackbody,
00189   // and their uncertainties.
00190   // It does not check whether everything is setup, since it assumes
00191   // compute() already took care of it!
00192   void compute_BB(Vector<Flux<Double> >& values,
00193                   Vector<Flux<Double> >& errors, const Double angdiam,
00194                   const Vector<MFrequency>& mfreqs);
00195 
00196   // Like compute_BB(), except it uses a graybody model where each frequency
00197   // has a corresponding temperature.
00198   void compute_GB(Vector<Flux<Double> >& values,
00199                   Vector<Flux<Double> >& errors, const Double angdiam,
00200                   const Vector<MFrequency>& mfreqs,
00201                   const Vector<Double>& temps);
00202 
00203   void compute_venus(Vector<Flux<Double> >& values,
00204                      Vector<Flux<Double> >& errors, const Double angdiam,
00205                      const Vector<MFrequency>& mfreqs);
00206   void compute_jupiter(Vector<Flux<Double> >& values,
00207                        Vector<Flux<Double> >& errors, const Double angdiam,
00208                        const Vector<MFrequency>& mfreqs);
00209   void compute_uranus(Vector<Flux<Double> >& values,
00210                       Vector<Flux<Double> >& errors, const Double angdiam,
00211                       const Vector<MFrequency>& mfreqs);
00212   void compute_neptune(Vector<Flux<Double> >& values,
00213                        Vector<Flux<Double> >& errors, const Double angdiam,
00214                        const Vector<MFrequency>& mfreqs);
00215   void compute_pluto(Vector<Flux<Double> >& values,
00216                      Vector<Flux<Double> >& errors, const Double angdiam,
00217                      const Vector<MFrequency>& mfreqs);
00218 
00219   // Uses objnum_p to look up a mean temperature, and uses that.
00220   // report: If False, suppress logger messages like references for the
00221   // temperature.  Intended for use in a loop, i.e. print the
00222   // messages for the 1st spw but do not repeat them for the others.
00223   // Returns whether or not it was successful.
00224   Bool compute_constant_temperature(Vector<Flux<Double> >& values,
00225                                     Vector<Flux<Double> >& errors,
00226                                     const Double angdiam,
00227                                     const Vector<MFrequency>& mfreqs,
00228                                     const Bool report=True);  
00229 
00230   // Find the row in mjd closest to time_p, and the rows just before and after
00231   // it, taking boundaries into account.
00232   Bool get_row_numbers(uInt& rowbef, uInt& rowclosest, uInt& rowaft,
00233                        const ROScalarColumn<Double>& mjd);
00234 
00235   // Put a quadratic, linear, or nearest neighbor interpolation of colname into
00236   // val.  Returns whether or not it did it.
00237   // verbose: Send a message to the logger if nearest neighbor is used.
00238   static Bool get_interpolated_value(Double& val, const String& colname,
00239                                      const Table& tab, const uInt rowbef,
00240                                      const uInt rowclosest, const uInt rowaft,
00241                                      const Double f, const Double dt,
00242                                      const Double tp1mt0, const Double t0mtm1,
00243                                      const Bool verbose=True);
00244 
00245   // Data members which are initialized in the c'tor's initialization list:
00246   String     name_p;
00247   Bool       hasName_p;
00248   MEpoch     time_p;
00249   Bool       hasTime_p;
00250   // MFrequency freq_p;
00251   // Bool       hasFreq_p;
00252   Bool       hasEphemInfo_p;
00253   Unit       hertz_p;           // make it static and/or const?
00254   Bool       has_ra_p;
00255   Bool       has_dec_p;
00256   Bool       has_illu_p;
00257 
00258   // These are also initialized by the c'tor, but not in the initialization
00259   // list:
00260   FluxCalc_SS_JPL_Butler::KnownObjects objnum_p;
00261   Bool                                 hasObjNum_p;
00262 
00263   // Data members that are not initialized by the c'tor:
00264   Double temperature_p; // in K
00265   Double mean_rad_p;    // in AU (really!)
00266   Double r_p;           // heliocentric distance in AU
00267   Double delta_p;       // geocentric distance in AU
00268   Double phang_p;       // Phase angle in radians.
00269   Bool   has_r_p;
00270   Double illu_p;        // Illumination, as a fraction.
00271   Double ra_p;          // RA, in deg.
00272   Double dec_p;         // Declination, in deg.
00273 };
00274 
00275 
00276 } //# NAMESPACE CASA - END
00277 
00278 #endif