source: Sophya/trunk/SophyaProg/PrgMap/map2cl.cc@ 1683

Last change on this file since 1683 was 1683, checked in by lemeur, 24 years ago

methode iterative pour analyse harmonique

File size: 6.2 KB
Line 
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 PrgMap
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 */
43void 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] [-iter_order lval]\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 << " -iter_order lval : 1,2,3,4... order of an iterative analysis , 3rd order is usually optimal (default=0 -> standard analysis)\n"
59 << " -fitsout: Select the FITS format for the output map (default PPF format) \n"
60 << " -fitsin : Select the FITS format for the input vector (default PPF format) \n"
61 << " InFileName : Input file name (HEALPix map) \n"
62 << " OutFileName : Output file name (the C_l vector) \n" << endl;
63 exit(0);
64 }
65}
66
67/* Nouvelle-Fonction */
68template <class T>
69class _Map2Cl {
70public :
71static void ComputeCl(string & infile, string & outfile, int lmax, double tcut,
72 int iterationOrder, bool fgfitsin, bool fgfitsout)
73{
74 double deg2rad = M_PI/180.;
75 double minute2rad = M_PI/(180.*60.);
76
77 SphereHEALPix<T> sph;
78 if (fgfitsin) {
79 cout << "--- Reading Input FITS file " << infile << endl;
80 FitsInFile fii(infile);
81 fii >> sph;
82 }
83 else {
84 cout << "--- Reading Input PPF file " << infile << endl;
85 PInPersist ppi(infile);
86 ppi >> sph;
87 }
88
89 cout << " Input map : NbPixels= " << sph.NbPixels() << " NSide= "
90 << sph.SizeIndex() << " Resolution= "
91 << sqrt(sph.PixSolAngle(0))/minute2rad << " Arcminutes " << endl;
92
93 double ctcut = (tcut < 1.e-19) ? 0. : cos((90.-tcut)*deg2rad);
94 cout << "--- Calling DecomposeToCl() (lmax= " << lmax
95 << " cos_theta_cut= " << ctcut << " iter_order= " << iterationOrder << ") theta_cut=" << tcut << " deg" << endl;
96 // Decomposition de la carte en C_l
97 SphericalTransformServer<T> sphtr;
98 TVector<T> clvec = sphtr.DecomposeToCl(sph, lmax, ctcut, iterationOrder);
99
100 T min, max;
101 double mean, sigma;
102 clvec.MinMax(min, max);
103 MeanSigma(clvec, mean, sigma);
104 cout << "--- Statistics on the computed C_l vector: Size=" << clvec.Size() << endl;
105 cout << " C_l.Min= " << min << " C_l.Max= " << max
106 << " C_l.Mean= " << mean << " C_l.Sigma= " << sigma << endl;
107
108 if (fgfitsout) {
109 cout << "--- Writing C_l vector to Output FITS file " << outfile << endl;
110 FitsOutFile fio(outfile);
111 fio << clvec;
112 }
113 else {
114 cout << "--- Writing C_l vector to Output PPF file " << outfile << endl;
115 POutPersist ppo(outfile);
116 ppo << clvec;
117 }
118}
119
120};
121
122/* Main-Program */
123int main(int narg, char *arg[])
124{
125 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
126
127 int lmax = 255;
128 int iterationOrder = 0;
129 double tcut = 0.;
130 string infile;
131 string outfile;
132 bool fgfitsin = false;
133 bool fgfitsout = false;
134 bool fgr4 = false;
135 cout << " map2cl : Decoding command line options ... " << endl;
136
137 int ko=1;
138 for (int k=1; k<narg; k++) {
139 if (strcmp(arg[k], "-lmax") == 0) {
140 if (k == narg-1) Usage(true); // -lmax est suivi d'un argument
141 lmax = atoi(arg[k+1]); k++; // k++ pour sauter au suivant
142 }
143 else if (strcmp(arg[k], "-thetacut") == 0) {
144 if (k == narg-1) Usage(true); // -thetacut est suivi d'un argument
145 tcut = atof(arg[k+1]); k++; // k++ pour sauter au suivant
146 }
147 else if (strcmp(arg[k], "-iter_order") == 0) {
148 if (k == narg-1) Usage(true); // -iter_order est suivi d'un argument
149 iterationOrder = atof(arg[k+1]); k++; // k++ pour sauter au suivant
150 }
151 else if (strcmp(arg[k], "-fitsin") == 0) {
152 fgfitsin = true;
153 }
154 else if (strcmp(arg[k], "-fitsout") == 0) {
155 fgfitsout = true;
156 }
157 else if ((strcmp(arg[k], "-float") == 0) || (strcmp(arg[k], "-r4") == 0) ) {
158 fgr4 = true;
159 }
160
161 else { ko = k; break; } // Debut des noms
162 }
163
164 if ((narg-ko) < 2) Usage(true);
165 infile = arg[ko];
166 outfile = arg[ko+1];
167
168 // Bloc try de gestion des exception
169 try {
170 InitTim();
171 SophyaInit();
172 if (fgr4) {
173 cout << " SphereHEALPix<r_4> --> Power spectrum C_l<r_4> (float)" << endl;
174 _Map2Cl<r_4>::ComputeCl(infile, outfile, lmax, tcut, iterationOrder, fgfitsin, fgfitsout);
175 }
176 else {
177 cout << " SphereHEALPix<r_8> --> Power spectrum C_l<r_8> (double)" << endl;
178 _Map2Cl<r_8>::ComputeCl(infile, outfile, lmax, tcut, iterationOrder,fgfitsin, fgfitsout);
179 }
180 }
181 catch (PThrowable & exc) { // Exceptions de SOPHYA
182 cerr << " map2cl: Catched Exception " << (string)typeid(exc).name()
183 << " - Msg= " << exc.Msg() << endl;
184 }
185 catch (...) { // Autres Exceptions
186 cerr << " map2cl: some other exception was caught ! " << endl;
187 }
188
189 PrtTim("End of map2cl ");
190 return(0);
191}
192
193
194
Note: See TracBrowser for help on using the repository browser.