1 | /* ------------------------ Projet BAORadio --------------------
|
---|
2 | Programme de calcul du spectre de puissance de bruit pour
|
---|
3 | un interferometre (spectre moyenne sur 3D -> P_noise(k) )
|
---|
4 |
|
---|
5 | R. Ansari , C. Magneville - Juin 2010
|
---|
6 |
|
---|
7 | Usage: pknoise pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName
|
---|
8 | -parname : -noise , -renmax , -scut , -ngen , -z , -prt
|
---|
9 | --------------------------------------------------------------- */
|
---|
10 |
|
---|
11 | #include "machdefs.h"
|
---|
12 | #include "sopnamsp.h"
|
---|
13 | #include <iostream>
|
---|
14 | #include <string>
|
---|
15 | #include <math.h>
|
---|
16 |
|
---|
17 | #include <typeinfo>
|
---|
18 |
|
---|
19 | #include "mdish.h"
|
---|
20 | #include "specpk.h"
|
---|
21 | #include "interfconfigs.h"
|
---|
22 | #include "radutil.h"
|
---|
23 |
|
---|
24 | #include "histinit.h"
|
---|
25 | // #include "fiosinit.h"
|
---|
26 | // #include "fitsioserver.h"
|
---|
27 |
|
---|
28 | #include "randr48.h"
|
---|
29 |
|
---|
30 | #include "timing.h"
|
---|
31 | #include "ctimer.h"
|
---|
32 |
|
---|
33 | typedef DR48RandGen RandomGenerator ;
|
---|
34 |
|
---|
35 | // ---------------------------------------------------------------------
|
---|
36 | // Test main
|
---|
37 | // R. Ansari - Avril-Dec 2010
|
---|
38 | // ---------------------------------------------------------------------
|
---|
39 |
|
---|
40 | void Usage()
|
---|
41 | {
|
---|
42 | cout << " Usage: pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName \n"
|
---|
43 | << " -noise NoiseLevel (default=1.) \n"
|
---|
44 | << " -renmax MaxValue (default : Do NOT renormalize 2D response value \n"
|
---|
45 | << " -scut SCutValue (default=100.) \n"
|
---|
46 | << " -ngen NGen (default=0) number of noise fourier amp generations \n"
|
---|
47 | << " NGen=0 -> Call ComputeNoisePk(), else generate Fourier Amplitudes (random) \n"
|
---|
48 | << " -z redshift (default=0.7) \n"
|
---|
49 | << " -prt PrtLev,PrtModulo (default=0,10) " << endl;
|
---|
50 | return;
|
---|
51 | }
|
---|
52 |
|
---|
53 | //-------------------------------------------------------------------------
|
---|
54 | // ------------------ MAIN PROGRAM ------------------------------
|
---|
55 | //-------------------------------------------------------------------------
|
---|
56 | int main(int narg, const char* arg[])
|
---|
57 | {
|
---|
58 | if ( (narg<3)||((narg>1)&&(strcmp(arg[1],"-h")==0)) ) {
|
---|
59 | Usage();
|
---|
60 | return 1;
|
---|
61 | }
|
---|
62 | cout << " ==== pknoise.cc : interferometer noise power spectrum computation ==== " << endl;
|
---|
63 | // make sure SOPHYA modules are initialized
|
---|
64 | SophyaInit();
|
---|
65 | // FitsIOServerInit();
|
---|
66 | InitTim();
|
---|
67 | //--- decoding command line arguments
|
---|
68 | string tits="pknoise";
|
---|
69 | char cbuff[64];
|
---|
70 | bool fgresptbl=false;
|
---|
71 | double DIAMETRE=100.;
|
---|
72 | string resptblname;
|
---|
73 | double NoiseLevel=1.;
|
---|
74 |
|
---|
75 | bool fgrenorm=false;
|
---|
76 | double rmax=1.;
|
---|
77 | int NMAX = 0;
|
---|
78 | double SCut=0.;
|
---|
79 | double z_Redshift=0.7 ; // 21 cm at z=0.7 -> 0.357 m
|
---|
80 | int prtlev=0;
|
---|
81 | int prtmod=10;
|
---|
82 |
|
---|
83 | int ka=1;
|
---|
84 | while (ka<(narg-1)) {
|
---|
85 | if (strcmp(arg[ka],"-noise")==0) {
|
---|
86 | NoiseLevel=atof(arg[ka+1]);
|
---|
87 | ka+=2;
|
---|
88 | }
|
---|
89 | else if (strcmp(arg[ka],"-renmax")==0) {
|
---|
90 | rmax=atof(arg[ka+1]); fgrenorm=true; ka+=2;
|
---|
91 | }
|
---|
92 | else if (strcmp(arg[ka],"-scut")==0) {
|
---|
93 | SCut=atof(arg[ka+1]); ka+=2;
|
---|
94 | }
|
---|
95 | else if (strcmp(arg[ka],"-ngen")==0) {
|
---|
96 | NMAX=atoi(arg[ka+1]); ka+=2;
|
---|
97 | }
|
---|
98 | else if (strcmp(arg[ka],"-z")==0) {
|
---|
99 | z_Redshift=atof(arg[ka+1]); ka+=2;
|
---|
100 | }
|
---|
101 | else if (strcmp(arg[ka],"-prt")==0) {
|
---|
102 | sscanf(arg[ka+1],"%d,%d",&prtlev,&prtmod); ka+=2;
|
---|
103 | }
|
---|
104 | else break;
|
---|
105 | }
|
---|
106 |
|
---|
107 | if ((ka+1)>=narg) {
|
---|
108 | cout << " pknoise / Argument error " << endl;
|
---|
109 | Usage();
|
---|
110 | return 2;
|
---|
111 | }
|
---|
112 | if (isdigit(*arg[ka])) {
|
---|
113 | fgresptbl=false;
|
---|
114 | DIAMETRE=atof(arg[ka]);
|
---|
115 | sprintf(cbuff,"pknoise_Dish(%g m)", DIAMETRE);
|
---|
116 | }
|
---|
117 | else {
|
---|
118 | resptblname=arg[ka];
|
---|
119 | fgresptbl=true;
|
---|
120 | sprintf(cbuff,"pknoise_RespTblName=%s", arg[ka]);
|
---|
121 | }
|
---|
122 | tits=cbuff;
|
---|
123 | string outfile = arg[ka+1];
|
---|
124 | if (outfile==".") outfile = "pknoise.ppf";
|
---|
125 | //-- end command line arguments
|
---|
126 |
|
---|
127 | int rc = 1;
|
---|
128 | try { // exception handling try bloc at top level
|
---|
129 | cout << " pknoise[0] : Executing, output file= " << outfile << endl;
|
---|
130 | POutPersist po(outfile);
|
---|
131 |
|
---|
132 | H21Conversions conv;
|
---|
133 | conv.setRedshift(z_Redshift);
|
---|
134 | double lambda = conv.getLambda();
|
---|
135 |
|
---|
136 | double Dol = DIAMETRE/lambda;
|
---|
137 |
|
---|
138 | Four2DResponse arep(2, DIAMETRE/lambda, DIAMETRE/lambda, lambda);
|
---|
139 | Four2DResponse* arep_p=&arep;
|
---|
140 | Four2DRespTable resptbl;
|
---|
141 | if (fgresptbl) {
|
---|
142 | cout << "pknoise[1]: initializing Four2DRespTable from file" << resptblname << endl;
|
---|
143 | resptbl.readFromPPF(resptblname);
|
---|
144 | cout << "pknoise[1.b] Four2DRespTable.LambdaRef=" << resptbl.getLambdaRef() << " setLambda("
|
---|
145 | << lambda << ")" << endl;
|
---|
146 | resptbl.setLambda(lambda);
|
---|
147 | arep_p=&resptbl;
|
---|
148 | if (fgrenorm) {
|
---|
149 | cout << "pknoise[1.c] call to resptbl.renormalize(" << rmax << ")";
|
---|
150 | double omax=resptbl.renormalize(rmax);
|
---|
151 | cout << " ... Old Max=" << omax << endl;
|
---|
152 | }
|
---|
153 | }
|
---|
154 | else cout << " pknoise[1]: Four2DResponse ( Diameter=" << DIAMETRE << " Lambda= " << lambda
|
---|
155 | << " DoL=" << DIAMETRE/lambda << " ) " << endl;
|
---|
156 |
|
---|
157 |
|
---|
158 | cout << " pknoise[2]: Instanciating object type Four3DPk " << endl;
|
---|
159 | RandomGenerator rg;
|
---|
160 | Four3DPk m3d(rg);
|
---|
161 | m3d.SetCellSize(2.*DeuxPI, 2.*DeuxPI, 2.*DeuxPI);
|
---|
162 | m3d.SetPrtLevel(prtlev,prtmod);
|
---|
163 |
|
---|
164 | cout << " pknoise[3]: Computing Noise P(k) using PkNoiseCalculator ..." << endl;
|
---|
165 | if (NMAX>0) {
|
---|
166 | PkNoiseCalculator pkn(m3d, *(arep_p), SCut, NMAX, tits.c_str());
|
---|
167 | pkn.SetPrtLevel(prtlev,prtmod);
|
---|
168 | HProf hpn = pkn.Compute();
|
---|
169 | po << hpn;
|
---|
170 | }
|
---|
171 | else {
|
---|
172 | Histo fracmodok;
|
---|
173 | DataTable dtnoise;
|
---|
174 | HProf hpn = m3d.ComputeNoisePk(*(arep_p),fracmodok,dtnoise,SCut);
|
---|
175 | po << hpn;
|
---|
176 | string outfile2 = "x"+outfile;
|
---|
177 | POutPersist po2(outfile2);
|
---|
178 | HProf h1dnoise=arep_p->GetProjNoiseLevel();
|
---|
179 | HProf h1drep=arep_p->GetProjResponse();
|
---|
180 | po2 << PPFNameTag("dtnoise") << dtnoise;
|
---|
181 | po2 << PPFNameTag("hpnoise") << hpn;
|
---|
182 | po2 << PPFNameTag("fracmodok") << fracmodok;
|
---|
183 | po2 << PPFNameTag("h1dnoise") << h1dnoise;
|
---|
184 | po2 << PPFNameTag("h1drep") << h1drep;
|
---|
185 | }
|
---|
186 | rc = 0;
|
---|
187 | } // End of try bloc
|
---|
188 | catch (PThrowable & exc) { // catching SOPHYA exceptions
|
---|
189 | cerr << " pknoise.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
190 | << "\n...exc.Msg= " << exc.Msg() << endl;
|
---|
191 | rc = 99;
|
---|
192 | }
|
---|
193 | catch (std::exception & e) { // catching standard C++ exceptions
|
---|
194 | cerr << " pknoise.cc: Catched std::exception " << " - what()= " << e.what() << endl;
|
---|
195 | rc = 98;
|
---|
196 | }
|
---|
197 | catch (...) { // catching other exceptions
|
---|
198 | cerr << " pknoise.cc: some other exception (...) was caught ! " << endl;
|
---|
199 | rc = 97;
|
---|
200 | }
|
---|
201 | PrtTim("End-pknoise");
|
---|
202 | cout << " ==== End of pknoise.cc program Rc= " << rc << endl;
|
---|
203 | return rc;
|
---|
204 | }
|
---|
205 |
|
---|
206 |
|
---|