| 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 | #include "timing.h" | 
|---|
| 47 | #include "ctimer.h" | 
|---|
| 48 |  | 
|---|
| 49 | #include "cubedef.h" | 
|---|
| 50 |  | 
|---|
| 51 | //---------------------------------------------------------------------------- | 
|---|
| 52 | //---------------------------------------------------------------------------- | 
|---|
| 53 | int main(int narg, char* arg[]) | 
|---|
| 54 | { | 
|---|
| 55 | // Sophya modules initialization | 
|---|
| 56 | TArrayInitiator  _inia; | 
|---|
| 57 | SkyMapInitiator  _inis; | 
|---|
| 58 | FitsIOServerInitiator  _inif; | 
|---|
| 59 | //------- AU LIEU DE ------>  SophyaInit(); | 
|---|
| 60 |  | 
|---|
| 61 | InitTim();   // Initializing the CPU timer | 
|---|
| 62 | Timer tm("syncube"); | 
|---|
| 63 |  | 
|---|
| 64 | if (narg < 3) { | 
|---|
| 65 | cout << "Usage: syncube InFitsName Out3DPPFName [Out2DMapName] \n" << endl; | 
|---|
| 66 | return 1; | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | // decodage arguments | 
|---|
| 70 | string outname = arg[2]; | 
|---|
| 71 | string inname = arg[1]; | 
|---|
| 72 | int rc = 91; | 
|---|
| 73 |  | 
|---|
| 74 | cout << " ====== syncube :   Input map name= " << inname << " OutName=" << outname; | 
|---|
| 75 | bool fginmap=true; | 
|---|
| 76 | try { | 
|---|
| 77 | SphereHEALPix<r_4> inmap0; | 
|---|
| 78 | if (fginmap) {  // Lecture eventuelle de la carte en entree | 
|---|
| 79 | cout << " syncube[0]: Reading input map : " << inname << endl; | 
|---|
| 80 | FitsInOutFile fis(inname, FitsInOutFile::Fits_RO); | 
|---|
| 81 | fis >> inmap0; | 
|---|
| 82 | cout << inmap0; | 
|---|
| 83 | } | 
|---|
| 84 | // On fait une carte en doublant la resolution | 
|---|
| 85 | int nside = inmap0.SizeIndex() ;  // Parametre de pixelisation HEALPix - definit la resolution | 
|---|
| 86 | SphereHEALPix<r_4> inmap(2*nside); | 
|---|
| 87 | for(int_4 kk=0; kk<inmap.NbPixels(); kk++) { | 
|---|
| 88 | double theta, phi;  // Theta, Phi en radians | 
|---|
| 89 | inmap.PixThetaPhi(kk, theta, phi); | 
|---|
| 90 | inmap(kk) = inmap0(theta, phi); | 
|---|
| 91 | } | 
|---|
| 92 | //    Sph2Sph(inmap0, inmap); | 
|---|
| 93 | cout << "syncube[1]: Input resolution doubled : " << inmap << endl; | 
|---|
| 94 |  | 
|---|
| 95 | LocalMap<r_4> outmap(NPhi,NTheta,60.,60.,110.,150.); | 
|---|
| 96 | for(int_4 kk=0; kk<outmap.NbPixels(); kk++) { | 
|---|
| 97 | double theta, phi;  // Theta, Phi en radians | 
|---|
| 98 | outmap.PixThetaPhi(kk, theta, phi); | 
|---|
| 99 | outmap(kk) = inmap(theta, phi); | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | TArray<r_4> omap(NPhi,NTheta); | 
|---|
| 103 | double tet0 = Angle(Theta0Degre,Angle::Degree).ToRadian(); | 
|---|
| 104 | double phi0 = Angle(Phi0Degre,Angle::Degree).ToRadian(); | 
|---|
| 105 | double dtet = Angle(ThetaSizeDegre,Angle::Degree).ToRadian()/(double)NTheta; | 
|---|
| 106 | double dphi = Angle(PhiSizeDegre,Angle::Degree).ToRadian()/(double)NPhi; | 
|---|
| 107 | for (sa_size_t j=0; j<omap.SizeY(); j++)  { | 
|---|
| 108 | double theta = j*dtet+tet0; | 
|---|
| 109 | for (sa_size_t i=0; i<omap.SizeX(); i++)  { | 
|---|
| 110 | double phi = i*dphi+phi0; | 
|---|
| 111 | omap(i,j) = inmap(theta, phi); | 
|---|
| 112 | } | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | double mean, sigma; | 
|---|
| 116 | MeanSigma(omap, mean, sigma); | 
|---|
| 117 | cout << "syncube[2] omap : Mean=" << mean << " Sigma=" << sigma << " Sizes:" << endl; | 
|---|
| 118 | omap.Show(); | 
|---|
| 119 |  | 
|---|
| 120 | //    Sph2Sph(inmap,outmap); | 
|---|
| 121 |  | 
|---|
| 122 | if (narg > 3) { | 
|---|
| 123 | string ppfname = arg[3]; | 
|---|
| 124 | cout << " syncube[3]: Saving inmap/outmap tp PPF file-> " << ppfname << endl; | 
|---|
| 125 | POutPersist po(ppfname); | 
|---|
| 126 | po << PPFNameTag("inmap") << inmap; | 
|---|
| 127 | po << PPFNameTag("outmap") << outmap; | 
|---|
| 128 | po << PPFNameTag("omap") << omap; | 
|---|
| 129 | } | 
|---|
| 130 |  | 
|---|
| 131 | TArray<r_4> ocube(NPhi,NTheta,NFreq); | 
|---|
| 132 |  | 
|---|
| 133 | double infreq = FreqHASLAM; // Frequence carte input en MHz | 
|---|
| 134 | double freq0 = Freq0MHz;  // Freq0 du cube de sortie | 
|---|
| 135 | double dfreq = FreqSizeMHz/(double)NFreq; | 
|---|
| 136 |  | 
|---|
| 137 | ThSDR48RandGen rg; | 
|---|
| 138 | for (sa_size_t j=0; j<ocube.SizeY(); j++)  { | 
|---|
| 139 | for (sa_size_t i=0; i<ocube.SizeX(); i++)  { | 
|---|
| 140 | double freqexpo = rg.Gaussian(sigPLidx1,PLidx1); | 
|---|
| 141 | for (sa_size_t k=0; k<ocube.SizeZ(); k++)  { | 
|---|
| 142 | double rapfreq = pow((freq0+k*dfreq)/infreq, freqexpo); | 
|---|
| 143 | ocube(i,j,k) = AmpPL1*omap(i,j)*rapfreq; | 
|---|
| 144 | } | 
|---|
| 145 | if (AmpPL2<1.e-6)  continue; | 
|---|
| 146 | // On ajoute une autre composante avec un indice spectral different | 
|---|
| 147 | freqexpo = rg.Gaussian(sigPLidx2,PLidx2); | 
|---|
| 148 | double famp = rg.Flat01()*AmpPL2; | 
|---|
| 149 | for (sa_size_t k=0; k<ocube.SizeZ(); k++)  { | 
|---|
| 150 | double rapfreq = pow((freq0+k*dfreq)/infreq, freqexpo); | 
|---|
| 151 | ocube(i,j,k) += famp*omap(i,j)*rapfreq; | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 | } | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | // On sauve le cube de sortie | 
|---|
| 158 | { | 
|---|
| 159 | cout << " syncube[4]: Saving output cube to -> " << outname << endl; | 
|---|
| 160 | POutPersist poc(outname); | 
|---|
| 161 | poc << ocube; | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | rc = 0; | 
|---|
| 165 | } | 
|---|
| 166 | catch (PThrowable& exc) { | 
|---|
| 167 | cerr << " syncube.cc catched Exception " << exc.Msg() << endl; | 
|---|
| 168 | rc = 77; | 
|---|
| 169 | } | 
|---|
| 170 | catch (std::exception& sex) { | 
|---|
| 171 | cerr << "\n syncube.cc std::exception :" | 
|---|
| 172 | << (string)typeid(sex).name() << "\n msg= " | 
|---|
| 173 | << sex.what() << endl; | 
|---|
| 174 | } | 
|---|
| 175 | catch (...) { | 
|---|
| 176 | cerr << " syncube.cc catched unknown (...) exception  " << endl; | 
|---|
| 177 | rc = 78; | 
|---|
| 178 | } | 
|---|
| 179 |  | 
|---|
| 180 | cout << ">>>> syncube[9] ------- FIN ----------- Rc=" << rc << endl; | 
|---|
| 181 | return rc; | 
|---|
| 182 | } | 
|---|
| 183 |  | 
|---|
| 184 |  | 
|---|