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