Changeset 3788 in Sophya for trunk/Cosmo/RadioBeam
- Timestamp:
- Jun 25, 2010, 7:35:17 PM (15 years ago)
- Location:
- trunk/Cosmo/RadioBeam
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/RadioBeam/README
r3787 r3788 25 25 26 26 A.3/ List of other common files : 27 - fgndsub.h fgndsub.h : radio source, synchrotron subtraction class 28 - lobe.h lobe.cc : 2D (k_alpha, k_delta) beam effect on 3D sky cubes 27 29 - specpk.h specpk.cc : 3D power spectrum computation classes 28 - lobe.h lobe.cc : 2D (k_alpha, k_delta) beam effect on 3D sky cubes29 30 - mdish.h mdish.cc : Classes for representing Multi-Dish interferometer configurations 30 31 - radutil.h radutil.cc : utilitaire de conversion a 21 cm -
trunk/Cosmo/RadioBeam/applobe.cc
r3787 r3788 68 68 pin >> incube; 69 69 } 70 cout << incube;70 incube.Show(); 71 71 72 72 double dxdeg = ThetaSizeDegre/(double)NTheta; … … 85 85 86 86 cout << "applobe[2]: creating Four2DResponse and BeamEffect objects..." << endl; 87 // Dish de 64 m de diametre88 double Diametre = 64.;89 87 H21Conversions conv; 90 88 conv.setFrequency(Freq0MHz); 91 89 double lambda = conv.getLambda(); 92 Four2DResponse fresp(2, Diametre/lambda,Diametre/lambda);90 Four2DResponse fresp(2, InterfArrayDiametre/lambda, InterfArrayDiametre/lambda); 93 91 BeamEffect beam(fresp); 94 92 … … 96 94 beam.ApplyLobe3D(incube, dx, dy, Freq0MHz, dfreq); 97 95 98 cout << "applobe[4]: calling ReSample(incube, 0. 25, 0.25, 1.) ... " << endl;99 TArray< r_4 > outcube = beam.ReSample(incube, 0. 25, 0.25, 1.);96 cout << "applobe[4]: calling ReSample(incube, 0.5, 0.5, 1.) ... " << endl; 97 TArray< r_4 > outcube = beam.ReSample(incube, 0.5, 0.5, 1.); 100 98 101 cout << outcube;99 outcube.Show(); 102 100 MeanSigma(outcube, mean, sigma); 103 101 cout << " OutCube 3D- : Mean=" << mean << " Sigma=" << sigma << endl; -
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 } -
trunk/Cosmo/RadioBeam/cubedef.h
r3787 r3788 32 32 static double sigPLidxSrc = 0.15; // Sigma de la variation (gaussienne) de l'index 33 33 34 // Parametres pour la reponse en Fourier de l'instrument : 35 static double InterfArrayDiametre = 64.; 36 34 37 /* 35 38 static sa_size_t NTheta=256; -
trunk/Cosmo/RadioBeam/lobe.cc
r3787 r3788 17 17 } 18 18 19 /* --Methode-- */20 void BeamEffect::ApplyLobeK2D(TArray< complex<TF> >& fourAmp, double dkx, double dky, double lambda)21 // dx, dy en radians, lambda en metres22 {23 fresp_.setLambda(lambda);24 double kxx, kyy;25 for(sa_size_t ky=0; ky<fourAmp.SizeY(); ky++) {26 kyy = (ky>fourAmp.SizeY()/2) ? -(double)(fourAmp.SizeY()-ky)*dky : (double)ky*dky;27 for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) {28 kxx=(double)kx*dkx;29 fourAmp(kx, ky) *= complex<TF>(fresp_(kxx, kyy), 0.);30 }31 }32 return;33 }34 19 35 20 … … 52 37 ffts.FFTForward(slice, fourAmp); 53 38 conv.setFrequency(f0+kz*df); 54 ApplyLobeK2D(fourAmp, dkx, dky, conv.getLambda()); 39 fresp_.setLambda(conv.getLambda()); 40 ApplyLobeK2D(fresp_, fourAmp, dkx, dky); 55 41 ffts.FFTBackward(fourAmp, slice, true); 56 if (kz%10==0) cout << "BeamEffect::ApplyLobe3D() done kz=" << kz << " / a.SizeZ()=" << a.SizeZ() << endl; 42 if (kz%20==0) cout << "BeamEffect::ApplyLobe3D() done kz=" << kz << " / a.SizeZ()=" << a.SizeZ() << endl; 43 } 44 return; 45 } 46 47 /* --Methode-- */ 48 void BeamEffect::Correct2RefLobe(Four2DResponse& rep, TArray< TF >& a, double dx, double dy, double f0, double df) 49 // dx, dy en radioans, f0, df en MHz 50 { 51 Timer tm("BeamEffect::Correct2RefLobe"); 52 FFTWServer ffts(true); 53 ffts.setNormalize(true); 54 55 H21Conversions conv; 56 57 TArray< complex<TF> > fourAmp; 58 double dkx = DeuxPI/(double)a.SizeX()/dx; 59 double dky = DeuxPI/(double)a.SizeY()/dy; 60 61 for(sa_size_t kz=0; kz<a.SizeZ(); kz++) { 62 TArray< TF > slice( a(Range::all(), Range::all(), kz) ); 63 ffts.FFTForward(slice, fourAmp); 64 conv.setFrequency(f0+kz*df); 65 fresp_.setLambda(conv.getLambda()); 66 Four2DRespRatio rratio(fresp_, rep); 67 ApplyLobeK2D(rratio, fourAmp, dkx, dky); 68 ffts.FFTBackward(fourAmp, slice, true); 69 if (kz%20==0) cout << "BeamEffect::Correct2RefLobe() done kz=" << kz << " / a.SizeZ()=" << a.SizeZ() << endl; 70 } 71 return; 72 } 73 74 /* --Methode-- */ 75 void BeamEffect::ApplyLobeK2D(Four2DResponse& rep, TArray< complex<TF> >& fourAmp, double dkx, double dky) 76 // dx, dy en radians, lambda en metres 77 { 78 double kxx, kyy; 79 for(sa_size_t ky=0; ky<fourAmp.SizeY(); ky++) { 80 kyy = (ky>fourAmp.SizeY()/2) ? -(double)(fourAmp.SizeY()-ky)*dky : (double)ky*dky; 81 for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) { 82 kxx=(double)kx*dkx; 83 fourAmp(kx, ky) *= complex<TF>(rep(kxx, kyy), 0.); 84 } 57 85 } 58 86 return; -
trunk/Cosmo/RadioBeam/lobe.h
r3787 r3788 1 1 /* ------------------------ Projet BAORadio -------------------- 2 2 Calcul de l'effet de lobe sur Carte2D (angleX,angleY) et 3 cube 3D (angleX,angleY )3 cube 3D (angleX,angleY, frquences) 4 4 R. Ansari , C. Magneville - Juin 2010 5 5 --------------------------------------------------------------- */ … … 25 25 class BeamEffect { 26 26 public: 27 // Definition de l'objet avec la reponse en frequence de l'instrument 27 28 BeamEffect(Four2DResponse& resp); 28 void ApplyLobeK2D(TArray< complex<TF> >& f2d, double dkx, double dky, double lambda=1.);29 // Applique l'effet de lobe au cube 3D (2 angles, frequence), pour chaque plan de frequence successivement 29 30 void ApplyLobe3D(TArray< TF >& a, double dx, double dy, double f0, double df); 30 31 32 // Corrige de l'effet de l'effet de lobe, pour chaque plan de frequence, pour tout ramener au lobe defini par "rep" 33 void Correct2RefLobe(Four2DResponse& rep, TArray< TF >& a, double dx, double dy, double f0, double df); 34 35 // Applique l'effet de lobe "rep" dans le plan de Fourier pour une frequence (longueur d'onde) fixee 36 static void ApplyLobeK2D(Four2DResponse& rep, TArray< complex<TF> >& f2d, double dkx, double dky); 37 38 // Re-echntillonnage du cube 3D en appliquant les facteurs xfac,yfac,zfac selon chaque direction 39 // fac = 2 ---> on double le nombre d'echantillon , fac=0.5 : un echantillon sur deux 31 40 static TArray< TF > ReSample(TArray< TF >& a, double xfac, double yfac, double zfac); 41 42 // On ajoute du bruit gaussien au cube 3D - espace des positions 32 43 static void AddNoise(TArray< TF >& a, double pixsignoise, bool fgcmsig=true); 33 44 -
trunk/Cosmo/RadioBeam/makefile
r3787 r3788 11 11 rm Objs/* 12 12 13 PKGOLIST = Objs/ lobe.o Objs/specpk.o Objs/mdish.o Objs/qhist.o Objs/radutil.o14 PKGHLIST = lobe.h specpk.h mdish.h qhist.h radutil.h cubedef.h13 PKGOLIST = Objs/fgndsub.o Objs/lobe.o Objs/specpk.o Objs/mdish.o Objs/qhist.o Objs/radutil.o 14 PKGHLIST = fgndsub.h lobe.h specpk.h mdish.h qhist.h radutil.h cubedef.h 15 15 16 16 ### les executables … … 87 87 88 88 ### les classes / fonctions 89 Objs/specpk.o : specpk.cc specpk.h mdish.h qhist.h 89 Objs/fgndsub.o : fgndsub.cc $(PKGHLIST) 90 $(CXXCOMPILE) -o Objs/fgndsub.o fgndsub.cc 91 92 Objs/specpk.o : specpk.cc $(PKGHLIST) 90 93 $(CXXCOMPILE) -o Objs/specpk.o specpk.cc 91 94 92 Objs/mdish.o : mdish.cc mdish.h qhist.h95 Objs/mdish.o : mdish.cc $(PKGHLIST) 93 96 $(CXXCOMPILE) -o Objs/mdish.o mdish.cc 94 97 95 Objs/lobe.o : lobe.cc lobe.h mdish.h qhist.h98 Objs/lobe.o : lobe.cc $(PKGHLIST) 96 99 $(CXXCOMPILE) -o Objs/lobe.o lobe.cc 97 100 -
trunk/Cosmo/RadioBeam/mdish.cc
r3787 r3788 75 75 } 76 76 77 //--------------------------------------------------------------- 78 // -- Four2DRespRatio : rapport de la reponse entre deux objets Four2DResponse 79 //--------------------------------------------------------------- 80 Four2DRespRatio::Four2DRespRatio(Four2DResponse& a, Four2DResponse& b) 81 : Four2DResponse(0, a.D(), a.D()), a_(a), b_(b) 82 { 83 } 84 85 double Four2DRespRatio::Value(double kx, double ky) 86 { 87 double ra = a_.Value(kx,ky); 88 double rb = b_.Value(kx,ky); 89 if (rb<1.e-19) rb = 1.e-19; 90 return (ra/rb); 91 } 92 93 //--------------------------------------------------------------- 77 94 //--- Classe simple pour le calcul de rotation 78 95 class Rotation { -
trunk/Cosmo/RadioBeam/mdish.h
r3787 r3788 55 55 }; 56 56 57 57 58 // -- Four2DRespTable : Reponse tabulee instrumentale ds le plan k_x,k_y (angles theta,phi) 58 59 class Four2DRespTable : public Four2DResponse { … … 63 64 virtual double Value(double kx, double ky); 64 65 Histo2D hrep_; 66 }; 67 68 69 // -- Four2DRespRatio: Retourne le rapport de la reponse entre deux objets Four2DResponse 70 class Four2DRespRatio : public Four2DResponse { 71 public: 72 Four2DRespRatio(Four2DResponse& a, Four2DResponse& b); 73 // Return the ratio a.Value(kx,ky) / b.Value(kx, ky) - with protection against divide by zero 74 virtual double Value(double kx, double ky); 75 Four2DResponse& a_; 76 Four2DResponse& b_; 65 77 }; 66 78
Note:
See TracChangeset
for help on using the changeset viewer.