casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MSDerivedValues.h
Go to the documentation of this file.
00001 //# MSDerivedValues.h: a server for values derived from a MS (e.g. P.A.)
00002 //# Copyright (C) 1997,1999,2000
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: MSDerivedValues.h 20459 2008-12-02 12:51:13Z gervandiepen $
00028 
00029 #ifndef MS_MSDERIVEDVALUES_H
00030 #define MS_MSDERIVEDVALUES_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <measures/Measures.h>
00035 #include <measures/Measures/MCDirection.h>
00036 #include <measures/Measures/MDoppler.h>
00037 #include <measures/Measures/MFrequency.h>
00038 #include <measures/Measures/MCEpoch.h>
00039 #include <measures/Measures/MCRadialVelocity.h>
00040 #include <measures/Measures/MPosition.h>
00041 #include <ms/MeasurementSets/MeasurementSet.h>
00042 namespace casa { //# NAMESPACE CASA - BEGIN
00043 
00044 //# Forward Declarations
00045 class ROMSAntennaColumns;
00046 class String;
00047 // <summary>
00048 // MSDerivedValues calculates values derived from a MS
00049 // </summary>
00050 
00051 // <use visibility=export>
00052 
00053 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00054 // </reviewed>
00055 
00056 // <prerequisite>
00057 //   <li> MeasurementSet
00058 //   <li> SomeOtherClass
00059 //   <li> some concept
00060 // </prerequisite>
00061 //
00062 // <etymology>
00063 // MSDerivedValues calculates values derived from those in a MS
00064 // </etymology>
00065 //
00066 // <synopsis>
00067 // MSDerivedValues is a class that computes values derived from those present
00068 // in a MeasurementSet. E.g., calculate feed position angles on the sky from
00069 // time, antenna positions and feed characteristics.
00070 // </synopsis>
00071 //
00072 // <example>
00073 // <srcblock>
00074 // // calculate the parallactic angle and the observatory velocity for the
00075 // // first time and first source in the MS.
00076 // // set up 
00077 // MSDerivedValues msd;
00078 // MS myMS("myMS");
00079 // ROMSColumns msc(myMS);
00080 // msd.setAntennas(msc.antenna());
00081 // MEpoch ep=MS::epochMeasure(msc.time());
00082 // ep.set(MVEpoch(Quantity(msc.time()(0),"s")));
00083 // msd.setEpoch(ep);
00084 // MDirection dir=MS::directionMeasure(msc.field().phaseDir());
00085 // dir.set(MVDirection(Vector<Double>(msc.field().phaseDir()(0))));
00086 // msd.setFieldCenter(dir);
00087 // msd.setVelocityFrame(MRadialVelocity::LSRK);
00088 // // now we are ready for the calculations:
00089 // Double parAngle = msd.parangle();
00090 // MRadialVelocity observatoryVel = msd.obsVel();
00091 // </srcblock>
00092 // </example>
00093 //
00094 // <motivation>
00095 // Values derived from those in a MS are needed in various places, e.g., for
00096 // plotting purposes. This class combines the commonly needed calculations 
00097 // in one place.
00098 // </motivation>
00099 //
00100 // <thrown>
00101 //    <li>
00102 //    <li>
00103 // </thrown>
00104 //
00105 // <todo asof="1997/05/30">
00106 //   <li> the interface should be less cumbersome
00107 //   <li> probably needs speeding up
00108 // </todo>
00109 
00110 class MSDerivedValues
00111 {
00112     friend class VisBufferAsync; // to work around dysfunctional operator= and
00113                                  // thread-hostile shared pointers (Jim Jacobs 111104)
00114 public:
00115   MSDerivedValues();
00116   ~MSDerivedValues();
00117 
00118   // Copy constructor, this will initialize with other's MS
00119   MSDerivedValues(const MSDerivedValues& other);
00120   
00121   // Assignment, this will initialize with other's MS
00122   MSDerivedValues& operator=(const MSDerivedValues& other);
00123   
00124   // Set antenna position from an antenna table
00125   // Returns the number of antennas. Also
00126   // sets the observatory position to the average of the antenna positions.
00127   Int setAntennas(const ROMSAntennaColumns& ac);
00128 
00129   // Set antenna positions, index in vector is antenna number
00130   // for calls below.
00131   MSDerivedValues& setAntennaPositions(const Vector<MPosition>& antPosition);
00132   const Vector<MPosition> & getAntennaPositions () const;
00133   
00134   // Set the observatory position. Note that setAntennas will reset this.
00135   MSDerivedValues& setObservatoryPosition(const MPosition& obsPosition);
00136 
00137   // Set antenna mounts, should have same number of entries as
00138   // antPosition in setAntennaPosition
00139   MSDerivedValues& setAntennaMount(const Vector<String>& mount);
00140   
00141   // Set epoch
00142   MSDerivedValues& setEpoch(const MEpoch& time);
00143 
00144   // Set field center
00145   MSDerivedValues& setFieldCenter(const MDirection& fieldCenter);
00146 
00147   //If you have used setMeasurementSet then this version of 
00148   //setFieldCenter using field id makes sense
00149   MSDerivedValues& setFieldCenter(uInt fieldid=0);
00150 
00151   // Set antenna index, sets the position reference for the conversions. 
00152   // Use -1 to set the reference frame to the observatory position.
00153   MSDerivedValues& setAntenna(Int antenna);
00154 
00155   // Set the velocity frame type (e.g., MRadialVelocity::LSRK) 
00156   MSDerivedValues& setVelocityFrame(MRadialVelocity::Types vType);
00157 
00158   // Set the velocity frame type (e.g., MRDoppler::RADIO) 
00159   MSDerivedValues& setVelocityReference(MDoppler::Types dopType);
00160   MRadialVelocity::Types getRadialVelocityType () const;
00161 
00162   // Set the frequency frame  (e.g., MFrequency::LSRK) 
00163   MSDerivedValues& setFrequencyReference(MFrequency::Types frqType);
00164 
00165   // get hour angle
00166   Double hourAngle();
00167 
00168   // get parallactic angle
00169   Double parAngle();
00170 
00171   // get azimuth & elevation
00172   const MDirection& azel();
00173   
00174   // get LAST for given time, antenna
00175   const MEpoch& last();
00176 
00177   // get observatory radial velocity for given epoch, position and direction
00178   const MRadialVelocity& obsVel();
00179 
00180   //Set an ms does not need to explicity setAntennas and is necessary if 
00181   //setRestFreqency(fieldid, spwid) is used  
00182   MSDerivedValues& setMeasurementSet(const MeasurementSet& ms);
00183 
00184 
00185   //Set restFrequencies...make it look for it for the fieldid, spwid and line 
00186   //number defined in the SOURCE table return False if it fails to find the 
00187   //restFrquency
00188   Bool setRestFrequency(const Int fieldid, const Int spwid, 
00189                        const Int linenum=0);
00190 
00191   //
00192   MSDerivedValues& setRestFrequency(const Quantity& restFreq);
00193   
00194   
00195   // get frequency from velocity
00196 
00197   Quantity toFrequency(const Quantity& vel, const Quantity& restFreq);
00198   Quantity toFrequency(const Quantity& vel);
00199 
00200   // get velocity from frequency
00201   Quantity toVelocity(const Quantity& freq, const Quantity& restFreq);
00202   Quantity toVelocity(const Quantity& freq);
00203 
00204 protected:
00205 
00206 private:
00207 
00208   // initialize data
00209   void init();
00210 
00211   Int antenna_p;
00212   MEpoch::Convert cUTCToLAST_p;
00213   Vector<MPosition> mAntPos_p;
00214   MDirection::Convert cRADecToAzEl_p;
00215   MDirection::Convert cHADecToAzEl_p;
00216   MDirection::Convert cRADecToHADec_p;
00217   MeasFrame fAntFrame_p;
00218   MDirection mRADecInAzEl_p;
00219   MDirection mHADecPoleInAzEl_p;
00220   MDirection mFieldCenter_p;
00221   MPosition mObsPos_p;
00222   MRadialVelocity::Convert cTOPOToLSR_p;
00223   MDoppler::Ref velref_p;
00224   MFrequency::Ref frqref_p;
00225   Bool hasMS_p;
00226   Quantity restFreq_p;
00227   Vector<Int> mount_p;
00228   MeasurementSet ms_p;
00229   MRadialVelocity::Types radialVelocityType_p;
00230 
00231   //  Vector<Double> receptorAngle_p;
00232  
00233 
00234 };
00235 
00236 
00237 } //# NAMESPACE CASA - END
00238 
00239 #endif