Changeset 3830 in Sophya


Ignore:
Timestamp:
Aug 4, 2010, 1:59:10 PM (15 years ago)
Author:
ansari
Message:

Amelioration soustraction des avant-plans par l'introduction d'un fit polynome deg 2 sur ln(Temp)=f(ln(freq)), Reza 04/08/2010

Location:
trunk/Cosmo/RadioBeam
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/RadioBeam/calcpk2.cc

    r3796 r3830  
    4343int main(int narg, const char* arg[])
    4444{
    45   if (narg<6) {
    46     cout << " Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync  OutPkFile \n"
    47          << "        [PixNoiseLevel] [Diameter/Four2DRespTableFile] [TargetBeamArcmin] [NSigSrcThr]" << endl;
    48     return 1;
     45  if ( (narg<6)||((narg>1)&&(strcmp(arg[1],"-h")==0)) ) {
     46    cout << " Usage: calcpk2 InMapLSS convFacLSS InMapFgnd convFacFgnd OutPkFile \n"
     47         << "        [PixNoiseLevel] [D_Dish/Four2DRespTableFile CorBeamDoL] \n"
     48         << "        [NSigSrcThr] [P2/P1] [RecMapFile] " << endl;
     49    if ((narg>1)&&(strcmp(arg[1],"-h")==0)) {
     50      cout << "- InMapLSS: Input 3D LSS cube (PPF file name) \n "
     51           << "- convFacLSS: LSS cube conversion factor to mK (milliKelvin) \n"
     52           << "- InMapFgnd: Input 3D foreground cube (PPF file name) \n"
     53           << "- convFacFgnd: Foreground cube conversion factor to mK (milliKelvin) \n"
     54           << "- PixNoiseLevel: White noise level per pixel (mK) (default=0.) \n"
     55           << "- D_Dish/Four2DRespTableFile: Dish diameter or 2D (u,v) plane response (PPF file name) \n"
     56           << "- CorBeamDoL: Beam correction target Diameter/Lambda \n"
     57           << "    These two parameters are used to correct for beam effect for a \n"
     58           << "    target beam (independent of frequency) defined by D/Lambda \n"
     59           << "    DoL = 100 --> beam ~ 35 arcmin (D=30m @ z~0.5) \n"
     60           << "    default : no beam correction applied \n "
     61           << " - NSigSrcThr: Point source cleaning, Nb_Sigmas on stacked 2D temperature \n"
     62           << "    default : no point source cleaning, use NSigSrcThr ~ 3..5 \n"
     63           << " - P2/P1: 2nd/first degree polynomial fit on ln(Temp) = f(ln(freq)) \n "
     64           << "    foreground subtraction. default is P2 \n"
     65           << "- RecMapFile: output PPF file for reconstructed foreground template \n"
     66           << "    (Temperature,SpectralIndex) and extracted LSS cube \n"
     67         << endl;
     68      return 1;
     69    }
     70    else cout << "   calcpk2 -h for detailed usage " << endl;
     71    return 2;
    4972  }
    5073  Timer tm("calcpk2");
     
    79102      }
    80103    }
    81     double tbeamDoL=135;
     104    double tbeamDoL=0.;
    82105    if (narg>8) {
    83106      tbeamDoL=atof(arg[8]);
     
    90113      if (nsigsrc<1.e-6)  fgclnsrc=false;
    91114    }
    92 
     115    bool fgpoly2=true;  // true -> soustraction polynome degre 2
     116    if ((narg>0)&&(strcmp(arg[10],"P1")==0)) fgpoly2=false;     
     117    bool fgsavemaps=false;
     118    string outmap_ppfname="extlss.ppf";
     119    if (narg>11) {
     120      outmap_ppfname=arg[11];
     121      fgsavemaps=true;
     122    }
     123   
    93124    TArray<r_4> maplss, mapsync;
    94125    const char * tits[2]={"LSS", "Sync/RadioSrc"};
     
    165196    cout << "calcpk2[4] : calling cleaner.extractLSSCube(...) " << endl;
    166197    TArray<r_4> synctemp, specidx;
    167     TArray<r_4> exlss = cleaner.extractLSSCube(synctemp, specidx);
     198    TArray<r_4> exlss;
     199    if (fgpoly2) exlss = cleaner.extractLSSCubeP2(synctemp, specidx);
     200    else  exlss = cleaner.extractLSSCubeP1(synctemp, specidx);
    168201
    169202    MeanSigma(exlss, mean, sigma);
     
    188221
    189222    tm.Split(" Done ComputePk ");   
    190    
     223    {
    191224    cout << "calcpk2[7.a] : writing profile P(k)  to  " << outname << endl;
    192225    POutPersist po(outname);
    193226    po << hp;
    194     outname = "fgm_" + outname;
    195     cout << "calcpk2[7.b] : writing foreground maps to  " << outname << endl;
    196     POutPersist pom(outname);
    197     pom << PPFNameTag("Tsync") << synctemp;
    198     pom << PPFNameTag("async") << specidx;
     227    }
     228    if (fgsavemaps) {
     229      cout << "calcpk2[7.b] : writing foreground maps and extracted LSS to  " << outmap_ppfname << endl;
     230      POutPersist pom(outmap_ppfname);
     231      pom << PPFNameTag("Tsync") << synctemp;
     232      pom << PPFNameTag("async") << specidx;
     233      pom << PPFNameTag("extlss") << exlss;
     234    }
    199235
    200236  }  // End of try bloc
  • trunk/Cosmo/RadioBeam/fgndsub.cc

    r3789 r3830  
    99#include "cubedef.h"
    1010#include "matharr.h"
     11#include "poly.h"
    1112
    1213#include "ctimer.h"
     
    9091
    9192/* --Methode-- */
    92 TArray< TF >  ForegroundCleaner::extractLSSCube(TArray< TF >& synctemp, TArray< TF >& specidx)
    93 {
    94   Timer tm("ForegroundCleaner::extractLSSCube");
     93TArray< TF >  ForegroundCleaner::extractLSSCubeP1(TArray< TF >& synctemp, TArray< TF >& specidx)
     94{
     95  Timer tm("ForegroundCleaner::extractLSSCubeP1");
    9596// Inputs : maplss, mapsyc, freq0, dfreq
    9697// Outputs : synctemp, specidx  (reconstructed foreground temperature and spectral index
     
    130131      bool fgnan = false;
    131132      if (!isfinite(alpha)||(!isfinite(beta))) {
    132         cout << "extractLSSCube[" << i << "," << j << "]/ Not finite alpha, beta - (mapsync="
     133        cout << "extractLSSCubeP1[" << i << "," << j << "]/ Not finite alpha, beta - (mapsync="
    133134             << skycube_(i,j,0) << " ... " << skycube_(i,j,skycube_.SizeZ()-1) << ")" << endl;
    134135        alpha=beta=-999.;
     
    140141       
    141142        if ((axp1<-70.)||(axp1>70.)||(axp2<-70.)||(axp2>70.)) {
    142         cout << "extractLSSCube[" << i << "," << j << "] BAD alpha=" << alpha
     143        cout << "extractLSSCubeP1[" << i << "," << j << "] BAD alpha=" << alpha
    143144             << " beta=" << beta << " T0=" << T0 << " - (mapsync="
    144145             << skycube_(i,j,0) << " ... " << skycube_(i,j,skycube_.SizeZ()-1) << ")" << endl;
     
    147148      }
    148149      if ((i%imodprt==0)&&(j%jmodprt==0))
    149         cout << "extractLSSCube[" << i << "," << j << "]: T0=" << T0 << " alpha=" << alpha
     150        cout << "extractLSSCubeP1[" << i << "," << j << "]: T0=" << T0 << " alpha=" << alpha
    150151             << " (mapsync=" << skycube_(i,j,0) << " ... " << skycube_(i,j,skycube_.SizeZ()-1) << ")" << endl;
    151152      synctemp(i,j) = T0;
     
    161162      }
    162163    }
    163   cout << " ForegroundCleaner::extractLSSCube() - NbNan alpha/beta=" << nbinfini << " NbBAD =" << nbbad << endl;
     164  cout << " ForegroundCleaner::extractLSSCubeP1() - NbNan alpha/beta=" << nbinfini << " NbBAD =" << nbbad << endl;
    164165  return omap;
    165166}
    166167
     168/*
     169static inline val_polyn2(double alpha, double beta, double gamma, double x)
     170{
     171  return (beta+alpha*x+gamma*x*x);
     172}
     173*/
     174
     175/* --Methode-- */
     176TArray< TF >  ForegroundCleaner::extractLSSCubeP2(TArray< TF >& synctemp, TArray< TF >& specidx)
     177{
     178  Timer tm("ForegroundCleaner::extractLSSCubeP2");
     179// Inputs : maplss, mapsyc, freq0, dfreq
     180// Outputs : synctemp, specidx  (reconstructed foreground temperature and spectral index
     181// Return_Array : foreground subtracted LSS signal
     182  sa_size_t sz[5];   sz[0]=skycube_.SizeX();  sz[1]=skycube_.SizeY();
     183  synctemp.SetSize(2, sz);
     184  specidx.SetSize(2, sz);
     185  TArray<r_4> omap;
     186  omap.SetSize(skycube_, true);
     187  Vector vlnf(skycube_.SizeZ());
     188  Vector vlnT(skycube_.SizeZ());
     189  int nprt = 0;
     190  // double freq0 : Frequence premier index en k (MHz)
     191  // double dfreq :   // largeur en frequence de chaque plan (Mhz) 
     192  for(sa_size_t k=0; k<skycube_.SizeZ(); k++) 
     193    vlnf(k)=log((double)k*dfreq_+freq0_);
     194  vlnf -= vlnf(0);
     195  //  cout << " DBG*extractLSSCubeP2 vlnf(0)=" << vlnf(0) << " vlnf(1)=" << vlnf(1)
     196  //       << "vlnf(last)=" << vlnf(vlnf.Size()-1) << endl;
     197  sa_size_t nbinfini=0;
     198  sa_size_t nbbad=0;
     199  sa_size_t imodprt=skycube_.SizeX()/6;
     200  sa_size_t jmodprt=skycube_.SizeY()/6;
     201  for(sa_size_t i=0; i<skycube_.SizeX(); i++)
     202    for(sa_size_t j=0; j<skycube_.SizeY(); j++)  {
     203      vlnT = -12.;
     204      Poly polyn;
     205      for(sa_size_t k=0; k<skycube_.SizeZ(); k++)  {
     206        double lnf = vlnf(k);
     207        double ttot=(r_8)(skycube_(i,j,k));
     208        if (ttot < 1.e-5) continue;
     209        vlnT(k)=log(ttot);
     210      }
     211      polyn.Fit(vlnf,vlnT,2);
     212      double beta = polyn[0];
     213      double alpha = polyn[1];
     214      double gamma = polyn[2];
     215      double T0 = exp(polyn(vlnf(0))); // exp( val_polyn2(alpha, beta, gamma, vlnf(0)) );
     216
     217      bool fgnan = false;
     218      if (!isfinite(alpha)||(!isfinite(beta))||(!isfinite(gamma))) {
     219        cout << "extractLSSCubeP2[" << i << "," << j << "]/ Not finite alpha, beta - (mapsync="
     220             << skycube_(i,j,0) << " ... " << skycube_(i,j,skycube_.SizeZ()-1) << ")" << endl;
     221        alpha=beta=gamma=-999.;
     222        fgnan = true;  nbinfini++;
     223      }
     224      else {
     225        double axp1 = polyn(vlnf(0));
     226        double axp2 = polyn(vlnf(vlnf.Size()-1));
     227       
     228        if ((axp1<-70.)||(axp1>70.)||(axp2<-70.)||(axp2>70.)) {
     229          cout << "extractLSSCubeP2[" << i << "," << j << "] BAD alpha=" << alpha
     230            //         << " beta=" << beta << " gamma=" << gamma << " T0=" << T0 << " axp1=" << axp1 << " axp2=" << axp2
     231               << " beta=" << beta << " gamma=" << gamma << " T0=" << T0 << " - (mapsync=" << skycube_(i,j,0)
     232               << " ... " << skycube_(i,j,skycube_.SizeZ()-1) << ")" << endl;
     233          fgnan = true;  nbbad++;
     234        }
     235      }
     236      if ((i%imodprt==0)&&(j%jmodprt==0))
     237        cout << "extractLSSCubeP2[" << i << "," << j << "]: T0=" << T0 << " alpha=" << alpha << " gamma=" << gamma 
     238             << " (mapsync=" << skycube_(i,j,0) << " ... " << skycube_(i,j,skycube_.SizeZ()-1) << ")" << endl;
     239      synctemp(i,j) = T0;
     240      specidx(i,j) = alpha;
     241      if (fgnan) {
     242        for(sa_size_t k=0; k<skycube_.SizeZ(); k++)   omap(i,j,k) = 0.;
     243      }
     244      else {
     245        for(sa_size_t k=0; k<skycube_.SizeZ(); k++) {
     246          r_4 fittedtemp = (r_4)( exp(polyn(vlnf(k))) );
     247          omap(i,j,k) = skycube_(i,j,k)-fittedtemp;
     248        }
     249      }
     250    }
     251  cout << " ForegroundCleaner::extractLSSCubeP2() - NbNan alpha/beta=" << nbinfini << " NbBAD =" << nbbad << endl;
     252  return omap;
     253}
     254
  • trunk/Cosmo/RadioBeam/fgndsub.h

    r3789 r3830  
    2929  int CleanNegatives(TF seuil=1.e-6);
    3030  int CleanPointSources(double nsigmas=5.);
    31   TArray< TF > extractLSSCube(TArray< TF >& synctemp, TArray< TF >& specidx);
     31  // Ajustement d'une droite (a x + b) sur ln(Temp) = f(ln(Freq))
     32  TArray< TF > extractLSSCubeP1(TArray< TF >& synctemp, TArray< TF >& specidx);
     33  // Ajustement d'une parabole (a x^2 + b x + c) sur ln(Temp) = f(ln(Freq))
     34  TArray< TF > extractLSSCubeP2(TArray< TF >& synctemp, TArray< TF >& specidx);
    3235
    3336  Four2DResponse& arrep_;   // Array/Instrument beam response
  • trunk/Cosmo/RadioBeam/subtractradsrc.cmd

    r3829 r3830  
    8484
    8585# 4.c/ Extract LSS P(k) from Foreground+LSS+noise , after cleaning/subtraction without beam
    86 csh> ./Objs/calcpk2 lsscube.ppf 0.2 fgndcube.ppf 1000 subpk.ppf 0.35 50. 0. 0.
     86csh> ./Objs/calcpk2 lsscube.ppf 0.2 fgndcube.ppf 1000 subpk.ppf 0.35 50. 0. 0. P2
    8787# 4.d / Extract LSS P(k) from Foreground+LSS+noise and beam effect, without beam correction 
    88 csh> ./Objs/calcpk2 lsscube_lobe.ppf 0.2 fgndcube_lobe.ppf 1000 subpklobe.ppf 0.35 50. 0. 3.
     88csh> ./Objs/calcpk2 lsscube_lobe.ppf 0.2 fgndcube_lobe.ppf 1000 subpklobe.ppf 0.35 50. 0. 3. P2
    8989# 4.e / Extract LSS P(k) from Foreground+LSS+noise and beam effect - correcting to a beam of Diam/Lambda = 130
    90 csh> ./Objs/calcpk2 lsscube_lobe.ppf 0.2 fgndcube_lobe.ppf 1000 subpkcorlobe.ppf 0.35 50. 130. 3.
     90csh> ./Objs/calcpk2 lsscube_lobe.ppf 0.2 fgndcube_lobe.ppf 1000 subpkcorlobe.ppf 0.35 50. 130. 3. P2
     91#  Or using a linear fit for foreground subtraction (old version)
     92csh> ./Objs/calcpk2 lsscube_lobe.ppf 0.2 fgndcube_lobe.ppf 1000 subpkcorlobep1.ppf 0.35 50. 130. 3. P1
    9193# 4.f / Estimate residual noise from Foreground removal :
    92 csh> ./Objs/calcpk2 zerolss.ppf 0. fgndcube_lobe.ppf 1000 subpknolss.ppf 0.35 50. 130. 3.
     94csh> ./Objs/calcpk2 zerolss.ppf 0. fgndcube_lobe.ppf 1000 subpknolss.ppf 0.35 50. 130. 3. P2
    9395csh> ./Objs/calcpk2 zerolss.ppf 0. fgndcube_lobe.ppf 1000 subpknolssnocor.ppf 0.35 50. 0. 3.
    9496
     
    103105openppf lsspklobewn.ppf
    104106openppf subpklobe.ppf
     107
    105108openppf subpkcorlobe.ppf
     109openppf subpknolss.ppf
    106110
    107 openppf subpknolss.ppf
    108 openppf subpknolssnocor.ppf
     111# openppf subpknolssnocor.ppf
    109112
    110113disp lsspk 'logx logy nsta xylimits=0.005,2.,4e-11,8e-6 gold'
     
    113116settitle ' Pk[LSS] - without normalisation' ' ' 'font=helvetica,bold,16 black'
    114117
    115 #  Calcul du volume total en Mpc^3
    116 set VOL 3*3*3*360*360*256
    117 plot2d lsspklobe x val*$VOL 1 'same nsta orange'
    118 plot2d lsspklobe x val*$VOL 1 'same nsta orange'
    119118
    120119disp fgndpk 'logx logy nsta xylimits=0.005,2.,1e-10,1. navyblue'
     
    123122disp lsspk 'same nsta gold'
    124123disp lsspklobewn 'same nsta siennared'
    125 settitle 'Pk[LSS] , Pk[Foreground] and lobe effect (Dish D=50 m)' ' ' 'font=helvetica,bold,18'
     124# settitle 'Pk[LSS] , Pk[Foreground] and lobe effect (Dish D=50 m)' ' ' 'font=helvetica,bold,18'
     125settitle 'Pk[LSS] , Pk[Foreground=GSM] and lobe effect (Dish D=50 m)' ' ' 'font=helvetica,bold,18'
     126
    126127set lines ( 'Pk[Foreground]'  'Pk[fgnd]*Lobe' 'Pk[fgnd]*Lobe/Corrected' 'Pk[LSS]' 'Pk[LSS]*Lobe+Noise' )
    127128set cols ( navyblue blue skyblue gold siennared )
    128129textdrawer lines cols 'font=helvetica,bold,16 frame'
     130
    129131
    130132disp lsspk 'logx logy nsta xylimits=0.005,2.,4e-9,4e-5 gold'
     
    141143plot2d subpknolss x val*$VOL 1 'same nsta cpts marker=box,5 green'
    142144
     145# settitle 'Recovered Pk[LSS] In=LSS+(GSM) (D=50 m)' ' ' 'font=helvetica,bold,18'
    143146settitle 'Recovered Pk[LSS] In=LSS+(Haslam+North20cm) (D=50 m)' ' ' 'font=helvetica,bold,18'
    144147setaxelabels 'k (Mpc^-1)   h=0.7' 'P(k)    (mK^2 Mpc^3)' 'font=helvetica,bolditalic,16'
Note: See TracChangeset for help on using the changeset viewer.