| 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 | double teta,phi; | 
|---|
| 14 | double gmoy=0., gsig=0.; | 
|---|
| 15 |  | 
|---|
| 16 | SophyaInit(); | 
|---|
| 17 | InitTim();   // Initializing the CPU timer | 
|---|
| 18 | if ((narg < 5) || ((narg>1) && (strcmp(arg[1],"-h") == 0)) )  { | 
|---|
| 19 | cout << " tgsky : Generation of random skies  " << endl; | 
|---|
| 20 | cout << " Usage: tgsky NSide TypSky Params FitsFileName [PPFName] " << endl; | 
|---|
| 21 | cout << "   - TypSky = 0  Params= m,sig  , Gaussian(m,sig) " << endl; | 
|---|
| 22 | cout << "   - TypSky = 1  Params= m,sig  , OOFNoise(sig) + m" << endl; | 
|---|
| 23 | cout << "   - TypSky = 2  Params= K,a,b,m  K*cos(a*teta)*sin(b*phi)+m" << endl; | 
|---|
| 24 | cout << "   - TypSky = 3  Params= theta,phi DIPOLE" << endl; | 
|---|
| 25 | exit(0); | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | int  ns = atoi(arg[1]); | 
|---|
| 29 | SphereHEALPix<float> sph(ns); | 
|---|
| 30 |  | 
|---|
| 31 | cout << "Filling SphereHEALPix<float> NSide= " << ns | 
|---|
| 32 | << "  NPixels= " << sph.NbPixels() << endl; | 
|---|
| 33 |  | 
|---|
| 34 | int typ = atoi(arg[2]); | 
|---|
| 35 | double m,s,a,b,K; | 
|---|
| 36 | double Theta,Phi; | 
|---|
| 37 | Theta = 0.; | 
|---|
| 38 | Phi   = 0.; | 
|---|
| 39 | m = 0.; | 
|---|
| 40 | s = 1.; | 
|---|
| 41 | a = b = 1.; | 
|---|
| 42 | K = 1.; | 
|---|
| 43 | if ((typ < 0) || (typ > 3)) typ = 0; | 
|---|
| 44 | if (typ < 2)  { | 
|---|
| 45 | sscanf(arg[3],"%lg,%lg",&m,&s); | 
|---|
| 46 | cout << "  TypSky= " << typ << " m= " << m << " sig= " << s << endl; | 
|---|
| 47 | if (typ == 1) cout << "  ---> OOFNoise() " << endl; | 
|---|
| 48 | else cout << "  ---> NoiseGenerator() " << endl; | 
|---|
| 49 | } | 
|---|
| 50 | else if(typ==2) { | 
|---|
| 51 | sscanf(arg[3],"%lg,%lg,%lg,%lg",&K,&a,&b,&m); | 
|---|
| 52 | cout << "  TypSky= " << typ << " K= " << m << " a= " << a << " b=" | 
|---|
| 53 | << b << " m= " << m << endl; | 
|---|
| 54 | cout << "    ---> K * cos(a*teta) * sin(b*teta) + m" << endl; | 
|---|
| 55 | } | 
|---|
| 56 | else if(typ==3) { | 
|---|
| 57 | sscanf(arg[3],"%lg,%lg",&Theta,&Phi); | 
|---|
| 58 | cout << "  TypSky= " << typ << " Theta= " << Theta << " phi= " << Phi ; | 
|---|
| 59 | cout << "    ---> DIPOLE " << endl; | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | PrtTim("End of Init "); | 
|---|
| 63 |  | 
|---|
| 64 | if (typ == 2) { | 
|---|
| 65 | for (int j=0;j<sph.NbPixels();j++)   { | 
|---|
| 66 | sph.PixThetaPhi(j,teta,phi); | 
|---|
| 67 | sph(j)= K * cos(a*teta)*sin(b*phi) + m; | 
|---|
| 68 | } | 
|---|
| 69 | } | 
|---|
| 70 | else if(typ==3) | 
|---|
| 71 | { | 
|---|
| 72 | UnitVector vd(Theta,Phi); | 
|---|
| 73 | UnitVector vc(Theta,Phi); | 
|---|
| 74 | for(int i=0; i<sph.NbPixels(); i++) | 
|---|
| 75 | { | 
|---|
| 76 | double Thetar,Phir; | 
|---|
| 77 | sph.PixThetaPhi(i,Thetar,Phir); | 
|---|
| 78 | vc.SetThetaPhi(Thetar,  Phir); | 
|---|
| 79 | sph(i) += vd.Psc(vc); | 
|---|
| 80 | } | 
|---|
| 81 | } | 
|---|
| 82 | else{ | 
|---|
| 83 | NoiseGenerator * ng; | 
|---|
| 84 | if (typ == 0) ng = new NoiseGenerator(s); | 
|---|
| 85 | else ng = new OOFNoise(s); | 
|---|
| 86 | for (int j=0;j<sph.NbPixels();j++)   sph(j) = ng->Noise()+m; | 
|---|
| 87 | delete ng; | 
|---|
| 88 | } | 
|---|
| 89 | PrtTim("End of Fill "); | 
|---|
| 90 |  | 
|---|
| 91 | // Computing mean and sigma on the sphere | 
|---|
| 92 | MeanSig(sph.DataBlock(), gmoy, gsig); | 
|---|
| 93 | cout << "SphereHEALPix<float> Mean= " << gmoy << "  Sigma = " << gsig << endl; | 
|---|
| 94 | PrtTim("End of Mean-Sig "); | 
|---|
| 95 |  | 
|---|
| 96 | if (narg > 5) { | 
|---|
| 97 | POutPersist s(arg[5]); | 
|---|
| 98 | FIO_SphereHEALPix<float> fiog(&sph) ; | 
|---|
| 99 | fiog.Write(s); | 
|---|
| 100 | cout << "SphereHEALPix<float> written to POutPersist file" | 
|---|
| 101 | << (string)(arg[5]) << endl; | 
|---|
| 102 | PrtTim("End of WritePPF "); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 |  | 
|---|
| 106 |  | 
|---|
| 107 | FitsIoServer fios; | 
|---|
| 108 | fios.save(sph, arg[4]); | 
|---|
| 109 | cout << "SphereHEALPix<float> written to FITS file " << (string)(arg[4]) << endl; | 
|---|
| 110 | PrtTim("End of WriteFITS "); | 
|---|
| 111 |  | 
|---|
| 112 | cout <<  " ============ End of tgsky program ======== " << endl; | 
|---|
| 113 | return 0; | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|