| [1427] | 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 |  | 
|---|
| [1441] | 17 | /*! | 
|---|
| [1607] | 18 | \ingroup PrgMap | 
|---|
| [1441] | 19 | \file map2cl.cc | 
|---|
|  | 20 | \brief \b map2cl: Computes power spectra (C(l)) on spherical maps. | 
|---|
| [1427] | 21 |  | 
|---|
| [1441] | 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 |  | 
|---|
| [1427] | 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" | 
|---|
| [1683] | 52 | << " Usage: map2cl [-float/-r4] [-lmax lval] [-thetacut dtdeg] [-iter_order lval]\n" | 
|---|
| [1430] | 53 | << "        [-fitsin] [-fitsout] InFileName OutFileName \n" | 
|---|
| [1427] | 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" | 
|---|
| [1683] | 58 | << "   -iter_order lval : 1,2,3,4... order of an iterative analysis , 3rd order is usually optimal (default=0 -> standard analysis)\n" | 
|---|
| [1427] | 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 */ | 
|---|
|  | 68 | template <class T> | 
|---|
|  | 69 | class _Map2Cl { | 
|---|
|  | 70 | public : | 
|---|
|  | 71 | static void ComputeCl(string & infile, string & outfile, int lmax, double tcut, | 
|---|
| [1683] | 72 | int iterationOrder, bool fgfitsin, bool fgfitsout) | 
|---|
| [1427] | 73 | { | 
|---|
|  | 74 | double deg2rad =  M_PI/180.; | 
|---|
|  | 75 | double minute2rad =  M_PI/(180.*60.); | 
|---|
| [1683] | 76 |  | 
|---|
| [1427] | 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; | 
|---|
| [1683] | 87 | } | 
|---|
| [1427] | 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 | 
|---|
| [1683] | 95 | << " cos_theta_cut= " << ctcut << " iter_order= " << iterationOrder << ") theta_cut=" << tcut << " deg"  << endl; | 
|---|
| [1427] | 96 | // Decomposition de la carte en C_l | 
|---|
|  | 97 | SphericalTransformServer<T> sphtr; | 
|---|
| [1683] | 98 | TVector<T> clvec = sphtr.DecomposeToCl(sph, lmax, ctcut, iterationOrder); | 
|---|
| [1427] | 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 */ | 
|---|
|  | 123 | int main(int narg, char *arg[]) | 
|---|
|  | 124 | { | 
|---|
|  | 125 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false); | 
|---|
|  | 126 |  | 
|---|
|  | 127 | int lmax = 255; | 
|---|
| [1683] | 128 | int iterationOrder = 0; | 
|---|
| [1427] | 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 | } | 
|---|
| [1683] | 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 | } | 
|---|
| [1427] | 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 |  | 
|---|
| [1441] | 164 | if ((narg-ko) < 2)  Usage(true); | 
|---|
| [1427] | 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; | 
|---|
| [1683] | 174 | _Map2Cl<r_4>::ComputeCl(infile, outfile, lmax, tcut, iterationOrder, fgfitsin, fgfitsout); | 
|---|
| [1427] | 175 | } | 
|---|
|  | 176 | else { | 
|---|
|  | 177 | cout << " SphereHEALPix<r_8>  --> Power spectrum C_l<r_8> (double)" << endl; | 
|---|
| [1683] | 178 | _Map2Cl<r_8>::ComputeCl(infile, outfile, lmax, tcut, iterationOrder,fgfitsin, fgfitsout); | 
|---|
| [1427] | 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 |  | 
|---|