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