[2615] | 1 | #include "sopnamsp.h"
|
---|
[1427] | 2 | #include "machdefs.h" // Definitions specifiques SOPHYA
|
---|
| 3 |
|
---|
| 4 | #include <math.h>
|
---|
[2322] | 5 | #include <iostream>
|
---|
[1427] | 6 |
|
---|
| 7 | #include "nbmath.h"
|
---|
| 8 | #include "timing.h"
|
---|
| 9 |
|
---|
| 10 | #include "array.h"
|
---|
| 11 | #include "skymap.h"
|
---|
| 12 | #include "samba.h"
|
---|
| 13 | #include "sambainit.h"
|
---|
| 14 | #include "fitsspherehealpix.h"
|
---|
| 15 | #include "fitstarray.h"
|
---|
| 16 |
|
---|
[1441] | 17 | /*!
|
---|
[1626] | 18 | \defgroup PrgMap PrgMap module
|
---|
| 19 | This module contains simple programs to perform various tasks
|
---|
| 20 | on spherical maps.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /*!
|
---|
[1607] | 24 | \ingroup PrgMap
|
---|
[1441] | 25 | \file cl2map.cc
|
---|
| 26 | \brief \b cl2map: generates spherical maps from power spectra (C(l))
|
---|
[1427] | 27 |
|
---|
[1441] | 28 | \verbatim
|
---|
[1427] | 29 |
|
---|
[1441] | 30 | csh> cl2map -h
|
---|
| 31 | SOPHYA Version 1.1 Revision 0 (V_Fev2001) -- Mar 9 2001 15:45:31 cxx
|
---|
| 32 |
|
---|
| 33 | cl2map : Spherical harmonics synthesis - Power spectrum C_l -> HEALPix map
|
---|
| 34 | Usage: cl2map [-float/-r4] [-msph pixp] [-beam fwhm]
|
---|
| 35 | [-fitsin] [-fitsout] [-autoinirand] InFileName OutFileName
|
---|
| 36 | -float (-r4): single precision C_l and map (default = double)
|
---|
| 37 | -msph pix: Spherical map pixelization parameter
|
---|
| 38 | nside=2^n for HEALPix - default=128
|
---|
| 39 | lmax = 2^n default=128
|
---|
| 40 | -beam fwhm : Beam moothing (in l-space) FWHM in arcmin, default=0
|
---|
| 41 | -fitsout: Select the FITS format for the output map (default PPF format)
|
---|
| 42 | -fitsin : Select the FITS format for the input vector (default PPF format)
|
---|
| 43 | -autoinirand : Automtatic random number generator initialization
|
---|
| 44 | InFileName : Input file name containing the C_l vector
|
---|
| 45 | OutFileName : Output file name (HEALPix map)
|
---|
| 46 |
|
---|
| 47 | \endverbatim
|
---|
| 48 | */
|
---|
| 49 |
|
---|
| 50 |
|
---|
[1427] | 51 | /* Nouvelle-Fonction */
|
---|
| 52 | void Usage(bool fgerr)
|
---|
| 53 | {
|
---|
| 54 | cout << endl;
|
---|
| 55 | if (fgerr) {
|
---|
| 56 | cout << " cl2map : Argument Error ! cl2map -h for usage " << endl;
|
---|
| 57 | exit(1);
|
---|
| 58 | }
|
---|
| 59 | else {
|
---|
| 60 | cout << " cl2map : Spherical harmonics synthesis - Power spectrum C_l -> HEALPix map \n"
|
---|
| 61 | << " Usage: cl2map [-float/-r4] [-msph pixp] [-beam fwhm] \n"
|
---|
[1430] | 62 | << " [-fitsin] [-fitsout] [-autoinirand] InFileName OutFileName \n"
|
---|
[1427] | 63 | << " -float (-r4): single precision C_l and map (default = double) \n"
|
---|
| 64 | << " -msph pix: Spherical map pixelization parameter \n"
|
---|
| 65 | << " nside=2^n for HEALPix - default=128 \n"
|
---|
| 66 | << " lmax = 2^n default=128 \n"
|
---|
| 67 | << " -beam fwhm : Beam moothing (in l-space) FWHM in arcmin, default=0 \n"
|
---|
| 68 | << " -fitsout: Select the FITS format for the output map (default PPF format) \n"
|
---|
| 69 | << " -fitsin : Select the FITS format for the input vector (default PPF format) \n"
|
---|
| 70 | << " -autoinirand : Automtatic random number generator initialization \n"
|
---|
| 71 | << " InFileName : Input file name containing the C_l vector \n"
|
---|
| 72 | << " OutFileName : Output file name (HEALPix map) \n" << endl;
|
---|
| 73 | exit(0);
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | /* Nouvelle-Classe */
|
---|
| 78 | template <class T>
|
---|
| 79 | class _Cl2Map {
|
---|
| 80 | public :
|
---|
| 81 | static void BuildMap(string & infile, string & outfile, int msph, double beam,
|
---|
| 82 | bool fgfitsin, bool fgfitsout)
|
---|
| 83 | {
|
---|
| 84 | double deg2rad = M_PI/180.;
|
---|
| 85 | double minute2rad = M_PI/(180.*60.);
|
---|
| 86 |
|
---|
| 87 | TArray<T> cla;
|
---|
| 88 | SphereHEALPix<T> sph;
|
---|
| 89 | if (fgfitsin) {
|
---|
| 90 | cout << "--- Reading Input FITS file " << infile << endl;
|
---|
| 91 | FitsInFile fii(infile);
|
---|
| 92 | fii >> cla;
|
---|
| 93 | }
|
---|
| 94 | else {
|
---|
| 95 | cout << "--- Reading Input PPF file " << infile << endl;
|
---|
| 96 | PInPersist ppi(infile);
|
---|
| 97 | ppi >> cla;
|
---|
| 98 | }
|
---|
| 99 | TVector<T> clvec(cla);
|
---|
| 100 | cout << " Input vector : " ;
|
---|
| 101 | clvec.Show();
|
---|
| 102 | T min, max;
|
---|
| 103 | double mean, sigma;
|
---|
| 104 | clvec.MinMax(min, max);
|
---|
| 105 | MeanSigma(clvec, mean, sigma);
|
---|
| 106 | cout << " C_l.Min= " << min << " C_l.Max= " << max
|
---|
| 107 | << " C_l.Mean= " << mean << " C_l.Sigma= " << sigma << endl;
|
---|
| 108 |
|
---|
| 109 | cout << "--- Calling GenerateFromCl() (beam= " << beam
|
---|
| 110 | << "' msph= " << msph << ") beam=" << beam*minute2rad << " rad" << endl;
|
---|
| 111 | // on cree la carte
|
---|
| 112 | SphericalTransformServer<T> sphtr;
|
---|
| 113 | sphtr.GenerateFromCl(sph, msph, clvec, beam*minute2rad);
|
---|
| 114 |
|
---|
| 115 | cout << " Output map : NbPixels= " << sph.NbPixels() << " NSide= "
|
---|
| 116 | << sph.SizeIndex() << " Resolution= "
|
---|
| 117 | << sqrt(sph.PixSolAngle(0))/minute2rad << " Arcminutes " << endl;
|
---|
| 118 |
|
---|
| 119 | if (fgfitsout) {
|
---|
[1535] | 120 | cout << "--- Writing map to Output FITS file " << outfile << endl;
|
---|
| 121 | string dum = "rm -f "; dum += outfile; system(dum.c_str());
|
---|
[1841] | 122 | FitsOutFile fio(outfile, FitsFile::clear);
|
---|
[1427] | 123 | fio << sph;
|
---|
| 124 | }
|
---|
| 125 | else {
|
---|
| 126 | cout << "--- Writing map to Output PPF file " << outfile << endl;
|
---|
| 127 | POutPersist ppo(outfile);
|
---|
| 128 | ppo << sph;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | };
|
---|
| 133 |
|
---|
| 134 | /* Main-Program */
|
---|
| 135 | int main(int narg, char *arg[])
|
---|
| 136 | {
|
---|
| 137 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
|
---|
| 138 |
|
---|
| 139 | int msph = 128;
|
---|
| 140 | double beam = 0.;
|
---|
| 141 | string infile;
|
---|
| 142 | string outfile;
|
---|
| 143 | bool fgfitsin = false;
|
---|
| 144 | bool fgfitsout = false;
|
---|
| 145 | bool fginirand = false;
|
---|
| 146 | bool fgr4 = false;
|
---|
| 147 | cout << " cl2map : Decoding command line options ... " << endl;
|
---|
| 148 |
|
---|
| 149 | int ko=1;
|
---|
| 150 | for (int k=1; k<narg; k++) {
|
---|
| 151 | if (strcmp(arg[k], "-msph") == 0) {
|
---|
| 152 | if (k == narg-1) Usage(true); // -msph est suivi d'un argument
|
---|
| 153 | msph = atoi(arg[k+1]); k++; // k++ pour sauter au suivant
|
---|
| 154 | }
|
---|
| 155 | else if (strcmp(arg[k], "-beam") == 0) {
|
---|
| 156 | if (k == narg-1) Usage(true); // -beam est suivi d'un argument
|
---|
| 157 | beam = atof(arg[k+1]); k++; // k++ pour sauter au suivant
|
---|
| 158 | }
|
---|
| 159 | else if (strcmp(arg[k], "-fitsin") == 0) {
|
---|
| 160 | fgfitsin = true;
|
---|
| 161 | }
|
---|
| 162 | else if (strcmp(arg[k], "-fitsout") == 0) {
|
---|
| 163 | fgfitsout = true;
|
---|
| 164 | }
|
---|
| 165 | else if (strcmp(arg[k], "-autoinirand") == 0) {
|
---|
| 166 | fginirand = true;
|
---|
| 167 | }
|
---|
| 168 | else if ((strcmp(arg[k], "-float") == 0) || (strcmp(arg[k], "-r4") == 0) ) {
|
---|
| 169 | fgr4 = true;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | else { ko = k; break; } // Debut des noms
|
---|
| 173 | }
|
---|
| 174 |
|
---|
[1441] | 175 | if ((narg-ko) < 2) Usage(true);
|
---|
[1427] | 176 | infile = arg[ko];
|
---|
| 177 | outfile = arg[ko+1];
|
---|
| 178 |
|
---|
| 179 | // Bloc try de gestion des exception
|
---|
| 180 | try {
|
---|
| 181 | InitTim();
|
---|
| 182 | SophyaInit();
|
---|
| 183 | if (fginirand) {
|
---|
| 184 | cout << " Setting random number generator seed (using time) " << endl;
|
---|
| 185 | Auto_Ini_Ranf(1);
|
---|
| 186 | }
|
---|
| 187 | if (fgr4) {
|
---|
| 188 | cout << " Power spectrum C_l (r_4) --> SphereHEALPix<r_4> (float) " << endl;
|
---|
| 189 | _Cl2Map<r_4>::BuildMap(infile, outfile, msph, beam, fgfitsin, fgfitsout);
|
---|
| 190 | }
|
---|
| 191 | else {
|
---|
| 192 | cout << " Power spectrum C_l (r_8) --> SphereHEALPix<r_8> (double) " << endl;
|
---|
| 193 | _Cl2Map<r_8>::BuildMap(infile, outfile, msph, beam, fgfitsin, fgfitsout);
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | catch (PThrowable & exc) { // Exceptions de SOPHYA
|
---|
| 197 | cerr << " cl2map: Catched Exception " << (string)typeid(exc).name()
|
---|
| 198 | << " - Msg= " << exc.Msg() << endl;
|
---|
| 199 | }
|
---|
| 200 | catch (...) { // Autres Exceptions
|
---|
| 201 | cerr << " cl2map: some other exception was caught ! " << endl;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | PrtTim("End of cl2map ");
|
---|
| 205 | return(0);
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 |
|
---|
| 209 |
|
---|