1 | #include "machdefs.h"
|
---|
2 | #include <iostream.h>
|
---|
3 | #include <math.h>
|
---|
4 |
|
---|
5 | #include "sambainit.h"
|
---|
6 | #include "spherehealpix.h"
|
---|
7 | #include "fiospherehealpix.h"
|
---|
8 | #include "fitsioserver.h"
|
---|
9 | #include "nbrandom.h"
|
---|
10 | #include "bruit.h"
|
---|
11 | #include "timing.h"
|
---|
12 | /*! \ingroup PMixer
|
---|
13 | \file tgsky.cc
|
---|
14 | * \brief \b PROGRAM \b tgsky <BR>
|
---|
15 | * \l Program which generates different types of random skies
|
---|
16 | */
|
---|
17 |
|
---|
18 | // Test program to generate different type of random skies
|
---|
19 | template <class T>
|
---|
20 | void MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig);
|
---|
21 |
|
---|
22 | // ------------- Main program --------------
|
---|
23 | int main(int narg, char* arg[])
|
---|
24 | {
|
---|
25 | double teta,phi;
|
---|
26 | double gmoy=0., gsig=0.;
|
---|
27 |
|
---|
28 | SophyaInit();
|
---|
29 | InitTim(); // Initializing the CPU timer
|
---|
30 | if ((narg < 5) || ((narg>1) && (strcmp(arg[1],"-h") == 0)) ) {
|
---|
31 | cout << " tgsky : Generation of random skies " << endl;
|
---|
32 | cout << " Usage: tgsky NSide TypSky Params FitsFileName [PPFName] " << endl;
|
---|
33 | cout << " - TypSky = 0 Params= m,sig , Gaussian(m,sig) " << endl;
|
---|
34 | cout << " - TypSky = 1 Params= m,sig , OOFNoise(sig) + m" << endl;
|
---|
35 | cout << " - TypSky = 2 Params= K,a,b,m K*cos(a*teta)*sin(b*phi)+m" << endl;
|
---|
36 | cout << " - TypSky = 3 Params= theta,phi DIPOLE" << endl;
|
---|
37 | exit(0);
|
---|
38 | }
|
---|
39 |
|
---|
40 | int ns = atoi(arg[1]);
|
---|
41 | SphereHEALPix<float> sph(ns);
|
---|
42 |
|
---|
43 | cout << "Filling SphereHEALPix<float> NSide= " << ns
|
---|
44 | << " NPixels= " << sph.NbPixels() << endl;
|
---|
45 |
|
---|
46 | int typ = atoi(arg[2]);
|
---|
47 | double m,s,a,b,K;
|
---|
48 | double Theta,Phi;
|
---|
49 | Theta = 0.;
|
---|
50 | Phi = 0.;
|
---|
51 | m = 0.;
|
---|
52 | s = 1.;
|
---|
53 | a = b = 1.;
|
---|
54 | K = 1.;
|
---|
55 | if ((typ < 0) || (typ > 3)) typ = 0;
|
---|
56 | if (typ < 2) {
|
---|
57 | sscanf(arg[3],"%lg,%lg",&m,&s);
|
---|
58 | cout << " TypSky= " << typ << " m= " << m << " sig= " << s << endl;
|
---|
59 | if (typ == 1) cout << " ---> OOFNoise() " << endl;
|
---|
60 | else cout << " ---> NoiseGenerator() " << endl;
|
---|
61 | }
|
---|
62 | else if(typ==2) {
|
---|
63 | sscanf(arg[3],"%lg,%lg,%lg,%lg",&K,&a,&b,&m);
|
---|
64 | cout << " TypSky= " << typ << " K= " << m << " a= " << a << " b="
|
---|
65 | << b << " m= " << m << endl;
|
---|
66 | cout << " ---> K * cos(a*teta) * sin(b*teta) + m" << endl;
|
---|
67 | }
|
---|
68 | else if(typ==3) {
|
---|
69 | sscanf(arg[3],"%lg,%lg",&Theta,&Phi);
|
---|
70 | cout << " TypSky= " << typ << " Theta= " << Theta << " phi= " << Phi ;
|
---|
71 | cout << " ---> DIPOLE " << endl;
|
---|
72 | }
|
---|
73 |
|
---|
74 | PrtTim("End of Init ");
|
---|
75 |
|
---|
76 | if (typ == 2) {
|
---|
77 | for (int j=0;j<sph.NbPixels();j++) {
|
---|
78 | sph.PixThetaPhi(j,teta,phi);
|
---|
79 | sph(j)= K * cos(a*teta)*sin(b*phi) + m;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | else if(typ==3)
|
---|
83 | {
|
---|
84 | UnitVector vd(Theta,Phi);
|
---|
85 | UnitVector vc(Theta,Phi);
|
---|
86 | for(int i=0; i<sph.NbPixels(); i++)
|
---|
87 | {
|
---|
88 | double Thetar,Phir;
|
---|
89 | sph.PixThetaPhi(i,Thetar,Phir);
|
---|
90 | vc.SetThetaPhi(Thetar, Phir);
|
---|
91 | sph(i) += vd.Psc(vc);
|
---|
92 | }
|
---|
93 | }
|
---|
94 | else{
|
---|
95 | NoiseGenerator * ng;
|
---|
96 | if (typ == 0) ng = new NoiseGenerator(s);
|
---|
97 | else ng = new OOFNoise(s);
|
---|
98 | for (int j=0;j<sph.NbPixels();j++) sph(j) = ng->Noise()+m;
|
---|
99 | delete ng;
|
---|
100 | }
|
---|
101 | PrtTim("End of Fill ");
|
---|
102 |
|
---|
103 | // Computing mean and sigma on the sphere
|
---|
104 | MeanSig(sph, gmoy, gsig);
|
---|
105 | cout << "SphereHEALPix<float> Mean= " << gmoy << " Sigma = " << gsig << endl;
|
---|
106 | PrtTim("End of Mean-Sig ");
|
---|
107 |
|
---|
108 | if (narg > 5) {
|
---|
109 | POutPersist s(arg[5]);
|
---|
110 | FIO_SphereHEALPix<float> fiog(&sph) ;
|
---|
111 | fiog.Write(s);
|
---|
112 | cout << "SphereHEALPix<float> written to POutPersist file"
|
---|
113 | << (string)(arg[5]) << endl;
|
---|
114 | PrtTim("End of WritePPF ");
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 |
|
---|
119 | FitsIoServer fios;
|
---|
120 | fios.save(sph, arg[4]);
|
---|
121 | cout << "SphereHEALPix<float> written to FITS file " << (string)(arg[4]) << endl;
|
---|
122 | PrtTim("End of WriteFITS ");
|
---|
123 |
|
---|
124 | cout << " ============ End of tgsky program ======== " << endl;
|
---|
125 | return 0;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /* Nouvelle-Methode */
|
---|
129 | template <class T>
|
---|
130 | void MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig)
|
---|
131 |
|
---|
132 | {
|
---|
133 | gmoy=0.;
|
---|
134 | gsig = 0.;
|
---|
135 | double valok;
|
---|
136 | for(int k=0; k<map.NbPixels(); k++) {
|
---|
137 | valok = map(k);
|
---|
138 | gmoy += valok; gsig += valok*valok;
|
---|
139 | }
|
---|
140 | gmoy /= (double)map.NbPixels();
|
---|
141 | gsig = gsig/(double)map.NbPixels() - gmoy*gmoy;
|
---|
142 | if (gsig >= 0.) gsig = sqrt(gsig);
|
---|
143 | }
|
---|