Changeset 4026 in Sophya for trunk/Cosmo/RadioBeam


Ignore:
Timestamp:
Oct 10, 2011, 11:31:03 PM (14 years ago)
Author:
ansari
Message:

Modif programme pknoise.cc et classes Four3DPk, PkNoiseCalculator pour calcul spectre de bruit en faisant varier la reponse instrumentale avec la frequence, Reza 10/10/2011

Location:
trunk/Cosmo/RadioBeam
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/RadioBeam/README

    r3973 r4026  
    2424  - gsm2cube.cc : Computes 3D temperature cube from a set of GSM (Global Sky Model) healpix PPF maps 
    2525  - tjyk.cc : test de la classe H21Conversions
     26  - ckpowl.cc : Programme de verification comportement en loi de puissance
    2627
    2728A.3/ List of other common files :
  • trunk/Cosmo/RadioBeam/pknoise.cc

    r3948 r4026  
    66
    77  Usage:  pknoise pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName
    8           -parname : -noise , -renmax , -scut , -ngen , -z , -prt
     8          -parname : -noise , -renmax , -scut , -ngen , -z , -bsize , -cszmpc ,  -prt
    99---------------------------------------------------------------  */
    1010
     
    4545       << "    -ngen NGen (default=0) number of noise fourier amp generations \n"
    4646       << "       NGen=0 -> Call ComputeNoisePk(), else generate Fourier Amplitudes (random) \n"
    47        << "    -z redshift (default=0.7) \n"
     47       << "       NGen=-1 -> Call ComputeNoisePk(), dont change Four3DPk cell size \n"
     48       << "    -bsize sx,sy,sz : 3D real space box size (default=512x512x256) \n"   
     49       << "    -cszmpc sx,sy,sz : 3D real space box cell size in Mpc (default=3x3x3) \n"   
     50       << "    -z z,dA,H_z : redshift,ComovDist(z),H(z) (default=1.0,3330,120.5) \n"
    4851       << "    -scut SCutValue (default= -100.) \n"
    4952       << "       if SCutValue<0. ==> SCut=MinNoisePower*(-SCutValue) \n"
     
    8083  bool fgautoscut=true;
    8184  double FacSCut=-SCut;
    82   double z_Redshift=0.7 ;  // 21 cm at z=0.7 -> 0.357 m 
     85  double z_Redshift=1.0 ;  // z=0.7 : 21 cm at z=0.7 -> 0.357 m 
     86  double comov_dA_z=3330.;  // Comoving radial distance = (1+z)dA
     87  double H_z=120.5;  // Hubble_param(z)
     88  int box3dsz[3]={512,512,256};
     89  double cellsz[3]={3.5,3.5,3.5};
     90
    8391  int prtlev=0;
    8492  int prtmod=10;
     
    101109    }
    102110    else if (strcmp(arg[ka],"-z")==0) {
    103       z_Redshift=atof(arg[ka+1]);  ka+=2;
     111      sscanf(arg[ka+1],"%lg,%lg,%lg",&z_Redshift,&comov_dA_z,&H_z);  ka+=2;
     112    }
     113    else if (strcmp(arg[ka],"-bsize")==0) {
     114      sscanf(arg[ka+1],"%d,%d,%d",box3dsz,box3dsz+1,box3dsz+2);   ka+=2;
     115    }
     116    else if (strcmp(arg[ka],"-cszmpc")==0) {
     117      sscanf(arg[ka+1],"%lg,%lg,%lg",cellsz,cellsz+1,cellsz+2);   ka+=2;
    104118    }
    105119    else if (strcmp(arg[ka],"-prt")==0) {
     
    169183    cout << " pknoise[2]: Instanciating object type Four3DPk  " << endl;
    170184    RandomGenerator rg;
    171     Four3DPk m3d(rg);
    172     m3d.SetCellSize(2.*DeuxPI, 2.*DeuxPI, 2.*DeuxPI);
     185
     186    double dkxmpc=2.*DeuxPI;
     187    double dkympc=2.*DeuxPI;
     188    double dkzmpc=2.*DeuxPI;
     189    double angscale=1.;
     190    if (NMAX<0)  { box3dsz[0]=256; box3dsz[1]=256;  box3dsz[3]=128; }
     191    else {
     192      angscale=comov_dA_z;
     193      dkxmpc = DeuxPI/(double)box3dsz[0]/cellsz[0];
     194      dkympc = DeuxPI/(double)box3dsz[1]/cellsz[1];
     195      dkzmpc = DeuxPI/(double)box3dsz[2]/cellsz[2];
     196    }
     197    cout << " pknoise[2.b]: ComovDist" << comov_dA_z << " Mpc H(z)=" << H_z << " Mpc/km/s -> angscale=" << angscale << endl;
     198    cout << " pknoise[2.c]: Four3DPk m3d(rg," << box3dsz[0]/2 << "," << box3dsz[1] << ","
     199         << box3dsz[2] << ")" << endl;
     200    Four3DPk m3d(rg,box3dsz[0]/2,box3dsz[1],box3dsz[2]);
     201    cout << " pknoise[2.d]: m3d.SetCellSize(" << dkxmpc << "," << dkympc << "," << dkzmpc << endl;
     202    m3d.SetCellSize(dkxmpc, dkympc, dkzmpc);
    173203    m3d.SetPrtLevel(prtlev,prtmod);
    174204
     
    176206    if (NMAX>0) {
    177207      PkNoiseCalculator pkn(m3d, *(arep_p), SCut, NMAX, tits.c_str());
     208      double dfreq=H_z*cellsz[2]/(1+z_Redshift)/lambda/1000.;
     209      double freq0=conv.getFrequency()-dfreq*box3dsz[2]/2;
     210      cout << " pknoise[3.b]: Freq0=" << freq0 << " dFreq=" << dfreq << " freq(z=" << z_Redshift << ")="
     211           << conv.getFrequency() << " AngScale=" << angscale << endl;
     212      pkn.SetFreqRange(freq0, dfreq);
     213      pkn.SetAngScaleConversion(angscale);
    178214      pkn.SetPrtLevel(prtlev,prtmod);
    179215      HProf hpn = pkn.Compute();
    180       cout << " pknoise[3.b]: writing hpn noise profile to " << outfile << endl;
     216      cout << " pknoise[3.c]: writing hpn noise profile to " << outfile << endl;
    181217      po << hpn;
    182218    }
     
    184220      Histo fracmodok;
    185221      DataTable dtnoise;
    186       HProf hpn = m3d.ComputeNoisePk(*(arep_p),fracmodok,dtnoise,SCut);
     222      HProf hpn = m3d.ComputeNoisePk(*(arep_p),fracmodok,dtnoise,angscale,SCut);
    187223      HProf h1dnoise=arep_p->GetProjNoiseLevel();
    188224      HProf h1drep=arep_p->GetProjResponse();
  • trunk/Cosmo/RadioBeam/specpk.cc

    r3947 r4026  
    66
    77#include "specpk.h"
     8#include "radutil.h"
    89#include "randr48.h"     
    910#include "ctimer.h"     
     
    162163}
    163164
     165
    164166// Generate mass field Fourier Coefficient
    165 void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, bool crmask)
     167void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double angscale, bool crmask)
     168// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
     169// typically = ComovRadialDistance
    166170{
    167171  TMatrix<r_4> mask(fourAmp.SizeY(), fourAmp.SizeX());
     
    176180      for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) {
    177181        kxx=(double)kx*dkx_;
    178         rep = resp(kxx, kyy);
     182        rep = resp(kxx*angscale, kyy*angscale);
    179183        if (crmask&&(kz==0))  mask(ky,kx)=((rep<1.e-8)?9.e9:(1./rep));
    180184        if (rep<1.e-8)  fourAmp(kx, ky, kz) = complex<TF>(9.e9,0.);
     
    193197  if (prtlev_>0)
    194198    cout << " Four3DPk::ComputeNoiseFourierAmp() done ..." << endl;
     199}
     200
     201// Generate mass field Fourier Coefficient
     202void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, double angscale)
     203// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
     204// typically = ComovRadialDistance
     205{
     206  H21Conversions conv;
     207  // fourAmp represent 3-D fourier transform of a real input array.
     208  // The second half of the array along Y and Z contain negative frequencies
     209  double kxx, kyy, kzz, rep, amp;
     210  // sa_size_t is large integer type 
     211  for(sa_size_t kz=0; kz<fourAmp.SizeZ(); kz++) {
     212    conv.setFrequency(f0+kz*df);
     213    resp.setLambda(conv.getLambda());
     214    for(sa_size_t ky=0; ky<fourAmp.SizeY(); ky++) {
     215      kyy =  (ky>fourAmp.SizeY()/2) ? -(double)(fourAmp.SizeY()-ky)*dky_ : (double)ky*dky_;
     216      for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) {
     217        kxx=(double)kx*dkx_;
     218        rep = resp(kxx*angscale, kyy*angscale);
     219        if (rep<1.e-8)  fourAmp(kx, ky, kz) = complex<TF>(9.e9,0.);
     220        else {
     221          amp = 1./sqrt(rep)/sqrt(2.);
     222          fourAmp(kx, ky, kz) = complex<TF>(rg_.Gaussian(amp), rg_.Gaussian(amp));   
     223        }
     224      }
     225    }
     226  }
     227
     228  if (prtlev_>1)
     229    cout << " Four3DPk::ComputeNoiseFourierAmp(...) Computing FFT along frequency ..." << endl;
     230  TVector< complex<TF> >  veczin(fourAmp.SizeZ()), veczout(fourAmp.SizeZ());
     231  FFTWServer ffts(true);                     
     232  ffts.setNormalize(true);
     233
     234  for(sa_size_t ky=0; ky<fourAmp.SizeY(); ky++) {
     235    for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) {
     236      //      veczin=fourAmp(Range(kx), Range(ky), Range::all());
     237      for(sa_size_t kz=0; kz<fourAmp.SizeZ(); kz++)  veczin(kz)=fourAmp(kx,ky,kz);
     238      ffts.FFTBackward(veczin,veczout);
     239      veczout /= (TF)sqrt((double)fourAmp.SizeZ());
     240      //      fourAmp(Range(kx), Range(ky), Range::all())=veczout;
     241      for(sa_size_t kz=0; kz<fourAmp.SizeZ(); kz++)  fourAmp(kx,ky,kz)=veczout(kz);
     242    }
     243  }
     244
     245  if (prtlev_>2)  fourAmp.Show();
     246  if (prtlev_>0)
     247    cout << " Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df) done ..." << endl;
    195248}
    196249
     
    270323// cells with amp^2=re^2+im^2>s2cut are ignored
    271324// Output : noise power spectrum (profile histogram)
     325// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
     326// typically = ComovRadialDistance
    272327HProf Four3DPk::ComputeNoisePk(Four2DResponse& resp, Histo& fracmodok, DataTable& dt,
    273                                double s2cut, int nbin, double kmin, double kmax)
     328                               double angscale, double s2cut, int nbin, double kmin, double kmax)
    274329{
    275330  // The second half of the array along Y (matrix rows) contain
     
    305360        double kxx=(double)kx*dkx_;
    306361        double wk = sqrt(kxx*kxx+kyy*kyy+kzz*kzz);
    307         double amp2 = 1./resp(kxx, kyy);
     362        double rep=resp(kxx*angscale, kyy*angscale);
     363        double amp2 = (rep>1.e-19)?1./rep:1.e19;
    308364        hmcnt.Add(wk);
    309365        if ((s2cut>1.e-9)&&(amp2>s2cut))  continue;
     
    349405  : pkn3d(pk3), frep(rep), S2CUT(s2cut), NGEN(ngen), title(tit)
    350406{
     407  SetFreqRange();
     408  SetAngScaleConversion();
    351409  SetPrtLevel();
    352410}
     
    357415  tm.Nop();
    358416  HProf hnd;
    359   cout << "PkNoiseCalculator::Compute() " << title << "  NGEN=" << NGEN << " S2CUT=" << S2CUT << endl;
     417  cout << "PkNoiseCalculator::Compute() " << title << "  NGEN=" << NGEN << " S2CUT=" << S2CUT 
     418       << " Freq0=" << freq0_ << " dFreq=" << dfreq_ << " angscale=" << angscale_ << endl;
    360419  for(int igen=0; igen<NGEN; igen++) {
    361     pkn3d.ComputeNoiseFourierAmp(frep);
     420    pkn3d.ComputeNoiseFourierAmp(frep, freq0_, dfreq_, angscale_);
    362421    if (igen==0) hnd = pkn3d.ComputePk(S2CUT);
    363422    else pkn3d.ComputePkCumul(hnd,S2CUT);
  • trunk/Cosmo/RadioBeam/specpk.h

    r3947 r4026  
    5151  { int olev=prtlev_; prtlev_=lev; prtmodulo_=prtmod; return olev; }
    5252  void ComputeFourierAmp(SpectralShape& pk);
    53   void ComputeNoiseFourierAmp(Four2DResponse& resp, bool crmask=false);
     53// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
     54// typically = ComovRadialDistance
     55  void ComputeNoiseFourierAmp(Four2DResponse& resp, double angscale=1., bool crmask=false);
     56  void ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, double angscale=1.);
     57
    5458// Return the array size
    5559  inline sa_size_t NCells() { return fourAmp.Size(); }
     
    6569  void  ComputePkCumul(HProf& hp, double s2cut=0.);
    6670
    67   HProf ComputeNoisePk(Four2DResponse& resp, Histo& fracmodok, DataTable& dt,
     71// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
     72// typically = ComovRadialDistance
     73  HProf ComputeNoisePk(Four2DResponse& resp, Histo& fracmodok, DataTable& dt, double angscale=1.,
    6874                       double s2cut=0., int nbin=256, double kmin=0., double kmax=-1.);
    6975
     
    8591  PkNoiseCalculator(Four3DPk& pk3, Four2DResponse& rep, double s2cut=100., int ngen=1, const char* tit="PkNoise");
    8692 
     93  inline void SetFreqRange(double freq0=835.,double dfreq=0.5)
     94  { freq0_=freq0;  dfreq_=dfreq; }
     95  inline void SetAngScaleConversion(double angscale=1.)
     96  { angscale_=angscale; }
    8797  inline void SetS2Cut(double s2cut=100.)
    8898  {  S2CUT=s2cut; }
     
    95105  Four3DPk& pkn3d;
    96106  Four2DResponse& frep;
     107  double freq0_,dfreq_;
     108  double angscale_;
    97109  double S2CUT;
    98110  int NGEN;
Note: See TracChangeset for help on using the changeset viewer.