[3783] | 1 | /* ------------------------ Projet BAORadio --------------------
|
---|
| 2 | Programme d'extraction d'une partie de carte synchrotron
|
---|
| 3 | (HASLAM @ 400 MHz) et fabrication d'un cube 3D (angles,fre)
|
---|
| 4 | R. Ansari , C. Magneville - Juin 2010
|
---|
| 5 |
|
---|
| 6 | Usage: syncube InFitsName Out3DPPFName [Out2DMapName]
|
---|
| 7 | --------------------------------------------------------------- */
|
---|
| 8 |
|
---|
| 9 | #include "sopnamsp.h"
|
---|
| 10 | #include "machdefs.h"
|
---|
| 11 | #include <math.h>
|
---|
| 12 | #include <iostream>
|
---|
| 13 | #include <typeinfo>
|
---|
| 14 |
|
---|
| 15 | #include "tvector.h"
|
---|
| 16 | #include "srandgen.h"
|
---|
| 17 | #include "fioarr.h"
|
---|
| 18 | #include "sopemtx.h"
|
---|
| 19 | #include "pexceptions.h"
|
---|
| 20 |
|
---|
| 21 | #include "randr48.h"
|
---|
| 22 |
|
---|
| 23 | #include "tvector.h" // Pour l'utilisation des classes TArray, TMatrix , TVector
|
---|
| 24 | #include "matharr.h"
|
---|
| 25 |
|
---|
| 26 | /*
|
---|
| 27 | #include "spherehealpix.h" // Pour les cartes spheriques pixelisees au format HEALPix
|
---|
| 28 | #include "spherethetaphi.h" // Pour les cartes spheriques pixelisees au format Theta-Phi
|
---|
| 29 | #include "localmap.h" // Pour les cartes locales
|
---|
| 30 | #include "mapoperation.h" // Pour les cartes locales
|
---|
| 31 | */
|
---|
| 32 | #include "skymap.h"
|
---|
| 33 | #include "mapoperation.h" // Pour les cartes locales
|
---|
| 34 |
|
---|
| 35 | #include "fitsspherehealpix.h" // Pour les I/O fits de HEALPix
|
---|
| 36 | #include "fitsspherethetaphi.h" // Pour les I/O fits de SphereThetaPhi
|
---|
| 37 | #include "fitslocalmap.h" // Pour les I/O fits de LocalMap<T>
|
---|
| 38 |
|
---|
| 39 | #include "xastropack.h" // Pour faire les conversions de coordonnees celestes
|
---|
| 40 |
|
---|
| 41 | // Pour l'initialisation des modules
|
---|
| 42 | #include "tarrinit.h"
|
---|
| 43 | #include "skymapinit.h"
|
---|
| 44 | #include "fiosinit.h"
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | #include "timing.h"
|
---|
| 48 | #include "ctimer.h"
|
---|
| 49 |
|
---|
| 50 | //----------------------------------------------------------------------------
|
---|
| 51 | //----------------------------------------------------------------------------
|
---|
| 52 | int main(int narg, char* arg[])
|
---|
| 53 | {
|
---|
| 54 | // Sophya modules initialization
|
---|
| 55 | TArrayInitiator _inia;
|
---|
| 56 | SkyMapInitiator _inis;
|
---|
| 57 | FitsIOServerInitiator _inif;
|
---|
| 58 | //------- AU LIEU DE ------> SophyaInit();
|
---|
| 59 |
|
---|
| 60 | InitTim(); // Initializing the CPU timer
|
---|
| 61 | Timer tm("syncube");
|
---|
| 62 |
|
---|
| 63 | if (narg < 3) {
|
---|
| 64 | cout << "Usage: syncube InFitsName Out3DPPFName [Out2DMapName] \n" << endl;
|
---|
| 65 | return 1;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | //--- Parametres des lois de puissance en frequence
|
---|
| 69 | double AmpPL1 = 1.; // amp max PowerLaw 2
|
---|
| 70 | double PLidx1 = -2.5; // index de la loi de puissance synchrotron
|
---|
| 71 | double sigPLidx1 = 0.1; // Sigma de la variation (gaussienne) de index1
|
---|
| 72 | // Amplitude max de la 2eme composante en loi de puissance (tirage plat 0 ... AmpPL2)
|
---|
| 73 | double AmpPL2 = 0.1; // amp max PowerLaw 2
|
---|
| 74 | double PLidx2 = -3.2;
|
---|
| 75 | double sigPLidx2 = 0.15;
|
---|
| 76 |
|
---|
| 77 | // decodage arguments
|
---|
| 78 | string outname = arg[2];
|
---|
| 79 | string inname = arg[1];
|
---|
| 80 | int rc = 91;
|
---|
| 81 |
|
---|
| 82 | cout << " ====== syncube : Input map name= " << inname << " OutName=" << outname;
|
---|
| 83 | bool fginmap=true;
|
---|
| 84 | try {
|
---|
| 85 | SphereHEALPix<r_4> inmap0;
|
---|
| 86 | if (fginmap) { // Lecture eventuelle de la carte en entree
|
---|
| 87 | cout << " syncube[0]: Reading input map : " << inname << endl;
|
---|
| 88 | FitsInOutFile fis(inname, FitsInOutFile::Fits_RO);
|
---|
| 89 | fis >> inmap0;
|
---|
| 90 | cout << inmap0;
|
---|
| 91 | }
|
---|
| 92 | // On fait une carte en doublant la resolution
|
---|
| 93 | int nside = inmap0.SizeIndex() ; // Parametre de pixelisation HEALPix - definit la resolution
|
---|
| 94 | SphereHEALPix<r_4> inmap(2*nside);
|
---|
| 95 | for(int_4 kk=0; kk<inmap.NbPixels(); kk++) {
|
---|
| 96 | double theta, phi; // Theta, Phi en radians
|
---|
| 97 | inmap.PixThetaPhi(kk, theta, phi);
|
---|
| 98 | inmap(kk) = inmap0(theta, phi);
|
---|
| 99 | }
|
---|
| 100 | // Sph2Sph(inmap0, inmap);
|
---|
| 101 | cout << "syncube[1]: Input resolution doubled : " << inmap << endl;
|
---|
| 102 |
|
---|
| 103 | sa_size_t NTet=256;
|
---|
| 104 | sa_size_t NPhi=256;
|
---|
| 105 | LocalMap<r_4> outmap(NPhi,NTet,60.,60.,110.,150.);
|
---|
| 106 | for(int_4 kk=0; kk<outmap.NbPixels(); kk++) {
|
---|
| 107 | double theta, phi; // Theta, Phi en radians
|
---|
| 108 | outmap.PixThetaPhi(kk, theta, phi);
|
---|
| 109 | outmap(kk) = inmap(theta, phi);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | TArray<r_4> omap(NPhi,NTet);
|
---|
| 113 | double tet0 = Angle(60.,Angle::Degree).ToRadian();
|
---|
| 114 | double phi0 = Angle(120.,Angle::Degree).ToRadian();
|
---|
| 115 | double dtet = Angle(60.,Angle::Degree).ToRadian()/(double)NTet;
|
---|
| 116 | double dphi = Angle(60.,Angle::Degree).ToRadian()/(double)NPhi;
|
---|
| 117 | for (sa_size_t j=0; j<omap.SizeY(); j++) {
|
---|
| 118 | double theta = j*dtet+tet0;
|
---|
| 119 | for (sa_size_t i=0; i<omap.SizeX(); i++) {
|
---|
| 120 | double phi = i*dphi+phi0;
|
---|
| 121 | omap(i,j) = inmap(theta, phi);
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | // Sph2Sph(inmap,outmap);
|
---|
| 125 |
|
---|
| 126 | cout << "syncube[2]: Output rectangular map computed " << outmap << endl;
|
---|
| 127 | if (narg > 3) {
|
---|
| 128 | string ppfname = arg[3];
|
---|
| 129 | cout << " syncube[3]: Saving inmap/outmap tp PPF file-> " << ppfname << endl;
|
---|
| 130 | POutPersist po(ppfname);
|
---|
| 131 | po << PPFNameTag("inmap") << inmap;
|
---|
| 132 | po << PPFNameTag("outmap") << outmap;
|
---|
| 133 | po << PPFNameTag("omap") << omap;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | sa_size_t NFreq = 128;
|
---|
| 137 | TArray<r_4> ocube(NPhi,NTet,NFreq);
|
---|
| 138 |
|
---|
| 139 | double infreq = 400.; // Frequence carte input en MHz
|
---|
| 140 | double freq0 = 840.; // Freq0 du cube de sortie
|
---|
| 141 | double dfreq = 1.;
|
---|
| 142 |
|
---|
| 143 | ThSDR48RandGen rg;
|
---|
| 144 | for (sa_size_t j=0; j<ocube.SizeY(); j++) {
|
---|
| 145 | for (sa_size_t i=0; i<ocube.SizeX(); i++) {
|
---|
| 146 | double freqexpo = rg.Gaussian(sigPLidx1,PLidx1);
|
---|
| 147 | for (sa_size_t k=0; k<ocube.SizeZ(); k++) {
|
---|
| 148 | double rapfreq = pow((freq0+k*dfreq)/infreq, freqexpo);
|
---|
| 149 | ocube(i,j,k) = AmpPL1*omap(i,j)*rapfreq;
|
---|
| 150 | }
|
---|
| 151 | // On ajoute une autre composante avec un indice spectral different
|
---|
| 152 | freqexpo = rg.Gaussian(sigPLidx2,PLidx2);
|
---|
| 153 | double famp = rg.Flat01()*AmpPL2;
|
---|
| 154 | for (sa_size_t k=0; k<ocube.SizeZ(); k++) {
|
---|
| 155 | double rapfreq = pow((freq0+k*dfreq)/infreq, freqexpo);
|
---|
| 156 | ocube(i,j,k) += famp*omap(i,j)*rapfreq;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | // On sauve le cube de sortie
|
---|
| 163 | {
|
---|
| 164 | cout << " syncube[2]: Saving output cube to -> " << outname << endl;
|
---|
| 165 | POutPersist poc(outname);
|
---|
| 166 | poc << ocube;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | rc = 0;
|
---|
| 170 | }
|
---|
| 171 | catch (PThrowable& exc) {
|
---|
| 172 | cerr << " treccyl.cc catched Exception " << exc.Msg() << endl;
|
---|
| 173 | rc = 77;
|
---|
| 174 | }
|
---|
| 175 | catch (std::exception& sex) {
|
---|
| 176 | cerr << "\n syncube.cc std::exception :"
|
---|
| 177 | << (string)typeid(sex).name() << "\n msg= "
|
---|
| 178 | << sex.what() << endl;
|
---|
| 179 | }
|
---|
| 180 | catch (...) {
|
---|
| 181 | cerr << " syncube.cc catched unknown (...) exception " << endl;
|
---|
| 182 | rc = 78;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | cout << ">>>> syncube[9] ------- FIN ----------- Rc=" << rc << endl;
|
---|
| 186 | return rc;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|