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