[761] | 1 | #include "machdefs.h"
|
---|
| 2 | #include <iostream.h>
|
---|
| 3 | #include <math.h>
|
---|
| 4 |
|
---|
| 5 | #include "sambainit.h"
|
---|
[856] | 6 | #include "spherehealpix.h"
|
---|
| 7 | #include "fiospherehealpix.h"
|
---|
[761] | 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 |
|
---|
[809] | 23 | SophyaInit();
|
---|
[761] | 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]);
|
---|
[856] | 35 | SphereHEALPix<float> sph(ns);
|
---|
[761] | 36 |
|
---|
[856] | 37 | cout << "Filling SphereHEALPix<float> NSide= " << ns
|
---|
[761] | 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);
|
---|
[856] | 79 | cout << "SphereHEALPix<float> Mean= " << gmoy << " Sigma = " << gsig << endl;
|
---|
[761] | 80 | PrtTim("End of Mean-Sig ");
|
---|
| 81 |
|
---|
| 82 | if (narg > 5) {
|
---|
| 83 | POutPersist s(arg[5]);
|
---|
[856] | 84 | FIO_SphereHEALPix<float> fiog(&sph) ;
|
---|
[761] | 85 | fiog.Write(s);
|
---|
[856] | 86 | cout << "SphereHEALPix<float> written to POutPersist file"
|
---|
[761] | 87 | << (string)(arg[5]) << endl;
|
---|
| 88 | PrtTim("End of WritePPF ");
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | FitsIoServer fios;
|
---|
| 94 | fios.save(sph, arg[4]);
|
---|
[856] | 95 | cout << "SphereHEALPix<float> written to FITS file " << (string)(arg[4]) << endl;
|
---|
[761] | 96 | PrtTim("End of WriteFITS ");
|
---|
| 97 |
|
---|
| 98 | cout << " ============ End of tgsky program ======== " << endl;
|
---|
| 99 | return 0;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /* Nouvelle-Methode */
|
---|
| 103 | template <class T>
|
---|
| 104 | void 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 | }
|
---|