SloanCoords.hxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 //-----------------------------------------------------------------------------
00005 // CVS: $Revision: 7503 $, $Date: 2010-09-07 16:34:15 +0100 (Tue, 07 Sep 2010) $, $Author: EckhardSutorius $
00006 //-----------------------------------------------------------------------------
00007 #ifndef SLOANCOORDS_H
00008 #define SLOANCOORDS_H
00009 
00010 #include <cmath>
00011 #include <limits>
00012 
00013 #include "Constants.h"
00014 #include "Converter.h"
00015 #include "DataMethod.hxx"
00016 #include "Logger.h"
00017 #include "StringOps.h"
00018 //-----------------------------------------------------------------------------
00021 template<typename DataType>
00022 class SloanCoords : public DataMethod<DataType>
00023 {
00024 public:
00026   SloanCoords() { DataMethod<DataType>::methodName = "SloanCoords"; }
00027 
00029   virtual ~SloanCoords() { }
00030 
00031   //---------------------------------------------------------------------------
00033   void setSource(IntMap& tbls, IntMap& cols, StringMap units)
00034   {
00035     raColno  = cols[0];
00036     decColno = cols[1];
00037 
00038     // Require radians for the calculation
00039     decFact = converter.getFactor(units[0], "RADIANS");
00040     raFact  = converter.getFactor(units[1], "RADIANS");
00041 
00042     // Constants for the co-ordinate transformation
00043     degToRad = converter.getFactor("degrees", "radians");
00044     raOffset = -95.0*degToRad;
00045     etaOffset = +32.5*degToRad;
00046   }
00047   //---------------------------------------------------------------------------
00050   void setTarget(IntMap& cols, StringMap units)
00051   {
00052     lambdaColno = cols[0];
00053     etaColno = cols[1];
00054 
00055     // Check required output units for lambda and eta
00056     lFact = converter.getFactor("RADIANS", units[0]);
00057     eFact = converter.getFactor("RADIANS", units[1]);
00058   }
00059   //---------------------------------------------------------------------------
00061   void doit(TableData<DataType>& data, int row1, int row2)
00062   {
00063     Logger log;
00064     for (int rowNo = row1; rowNo < row2; ++rowNo)
00065     {
00066       // Input RA and DEC
00067       double ra, dec;
00068       data.value(raColno, rowNo, ra);
00069       data.value(decColno, rowNo, dec);
00070 
00071       // Convert RA and DEC to radians
00072       ra  *= raFact;
00073       dec *= decFact;
00074 
00075       double x = cos(ra + raOffset)*cos(dec);
00076       double y = sin(ra + raOffset)*cos(dec);
00077       double z = sin(dec);
00078 
00079       Numeric lambda = -1.0 * asin(x) * lFact;
00080       Numeric eta = (atan2(z,y) - etaOffset) * eFact;
00081 
00082       if (eta < -180.0) eta += 360.0;
00083       if (eta > 180.0) eta -= 360.0;
00084 
00085       // Assign to correct columns
00086       if (eta != eta or std::isinf(eta) or
00087           lambda != lambda  or std::isinf(lambda))
00088       {
00089         string mess = "WCS error in lambda, eta ";
00090         mess += StringOps::NumToString(lambdaColno) + ",";
00091         mess += StringOps::NumToString(etaColno) + " ";
00092         mess += StringOps::NumToString(rowNo) + " : ";
00093         mess += "value replaced with dbl_max";
00094         log.addError(mess);
00095         data.assign(lambdaColno, rowNo, std::numeric_limits<double>::max( )-1);
00096         data.assign(etaColno, rowNo, std::numeric_limits<double>::max( )-1);
00097       } else {
00098         data.assign(lambdaColno, rowNo, lambda);
00099         data.assign(etaColno, rowNo, eta);
00100       }
00101     }
00102   }
00103 
00104   // No data from raw data included
00105   void doit2(TableData<DataType>& rawData, TableData<DataType>& data, int row1, int row2) { }
00106   //---------------------------------------------------------------------------
00107 private:
00108   int lambdaColno, etaColno, raColno, decColno;
00109   double decFact, raFact, lFact, eFact;
00110   double degToRad, raOffset, etaOffset;
00111   Converter converter;
00112 };
00113 //-----------------------------------------------------------------------------
00114 #endif
00115 //-----------------------------------------------------------------------------
00116 // Change log:
00117 //
00118 // 27-May-2004,  IAB: Original version; "Not complete as I can't find
00119 //                    the formula."
00120 //  4-Aug-2004,  NCH: Added in co-ordinate transformations from
00121 //                    Stoughton et al., Astronomical Journal, 123, 485 (2002)
00122 // 28-Oct-2005, ETWS: Changed to SDSSPix code to take care of the
00123 //                    singularity at the pole.
00124 // 22-Mar-2007,  RSC: Robustified against dodgy WCS values.
00125 //  2-May-2007,  RSC: Reverted to original design of allowing dodgy WCS values.
00126 //  7-Apr-2008, ETWS: Upgraded to use new detection table layout.
Generated on Mon Oct 4 10:38:34 2010 for WfcamSrc by  doxygen 1.6.3