Changeset 606 in Sophya for trunk/SophyaProg/Tests


Ignore:
Timestamp:
Nov 20, 1999, 9:47:42 PM (26 years ago)
Author:
ansari
Message:

Amelioration test spheres - Reza 20/11/99

Location:
trunk/SophyaProg/Tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/Tests/tspm.cc

    r575 r606  
    22#include "sambainit.h"
    33#include "spheregorski.h"
     4#include "spherethetaphi.h"
    45
    56#include "tod.h"
    67#include "timing.h"
    78
     9template <class T>
     10void  MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig)
     11{
     12  gmoy=0.;
     13  gsig = 0.;
     14  double valok;
     15  for(int k=0; k<map.NbPixels(); k++) {
     16    valok = map(k);
     17    gmoy += valok;  gsig += valok*valok;
     18  }
     19  gmoy /= (double)map.NbPixels();
     20  gsig = gsig/(double)map.NbPixels() - gmoy*gmoy;
     21  if (gsig >= 0.) gsig = sqrt(gsig);
     22}
    823
    924int main(int narg, char* arg[])
    1025{
    1126  double teta,phi;
     27  double gmoy, gsig;
     28
    1229  PeidaInit();
    1330  InitTim();   // Initializing the CPU timer
    1431  if ((narg > 1) && (strcmp(arg[1],"-h") == 0) )  {
    15     cout << " tspm [Gorski_M=32] : Gorski Spherical Map Test " << endl;
     32    cout << " tspm [Gorski_M=32] [M_TetaPhi=64] : Spherical Map Test " << endl;
    1633    exit(0);
    1734    }
     
    3249
    3350  // Computing mean and sigma on the sphere
    34   double gmoy=0. , gsig = 0.;
    35   double valok;
    36   for(int k=0; k<sph.NbPixels(); k++) {
    37     valok = sph(k);
    38     gmoy += valok;  gsig += valok*valok;
    39   }
    40   cout << "SphMap Mean= " << gmoy << "  Sigma = " << gsig << endl;
     51  MeanSig(sph, gmoy, gsig);
     52  cout << "SphereGorski<double> Mean= " << gmoy << "  Sigma = " << gsig << endl;
    4153  PrtTim("End of Mean-Sig ");
    4254
     
    4456  {
    4557  POutPersist s("sphg.ppf");
    46   FIO_SphereGorski<double> fiog(sph) ;
     58  FIO_SphereGorski<double> fiog(&sph) ;
    4759  fiog.Write(s);
    48   cout << "SphMap written to sphg.ppf "  << endl;
     60  cout << "SphereGorski<double> written to sphg.ppf "  << endl;
    4961  }
    5062
     
    5264  {
    5365  FIO_SphereGorski<double> fiog("sphg.ppf");
    54   double gmoy=0. , gsig = 0.;
    55   double valok;
    5666  SphereGorski<double>  sph2 = fiog;
    5767  PrtTim("End of Write/Read ");
    5868
     69  cout << " Spherical map from file sphg.ppf NPixels= " << sph2.NbPixels() << endl;
     70
    5971  int ndiff = 0;
    6072  for(int k=0; k<sph2.NbPixels(); k++) {
    61     valok = sph2(k);
    62     gmoy += valok;  gsig += valok*valok;
    63     if ((sph2(k)-sph(k)) > 1.e-49)  ndiff++;
     73//    if ((sph2(k)-sph(k)) > 1.e-49)  {
     74    if ( sph2(k) != sph(k) )   {
     75      ndiff++;
     76      if (ndiff < 20)  cout << "!!!Diff: K= " << k << " SPH2= " << sph2(k) << " SPH= " << sph(k) << endl;
     77    }
    6478  }
     79  MeanSig(sph, gmoy, gsig);
     80  cout << "SphMapFromFile Mean= " << gmoy << "  Sigma = " << gsig << endl;
     81  cout << " NDiff = " << ndiff << " (should be zero = 0) " << endl;
     82  PrtTim("End of Mean-Sig ");
     83  }
     84
     85
     86  int  mt=64;
     87  if (narg > 2)  mt = atoi(arg[2]);
     88  cout <<  "\n ===== ThetaPhi Spherical Map Test MT= " << mt << endl;
     89
     90  SphereThetaPhi<float> spht(m);
     91
     92  cout << "Filling spherical map NPixels= " << spht.NbPixels() << endl;
     93  for (int j=0;j<spht.NbPixels();j++)
     94    {
     95      spht.PixThetaPhi(j,teta,phi);
     96      spht(j)= 0.5* cos(5.*teta)*sin(10.*phi);
     97    }
     98  PrtTim("End of Fill ");
     99
     100  // Computing mean and sigma on the sphere
     101  MeanSig(spht, gmoy, gsig);
     102  cout << "SphereThetaPhi<float> Mean= " << gmoy << "  Sigma = " << gsig << endl;
     103  PrtTim("End of Mean-Sig ");
     104
     105//  Writing to a PPF file
     106  {
     107  POutPersist s("spht.ppf");
     108  FIO_SphereThetaPhi<float> fiog(spht) ;
     109  fiog.Write(s);
     110  cout << "SphereThetaPhi<float> written to spht.ppf "  << endl;
     111  }
     112
     113  // Reading from the file
     114  {
     115  FIO_SphereThetaPhi<float> fiog("spht.ppf");
     116  SphereThetaPhi<float>  sph2 = fiog;
     117  PrtTim("End of Write/Read ");
     118
     119  cout << " Spherical map from file sph.ppf NPixels= " << sph2.NbPixels() << endl;
     120
     121  int ndiff = 0;
     122  for(int k=0; k<sph2.NbPixels(); k++) {
     123//    if ((sph2(k)-sph(k)) > 1.e-49)  {
     124    if ( sph2(k) != spht(k) )   {
     125      ndiff++;
     126      if (ndiff < 20)  cout << "!!!Diff: K= " << k << " SPH2= " << sph2(k) << " SPH= " << sph(k) << endl;
     127    }
     128  }
     129  MeanSig(sph, gmoy, gsig);
    65130  cout << "SphMapFromFile Mean= " << gmoy << "  Sigma = " << gsig << endl;
    66131  cout << " NDiff = " << ndiff << " (should be zero = 0) " << endl;
  • trunk/SophyaProg/Tests/tspm2.cc

    r591 r606  
    5858  printf("Xsize= %d   Ysize= %d  NPix= %d\n",img.XSize(),img.YSize(),img.XSize()*img.YSize() );
    5959  n = 0;
     60  img.Zero();
    6061  for(j=0; j<img.YSize(); j++) {
    6162    yd = (r_4)(j+0.5)/(r_4)img.YSize()-0.5;
     
    112113   nomobj = "sphg1";
    113114   fiog.Write(s, nomobj);
    114    cout << "SphMap written to POutPersist with name "  << nomobj << endl;
    115    }
    116 
     115   cout << "SphMap SphereGorski<double> written to POutPersist with name "  << nomobj << endl;
     116   }
     117
     118  FitsIoServer fios;
    117119  // On projete dans un fichier FITS
    118   FitsIoServer fios;
    119120  fios.sinus_picture_projection(sph, "gsin1.fits");
    120121  fios.save(sph, "sph1.fits");
     
    146147  PrtTim("End of Mean-Sig ");
    147148  }
     149
    148150  {
    149   SphereGorski<double> sph(m);
     151  SphereGorski<float> sph(m);
    150152
    151153  cout << "Filling spherical map2 NPixels= " << sph.NbPixels() << endl;
     
    164166
    165167   {
    166    FIO_SphereGorski<double> fiog(&sph) ;
     168   FIO_SphereGorski<float> fiog(&sph) ;
    167169   nomobj = "sphg2";
    168170   fiog.Write(s, nomobj);
    169    cout << "SphMap written to POutPersist with name "  << nomobj << endl;
     171   cout << "SphMap SphereGorski<float> written to POutPersist with name "  << nomobj << endl;
    170172   }
    171173
     
    173175  // On projete dans un fichier FITS
    174176  FitsIoServer fios;
     177   {
     178   cout << "Test of Write/Read SphereGorski<float> to FITS (sphg_r4.fits) " << endl;
     179   fios.save(sph, "sphg_r4.fits");
     180 
     181   SphereGorski<float> sphr(4);
     182   fios.load(sphr, "sphg_r4.fits", 2);
     183   cout << " Read from file - SphereGorski<float> NPixels= " << sphr.NbPixels() << endl;
     184   int ndiff = 0;
     185   for(int k=0; k<sphr.NbPixels(); k++) {
     186    if ( sphr(k) != sph(k) )   {
     187      ndiff++;
     188      if (ndiff < 20)  cout << "!!!Diff: K= " << k << " SPHR= " << sphr(k) << " SPH= " << sph(k) << endl;
     189      }
     190    }
     191   cout << " ReadFrom FITS NDiff = " << ndiff << " (should be zero = 0) " << endl;
     192   
     193   }
     194
     195
    175196  fios.sinus_picture_projection(sph, "gsin2.fits");
    176197  fios.save(sph, "sph2.fits");
    177198
    178   TMatrix<double> mtx(3*m, 6*m);
     199  TMatrix<float> mtx(3*m, 6*m);
    179200  Project_Mol(sph, mtx);
    180201  fios.save(mtx, "mtx2.fits");
Note: See TracChangeset for help on using the changeset viewer.