1 | #include "machdefs.h" // Definitions specifiques SOPHYA
|
---|
2 |
|
---|
3 | #include <math.h>
|
---|
4 | #include <iostream.h>
|
---|
5 |
|
---|
6 | #include "nbmath.h"
|
---|
7 | #include "timing.h"
|
---|
8 |
|
---|
9 | #include "array.h"
|
---|
10 | #include "skymap.h"
|
---|
11 | #include "samba.h"
|
---|
12 | #include "sambainit.h"
|
---|
13 | #include "fitsspherehealpix.h"
|
---|
14 | #include "fitstarray.h"
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 | /* Nouvelle-Fonction */
|
---|
19 | void Usage(bool fgerr)
|
---|
20 | {
|
---|
21 | cout << endl;
|
---|
22 | if (fgerr) {
|
---|
23 | cout << " map2cl : Argument Error ! map2cl -h for usage " << endl;
|
---|
24 | exit(1);
|
---|
25 | }
|
---|
26 | else {
|
---|
27 | cout << " map2cl : Spherical harmonics analysis - HEALPix map -> Power spectrum C_l \n"
|
---|
28 | << " Usage: map2cl [-float/-r4] [-lmax lval] [-thetacut dtdeg] \n"
|
---|
29 | << " [-fitsin] [-fitsout] InFileName OutFileName \n"
|
---|
30 | << " -float (-r4): single precision C_l and map (default = double) \n"
|
---|
31 | << " -lmax lval: Maximum value for l index (default=255)\n"
|
---|
32 | << " -thetacut dtdeg : Symmetric delta-theta cut (in degree) along equator \n"
|
---|
33 | << " (default=0 -> no cut)\n"
|
---|
34 | << " -fitsout: Select the FITS format for the output map (default PPF format) \n"
|
---|
35 | << " -fitsin : Select the FITS format for the input vector (default PPF format) \n"
|
---|
36 | << " InFileName : Input file name (HEALPix map) \n"
|
---|
37 | << " OutFileName : Output file name (the C_l vector) \n" << endl;
|
---|
38 | exit(0);
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | /* Nouvelle-Fonction */
|
---|
43 | template <class T>
|
---|
44 | class _Map2Cl {
|
---|
45 | public :
|
---|
46 | static void ComputeCl(string & infile, string & outfile, int lmax, double tcut,
|
---|
47 | bool fgfitsin, bool fgfitsout)
|
---|
48 | {
|
---|
49 | double deg2rad = M_PI/180.;
|
---|
50 | double minute2rad = M_PI/(180.*60.);
|
---|
51 |
|
---|
52 | SphereHEALPix<T> sph;
|
---|
53 | if (fgfitsin) {
|
---|
54 | cout << "--- Reading Input FITS file " << infile << endl;
|
---|
55 | FitsInFile fii(infile);
|
---|
56 | fii >> sph;
|
---|
57 | }
|
---|
58 | else {
|
---|
59 | cout << "--- Reading Input PPF file " << infile << endl;
|
---|
60 | PInPersist ppi(infile);
|
---|
61 | ppi >> sph;
|
---|
62 | }
|
---|
63 |
|
---|
64 | cout << " Input map : NbPixels= " << sph.NbPixels() << " NSide= "
|
---|
65 | << sph.SizeIndex() << " Resolution= "
|
---|
66 | << sqrt(sph.PixSolAngle(0))/minute2rad << " Arcminutes " << endl;
|
---|
67 |
|
---|
68 | double ctcut = (tcut < 1.e-19) ? 0. : cos((90.-tcut)*deg2rad);
|
---|
69 | cout << "--- Calling DecomposeToCl() (lmax= " << lmax
|
---|
70 | << " cos_theta_cut= " << ctcut << ") theta_cut=" << tcut << " deg" << endl;
|
---|
71 | // Decomposition de la carte en C_l
|
---|
72 | SphericalTransformServer<T> sphtr;
|
---|
73 | TVector<T> clvec = sphtr.DecomposeToCl(sph, lmax, ctcut);
|
---|
74 |
|
---|
75 | T min, max;
|
---|
76 | double mean, sigma;
|
---|
77 | clvec.MinMax(min, max);
|
---|
78 | MeanSigma(clvec, mean, sigma);
|
---|
79 | cout << "--- Statistics on the computed C_l vector: Size=" << clvec.Size() << endl;
|
---|
80 | cout << " C_l.Min= " << min << " C_l.Max= " << max
|
---|
81 | << " C_l.Mean= " << mean << " C_l.Sigma= " << sigma << endl;
|
---|
82 |
|
---|
83 | if (fgfitsout) {
|
---|
84 | cout << "--- Writing C_l vector to Output FITS file " << outfile << endl;
|
---|
85 | FitsOutFile fio(outfile);
|
---|
86 | fio << clvec;
|
---|
87 | }
|
---|
88 | else {
|
---|
89 | cout << "--- Writing C_l vector to Output PPF file " << outfile << endl;
|
---|
90 | POutPersist ppo(outfile);
|
---|
91 | ppo << clvec;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | };
|
---|
96 |
|
---|
97 | /* Main-Program */
|
---|
98 | int main(int narg, char *arg[])
|
---|
99 | {
|
---|
100 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
|
---|
101 |
|
---|
102 | int lmax = 255;
|
---|
103 | double tcut = 0.;
|
---|
104 | string infile;
|
---|
105 | string outfile;
|
---|
106 | bool fgfitsin = false;
|
---|
107 | bool fgfitsout = false;
|
---|
108 | bool fgr4 = false;
|
---|
109 | cout << " map2cl : Decoding command line options ... " << endl;
|
---|
110 |
|
---|
111 | int ko=1;
|
---|
112 | for (int k=1; k<narg; k++) {
|
---|
113 | if (strcmp(arg[k], "-lmax") == 0) {
|
---|
114 | if (k == narg-1) Usage(true); // -lmax est suivi d'un argument
|
---|
115 | lmax = atoi(arg[k+1]); k++; // k++ pour sauter au suivant
|
---|
116 | }
|
---|
117 | else if (strcmp(arg[k], "-thetacut") == 0) {
|
---|
118 | if (k == narg-1) Usage(true); // -thetacut est suivi d'un argument
|
---|
119 | tcut = atof(arg[k+1]); k++; // k++ pour sauter au suivant
|
---|
120 | }
|
---|
121 | else if (strcmp(arg[k], "-fitsin") == 0) {
|
---|
122 | fgfitsin = true;
|
---|
123 | }
|
---|
124 | else if (strcmp(arg[k], "-fitsout") == 0) {
|
---|
125 | fgfitsout = true;
|
---|
126 | }
|
---|
127 | else if ((strcmp(arg[k], "-float") == 0) || (strcmp(arg[k], "-r4") == 0) ) {
|
---|
128 | fgr4 = true;
|
---|
129 | }
|
---|
130 |
|
---|
131 | else { ko = k; break; } // Debut des noms
|
---|
132 | }
|
---|
133 |
|
---|
134 | if ((narg-ko) < 1) Usage(true);
|
---|
135 | infile = arg[ko];
|
---|
136 | outfile = arg[ko+1];
|
---|
137 |
|
---|
138 | // Bloc try de gestion des exception
|
---|
139 | try {
|
---|
140 | InitTim();
|
---|
141 | SophyaInit();
|
---|
142 | if (fgr4) {
|
---|
143 | cout << " SphereHEALPix<r_4> --> Power spectrum C_l<r_4> (float)" << endl;
|
---|
144 | _Map2Cl<r_4>::ComputeCl(infile, outfile, lmax, tcut, fgfitsin, fgfitsout);
|
---|
145 | }
|
---|
146 | else {
|
---|
147 | cout << " SphereHEALPix<r_8> --> Power spectrum C_l<r_8> (double)" << endl;
|
---|
148 | _Map2Cl<r_8>::ComputeCl(infile, outfile, lmax, tcut, fgfitsin, fgfitsout);
|
---|
149 | }
|
---|
150 | }
|
---|
151 | catch (PThrowable & exc) { // Exceptions de SOPHYA
|
---|
152 | cerr << " map2cl: Catched Exception " << (string)typeid(exc).name()
|
---|
153 | << " - Msg= " << exc.Msg() << endl;
|
---|
154 | }
|
---|
155 | catch (...) { // Autres Exceptions
|
---|
156 | cerr << " map2cl: some other exception was caught ! " << endl;
|
---|
157 | }
|
---|
158 |
|
---|
159 | PrtTim("End of map2cl ");
|
---|
160 | return(0);
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|