source: Sophya/trunk/Cosmo/RadioBeam/applobe.cc@ 3988

Last change on this file since 3988 was 3973, checked in by ansari, 14 years ago

Corrections diverses: choix lobe gaussien/triangle et specif DishDiameter au lieu de DoL ds applobe/calcpk2, possibilite application lobe freq.independante ds applobe, Reza 18/04/2011

File size: 7.5 KB
RevLine 
[3787]1/* ------------------------ Projet BAORadio --------------------
2 Programme de convolution avec le lobe d'un cube 3D (angles,freq)
3 R. Ansari , C. Magneville - Juin 2010
4
[3973]5 Usage: applobe [-g -t -fib] Diameter/Four2DRespTableFile In3DPPFName Out3DPPFName
6 [TargetBeamDiam] [ResmapleFactor=0.5,0.333...]
7 o -t : triangle beam shape in k-space
8 o -g : gaussian beam shape in k-space
9 o -fib: application d'un lobe fixe (independant de la frequence)
10 o Diameter/Four2DRespTableFile : diametre dish ou nom de fichier PPF reponse 2D
11 o In3DPPFName Out3DPPFName : Noms des fichiers (TArray<r_4> 3D) entree-sortie
12 o TargetBeamDiam : Correction à un beam fiduciel, independant de la frequence
13 avec specification de la valeur du diametre pour la frequence la plus basse
14 o ResmapleFactor : reechantillonnage du cube (2 -> surechantillonnage, 0.5 : 1 sur 2)
[3787]15--------------------------------------------------------------- */
16
17#include "sopnamsp.h"
18#include "machdefs.h"
19#include <math.h>
20#include <iostream>
21#include <typeinfo>
22
23#include "array.h"
24#include "histats.h"
25
26#include "swfitsdtable.h"
27#include "fitshdtable.h"
28
29#include "randr48.h"
30#include "vector3d.h"
31
32// #include "xastropack.h" -- Pour faire les conversions de coordonnees celestes
33
34#include "radutil.h"
35#include "lobe.h"
36
37// Pour l'initialisation des modules
38#include "tarrinit.h"
39#include "histinit.h"
40#include "fiosinit.h"
41
42#include "timing.h"
43#include "ctimer.h"
44
45#include "cubedef.h"
46
47//----------------------------------------------------------------------------
48//----------------------------------------------------------------------------
49int main(int narg, char* arg[])
50{
51 // Sophya modules initialization
52 TArrayInitiator _inia;
53 HiStatsInitiator _inih;
54 FitsIOServerInitiator _inif;
55 //------- AU LIEU DE ------> SophyaInit();
56
57 InitTim(); // Initializing the CPU timer
[3973]58
59 if ((narg < 3)||(strcmp(arg[1],"-h")==0)) {
60 cout << "Usage: applobe [-t -g -fib] Diameter/Four2DRespTableFile In3DPPFName Out3DPPFName \n"
61 << " [TargetBeamDiam] [ResmapleFactor=0.5,0.333...] \n" << endl;
62 if ((narg>1)&&(strcmp(arg[1],"-h")==0)) {
63 cout << " -t -g : Triangular / gaussian beam shape (def=gaussian) \n"
64 << " -fib : Application of a fixed (freq.independent) lobe dish-triangle or gaussian \n"
65 << " Diameter/Four2DRespTableFile : dish diameter or 2D response PPF file name\n"
66 << " In3DPPFName Out3DPPFName: Input/Output PPF file names (TArray<r_4> 3D) \n"
67 << " TargetBeamDiam: Corrected beam target diameter (D/Lambda at lowest frequency) \n"
68 << " DoL = 100 --> beam ~ 35 arcmin (D=30m @ z~0.5 Lambda~30cm)) \n"
69 << " ResmapleFactor : Resampling (2-> oversampling, 0.5 : 1/2 undersampling) \n" << endl;
70 }
71 return 1;
72 }
73
[3787]74 Timer tm("applobe");
75
[3973]76 // decodage arguments
77 bool fggaussian=true; // true -> gaussian beam
78 bool fixedbeam=false; // true -> apply freq. independent beam
79
80 // decodage argument optionnel
81 bool fgoptarg=true;
82 while (fgoptarg) {
83 string fbo = arg[1];
84 if (fbo=="-t") { fggaussian=false; arg++; narg--; }
85 else if (fbo=="-g") { fggaussian=true; arg++; narg--; }
86 else if (fbo=="-fib") { fixedbeam=true; arg++; narg--; }
87 else fgoptarg=false;
88 }
[3787]89 if (narg < 3) {
[3973]90 cout << " applobe/error arguments , applobe -h for help " << endl;
91 return 2;
[3787]92 }
93
[3796]94 bool fgresptbl=true;
95 double DIAMETRE=100.;
96 string resptblname;
97 if (isdigit(*arg[1])) {
98 fgresptbl=false;
99 DIAMETRE=atof(arg[1]);
[3789]100 }
[3973]101 else resptblname=arg[1];
102
[3796]103 string inname = arg[2];
104 string outname = arg[3];
[3789]105 bool fgcorrbeam=false;
[3973]106 double tbeamDiam=50.;
[3789]107 if (narg>4) {
[3973]108 tbeamDiam=atof(arg[4]);
109 if (tbeamDiam>1.) fgcorrbeam=true;
[3789]110 }
[3796]111 bool fgresample=false;
112 double fresamp=1.;
113 if (narg>5) {
114 fresamp=atof(arg[5]);
115 if ((fabs(fresamp)>1.e-2)&&(fabs(fresamp-1.)>1.e-2)) fgresample=true;
116 }
[3789]117
[3787]118 int rc = 91;
119
[3973]120 cout << " ====== applobe : Input skycube name= " << inname << " OutName=" << outname << endl;
121 cout << ((fggaussian)?" Gaussian ":" Triangular") << ((fixedbeam)?" Fixed (freq.independent)":"") << " beams" << endl;
[3787]122 bool fginmap=true;
123 try {
124 TArray<r_4> incube;
125 cout << "applobe[1]: reading input 3D map (cube) from file " << inname << endl;
126 {
127 PInPersist pin(inname);
128 pin >> incube;
129 }
[3788]130 incube.Show();
[3787]131
132 double dxdeg = ThetaSizeDegre/(double)NTheta;
133 double dydeg = PhiSizeDegre/(double)NPhi;
134 double dx = DegreeToRadian(dxdeg);
135 double dy = DegreeToRadian(dydeg);
136 double dfreq = FreqSizeMHz/(double)NFreq;
137
138 cout << " X,Y map size in degrees , X/Phi=" << PhiSizeDegre << " Y/Theta=" << ThetaSizeDegre
139 << " \n dx=" << dxdeg << " dy=" << dydeg << " degres ( dx_rad=" << dx << " dy_rad=" << dy << ")"
140 << " FreqSize=" << FreqSizeMHz << " dfreq=dz= " << dfreq << " MHz" << endl;
141
142 double mean, sigma;
143 MeanSigma(incube, mean, sigma);
144 cout << " InCube 3D- : Mean=" << mean << " Sigma=" << sigma << endl;
145
146 cout << "applobe[2]: creating Four2DResponse and BeamEffect objects..." << endl;
147 H21Conversions conv;
148 conv.setFrequency(Freq0MHz);
149 double lambda = conv.getLambda();
[3796]150
[3973]151 int typbeam=(fggaussian)?1:2;
152 Four2DResponse fresp(typbeam, DIAMETRE/lambda, DIAMETRE/lambda, lambda);
[3796]153 Four2DResponse* fresp_p=&fresp;
154 Four2DRespTable resptbl;
155 if (fgresptbl) {
156 cout << "applobe[2.b]: initializing Four2DRespTable from file" << resptblname << endl;
157 resptbl.readFromPPF(resptblname);
[3973]158 resptbl.renormalize(1.);
[3796]159 fresp_p=&resptbl;
160 }
161 else cout << " applobe[2.b]: Four2DResponse ( Diameter=" << DIAMETRE << " Lambda= " << lambda
162 << " DoL=" << DIAMETRE/lambda << " ) " << endl;
163 BeamEffect beam(*fresp_p);
[3787]164
[3789]165 if (fgcorrbeam) {
[3973]166 double DoL = tbeamDiam/lambda;
[3792]167 double tbeamarcmin = RadianToDegree(1.22/DoL)*60.;
[3973]168 int typcb = (fggaussian)?1:2;
[3797]169 // if (fgresptbl) typcb=22;
[3796]170 Four2DResponse tbeam(typcb, DoL, DoL );
[3973]171 cout << "applobe[3]: calling Correct2RefLobe() with target beam Diameter=" << tbeamDiam
172 << " D/Lambda=" << DoL << " -> arcmin " << tbeamarcmin << " TypDishResp=" << typcb << endl;
[3789]173 beam.Correct2RefLobe(tbeam, incube, dx, dy, Freq0MHz, dfreq);
174 }
[3973]175 else if (fixedbeam) {
176 cout << "applobe[3]: calling ApplyLobe() (freq.independent beam) ... " << endl;
177 beam.ApplyLobe(incube, dx, dy, Freq0MHz);
178 }
[3789]179 else {
180 cout << "applobe[3]: calling ApplyLobe3D() ... " << endl;
181 beam.ApplyLobe3D(incube, dx, dy, Freq0MHz, dfreq);
182 }
183 TArray< r_4 > outcube;
184 if (fgresample) {
185 cout << "applobe[4]: calling ReSample(incube," << fresamp << "," << ",1.) ... " << endl;
186 outcube.Share(beam.ReSample(incube, fresamp, fresamp, 1.));
187 }
188 else outcube.Share(incube);
[3787]189
[3788]190 outcube.Show();
[3787]191 MeanSigma(outcube, mean, sigma);
192 cout << " OutCube 3D- : Mean=" << mean << " Sigma=" << sigma << endl;
193
194 // On sauve le cube de sortie
195 {
196 cout << " applobe[5]: Saving output cube to -> " << outname << endl;
197 POutPersist poc(outname);
198 poc << outcube;
199 }
200
201 rc = 0;
202 }
203 catch (PThrowable& exc) {
204 cerr << " applobe.cc catched SOPHYA Exception " << exc.Msg() << endl;
205 rc = 77;
206 }
207 catch (std::exception& sex) {
208 cerr << "\n applobe.cc std::exception :"
209 << (string)typeid(sex).name() << "\n msg= "
210 << sex.what() << endl;
211 }
212 catch (...) {
213 cerr << " applobe.cc catched unknown (...) exception " << endl;
214 rc = 78;
215 }
216
217 cout << ">>>> applobe[9] ------- FIN ----------- Rc=" << rc << endl;
218 return rc;
219}
220
221
Note: See TracBrowser for help on using the repository browser.