| 1 | /*  ------------------------ Projet BAORadio -------------------- 
 | 
|---|
| 2 |   Programme de fabrication d'un cube 3D (angles,fre) 
 | 
|---|
| 3 |   a partir du catalogue de source radio (NVSS) 
 | 
|---|
| 4 |     R. Ansari , C. Magneville - Juin 2010 
 | 
|---|
| 5 | 
 | 
|---|
| 6 |   Usage: srccat2cube CatalogFitsName Out3DPPFName [Out2DMapName]
 | 
|---|
| 7 | ---------------------------------------------------------------  */
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include "sopnamsp.h"
 | 
|---|
| 10 | #include "machdefs.h"
 | 
|---|
| 11 | #include <math.h>
 | 
|---|
| 12 | #include <iostream>
 | 
|---|
| 13 | #include <typeinfo>
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include "array.h"
 | 
|---|
| 16 | #include "histats.h"
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include "swfitsdtable.h"
 | 
|---|
| 19 | #include "fitshdtable.h"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "randr48.h"
 | 
|---|
| 22 | 
 | 
|---|
| 23 | #include "xastropack.h"     // Pour faire les conversions de coordonnees celestes
 | 
|---|
| 24 | 
 | 
|---|
| 25 | #include "radutil.h"
 | 
|---|
| 26 | 
 | 
|---|
| 27 | // Pour l'initialisation des modules 
 | 
|---|
| 28 | #include "tarrinit.h"
 | 
|---|
| 29 | #include "histinit.h"
 | 
|---|
| 30 | #include "fiosinit.h"     
 | 
|---|
| 31 | 
 | 
|---|
| 32 | #include "timing.h"
 | 
|---|
| 33 | #include "ctimer.h"
 | 
|---|
| 34 | 
 | 
|---|
| 35 | #include "cubedef.h"
 | 
|---|
| 36 | 
 | 
|---|
| 37 | //----------------------------------------------------------------------------
 | 
|---|
| 38 | //----------------------------------------------------------------------------   
 | 
|---|
| 39 | int main(int narg, char* arg[])
 | 
