source: Sophya/trunk/SophyaProg/PMixer/tgsky.cc@ 904

Last change on this file since 904 was 856, checked in by ansari, 25 years ago

Adapatation a SphereHEALPix (remplacement de SphereGorski) - Reza 10/4/2000

File size: 3.2 KB
Line 
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
14template <class T>
15void MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig);
16
17// ------------- Main program --------------
18int 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 exit(0);
32 }
33
34 int ns = atoi(arg[1]);
35 SphereHEALPix<float> sph(ns);
36
37 cout << "Filling SphereHEALPix<float> NSide= " << ns
38 << " NPixels= " << sph.NbPixels() << endl;
39
40 int typ = atoi(arg[2]);
41 double m,s,a,b,K;
42 m = 0.;
43 s = 1.;
44 a = b = 1.;
45 K = 1.;
46 if ((typ < 0) || (typ > 2)) typ = 0;
47 if (typ < 2) {
48 sscanf(arg[3],"%lg,%lg",&m,&s);
49 cout << " TypSky= " << typ << " m= " << m << " sig= " << s << endl;
50 if (typ == 1) cout << " ---> OOFNoise() " << endl;
51 else cout << " ---> NoiseGenerator() " << endl;
52 }
53 else {
54 sscanf(arg[3],"%lg,%lg,%lg,%lg",&K,&a,&b,&m);
55 cout << " TypSky= " << typ << " K= " << m << " a= " << a << " b="
56 << b << " m= " << m << endl;
57 cout << " ---> K * cos(a*teta) * sin(b*teta) + m" << endl;
58 }
59
60 PrtTim("End of Init ");
61
62 if (typ == 2) {
63 for (int j=0;j<sph.NbPixels();j++) {
64 sph.PixThetaPhi(j,teta,phi);
65 sph(j)= K * cos(a*teta)*sin(b*phi) + m;
66 }
67 }
68 else {
69 NoiseGenerator * ng;
70 if (typ == 0) ng = new NoiseGenerator(s);
71 else ng = new OOFNoise(s);
72 for (int j=0;j<sph.NbPixels();j++) sph(j) = ng->Noise()+m;
73 delete ng;
74 }
75 PrtTim("End of Fill ");
76
77 // Computing mean and sigma on the sphere
78 MeanSig(sph, gmoy, gsig);
79 cout << "SphereHEALPix<float> Mean= " << gmoy << " Sigma = " << gsig << endl;
80 PrtTim("End of Mean-Sig ");
81
82 if (narg > 5) {
83 POutPersist s(arg[5]);
84 FIO_SphereHEALPix<float> fiog(&sph) ;
85 fiog.Write(s);
86 cout << "SphereHEALPix<float> written to POutPersist file"
87 << (string)(arg[5]) << endl;
88 PrtTim("End of WritePPF ");
89 }
90
91
92
93 FitsIoServer fios;
94 fios.save(sph, arg[4]);
95 cout << "SphereHEALPix<float> written to FITS file " << (string)(arg[4]) << endl;
96 PrtTim("End of WriteFITS ");
97
98 cout << " ============ End of tgsky program ======== " << endl;
99 return 0;
100}
101
102/* Nouvelle-Methode */
103template <class T>
104void MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig)
105
106{
107 gmoy=0.;
108 gsig = 0.;
109 double valok;
110 for(int k=0; k<map.NbPixels(); k++) {
111 valok = map(k);
112 gmoy += valok; gsig += valok*valok;
113 }
114 gmoy /= (double)map.NbPixels();
115 gsig = gsig/(double)map.NbPixels() - gmoy*gmoy;
116 if (gsig >= 0.) gsig = sqrt(gsig);
117}
Note: See TracBrowser for help on using the repository browser.