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