1 | /* ------------------------ Projet BAORadio --------------------
|
---|
2 | Programme de calcul du spectre de puissance (3D) a partir d'un
|
---|
3 | cube de delta T/T LSS, d'un cube delta T/T LSS synchrotron
|
---|
4 | ou radio-sources, apres ajustement / soustraction d'une loi de
|
---|
5 | puissance en frequence (l'axe Z du tableau doit etre en frequence)
|
---|
6 |
|
---|
7 | R. Ansari , C. Magneville - Juin 2010
|
---|
8 |
|
---|
9 | Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPk
|
---|
10 | [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr]
|
---|
11 | --------------------------------------------------------------- */
|
---|
12 |
|
---|
13 | #include "machdefs.h"
|
---|
14 | #include "sopnamsp.h"
|
---|
15 | #include <iostream>
|
---|
16 | #include <string>
|
---|
17 | #include <math.h>
|
---|
18 |
|
---|
19 | #include <typeinfo>
|
---|
20 |
|
---|
21 | #include "specpk.h"
|
---|
22 | #include "histats.h"
|
---|
23 | #include "vector3d.h"
|
---|
24 |
|
---|
25 | #include "qhist.h"
|
---|
26 | #include "lobe.h"
|
---|
27 | #include "cubedef.h"
|
---|
28 | #include "fgndsub.h"
|
---|
29 | #include "radutil.h"
|
---|
30 |
|
---|
31 | #include "histinit.h"
|
---|
32 | #include "fftwserver.h"
|
---|
33 | #include "randr48.h"
|
---|
34 |
|
---|
35 | #include "ctimer.h"
|
---|
36 |
|
---|
37 | typedef ThSDR48RandGen RandomGenerator ;
|
---|
38 |
|
---|
39 | //-------------------------------------------------------------------------
|
---|
40 | // ------------------ MAIN PROGRAM ------------------------------
|
---|
41 | //-------------------------------------------------------------------------
|
---|
42 | /* --Fonction-- */
|
---|
43 | int main(int narg, const char* arg[])
|
---|
44 | {
|
---|
45 | if (narg<6) {
|
---|
46 | cout << " Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync OutPk \n"
|
---|
47 | << " [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr]" << endl;
|
---|
48 | return 1;
|
---|
49 | }
|
---|
50 | Timer tm("calcpk2");
|
---|
51 | int rc = 0;
|
---|
52 | try {
|
---|
53 | string inppflss = arg[1];
|
---|
54 | r_4 rfaclss = atof(arg[2]);
|
---|
55 | string inppfsync = arg[3];
|
---|
56 | r_4 rfacsync = atof(arg[4]);
|
---|
57 | string outname = arg[5];
|
---|
58 |
|
---|
59 | double pixsignoise = 0.;
|
---|
60 | bool fgaddnoise=false;
|
---|
61 | if (narg>6) {
|
---|
62 | pixsignoise=atof(arg[6]);
|
---|
63 | fgaddnoise=true;
|
---|
64 | }
|
---|
65 |
|
---|
66 | bool fgcorrbeam=true;
|
---|
67 | double tbeamarcmin=30.;
|
---|
68 | if (narg>7) {
|
---|
69 | tbeamarcmin=atof(arg[7]);
|
---|
70 | if (tbeamarcmin<1.e-6) fgcorrbeam=false;
|
---|
71 | }
|
---|
72 | bool fgclnsrc=true;
|
---|
73 | double nsigsrc=5.;
|
---|
74 | if (narg>8) {
|
---|
75 | nsigsrc=atof(arg[8]);
|
---|
76 | if (nsigsrc<1.e-6) fgclnsrc=false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | TArray<r_4> maplss, mapsync;
|
---|
80 | const char * tits[2]={"LSS", "Sync/RadioSrc"};
|
---|
81 | for(int ks=0; ks<2; ks++) {
|
---|
82 | string& ppfname=inppflss;
|
---|
83 | r_4 rfac=rfaclss;
|
---|
84 | TArray<r_4>* inmap=&maplss;
|
---|
85 | if (ks==1) { ppfname=inppfsync; rfac=rfacsync; inmap=&mapsync; }
|
---|
86 | cout << "calcpk2[" << ks+1 << "] : reading 3D map " << tits[ks] << " from file " << ppfname
|
---|
87 | << " RenormFactor=" << rfac << endl;
|
---|
88 | PInPersist pin(ppfname);
|
---|
89 | pin >> (*inmap);
|
---|
90 | (*inmap) *= rfac;
|
---|
91 | double mean, sigma;
|
---|
92 | MeanSigma(*inmap, mean, sigma);
|
---|
93 | cout << " ...InMap sizes " << inmap->InfoString() << endl;
|
---|
94 | inmap->Show();
|
---|
95 | cout << " ... Mean=" << mean << " Sigma=" << sigma << endl;
|
---|
96 | }
|
---|
97 |
|
---|
98 | bool smo;
|
---|
99 | if (!maplss.CompareSizes(mapsync,smo) ) {
|
---|
100 | cout << " calcpk2/ERROR sizes " << endl;
|
---|
101 | maplss.Show(); mapsync.Show();
|
---|
102 | return 99;
|
---|
103 | }
|
---|
104 |
|
---|
105 | TArray<r_4> skycube(mapsync);
|
---|
106 | skycube += maplss;
|
---|
107 |
|
---|
108 | if (fgaddnoise) {
|
---|
109 | cout << " calcpk2: adding noise to skycube cube ... " << endl;
|
---|
110 | BeamEffect::AddNoise(skycube, pixsignoise);
|
---|
111 | }
|
---|
112 |
|
---|
113 | double mean, sigma;
|
---|
114 | MeanSigma(skycube, mean, sigma);
|
---|
115 | cout << " input sky cube : Mean=" << mean << " Sigma=" << sigma << endl;
|
---|
116 | tm.Split(" After input ");
|
---|
117 |
|
---|
118 | H21Conversions conv;
|
---|
119 | conv.setFrequency(Freq0MHz);
|
---|
120 | double lambda = conv.getLambda();
|
---|
121 | Four2DResponse arep(2, InterfArrayDiametre/lambda, InterfArrayDiametre/lambda);
|
---|
122 | double DoL = 1.22/ArcminToRadian(tbeamarcmin);
|
---|
123 | Four2DResponse tbeam(2, DoL, DoL );
|
---|
124 | ForegroundCleaner cleaner(arep, tbeam, skycube);
|
---|
125 | if (fgcorrbeam) {
|
---|
126 | cout << "calcpk2[3.a] : calling cleaner.BeamCorrections() for target beam (" << tbeamarcmin << " arcmin)"
|
---|
127 | << " Diam/Lambda=" << DoL << endl;
|
---|
128 | cleaner.BeamCorrections();
|
---|
129 | }
|
---|
130 | if (fgclnsrc) {
|
---|
131 | cout << "calcpk2[3.b] : calling cleaner.CleanPointSources() with threshold NSigma=" << nsigsrc << endl;
|
---|
132 | cleaner.CleanPointSources(nsigsrc);
|
---|
133 | }
|
---|
134 |
|
---|
135 | cout << "calcpk2[4] : calling cleaner.extractLSSCube(...) " << endl;
|
---|
136 | TArray<r_4> synctemp, specidx;
|
---|
137 | TArray<r_4> exlss = cleaner.extractLSSCube(synctemp, specidx);
|
---|
138 |
|
---|
139 | MeanSigma(exlss, mean, sigma);
|
---|
140 | cout << " After cleaning/extractLSS: Mean=" << mean << " Sigma=" << sigma << endl;
|
---|
141 | tm.Split(" After CleanForeground");
|
---|
142 |
|
---|
143 | cout << "calcpk2[5] : computing 3D Fourier coefficients ... " << endl;
|
---|
144 | FFTWServer ffts;
|
---|
145 | TArray< complex<r_4> > four3d;
|
---|
146 | ffts.FFTForward(exlss, four3d);
|
---|
147 | tm.Split(" After FFTForward ");
|
---|
148 |
|
---|
149 | cout << "calcpk2[6] : computing power spectrum ... " << endl;
|
---|
150 | RandomGenerator rg;
|
---|
151 | Four3DPk pkc(four3d, rg);
|
---|
152 |
|
---|
153 | HProf hp = pkc.ComputePk(0.,256);
|
---|
154 |
|
---|
155 | tm.Split(" Done ComputePk ");
|
---|
156 |
|
---|
157 | cout << "calcpk2[7.a] : writing profile P(k) to " << outname << endl;
|
---|
158 | POutPersist po(outname);
|
---|
159 | po << hp;
|
---|
160 | outname = "fgm_" + outname;
|
---|
161 | cout << "calcpk2[7.b] : writing foreground maps to " << outname << endl;
|
---|
162 | POutPersist pom(outname);
|
---|
163 | pom << PPFNameTag("Tsync") << synctemp;
|
---|
164 | pom << PPFNameTag("async") << specidx;
|
---|
165 |
|
---|
166 | } // End of try bloc
|
---|
167 | catch (PThrowable & exc) { // catching SOPHYA exceptions
|
---|
168 | cerr << " calcpk2.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
169 | << "\n...exc.Msg= " << exc.Msg() << endl;
|
---|
170 | rc = 99;
|
---|
171 | }
|
---|
172 | catch (std::exception & e) { // catching standard C++ exceptions
|
---|
173 | cerr << " calcpk2.cc: Catched std::exception " << " - what()= " << e.what() << endl;
|
---|
174 | rc = 98;
|
---|
175 | }
|
---|
176 | catch (...) { // catching other exceptions
|
---|
177 | cerr << " calcpk2.cc: some other exception (...) was caught ! " << endl;
|
---|
178 | rc = 97;
|
---|
179 | }
|
---|
180 | cout << " ==== End of calcpk2.cc program Rc= " << rc << endl;
|
---|
181 | return rc;
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|