Changeset 3829 in Sophya for trunk/Cosmo/RadioBeam/srcat2cube.cc
- Timestamp:
- Aug 3, 2010, 6:38:00 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/RadioBeam/srcat2cube.cc
r3825 r3829 34 34 35 35 #include "cubedef.h" 36 37 //---------------- 38 int nvssTocube(DataTable& nvss, TArray<r_4>& omap, TArray<r_4>& cube); 39 int north20Tocube(DataTable& nor, TArray<r_4>& omap, TArray<r_4>& cube); 36 40 37 41 //---------------------------------------------------------------------------- … … 48 52 Timer tm("srcat2cube"); 49 53 50 if (narg < 3) {51 cout << "Usage: srccat2cube NVSS_CatalogFitsName Out3DPPFName [Out2DMapName]\n" << endl;54 if (narg < 4) { 55 cout << "Usage: srccat2cube -nvss/-north20 CatalogFitsName Out3DPPFName [Out2DMapName]\n" << endl; 52 56 return 1; 53 57 } … … 55 59 56 60 // decodage arguments 57 string outname = arg[2]; 58 string inname = arg[1]; 61 62 string copt=arg[1]; 63 string outname=arg[3]; 64 string inname=arg[2]; 59 65 int rc = 91; 60 66 61 cout << " ====== srccat2cube : Input NVSScatalog name= " << inname << " OutName=" << outname;67 cout << " ====== srccat2cube : Input catalog name= " << inname << " OutName=" << outname; 62 68 bool fginmap=true; 63 69 try { 64 DataTable nvss;65 cout << "srccat2cube[1]: reading NVSScatalog from " << inname << endl;70 DataTable cat; 71 cout << "srccat2cube[1]: reading source catalog from " << inname << endl; 66 72 { 67 73 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 74 fis >> cat; 75 } 76 cout << cat ; 80 77 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; 78 TArray<r_4> ocube(NPhi,NTheta,NFreq); 79 if (copt=="-nvss") nvssTocube(cat, omap, ocube); 80 else north20Tocube(cat, omap, ocube); 155 81 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; 82 { // On sauve le cube de sortie 83 cout << " srccat2cube[7]: Saving output cube to -> " << outname << endl; 183 84 POutPersist poc(outname); 184 85 poc << ocube; 185 86 } 186 87 88 if (narg > 4) { 89 string ppfname = arg[4]; 90 cout << " srccat2cube[8]: saving 2D source map to PPF file-> " << ppfname << endl; 91 POutPersist po(ppfname); 92 po << omap; 93 } 187 94 rc = 0; 188 95 } … … 206 113 207 114 115 116 /* -- Fonction -- */ 117 int nvssTocube(DataTable& nvss, TArray<r_4>& omap, TArray<r_4>& ocube) 118 { 119 sa_size_t idxa = nvss.IndexNom("C_RAJ2000"); 120 sa_size_t idxd = nvss.IndexNom("C_DEJ2000"); 121 sa_size_t idxf = nvss.IndexNom("S1_4"); 122 sa_size_t idxmajax = nvss.IndexNom("MajAxis"); 123 sa_size_t idxminax = nvss.IndexNom("MinAxis"); 124 125 cout << " NVSS catalog ... Index Alpha: " << idxa << " Delta: " << idxd << " Flux: " << idxf 126 << " MajAxis: " << idxmajax << " MajAxis: " << idxminax << endl; 127 128 double tet0 = Theta0Degre; 129 double phi0 = Phi0Degre; 130 double tetmax = tet0+ThetaSizeDegre; 131 double phimax = phi0+PhiSizeDegre; 132 133 cout << "srccat2cube/NVSS[2]: projecting sources to map ..." << endl; 134 135 sa_size_t srccnt=0; 136 sa_size_t extendedsrccnt=0; 137 138 double meanflx=0.; 139 double flxmin=9.e99; 140 double flxmax=-9.e99; 141 142 double dtet = ThetaSizeDegre/(double)NTheta; 143 double dphi = PhiSizeDegre/(double)NPhi; 144 double mpixsizarcmin = 0.5*(dtet+dphi)*60.; 145 146 for (sa_size_t n=0; n<nvss.NRows(); n++) { 147 r_8* pline=nvss.GetLineD(n); 148 double alpha=pline[idxa]; // alpha en degre 149 double delta=pline[idxd]; // delta en degre 150 double flx=pline[idxf]*1.e-3; // flux en Jy 151 double srcszarcmin=0.5*(pline[idxmajax]+pline[idxminax])/60.; // taille (extension de la source en arcmin 152 if (srcszarcmin<1.) srcszarcmin=1.; 153 double tet = 90.-delta; 154 double phi = alpha; 155 sa_size_t i = (phi-phi0)/dphi; 156 sa_size_t j = (tet-tet0)/dtet; 157 if ((i<0)||(i>=omap.SizeX())) continue; 158 if ((j<0)||(j>=omap.SizeY())) continue; 159 if (srcszarcmin<(0.5*mpixsizarcmin)) { // Toute l'energie dans un seul pixel 160 omap(i,j) += flx; 161 } 162 else { // on repartit l'energie de la source dans plusieurs pixels 163 extendedsrccnt++; 164 for(int bi=-1;bi<=1;bi++) { 165 for(sa_size_t bj=-1; bj<=1; bj++) { 166 sa_size_t ii = (phi-phi0+bi*srcszarcmin/60.)/dphi; 167 sa_size_t jj = (tet-tet0+bj*srcszarcmin/60.)/dtet; 168 if ((ii<0)||(ii>=omap.SizeX())) continue; 169 if ((jj<0)||(jj>=omap.SizeY())) continue; 170 if ((bi==0)&&(bj==0)) omap(ii,jj) += flx*0.3; 171 else omap(ii,jj) += flx*0.7/8.; 172 } 173 } 174 } 175 srccnt++; meanflx+=flx; 176 if (flx<flxmin) flxmin=flx; 177 if (flx>flxmax) flxmax=flx; 178 } 179 180 cout << "srccat2cube/NVSS[3]: Output rectangular map computed " << endl; 181 meanflx /= (double)srccnt; 182 cout << " SrcCount in map: " << srccnt << " extended=" << extendedsrccnt 183 << " -> meanFlx=" << meanflx << " min=" << flxmin 184 << " max=" << flxmax << " Jy" << endl; 185 186 double mean, sigma; 187 r_4 minjy, maxjy; 188 omap.MinMax(minjy, maxjy); 189 MeanSigma(omap, mean, sigma); 190 cout << " Src Map : Mean=" << mean << " Sigma=" << sigma << " Min=" << minjy << " Max=" << maxjy << " Jansky ; Sizes:" << endl; 191 omap.Show(); 192 193 H21Conversions conv; 194 conv.setRedshift(0.); 195 conv.setOmegaPixDeg2(dphi*dtet); 196 cout << "srccat2cube/NVSS[4] H21Conversions, OmegaPix=" << conv.getOmegaPix() << " srad" 197 << " toKelvin(1 Jy)= " << conv.toKelvin(1.) << endl; 198 omap *= (r_4)conv.toKelvin(1.); 199 MeanSigma(omap, mean, sigma); 200 r_4 minT, maxT; 201 omap.MinMax(minT, maxT); 202 cout << " NVSS/ After conversion : Mean=" << mean << " Sigma=" << sigma << " Min=" << minT 203 << " Max=" << maxT << " Kelvin " << endl; 204 205 double infreq = 1420.; // frequence de reference du flux des sources 206 double freq0 = Freq0MHz; // Freq0 du cube de sortie 207 double dfreq = FreqSizeMHz/(double)NFreq; 208 209 ThSDR48RandGen rg; 210 for (sa_size_t j=0; j<ocube.SizeY(); j++) { 211 for (sa_size_t i=0; i<ocube.SizeX(); i++) { 212 double freqexpo = rg.Gaussian(sigPLidxSrc,PLidxSrc); 213 for (sa_size_t k=0; k<ocube.SizeZ(); k++) { 214 double rapfreq = pow((freq0+k*dfreq)/infreq, freqexpo); 215 ocube(i,j,k) = AmpPL1*omap(i,j)*rapfreq; 216 } 217 } 218 } 219 cout << "srccat2cube/NVSS[5] data cube created from sources " << endl; 220 ocube.MinMax(minT, maxT); 221 MeanSigma(ocube, mean, sigma); 222 cout << "... Mean=" << mean << " Sigma=" << sigma << " Min=" << minT << " Max=" << maxT << " Kelvin" << endl; 223 224 return srccnt; 225 } 226 227 /* -- Fonction -- */ 228 int north20Tocube(DataTable& nor, TArray<r_4>& omap, TArray<r_4>& ocube) 229 { 230 231 sa_size_t idxa = nor.IndexNom("ra"); 232 sa_size_t idxd = nor.IndexNom("dec"); 233 sa_size_t idxf = nor.IndexNom("flux"); 234 sa_size_t idxslo = nor.IndexNom("SpLO"); 235 sa_size_t idxshi = nor.IndexNom("SpHI"); 236 237 cout << " North20cm catalog ... Index Alpha: " << idxa << " Delta: " << idxd << " Flux: " << idxf 238 << " SpLO: " << idxslo << " SpHI: " << idxshi << endl; 239 240 double tet0 = Theta0Degre; 241 double phi0 = Phi0Degre; 242 double tetmax = tet0+ThetaSizeDegre; 243 double phimax = phi0+PhiSizeDegre; 244 245 cout << "srccat2cube/North20[2]: projecting sources to map ..." << endl; 246 247 sa_size_t srccnt=0; 248 sa_size_t lowoksrccnt=0; 249 250 double meanflx=0.; 251 double flxmin=9.e99; 252 double flxmax=-9.e99; 253 254 double dtet = ThetaSizeDegre/(double)NTheta; 255 double dphi = PhiSizeDegre/(double)NPhi; 256 257 double infreq = 1420.; // frequence de reference du flux des sources 258 double freq0 = Freq0MHz; // Freq0 du cube de sortie 259 double dfreq = FreqSizeMHz/(double)NFreq; 260 261 for (sa_size_t n=0; n<nor.NRows(); n++) { 262 r_8* pline=nor.GetLineD(n); 263 double alpha=pline[idxa]; // alpha en degre 264 double delta=pline[idxd]; // delta en degre 265 double flx=pline[idxf]*1.e-3; // flux en Jy 266 double tet = 90.-delta; 267 double phi = alpha*360./24.; 268 sa_size_t i = (phi-phi0)/dphi; 269 sa_size_t j = (tet-tet0)/dtet; 270 if ((i<0)||(i>=omap.SizeX())) continue; 271 if ((j<0)||(j>=omap.SizeY())) continue; 272 omap(i,j) += flx; 273 srccnt++; meanflx+=flx; 274 if (flx<flxmin) flxmin=flx; 275 if (flx>flxmax) flxmax=flx; 276 double slo=pline[idxslo]; 277 if (slo<9.) { // source detected at 80 cm 278 lowoksrccnt++; 279 } 280 else slo=5.; 281 for (sa_size_t k=0; k<ocube.SizeZ(); k++) { 282 double rapfreq = pow((freq0+k*dfreq)/infreq, slo); 283 ocube(i,j,k) += flx*rapfreq; 284 } 285 } 286 287 cout << "srccat2cube/North20[3]: Output rectangular map computed " << endl; 288 meanflx /= (double)srccnt; 289 cout << " SrcCount in map: " << srccnt << " SpLowOK=" << lowoksrccnt 290 << " -> meanFlx=" << meanflx << " min=" << flxmin 291 << " max=" << flxmax << " Jy" << endl; 292 293 double mean, sigma; 294 r_4 minjy, maxjy; 295 omap.MinMax(minjy, maxjy); 296 MeanSigma(omap, mean, sigma); 297 cout << " Src Map : Mean=" << mean << " Sigma=" << sigma << " Min=" << minjy << " Max=" << maxjy << " Jansky" << endl; 298 299 ocube.MinMax(minjy, maxjy); 300 MeanSigma(ocube, mean, sigma); 301 cout << " Cube : Mean=" << mean << " Sigma=" << sigma << " Min=" << minjy << " Max=" << maxjy << " Jansky" << endl; 302 303 H21Conversions conv; 304 conv.setRedshift(0.); 305 conv.setOmegaPixDeg2(dphi*dtet); 306 cout << "srccat2cube/North20[4] H21Conversions, OmegaPix=" << conv.getOmegaPix() << " srad" 307 << " @1400MHz toKelvin(1 Jy)= " << conv.toKelvin(1.) << endl; 308 309 // Jansky to Kelvin conversion 310 for (sa_size_t k=0; k<ocube.SizeZ(); k++) { 311 conv.setFrequency(freq0+k*dfreq); 312 // cout << " DBG* Freq= " << freq0+k*dfreq << " -> toKelvin(1 Jy)= " << conv.toKelvin(1.) << endl; 313 ocube(Range::all(), Range::all(), Range(k)) *= (r_4)conv.toKelvin(1.); 314 } 315 cout << "srccat2cube/North20[5] data cube in Kelvin computed " << endl; 316 317 r_4 minT, maxT; 318 ocube.MinMax(minT, maxT); 319 MeanSigma(ocube, mean, sigma); 320 cout << "... Mean=" << mean << " Sigma=" << sigma << " Min=" << minT << " Max=" << maxT << " Kelvin" << endl; 321 322 return srccnt; 323 }
Note:
See TracChangeset
for help on using the changeset viewer.