RaDecByAst.hxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 //-----------------------------------------------------------------------------
00005 // CVS: $Revision: 4695 $, $Date: 2008-04-09 16:18:42 +0100 (Wed, 09 Apr 2008) $, $Author: EckhardSutorius $
00006 //-----------------------------------------------------------------------------
00007 #ifndef RADECBYAST_HXX
00008 #define RADECBYAST_HXX
00009 
00010 // We will make use of AST for operations involving WCS
00011 extern "C"
00012 {
00013   #include "ast.h"
00014 }
00015 
00016 #include <cmath>
00017 
00018 #include "Converter.h"
00019 #include "FitsFile.h"
00020 #include "Logger.h"
00021 #include "DataMethod.hxx"
00022 #include "StringOps.h"
00023 //-----------------------------------------------------------------------------
00026 template<typename DataType>
00027 class RaDecByAst : public DataMethod<DataType>
00028 {
00029 public:
00031   RaDecByAst(const FitsFile& aFile)
00032     : mFile(aFile)
00033     { DataMethod<DataType>::methodName = "RaDecByAst"; }
00034 
00036   virtual ~RaDecByAst() { }
00037 
00040   void setSource(IntMap& tbls, IntMap& cols, StringMap units)
00041   {
00042     extnumColno = cols[0];
00043     xColno = cols[1];
00044     yColno = cols[2];
00045     extnumTblno = tbls[0];
00046     xTblno = tbls[1];
00047     yTblno = tbls[2];
00048   }
00049 
00052   void setTarget(IntMap& cols, StringMap units)
00053   {
00054     raColno  = cols[0];
00055     decColno = cols[1];
00056 
00057     // AST will calculate angles in radians, so we need the conversion
00058     // factors for the required units in the schema
00059     Converter conv;
00060     raFact  = conv.getFactor("RADIANS", units[0]);
00061     decFact = conv.getFactor("RADIANS", units[1]);
00062   }
00063 
00065   void doit2(TableData<DataType>& inpData, TableData<DataType>& data, int row1, int row2)
00066   {
00067     double pi = M_PI;
00068     string filename = mFile.getFileName();
00069     double crval1,crval2;
00070 
00071     // Set up AST
00072     astBegin;
00073 
00074     // Create a new AST fits channel
00075     AstFitsChan *fitschan = astFitsChan( NULL, NULL, "" );
00076     AstFrameSet *wcsinfo0 = 0;
00077     AstFrameSet *wcsinfo1 = 0;
00078     AstFrameSet *wcsinfo2 = 0;
00079     AstFrameSet *wcsinfo3 = 0;
00080 
00081     for (int hduNo = 2; hduNo <= mFile.getNumHdus(); ++hduNo)
00082     {
00083       int ext = hduNo - 2;
00084 
00085       // Move to extension on the FITS file
00086       mFile.movabsHdu(hduNo);
00087 
00088       // Put all cards in the header of this extension into the AST
00089       // fits channel
00090       int ncards = mFile.getNumCards();
00091       for (int n = 0; n < ncards; ++n) {
00092           char card[80];
00093           mFile.readCard(n, card);
00094           astPutFits(fitschan, card, 0);
00095       }
00096       // Make AST wcsinfo object
00097       astClear( fitschan, "Card" );
00098       mFile.readKey(FitsFile::cCRVAL1,crval1);
00099       mFile.readKey(FitsFile::cCRVAL2,crval2);
00100       if (crval1 == 0 && crval2 == 0) {
00101           log.addError("Could not read WCS info for " + filename);
00102       } else {
00103           if (ext == 0) {
00104               wcsinfo0 = (AstFrameSet*)astRead(fitschan);
00105           } else if (ext == 1) {
00106               wcsinfo1 = (AstFrameSet*)astRead(fitschan);
00107           } else if (ext == 2) {
00108               wcsinfo2 = (AstFrameSet*)astRead(fitschan);
00109           } else if (ext == 3) {
00110               wcsinfo3 = (AstFrameSet*)astRead(fitschan);
00111           }
00112       }
00113     }
00114 
00115     // Use these arrays for AST input
00116     double xpix[1], ypix[1], xsky[1], ysky[1];
00117 
00118     for (int rowNo = row1; rowNo < row2; ++rowNo)
00119     {
00120       // Get the FITS extension number for the data in this row. Note
00121       // that the extension number is assumed to be in the fitsio
00122       // convention
00123       Numeric value;
00124       data.value(extnumColno, rowNo, value);
00125 
00126       int extNum = (int)value;
00127 
00128       if (crval1 != 0 || crval2 != 0)
00129       {
00130         // Input X and Y
00131         //double xpix, ypix;
00132         inpData.value(xColno, rowNo, xpix[0]);
00133         inpData.value(yColno, rowNo, ypix[0]);
00134 
00135         // Get the sky coordinates
00136         // Note these will be in radians. Angles can also be negative.
00137         if (extNum == 2)
00138         {
00139           astTran2(wcsinfo0, 1, xpix, ypix, 1, xsky, ysky);
00140         }
00141         else if (extNum == 3)
00142         {
00143           astTran2(wcsinfo1, 1, xpix, ypix, 1, xsky, ysky);
00144         }
00145         else if (extNum == 4)
00146         {
00147           astTran2(wcsinfo2, 1, xpix, ypix, 1, xsky, ysky);
00148         }
00149         else if (extNum == 5)
00150         {
00151           astTran2(wcsinfo3, 1, xpix, ypix, 1, xsky, ysky);
00152         }
00153 
00154         // Make sure all RAs are in the range 0 to 2*pi
00155         if (xsky[0] < 0) xsky[0] += 2 * pi;
00156 
00157         Numeric ra = raFact * xsky[0];
00158         Numeric dec = decFact * ysky[0];
00159 
00160         data.assign(raColno, rowNo, ra);
00161         data.assign(decColno, rowNo, dec);
00162       }
00163     }
00164     // Finshed with AST
00165     astEnd;
00166   }
00167 
00168   // No simple data model available
00169   void doit(TableData<DataType>& data, int row1, int row2) { }
00170 
00171 private:
00172   FitsFile mFile;
00173   int extnumColno, raColno, decColno, xColno, yColno;
00174   int extnumTblno, xTblno, yTblno;
00175   double decFact, raFact;
00176   Logger log;
00177 };
00178 //-----------------------------------------------------------------------------
00179 #endif
00180 //-----------------------------------------------------------------------------
00181 // Change log:
00182 //
00183 //  7-Jun-2005, ETWS: Original version.
00184 //  7-Apr-2008, ETWS: Upgraded to use new detection table layout.

Generated on Thu Apr 2 21:52:16 2009 for WfcamSrc by  doxygen 1.5.2