|---|
| 40 | {
 | 
|---|
| 41 |   // Sophya modules initialization
 | 
|---|
| 42 |   TArrayInitiator  _inia;
 | 
|---|
| 43 |   HiStatsInitiator  _inih;
 | 
|---|
| 44 |   FitsIOServerInitiator  _inif;
 | 
|---|
| 45 |   //------- AU LIEU DE ------>  SophyaInit();  
 | 
|---|
| 46 | 
 | 
|---|
| 47 |   InitTim();   // Initializing the CPU timer
 | 
|---|
| 48 |   Timer tm("srcat2cube");
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   if (narg < 3) {
 | 
|---|
| 51 |     cout << "Usage: srccat2cube NVSS_CatalogFitsName Out3DPPFName [Out2DMapName]\n" << endl;
 | 
|---|
| 52 |     return 1;
 | 
|---|
| 53 |   }
 | 
|---|
| 54 | 
 | 
|---|
| 55 | 
 | 
|---|
| 56 |   // decodage arguments 
 | 
|---|
| 57 |   string outname = arg[2];
 | 
|---|
| 58 |   string inname = arg[1];
 | 
|---|
| 59 |   int rc = 91;
 | 
|---|
| 60 | 
 | 
|---|
| 61 |   cout << " ====== srccat2cube :   Input NVSS catalog name= " << inname << " OutName=" << outname;
 | 
|---|
| 62 |   bool fginmap=true;
 | 
|---|
| 63 |   try {
 | 
|---|
| 64 |     DataTable nvss;
 | 
|---|
| 65 |     cout << "srccat2cube[1]: reading NVSS catalog from " << inname << endl;
 | 
|---|
| 66 |     {
 | 
|---|
| 67 |       FitsInOutFile fis(inname, FitsInOutFile::Fits_RO);
 | 
|---|
| 68 |       fis >> nvss;
 | 
|---|
| 69 |     }
 | 
|---|
| 70 |     cout << nvss;
 | 
|---|
| 71 |     sa_size_t idxa = nvss.IndexNom("C_RAJ2000");
 | 
|---|
| 72 |     sa_size_t idxd = nvss.IndexNom("C_DEJ2000");
 | 
|---|
| 73 |     sa_size_t idxf = nvss.IndexNom("S1_4");
 | 
|---|
| 74 |     cout << " ... Index Alpha: " << idxa << " Delta: " << idxd << " Flux: " << idxf << endl;
 | 
|---|
| 75 | 
 | 
|---|
| 76 |     TArray<r_4> omap(NPhi,NTheta);
 | 
|---|
| 77 |     double tet0 = Theta0Degre; 
 | 
|---|
| 78 |     double phi0 = Phi0Degre; 
 | 
|---|
| 79 |     double tetmax = tet0+ThetaSizeDegre;
 | 
|---|
| 80 |     double phimax = phi0+PhiSizeDegre;
 | 
|---|
| 81 | 
 | 
|---|
| 82 |     cout << "srccat2cube[2]: projecting sources to map ..." << endl;
 | 
|---|
| 83 | 
 | 
|---|
| 84 |     sa_size_t srccnt=0;
 | 
|---|
| 85 |     double meanflx=0.;
 | 
|---|
| 86 |     double flxmin=9.e99;
 | 
|---|
| 87 |     double flxmax=-9.e99;
 | 
|---|
| 88 | 
 | 
|---|
| 89 |     double dtet = ThetaSizeDegre/(double)NTheta;
 | 
|---|
| 90 |     double dphi = PhiSizeDegre/(double)NPhi;
 | 
|---|
| 91 |     for (sa_size_t n=0; n<nvss.NRows(); n++)  {
 | 
|---|
| 92 |       r_8* pline=nvss.GetLineD(n);
 | 
|---|
| 93 |       double alpha=pline[idxa];  // alpha en degre
 | 
|---|
| 94 |       double delta=pline[idxd];  // delta en degre 
 | 
|---|
| 95 |       double flx=pline[idxf]*1.e-3;  // flux en Jy
 | 
|---|
| 96 |       double tet = 90.-delta;
 | 
|---|
| 97 |       double phi = alpha;
 | 
|---|
| 98 |       sa_size_t i = (phi-phi0)/dphi;
 | 
|---|
| 99 |       sa_size_t j = (tet-tet0)/dtet;
 | 
|---|
| 100 |       if ((i<0)||(i>=omap.SizeX()))  continue;
 | 
|---|
| 101 |       if ((j<0)||(j>=omap.SizeY()))  continue;
 | 
|---|
| 102 |       omap(i,j) += flx;
 | 
|---|
| 103 |       srccnt++;   meanflx+=flx;
 | 
|---|
| 104 |       if (flx<flxmin) flxmin=flx;
 | 
|---|
| 105 |       if (flx>flxmax) flxmax=flx;
 | 
|---|
| 106 |     }
 | 
|---|
| 107 | 
 | 
|---|
| 108 |     cout << "srccat2cube[3]: Output rectangular map computed " << endl;
 | 
|---|
| 109 |     meanflx /= (double)srccnt;
 | 
|---|
| 110 |     cout << " SrcCount in map: " << srccnt << " -> meanFlx=" << meanflx << " min=" << flxmin 
 | 
|---|
| 111 |          << " max=" << flxmax << " Jy" << endl;
 | 
|---|
| 112 | 
 | 
|---|
| 113 |     double mean, sigma;
 | 
|---|
| 114 |     MeanSigma(omap, mean, sigma);
 | 
|---|
| 115 |     cout << " Src Map : Mean=" << mean << " Sigma=" << sigma << "  Jy - Sizes:" << endl;
 | 
|---|
| 116 |     omap.Show(); 
 | 
|---|
| 117 | 
 | 
|---|
| 118 |     H21Conversions conv;
 | 
|---|
| 119 |     conv.setRedshift(0.);
 | 
|---|
| 120 |     conv.setOmegaPixDeg2(dphi*dtet);
 | 
|---|
| 121 |     cout << "srccat2cube[4] H21Conversions,  OmegaPix=" << conv.getOmegaPix() << " srad"  
 | 
|---|
| 122 |          << " toKelvin(1 Jy)= " << conv.toKelvin(1.) << endl;
 | 
|---|
| 123 |     omap *= (r_4)conv.toKelvin(1.);
 | 
|---|
| 124 |     MeanSigma(omap, mean, sigma);
 | 
|---|
| 125 |     cout << " After conversion  : Mean=" << mean << " Sigma=" << sigma << "  Kelvin " << endl;
 | 
|---|
| 126 |     
 | 
|---|
| 127 |     if (narg > 3) {
 | 
|---|
| 128 |       string ppfname = arg[3];
 | 
|---|
| 129 |       cout << " srccat2cube[4]: Saving inmap/outmap tp PPF file-> " << ppfname << endl;
 | 
|---|
| 130 |       POutPersist po(ppfname);
 | 
|---|
| 131 |       po << PPFNameTag("omap") << omap;
 | 
|---|
| 132 |     }
 | 
|---|
| 133 | 
 | 
|---|
| 134 |     TArray<r_4> ocube(NPhi,NTheta,NFreq);
 | 
|---|
| 135 | 
 | 
|---|
| 136 |     double infreq = 1420.; //  frequence de reference du flux des sources 
 | 
|---|
| 137 |     double freq0 = Freq0MHz;  // Freq0 du cube de sortie 
 | 
|---|
| 138 |     double dfreq = FreqSizeMHz/(double)NFreq;  
 | 
|---|
| 139 | 
 | 
|---|
| 140 |     ThSDR48RandGen rg;
 | 
|---|
| 141 |     for (sa_size_t j=0; j<ocube.SizeY(); j++)  {
 | 
|---|
| 142 |       for (sa_size_t i=0; i<ocube.SizeX(); i++)  {
 | 
|---|
| 143 |         double freqexpo = rg.Gaussian(sigPLidxSrc,PLidxSrc);
 | 
|---|
| 144 |         for (sa_size_t k=0; k<ocube.SizeZ(); k++)  {
 | 
|---|
| 145 |           double rapfreq = pow((freq0+k*dfreq)/infreq, freqexpo);
 | 
|---|
| 146 |           ocube(i,j,k) = AmpPL1*omap(i,j)*rapfreq;
 | 
|---|
| 147 |         }
 | 
|---|
| 148 |       }
 | 
|---|
| 149 |     }
 | 
|---|
| 150 |     
 | 
|---|
| 151 |     // On sauve le cube de sortie
 | 
|---|
| 152 |     {
 | 
|---|
| 153 |       cout << " srccat2cube[5]: Saving output cube to -> " << outname << endl;
 | 
|---|
| 154 |       POutPersist poc(outname);
 | 
|---|
| 155 |       poc << ocube;
 | 
|---|
| 156 |     }
 | 
|---|
| 157 | 
 | 
|---|
| 158 |     rc = 0;
 | 
|---|
| 159 |   }
 | 
|---|
| 160 |   catch (PThrowable& exc) {
 | 
|---|
| 161 |     cerr << " srccat2cube.cc catched Exception " << exc.Msg() << endl;
 | 
|---|
| 162 |     rc = 77;
 | 
|---|
| 163 |   }  
 | 
|---|
| 164 |   catch (std::exception& sex) {
 | 
|---|
| 165 |     cerr << "\n srccat2cube.cc std::exception :" 
 | 
|---|
| 166 |          << (string)typeid(sex).name() << "\n msg= " 
 | 
|---|
| 167 |          << sex.what() << endl;
 | 
|---|
| 168 |   }
 | 
|---|
| 169 |   catch (...) {
 | 
|---|
| 170 |     cerr << " srccat2cube.cc catched unknown (...) exception  " << endl; 
 | 
|---|
| 171 |     rc = 78; 
 | 
|---|
| 172 |   } 
 | 
|---|
| 173 | 
 | 
|---|
| 174 |   cout << ">>>> srccat2cube[9] ------- FIN ----------- Rc=" << rc << endl;
 | 
|---|
| 175 |   return rc;
 | 
|---|
| 176 | }
 | 
|---|
| 177 | 
 | 
|---|
| 178 | 
 | 
|---|