Ignore:
Timestamp:
Jun 23, 2006, 12:47:49 PM (19 years ago)
Author:
ansari
Message:

Corrections dans SphericalTransformServer:

  • gestion taille tableau sortie + imag(f_nyquist) dans RfourierSynthesisFromB
  • Utilisation RfourierSynthesisFromB (TF cmplx->reel) pour synthese

depuis alm, pour tout type de carte

  • Optimisation acces aux pixels avec la methode GetThetaSliceDataPtr()

Reza , 23 Juin 2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/Samba/sphericaltransformserver.cc

    r2984 r2991  
    180180  Bm<complex<T> > b_m_theta(nmmax);
    181181
    182 
    183 
    184182  // pour chaque tranche en theta
    185   for (int_4 ith = premiereTranche; ith <= derniereTranche;ith++)
    186     {
    187       int_4 nph;
    188       r_8 phi0;
    189       r_8 theta;
    190       TVector<int_4> pixNumber;
    191       TVector<T> datan;
    192      
    193       map.GetThetaSlice(ith,theta,phi0, pixNumber,datan);
    194       nph = pixNumber.NElts();
    195       if (nph < 2) continue;  // On laisse tomber les tranches avec un point
    196       //       -----------------------------------------------------
    197       //              for each theta, and each m, computes
    198       //              b(m,theta) = sum_over_l>m (lambda_l_m(theta) * a_l_m)
    199       //              ------------------------------------------------------
    200       // ===> Optimisation Reza, Mai 2006
    201       /*---  Le bout de code suivant est remplace par l'appel a la nouvelle fonction
    202         qui calcule la somme au vol
     183  for (int_4 ith = premiereTranche; ith <= derniereTranche;ith++)  {
     184    int_4 nph;
     185    r_8 phi0;
     186    r_8 theta;
     187    TVector<int_4> pixNumber;
     188    TVector<T> datan;
     189   
     190    map.GetThetaSlice(ith,theta,phi0, pixNumber,datan);
     191    nph = pixNumber.NElts();
     192    if (nph < 2) continue;  // On laisse tomber les tranches avec un point
     193    //       -----------------------------------------------------
     194    //        for each theta, and each m, computes
     195    //        b(m,theta) = sum_over_l>m (lambda_l_m(theta) * a_l_m)
     196    //        ------------------------------------------------------
     197    // ===> Optimisation Reza, Mai 2006
     198    /*---  Le bout de code suivant est remplace par l'appel a la nouvelle fonction
     199      qui calcule la somme au vol
    203200      LambdaLMBuilder lb(theta,nlmax,nmmax);
    204201      //  somme sur m de 0 a l'infini
    205       for (int_4 m = 0; m <= nmmax; m++)
    206         {
    207           b_m_theta(m) = (T)( lb.lamlm(m,m) ) * alm(m,m);
    208           for (int l = m+1; l<= nlmax; l++)
    209             {
    210                b_m_theta(m) += (T)( lb.lamlm(l,m) ) * alm(l,m);
    211             }
    212         }
     202      for (int_4 m = 0; m <= nmmax; m++) {
     203      b_m_theta(m) = (T)( lb.lamlm(m,m) ) * alm(m,m);
     204      for (int l = m+1; l<= nlmax; l++)
     205        b_m_theta(m) += (T)( lb.lamlm(l,m) ) * alm(l,m);
     206      }
    213207      ------- Fin version PRE-Mai2006 */
    214       LambdaLMBuilder::ComputeBmFrAlm(theta,nlmax,nmmax, alm, b_m_theta);
    215       //Fin Optimisation Reza, Mai 2006 <====
     208    LambdaLMBuilder::ComputeBmFrAlm(theta,nlmax,nmmax, alm, b_m_theta);
     209    //Fin Optimisation Reza, Mai 2006 <====
    216210
    217211    //        obtains the negative m of b(m,theta) (= complex conjugate)
    218 
    219       for (int_4 m=1;m<=nmmax;m++)
    220         {
    221           b_m_theta(-m) = conj(b_m_theta(m));
    222         }
    223       // ---------------------------------------------------------------
    224       //    sum_m  b(m,theta)*exp(i*m*phi)   -> f(phi,theta)
    225       // ---------------------------------------------------------------*/
    226 
    227       /* ----- Reza, Juin 2006 :
    228          En verifiant la difference entre deux cartes
    229          cl -> map -> alm -> map2 et mapdiff = map-map2
    230          je me suis apercu qu'il y avait des differences importantes - dans les
    231          deux zones 'polar cap' de HEALPix - apres avoir pas mal chercher, il semble
    232          que la routine RfourierSynthesisFromB en soit responsable
    233          Je fais donc tout passer dans fourierSynthesisFromB
    234       if ( (sphere_type == "RING") || (sphere_type == "NESTED") ) {
    235           TVector<T> Temp = RfourierSynthesisFromB(b_m_theta,nph,phi0);
    236           for (int i=0;i< nph;i++) map(pixNumber(i))=Temp(i);
    237         }
    238       else
    239       */
    240         // pour des pixelisations quelconques (autres que HEALPix
    241         //  nph n'est pas toujours pair
    242         // ca fait des problemes pour les transformees de Fourier
    243         // car le server de TF ajuste la longueur du vecteur reel
    244         // en sortie de TF, bref, la securite veut qu'on prenne une
    245         // TF complexe
    246         {
    247           TVector<complex<T> > Temp = fourierSynthesisFromB(b_m_theta,nph,phi0);
    248           for (int i=0;i< nph;i++) map(pixNumber(i))=Temp(i).real();
    249         }
    250     }
     212    for (int_4 m=1;m<=nmmax;m++)
     213      b_m_theta(-m) = conj(b_m_theta(m));
     214    // ---------------------------------------------------------------
     215    //    sum_m  b(m,theta)*exp(i*m*phi)   -> f(phi,theta)
     216    // ---------------------------------------------------------------*/
     217
     218    /* ----- Reza, Juin 2006 :
     219       En verifiant la difference entre deux cartes
     220       cl -> map -> alm -> map2 et mapdiff = map-map2
     221       je me suis apercu qu'il y avait des differences importantes - dans les
     222       deux zones 'polar cap' de HEALPix - qui utilisait RfourierSynthesisFromB
     223       TF complex -> reel . Le probleme venant de l'ambiguite de taille, lie
     224       a la partie imaginaire de la composante a f_nyquist , j'ai corrige et
     225       tout mis en TF complexe -> reel
     226    */
     227    TVector<T> Temp = RfourierSynthesisFromB(b_m_theta,nph,phi0);
     228    // Si on peut acceder directement les pixels d'un tranche, on le fait
     229    T* pix = map.GetThetaSliceDataPtr(ith);
     230    if (pix != NULL)
     231      for (int_4 i=0;i< nph;i++) pix[i] = Temp(i);
     232    else
     233      for (int_4 i=0;i< nph;i++) map(pixNumber(i))=Temp(i);
     234  }
    251235}
    252236
     
    380364  //**********************************************************************
    381365  TVector< complex<T> > bw(nph);
    382   TVector< complex<T> > dataout(nph);
    383366  TVector< complex<T> > data(nph/2+1);
    384 
    385367
    386368  for (int kk=0; kk<bw.NElts(); kk++) bw(kk)=(T)0.;
    387369  int m;
    388   for (m=-b_m.Mmax();m<=-1;m++)
    389     {
    390       int maux=m;
    391       while (maux<0) maux+=nph;
    392       int iw=maux%nph;
    393       double aux=(m-iw)*phi0;
    394       bw(iw) += b_m(m) * complex<T>( (T)cos(aux),(T)sin(aux) )  ;
    395     }
    396   for (m=0;m<=b_m.Mmax();m++)
    397     {
    398       //      int iw=((m % nph) +nph) % nph; //between 0 and nph = m'
    399       int iw=m%nph;
    400       double aux=(m-iw)*phi0;
    401       bw(iw)+=b_m(m) * complex<T>( (T)cos(aux),(T)sin(aux) );
    402     }
     370  for (m=-b_m.Mmax();m<=-1;m++)  {
     371    int maux=m;
     372    while (maux<0) maux+=nph;
     373    int iw=maux%nph;
     374    double aux=(m-iw)*phi0;
     375    bw(iw) += b_m(m) * complex<T>( (T)cos(aux),(T)sin(aux) )  ;
     376  }
     377  for (m=0;m<=b_m.Mmax();m++) {
     378    //      int iw=((m % nph) +nph) % nph; //between 0 and nph = m'
     379    int iw=m%nph;
     380    double aux=(m-iw)*phi0;
     381    bw(iw)+=b_m(m) * complex<T>( (T)cos(aux),(T)sin(aux) );
     382  }
    403383
    404384  //     applies the shift in position <-> phase factor in Fourier space
    405   // cout << " TF : nph= " << nph << " vec. entree " << data.Size() << endl;
    406   for (int mprime=0; mprime <= nph/2; mprime++)
    407     {
    408       complex<double> aux(cos(mprime*phi0),sin(mprime*phi0));
    409       data(mprime)=bw(mprime)*
    410                        (complex<T>)(complex<double>(cos(mprime*phi0),sin(mprime*phi0)));
    411     }
    412 
    413   TVector<T> sortie;
    414   fftIntfPtr_-> FFTBackward(data, sortie);
    415  
     385  for (int mprime=0; mprime <= nph/2; mprime++) 
     386    data(mprime)=bw(mprime)*complex<T>((T)cos(mprime*phi0),(T)sin(mprime*phi0));   
     387  TVector<T> sortie(nph);
     388// On met la partie imaginaire du dernier element du data a zero pour nph pair
     389  if (nph%2 == 0) data(nph/2) = complex<T>(data(nph/2).real(), (T)0.);
     390// et on impose l'utilisation de la taille en sortie pour FFTBack (..., ..., true)
     391  fftIntfPtr_-> FFTBackward(data, sortie, true);
    416392  return sortie;
    417393}
Note: See TracChangeset for help on using the changeset viewer.