Changeset 3788 in Sophya for trunk/Cosmo


Ignore:
Timestamp:
Jun 25, 2010, 7:35:17 PM (15 years ago)
Author:
ansari
Message:

Ajout classe de soustraction d'avant plans, Reza 25/06/2010

Location:
trunk/Cosmo/RadioBeam
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/RadioBeam/README

    r3787 r3788  
    2525
    2626A.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
    2729  - specpk.h specpk.cc : 3D power spectrum computation classes 
    28   - lobe.h lobe.cc : 2D (k_alpha, k_delta) beam effect on 3D sky cubes
    2930  - mdish.h mdish.cc : Classes for representing Multi-Dish interferometer configurations
    3031  - radutil.h radutil.cc : utilitaire de conversion a 21 cm
  • trunk/Cosmo/RadioBeam/applobe.cc

    r3787 r3788  
    6868      pin >> incube;
    6969    }
    70     cout << incube;
     70    incube.Show();
    7171
    7272    double dxdeg = ThetaSizeDegre/(double)NTheta;
     
    8585
    8686    cout << "applobe[2]: creating Four2DResponse and BeamEffect objects..." << endl;
    87     // Dish de 64 m de diametre
    88     double Diametre = 64.;
    8987    H21Conversions conv;
    9088    conv.setFrequency(Freq0MHz);
    9189    double lambda = conv.getLambda();
    92     Four2DResponse fresp(2, Diametre/lambda, Diametre/lambda);
     90    Four2DResponse fresp(2, InterfArrayDiametre/lambda, InterfArrayDiametre/lambda);
    9391    BeamEffect beam(fresp);
    9492
     
    9694    beam.ApplyLobe3D(incube, dx, dy, Freq0MHz, dfreq);
    9795
    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.);
    10098   
    101     cout << outcube;
     99    outcube.Show();
    102100    MeanSigma(outcube, mean, sigma);
    103101    cout << " OutCube 3D- : Mean=" << mean << " Sigma=" << sigma <<  endl;
  • trunk/Cosmo/RadioBeam/calcpk2.cc

    r3787 r3788  
    77    R. Ansari , C. Magneville - Juin 2010
    88
    9 Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPk [PixNoiseLevel]
     9Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPk
     10               [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr]
    1011---------------------------------------------------------------  */
    1112
     
    2021#include "specpk.h"
    2122#include "histats.h"
     23#include "vector3d.h"
    2224
    2325#include "qhist.h"
    2426#include "lobe.h"
    2527#include "cubedef.h"
     28#include "fgndsub.h"
     29#include "radutil.h"
    2630
    2731#include "histinit.h"
     
    3236
    3337typedef ThSDR48RandGen RandomGenerator ;
    34 //--- Declaration des fonctions
    35 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);
    3738
    3839//-------------------------------------------------------------------------
     
    4344{
    4445  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;
    4648    return 1;
    4749  }
     
    6163      fgaddnoise=true;
    6264    }
     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    }
    6378
    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"};
    6781    for(int ks=0; ks<2; ks++)  {
    6882      string& ppfname=inppflss;
    6983      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; }
    7286      cout << "calcpk2[" << ks+1 << "] : reading 3D map " << tits[ks] << " from file " << ppfname
    7387           << "  RenormFactor=" << rfac << endl;
     
    8296    }
    8397
     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
    84108    if (fgaddnoise) {
    85       cout << " calcpk2: adding noise to LSS input cube ... " << endl;
    86       BeamEffect::AddNoise(inmaplss, pixsignoise);
     109      cout << " calcpk2: adding noise to skycube cube ... " << endl;
     110      BeamEffect::AddNoise(skycube, pixsignoise);
    87111    }
    88112
    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);
    95113    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;     
    98141    tm.Split(" After CleanForeground");
    99142
    100     cout << "calcpk2[4] : computing 3D Fourier coefficients ... " << endl;
     143    cout << "calcpk2[5] : computing 3D Fourier coefficients ... " << endl;
    101144    FFTWServer ffts;
    102145    TArray< complex<r_4> > four3d;
    103     ffts.FFTForward(inmap, four3d);
     146    ffts.FFTForward(exlss, four3d);
    104147    tm.Split(" After FFTForward ");
    105148
    106     cout << "calcpk2[5] : computing power spectrum ... " << endl;
     149    cout << "calcpk2[6] : computing power spectrum ... " << endl;
    107150    RandomGenerator rg;
    108151    Four3DPk pkc(four3d, rg);
     
    112155    tm.Split(" Done ComputePk ");   
    113156   
    114     cout << "calcpk2[4] : writing profile P(k) and foreground maps to  " << outname << endl;
     157    cout << "calcpk2[7.a] : writing profile P(k) to  " << outname << endl;
    115158    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;
    119165
    120166  }  // End of try bloc
     
    132178    rc = 97;
    133179  }
    134   cout << " ==== End of calcpk.cc program  Rc= " << rc << endl;
     180  cout << " ==== End of calcpk2.cc program  Rc= " << rc << endl;
    135181  return rc;   
    136182}
    137183
    138184
    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, dfreq
    143 // Outputs : synctemp, specidx  (reconstructed foreground temperature and spectral index
    144 // Return_Array : foreground subtracted LSS signal
    145 {
    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=" << alpha
    178              << " (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  
    3232static double sigPLidxSrc = 0.15;  // Sigma de la variation (gaussienne) de l'index 
    3333
     34// Parametres pour la reponse en Fourier de l'instrument :
     35static double InterfArrayDiametre = 64.;
     36
    3437/*
    3538static sa_size_t NTheta=256;
  • trunk/Cosmo/RadioBeam/lobe.cc

    r3787 r3788  
    1717}
    1818
    19 /* --Methode-- */
    20 void BeamEffect::ApplyLobeK2D(TArray< complex<TF> >& fourAmp, double dkx, double dky, double lambda)
    21 //  dx, dy en radians, lambda en metres
    22 {
    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 }
    3419
    3520
     
    5237    ffts.FFTForward(slice, fourAmp);
    5338    conv.setFrequency(f0+kz*df);
    54     ApplyLobeK2D(fourAmp, dkx, dky, conv.getLambda());
     39    fresp_.setLambda(conv.getLambda());
     40    ApplyLobeK2D(fresp_, fourAmp, dkx, dky);
    5541    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-- */
     48void 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-- */
     75void 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    }
    5785  }
    5886  return;
  • trunk/Cosmo/RadioBeam/lobe.h

    r3787 r3788  
    11/*  ------------------------ Projet BAORadio --------------------
    22    Calcul de l'effet de lobe sur Carte2D (angleX,angleY) et
    3     cube 3D (angleX,angleY)
     3    cube 3D (angleX,angleY, frquences)
    44    R. Ansari , C. Magneville - Juin 2010
    55---------------------------------------------------------------  */
     
    2525class BeamEffect {
    2626public:
     27  // Definition de l'objet avec la reponse en frequence de l'instrument
    2728  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 
    2930  void ApplyLobe3D(TArray< TF >& a, double dx, double dy, double f0, double df); 
    3031
     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
    3140  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
    3243  static void AddNoise(TArray< TF >& a, double pixsignoise, bool fgcmsig=true);
    3344
  • trunk/Cosmo/RadioBeam/makefile

    r3787 r3788  
    1111        rm Objs/*
    1212
    13 PKGOLIST =  Objs/lobe.o Objs/specpk.o Objs/mdish.o Objs/qhist.o Objs/radutil.o
    14 PKGHLIST =  lobe.h specpk.h mdish.h qhist.h radutil.h cubedef.h
     13PKGOLIST =  Objs/fgndsub.o Objs/lobe.o Objs/specpk.o Objs/mdish.o Objs/qhist.o Objs/radutil.o
     14PKGHLIST =  fgndsub.h lobe.h specpk.h mdish.h qhist.h radutil.h cubedef.h
    1515
    1616### les executables
     
    8787
    8888### les classes / fonctions
    89 Objs/specpk.o : specpk.cc specpk.h  mdish.h qhist.h
     89Objs/fgndsub.o : fgndsub.cc $(PKGHLIST)
     90        $(CXXCOMPILE) -o Objs/fgndsub.o fgndsub.cc
     91
     92Objs/specpk.o : specpk.cc $(PKGHLIST)
    9093        $(CXXCOMPILE) -o Objs/specpk.o specpk.cc
    9194
    92 Objs/mdish.o : mdish.cc mdish.h qhist.h
     95Objs/mdish.o : mdish.cc $(PKGHLIST)
    9396        $(CXXCOMPILE) -o Objs/mdish.o mdish.cc
    9497
    95 Objs/lobe.o : lobe.cc lobe.h mdish.h qhist.h
     98Objs/lobe.o : lobe.cc $(PKGHLIST)
    9699        $(CXXCOMPILE) -o Objs/lobe.o lobe.cc
    97100
  • trunk/Cosmo/RadioBeam/mdish.cc

    r3787 r3788  
    7575}
    7676
     77//---------------------------------------------------------------
     78// -- Four2DRespRatio : rapport de la reponse entre deux objets Four2DResponse
     79//---------------------------------------------------------------
     80Four2DRespRatio::Four2DRespRatio(Four2DResponse& a, Four2DResponse& b)
     81  : Four2DResponse(0, a.D(), a.D()), a_(a), b_(b)
     82{
     83}
     84
     85double 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//---------------------------------------------------------------
    7794//--- Classe simple pour le calcul de rotation
    7895class Rotation {
  • trunk/Cosmo/RadioBeam/mdish.h

    r3787 r3788  
    5555};
    5656
     57
    5758// -- Four2DRespTable : Reponse tabulee instrumentale ds le plan k_x,k_y (angles theta,phi)
    5859class Four2DRespTable : public  Four2DResponse {
     
    6364  virtual double Value(double kx, double ky);
    6465  Histo2D hrep_;
     66};
     67
     68
     69// -- Four2DRespRatio: Retourne le rapport de la reponse entre deux objets Four2DResponse
     70class Four2DRespRatio : public  Four2DResponse {
     71public:
     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_;
    6577};
    6678
Note: See TracChangeset for help on using the changeset viewer.