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