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

Last change on this file since 1713 was 1713, checked in by cmv, 24 years ago

commentaires... cmv 19/10/01

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