| 1 | #include "pmixer.h"
 | 
|---|
| 2 | #include "mapoperation.h"
 | 
|---|
| 3 | 
 | 
|---|
| 4 | /*! \ingroup PMixer
 | 
|---|
| 5 |  * \file tgsky.cc
 | 
|---|
| 6 |  * \brief \b PROGRAM \b tgsky  <BR>
 | 
|---|
| 7 |  * \l Program which generates different types of random skies
 | 
|---|
| 8 |  */
 | 
|---|
| 9 | // ------------- Main program --------------
 | 
|---|
| 10 | 
 | 
|---|
| 11 | int main(int narg, char* arg[]) 
 | 
|---|
| 12 | {
 | 
|---|
| 13 | 
 | 
|---|
| 14 |   if ((narg < 5) || ((narg>1) && (strcmp(arg[1],"-h") == 0)) )  {
 | 
|---|
| 15 |     cout << " tgsky : Generation of random skies  " << endl;
 | 
|---|
| 16 |     cout << " Usage: tgsky NSide TypSky Params FitsFileName [PPFName] " << endl;
 | 
|---|
| 17 |     cout << "   - TypSky = 0  Params= m,sig  , Gaussian(m,sig) " << endl;
 | 
|---|
| 18 |     cout << "   - TypSky = 1  Params= m,sig  , OOFNoise(sig) + m" << endl;
 | 
|---|
| 19 |     cout << "   - TypSky = 2  Params= K,a,b,m  K*cos(a*teta)*sin(b*phi)+m" << endl;   
 | 
|---|
| 20 |     cout << "   - TypSky = 3  Params= theta,phi DIPOLE" << endl;   
 | 
|---|
| 21 |     exit(0);
 | 
|---|
| 22 |     }
 | 
|---|
| 23 | 
 | 
|---|
| 24 |   try {
 | 
|---|
| 25 |   double teta,phi;
 | 
|---|
| 26 |   double gmoy=0., gsig=0.;
 | 
|---|
| 27 | #if !defined(SunOS) || !defined(__GNUG__)
 | 
|---|
| 28 |   // ca se plante sur Sun !
 | 
|---|
| 29 |   SophyaInit();
 | 
|---|
| 30 | #endif
 | 
|---|
| 31 |   InitTim();   // Initializing the CPU timer 
 | 
|---|
| 32 |   int  ns = atoi(arg[1]);
 | 
|---|
| 33 |   SphereHEALPix<float> sph(ns);
 | 
|---|
| 34 | 
 | 
|---|
| 35 |   cout << "Filling SphereHEALPix<float> NSide= " << ns 
 | 
|---|
| 36 |        << "  NPixels= " << sph.NbPixels() << endl;
 | 
|---|
| 37 | 
 | 
|---|
| 38 |   int typ = atoi(arg[2]);
 | 
|---|
| 39 |   double m,s,a,b,K;
 | 
|---|
| 40 |   double Theta,Phi;
 | 
|---|
| 41 |   Theta = 0.;
 | 
|---|
| 42 |   Phi   = 0.;
 | 
|---|
| 43 |   m = 0.;
 | 
|---|
| 44 |   s = 1.;
 | 
|---|
| 45 |   a = b = 1.;
 | 
|---|
| 46 |   K = 1.;
 | 
|---|
| 47 |   if ((typ < 0) || (typ > 3)) typ = 0;
 | 
|---|
| 48 |   if (typ < 2)  { 
 | 
|---|
| 49 |     sscanf(arg[3],"%lg,%lg",&m,&s);
 | 
|---|
| 50 |     cout << "  TypSky= " << typ << " m= " << m << " sig= " << s << endl;
 | 
|---|
| 51 |     if (typ == 1) cout << "  ---> OOFNoise() " << endl;
 | 
|---|
| 52 |     else cout << "  ---> NoiseGenerator() " << endl;
 | 
|---|
| 53 |   }
 | 
|---|
| 54 |   else if(typ==2) { 
 | 
|---|
| 55 |     sscanf(arg[3],"%lg,%lg,%lg,%lg",&K,&a,&b,&m);
 | 
|---|
| 56 |     cout << "  TypSky= " << typ << " K= " << m << " a= " << a << " b=" 
 | 
|---|
| 57 |          << b << " m= " << m << endl;
 | 
|---|
| 58 |     cout << "    ---> K * cos(a*teta) * sin(b*teta) + m" << endl;
 | 
|---|
| 59 |     }
 | 
|---|
| 60 |   else if(typ==3) { 
 | 
|---|
| 61 |     sscanf(arg[3],"%lg,%lg",&Theta,&Phi);
 | 
|---|
| 62 |     cout << "  TypSky= " << typ << " Theta= " << Theta << " phi= " << Phi ;
 | 
|---|
| 63 |     cout << "    ---> DIPOLE " << endl;
 | 
|---|
| 64 |     }
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   PrtTim("End of Init ");
 | 
|---|
| 67 | 
 | 
|---|
| 68 |   if (typ == 2) {
 | 
|---|
| 69 |     for (int j=0;j<sph.NbPixels();j++)   {
 | 
|---|
| 70 |       sph.PixThetaPhi(j,teta,phi);
 | 
|---|
| 71 |       sph(j)= K * cos(a*teta)*sin(b*phi) + m;
 | 
|---|
| 72 |     }
 | 
|---|
| 73 |   }
 | 
|---|
| 74 |   else if(typ==3)
 | 
|---|
| 75 |     {
 | 
|---|
| 76 |       UnitVector vd(Theta,Phi);
 | 
|---|
| 77 |       UnitVector vc(Theta,Phi);
 | 
|---|
| 78 |       for(int i=0; i<sph.NbPixels(); i++)
 | 
|---|
| 79 |         {
 | 
|---|
| 80 |           double Thetar,Phir;
 | 
|---|
| 81 |           sph.PixThetaPhi(i,Thetar,Phir);      
 | 
|---|
| 82 |           vc.SetThetaPhi(Thetar,  Phir);
 | 
|---|
| 83 |           sph(i) += vd.Psc(vc);
 | 
|---|
| 84 |         }
 | 
|---|
| 85 |     }
 | 
|---|
| 86 |   else{
 | 
|---|
| 87 |     NoiseGenerator * ng;
 | 
|---|
| 88 |     if (typ == 0) ng = new NoiseGenerator(s);
 | 
|---|
| 89 |     else ng = new OOFNoise(s);    
 | 
|---|
| 90 |     for (int j=0;j<sph.NbPixels();j++)   sph(j) = ng->Noise()+m;
 | 
|---|
| 91 |     delete ng;
 | 
|---|
| 92 |   }
 | 
|---|
| 93 |   PrtTim("End of Fill ");
 | 
|---|
| 94 | 
 | 
|---|
| 95 |   // Computing mean and sigma on the sphere 
 | 
|---|
| 96 |   MeanSig(sph.DataBlock(), gmoy, gsig);
 | 
|---|
| 97 |   cout << "SphereHEALPix<float> Mean= " << gmoy << "  Sigma = " << gsig << endl;
 | 
|---|
| 98 |   PrtTim("End of Mean-Sig ");
 | 
|---|
| 99 | 
 | 
|---|
| 100 |   if (narg > 5) {
 | 
|---|
| 101 |    POutPersist s(arg[5]); 
 | 
|---|
| 102 |    FIO_SphereHEALPix<float> fiog(&sph) ;
 | 
|---|
| 103 |    fiog.Write(s);
 | 
|---|
| 104 |    cout << "SphereHEALPix<float> written to POutPersist file"  
 | 
|---|
| 105 |         << (string)(arg[5]) << endl;
 | 
|---|
| 106 |    PrtTim("End of WritePPF ");
 | 
|---|
| 107 |    }
 | 
|---|
| 108 | 
 | 
|---|
| 109 | 
 | 
|---|
| 110 |   { 
 | 
|---|
| 111 |   FitsOutFile fios(arg[4]);
 | 
|---|
| 112 |   fios.firstImageOnPrimaryHeader(false); // Use secondary header 
 | 
|---|
| 113 |   DVList dvl;
 | 
|---|
| 114 |   dvl["PDMTYPE"] = "COMPMAP";
 | 
|---|
| 115 |   dvl.SetComment("PDMTYPE", "Planck Data Model Type"); 
 | 
|---|
| 116 |   dvl["SOPHYVER"] =  SophyaVersion();
 | 
|---|
| 117 |   dvl.SetComment("SOPHYVER", "Sophya Version"); 
 | 
|---|
| 118 |   dvl["TGSKYKW"] =  "Test Keyword from tgsky.cc";
 | 
|---|
| 119 |   fios.DVListIntoPrimaryHeader(dvl);  
 | 
|---|
| 120 |   sph.Info() = dvl;
 | 
|---|
| 121 |   fios << sph; 
 | 
|---|
| 122 |   cout << "SphereHEALPix<float> written to FITS file " << (string)(arg[4]) << endl;
 | 
|---|
| 123 |   PrtTim("End of WriteFITS ");
 | 
|---|
| 124 |   }
 | 
|---|
| 125 |   }
 | 
|---|
| 126 |   catch (PThrowable & exc) {
 | 
|---|
| 127 |     cerr << " tgsky: Catched Exception - Msg= " << exc.Msg() 
 | 
|---|
| 128 |          << " Type=" << (string)typeid(exc).name() << endl;
 | 
|---|
| 129 |   }
 | 
|---|
| 130 |   catch (...) {
 | 
|---|
| 131 |     cerr << " tgsky: Catched unknown exception (...) " << endl;
 | 
|---|
| 132 |   }
 | 
|---|
| 133 |   cout <<  " ============ End of tgsky program ======== " << endl;
 | 
|---|
| 134 |   return 0;
 | 
|---|
| 135 | }
 | 
|---|
| 136 | 
 | 
|---|