Changeset 3788 in Sophya for trunk/Cosmo/RadioBeam/calcpk2.cc
- Timestamp:
- Jun 25, 2010, 7:35:17 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/RadioBeam/calcpk2.cc
r3787 r3788 7 7 R. Ansari , C. Magneville - Juin 2010 8 8 9 Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPk [PixNoiseLevel] 9 Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPk 10 [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr] 10 11 --------------------------------------------------------------- */ 11 12 … … 20 21 #include "specpk.h" 21 22 #include "histats.h" 23 #include "vector3d.h" 22 24 23 25 #include "qhist.h" 24 26 #include "lobe.h" 25 27 #include "cubedef.h" 28 #include "fgndsub.h" 29 #include "radutil.h" 26 30 27 31 #include "histinit.h" … … 32 36 33 37 typedef ThSDR48RandGen RandomGenerator ; 34 //--- Declaration des fonctions35 TArray<r_4> CleanForeground(TArray<r_4>& maplss, TArray<r_4>& mapsync, double freq0, double dfreq,36 TArray<r_8>& synctemp, TArray<r_8>& specidx);37 38 38 39 //------------------------------------------------------------------------- … … 43 44 { 44 45 if (narg<6) { 45 cout << " Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync OutPk [PixNoiseLevel] " << endl; 46 cout << " Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync OutPk \n" 47 << " [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr]" << endl; 46 48 return 1; 47 49 } … … 61 63 fgaddnoise=true; 62 64 } 65 66 bool fgcorrbeam=true; 67 double tbeamarcmin=30.; 68 if (narg>7) { 69 tbeamarcmin=atof(arg[7]); 70 if (tbeamarcmin<1.e-6) fgcorrbeam=false; 71 } 72 bool fgclnsrc=true; 73 double nsigsrc=5.; 74 if (narg>8) { 75 nsigsrc=atof(arg[8]); 76 if (nsigsrc<1.e-6) fgclnsrc=false; 77 } 63 78 64 65 TArray<r_4> inmaplss, inmapsync; 66 const char * tits[2]={"LSS", "Sync"}; 79 TArray<r_4> maplss, mapsync; 80 const char * tits[2]={"LSS", "Sync/RadioSrc"}; 67 81 for(int ks=0; ks<2; ks++) { 68 82 string& ppfname=inppflss; 69 83 r_4 rfac=rfaclss; 70 TArray<r_4>* inmap=& inmaplss;71 if (ks==1) { ppfname=inppfsync; rfac=rfacsync; inmap=& inmapsync; }84 TArray<r_4>* inmap=&maplss; 85 if (ks==1) { ppfname=inppfsync; rfac=rfacsync; inmap=&mapsync; } 72 86 cout << "calcpk2[" << ks+1 << "] : reading 3D map " << tits[ks] << " from file " << ppfname 73 87 << " RenormFactor=" << rfac << endl; … … 82 96 } 83 97 98 bool smo; 99 if (!maplss.CompareSizes(mapsync,smo) ) { 100 cout << " calcpk2/ERROR sizes " << endl; 101 maplss.Show(); mapsync.Show(); 102 return 99; 103 } 104 105 TArray<r_4> skycube(mapsync); 106 skycube += maplss; 107 84 108 if (fgaddnoise) { 85 cout << " calcpk2: adding noise to LSS inputcube ... " << endl;86 BeamEffect::AddNoise( inmaplss, pixsignoise);109 cout << " calcpk2: adding noise to skycube cube ... " << endl; 110 BeamEffect::AddNoise(skycube, pixsignoise); 87 111 } 88 112 89 tm.Split(" After read ");90 TArray<r_8> synctemp, specidx;91 cout << "calcpk2[3] : calling CleanForeground(...) " << endl;92 double freq0 = Freq0MHz;93 double dfreq = FreqSizeMHz/(double)NFreq;94 TArray<r_4> inmap = CleanForeground(inmaplss, inmapsync, freq0, dfreq, synctemp, specidx);95 113 double mean, sigma; 96 MeanSigma(inmap, mean, sigma); 97 cout << " After cleaning: Mean=" << mean << " Sigma=" << sigma << endl; 114 MeanSigma(skycube, mean, sigma); 115 cout << " input sky cube : Mean=" << mean << " Sigma=" << sigma << endl; 116 tm.Split(" After input "); 117 118 H21Conversions conv; 119 conv.setFrequency(Freq0MHz); 120 double lambda = conv.getLambda(); 121 Four2DResponse arep(2, InterfArrayDiametre/lambda, InterfArrayDiametre/lambda); 122 double DoL = 1.22/ArcminToRadian(tbeamarcmin); 123 Four2DResponse tbeam(2, DoL, DoL ); 124 ForegroundCleaner cleaner(arep, tbeam, skycube); 125 if (fgcorrbeam) { 126 cout << "calcpk2[3.a] : calling cleaner.BeamCorrections() for target beam (" << tbeamarcmin << " arcmin)" 127 << " Diam/Lambda=" << DoL << endl; 128 cleaner.BeamCorrections(); 129 } 130 if (fgclnsrc) { 131 cout << "calcpk2[3.b] : calling cleaner.CleanPointSources() with threshold NSigma=" << nsigsrc << endl; 132 cleaner.CleanPointSources(nsigsrc); 133 } 134 135 cout << "calcpk2[4] : calling cleaner.extractLSSCube(...) " << endl; 136 TArray<r_4> synctemp, specidx; 137 TArray<r_4> exlss = cleaner.extractLSSCube(synctemp, specidx); 138 139 MeanSigma(exlss, mean, sigma); 140 cout << " After cleaning/extractLSS: Mean=" << mean << " Sigma=" << sigma << endl; 98 141 tm.Split(" After CleanForeground"); 99 142 100 cout << "calcpk2[ 4] : computing 3D Fourier coefficients ... " << endl;143 cout << "calcpk2[5] : computing 3D Fourier coefficients ... " << endl; 101 144 FFTWServer ffts; 102 145 TArray< complex<r_4> > four3d; 103 ffts.FFTForward( inmap, four3d);146 ffts.FFTForward(exlss, four3d); 104 147 tm.Split(" After FFTForward "); 105 148 106 cout << "calcpk2[ 5] : computing power spectrum ... " << endl;149 cout << "calcpk2[6] : computing power spectrum ... " << endl; 107 150 RandomGenerator rg; 108 151 Four3DPk pkc(four3d, rg); … … 112 155 tm.Split(" Done ComputePk "); 113 156 114 cout << "calcpk2[ 4] : writing profile P(k) and foreground mapsto " << outname << endl;157 cout << "calcpk2[7.a] : writing profile P(k) to " << outname << endl; 115 158 POutPersist po(outname); 116 po << PPFNameTag("Pk") << hp; 117 po << PPFNameTag("Tsync") << synctemp; 118 po << PPFNameTag("async") << specidx; 159 po << hp; 160 outname = "fgm_" + outname; 161 cout << "calcpk2[7.b] : writing foreground maps to " << outname << endl; 162 POutPersist pom(outname); 163 pom << PPFNameTag("Tsync") << synctemp; 164 pom << PPFNameTag("async") << specidx; 119 165 120 166 } // End of try bloc … … 132 178 rc = 97; 133 179 } 134 cout << " ==== End of calcpk .cc program Rc= " << rc << endl;180 cout << " ==== End of calcpk2.cc program Rc= " << rc << endl; 135 181 return rc; 136 182 } 137 183 138 184 139 /* --Fonction-- */140 TArray<r_4> CleanForeground(TArray<r_4>& maplss, TArray<r_4>& mapsync, double freq0, double dfreq,141 TArray<r_8>& synctemp, TArray<r_8>& specidx)142 // Inputs : maplss, mapsyc, freq0, dfreq143 // Outputs : synctemp, specidx (reconstructed foreground temperature and spectral index144 // Return_Array : foreground subtracted LSS signal145 {146 bool smo;147 if (!maplss.CompareSizes(mapsync,smo) ) {148 cout << " CleanForeground/ERROR sizes " << endl;149 maplss.Show(); mapsync.Show();150 throw ParmError("CleanForeground- maplss , mapsync not the same size !");151 }152 sa_size_t sz[5]; sz[0]=maplss.SizeX(); sz[1]=maplss.SizeY();153 synctemp.SetSize(2, sz);154 specidx.SetSize(2, sz);155 TArray<r_4>& omap=maplss;156 Vector vlnf(maplss.SizeZ());157 int nprt = 0;158 // double freq0 : Frequence premier index en k (MHz)159 // double dfreq : // largeur en frequence de chaque plan (Mhz)160 for(sa_size_t i=0; i<maplss.SizeX(); i++)161 for(sa_size_t j=0; j<maplss.SizeY(); j++) {162 r_8 s1, sx, sx2, sy, sxy;163 s1=sx=sx2=sy=sxy=0.;164 for(sa_size_t k=0; k<maplss.SizeZ(); k++) {165 double lnf=log((double)k*dfreq+freq0);166 vlnf(k)=lnf;167 double ttot=(r_8)(mapsync(i,j,k)+maplss(i,j,k));168 if (ttot < 1.e-5) continue;169 double lntt=log(ttot);170 s1+=1.; sx+=lnf; sx2+=(lnf*lnf);171 sy+=lntt; sxy+=(lnf*lntt);172 }173 double beta = (sx*sxy-sx2*sy)/(sx*sx-s1*sx2);174 double alpha = (s1*sxy-sx*sy)/(s1*sx2-sx*sx);175 double T0 = exp(beta+alpha*vlnf(0));176 if ((i%6==0)&&(j%7==0))177 cout << "CleanForeground[" << i << "," << j << "]: T0=" << T0 << " alpha=" << alpha178 << " (mapsync=" << mapsync(i,j,0) << " ... " << mapsync(i,j,125) << ")" << endl;179 synctemp(i,j) = T0;180 specidx(i,j) = alpha;181 for(sa_size_t k=0; k<maplss.SizeZ(); k++) {182 r_4 fittedtemp = (r_4)(exp(beta+alpha*vlnf(k)));183 omap(i,j,k) = mapsync(i,j,k)+maplss(i,j,k)-fittedtemp;184 }185 }186 return omap;187 }
Note:
See TracChangeset
for help on using the changeset viewer.