source: Sophya/trunk/Cosmo/RadioBeam/syncube.cc@ 3793

Last change on this file since 3793 was 3787, checked in by ansari, 15 years ago

Ajout classes / programmes de calcul d'effet de lobe sur les radio-sources, Reza 25/06/2010

File size: 5.7 KB
RevLine 
[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#include "timing.h"
47#include "ctimer.h"
48
[3785]49#include "cubedef.h"
50
[3783]51//----------------------------------------------------------------------------
52//----------------------------------------------------------------------------
53int 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
[3785]95 LocalMap<r_4> outmap(NPhi,NTheta,60.,60.,110.,150.);
[3783]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
[3785]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;
[3783]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 }
[3785]114
115 double mean, sigma;
116 MeanSigma(omap, mean, sigma);
[3787]117 cout << "syncube[2] omap : Mean=" << mean << " Sigma=" << sigma << " Sizes:" << endl;
[3785]118 omap.Show();
119
[3783]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
[3785]131 TArray<r_4> ocube(NPhi,NTheta,NFreq);
[3783]132
133 double infreq = 400.; // Frequence carte input en MHz
[3785]134 double freq0 = Freq0MHz; // Freq0 du cube de sortie
135 double dfreq = FreqSizeMHz/(double)NFreq;
[3783]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 // On ajoute une autre composante avec un indice spectral different
146 freqexpo = rg.Gaussian(sigPLidx2,PLidx2);
147 double famp = rg.Flat01()*AmpPL2;
148 for (sa_size_t k=0; k<ocube.SizeZ(); k++) {
149 double rapfreq = pow((freq0+k*dfreq)/infreq, freqexpo);
150 ocube(i,j,k) += famp*omap(i,j)*rapfreq;
151 }
152
153 }
154 }
155
156 // On sauve le cube de sortie
157 {
[3785]158 cout << " syncube[4]: Saving output cube to -> " << outname << endl;
[3783]159 POutPersist poc(outname);
160 poc << ocube;
161 }
162
163 rc = 0;
164 }
165 catch (PThrowable& exc) {
[3785]166 cerr << " syncube.cc catched Exception " << exc.Msg() << endl;
[3783]167 rc = 77;
168 }
169 catch (std::exception& sex) {
170 cerr << "\n syncube.cc std::exception :"
171 << (string)typeid(sex).name() << "\n msg= "
172 << sex.what() << endl;
173 }
174 catch (...) {
175 cerr << " syncube.cc catched unknown (...) exception " << endl;
176 rc = 78;
177 }
178
179 cout << ">>>> syncube[9] ------- FIN ----------- Rc=" << rc << endl;
180 return rc;
181}
182
183
Note: See TracBrowser for help on using the repository browser.