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 | sa_size_t idxmajax = nvss.IndexNom("MajAxis");
|
---|
75 | sa_size_t idxminax = nvss.IndexNom("MinAxis");
|
---|
76 |
|
---|
77 | cout << " ... Index Alpha: " << idxa << " Delta: " << idxd << " Flux: " << idxf
|
---|
78 | << " MajAxis: " << idxmajax << " MajAxis: " << idxminax << endl;
|
---|
79 |
|
---|
80 | TArray<r_4> omap(NPhi,NTheta);
|
---|
81 | double tet0 = Theta0Degre;
|
---|
82 | double phi0 = Phi0Degre;
|
---|
83 | double tetmax = tet0+ThetaSizeDegre;
|
---|
84 | double phimax = phi0+PhiSizeDegre;
|
---|
85 |
|
---|
86 | cout << "srccat2cube[2]: projecting sources to map ..." << endl;
|
---|
87 |
|
---|
88 | sa_size_t srccnt=0;
|
---|
89 | sa_size_t extendedsrccnt=0;
|
---|
90 |
|
---|
91 | double meanflx=0.;
|
---|
92 | double flxmin=9.e99;
|
---|
93 | double flxmax=-9.e99;
|
---|
94 |
|
---|
95 | double dtet = ThetaSizeDegre/(double)NTheta;
|
---|
96 | double dphi = PhiSizeDegre/(double)NPhi;
|
---|
97 | double mpixsizarcmin = 0.5*(dtet+dphi)*60.;
|
---|
98 |
|
---|
99 | for (sa_size_t n=0; n<nvss.NRows(); n++) {
|
---|
100 | r_8* pline=nvss.GetLineD(n);
|
---|
101 | double alpha=pline[idxa]; // alpha en degre
|
---|
102 | double delta=pline[idxd]; // delta en degre
|
---|
103 | double flx=pline[idxf]*1.e-3; // flux en Jy
|
---|
104 | double srcszarcmin=0.5*(pline[idxmajax]+pline[idxminax])/60.; // taille (extension de la source en arcmin
|
---|
105 | if (srcszarcmin<1.) srcszarcmin=1.;
|
---|
106 | double tet = 90.-delta;
|
---|
107 | double phi = alpha;
|
---|
108 | sa_size_t i = (phi-phi0)/dphi;
|
---|
109 | sa_size_t j = (tet-tet0)/dtet;
|
---|
110 | if ((i<0)||(i>=omap.SizeX())) continue;
|
---|
111 | if ((j<0)||(j>=omap.SizeY())) continue;
|
---|
112 | double srat = (4.*srcszarcmin*srcszarcmin)/(mpixsizarcmin*mpixsizarcmin);
|
---|
113 | if (srcszarcmin<(0.5*mpixsizarcmin)) { // Toute l'energie dans un seul pixel
|
---|
114 | omap(i,j) += flx*srat;
|
---|
115 | }
|
---|
116 | else { // on repartit l'energie de la source dans plusieurs pixels
|
---|
117 | extendedsrccnt++;
|
---|
118 | for(int bi=-1;bi<=1;bi++) {
|
---|
119 | for(sa_size_t bj=-1; bj<=1; bj++) {
|
---|
120 | sa_size_t ii = (phi-phi0+bi*srcszarcmin/60.)/dphi;
|
---|
121 | sa_size_t jj = (tet-tet0+bj*srcszarcmin/60.)/dtet;
|
---|
122 | if ((ii<0)||(ii>=omap.SizeX())) continue;
|
---|
123 | if ((jj<0)||(jj>=omap.SizeY())) continue;
|
---|
124 | if ((bi==0)&&(bj==0)) omap(ii,jj) += flx*srat*0.3;
|
---|
125 | else omap(ii,jj) += flx*srat*0.7/8.;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | srccnt++; meanflx+=flx;
|
---|
130 | if (flx<flxmin) flxmin=flx;
|
---|
131 | if (flx>flxmax) flxmax=flx;
|
---|
132 | }
|
---|
133 |
|
---|
134 | cout << "srccat2cube[3]: Output rectangular map computed " << endl;
|
---|
135 | meanflx /= (double)srccnt;
|
---|
136 | cout << " SrcCount in map: " << srccnt << " extended=" << extendedsrccnt
|
---|
137 | << " -> meanFlx=" << meanflx << " min=" << flxmin
|
---|
138 | << " max=" << flxmax << " Jy" << endl;
|
---|
139 |
|
---|
140 | double mean, sigma;
|
---|
141 | r_4 mintemp, maxtemp;
|
---|
142 | omap.MinMax(mintemp, maxtemp);
|
---|
143 | MeanSigma(omap, mean, sigma);
|
---|
144 | cout << " Src Map : Mean=" << mean << " Sigma=" << sigma << " Jy - Sizes:" << endl;
|
---|
145 | omap.Show();
|
---|
146 |
|
---|
147 | H21Conversions conv;
|
---|
148 | conv.setRedshift(0.);
|
---|
149 | conv.setOmegaPixDeg2(dphi*dtet);
|
---|
150 | cout << "srccat2cube[4] H21Conversions, OmegaPix=" << conv.getOmegaPix() << " srad"
|
---|
151 | << " toKelvin(1 Jy)= " << conv.toKelvin(1.) << endl;
|
---|
152 | omap *= (r_4)conv.toKelvin(1.);
|
---|
153 | MeanSigma(omap, mean, sigma);
|
---|
154 | cout << " After conversion : Mean=" << mean << " Sigma=" << sigma << " Kelvin " << endl;
|
---|
155 |
|
---|
156 | if (narg > 3) {
|
---|
157 | string ppfname = arg[3];
|
---|
158 | cout << " srccat2cube[4]: Saving inmap/outmap tp PPF file-> " << ppfname << endl;
|
---|
159 | POutPersist po(ppfname);
|
---|
160 | po << PPFNameTag("omap") << omap;
|
---|
161 | }
|
---|
162 |
|
---|
163 | TArray<r_4> ocube(NPhi,NTheta,NFreq);
|
---|
164 |
|
---|
165 | double infreq = 1420.; // frequence de reference du flux des sources
|
---|
166 | double freq0 = Freq0MHz; // Freq0 du cube de sortie
|
---|
167 | double dfreq = FreqSizeMHz/(double)NFreq;
|
---|
168 |
|
---|
169 | ThSDR48RandGen rg;
|
---|
170 | for (sa_size_t j=0; j<ocube.SizeY(); j++) {
|
---|
171 | for (sa_size_t i=0; i<ocube.SizeX(); i++) {
|
---|
172 | double freqexpo = rg.Gaussian(sigPLidxSrc,PLidxSrc);
|
---|
173 | for (sa_size_t k=0; k<ocube.SizeZ(); k++) {
|
---|
174 | double rapfreq = pow((freq0+k*dfreq)/infreq, freqexpo);
|
---|
175 | ocube(i,j,k) = AmpPL1*omap(i,j)*rapfreq;
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | // On sauve le cube de sortie
|
---|
181 | {
|
---|
182 | cout << " srccat2cube[5]: Saving output cube to -> " << outname << endl;
|
---|
183 | POutPersist poc(outname);
|
---|
184 | poc << ocube;
|
---|
185 | }
|
---|
186 |
|
---|
187 | rc = 0;
|
---|
188 | }
|
---|
189 | catch (PThrowable& exc) {
|
---|
190 | cerr << " srccat2cube.cc catched Exception " << exc.Msg() << endl;
|
---|
191 | rc = 77;
|
---|
192 | }
|
---|
193 | catch (std::exception& sex) {
|
---|
194 | cerr << "\n srccat2cube.cc std::exception :"
|
---|
195 | << (string)typeid(sex).name() << "\n msg= "
|
---|
196 | << sex.what() << endl;
|
---|
197 | }
|
---|
198 | catch (...) {
|
---|
199 | cerr << " srccat2cube.cc catched unknown (...) exception " << endl;
|
---|
200 | rc = 78;
|
---|
201 | }
|
---|
202 |
|
---|
203 | cout << ">>>> srccat2cube[9] ------- FIN ----------- Rc=" << rc << endl;
|
---|
204 | return rc;
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|