[3784] | 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 |
|
---|
[3788] | 9 | Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPk
|
---|
| 10 | [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr]
|
---|
[3784] | 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"
|
---|
[3788] | 23 | #include "vector3d.h"
|
---|
[3784] | 24 |
|
---|
| 25 | #include "qhist.h"
|
---|
[3787] | 26 | #include "lobe.h"
|
---|
| 27 | #include "cubedef.h"
|
---|
[3788] | 28 | #include "fgndsub.h"
|
---|
| 29 | #include "radutil.h"
|
---|
[3787] | 30 |
|
---|
[3784] | 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) {
|
---|
[3788] | 46 | cout << " Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync OutPk \n"
|
---|
| 47 | << " [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr]" << endl;
|
---|
[3784] | 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];
|
---|
[3787] | 58 |
|
---|
| 59 | double pixsignoise = 0.;
|
---|
| 60 | bool fgaddnoise=false;
|
---|
| 61 | if (narg>6) {
|
---|
| 62 | pixsignoise=atof(arg[6]);
|
---|
[3789] | 63 | if (pixsignoise>1.e-6) fgaddnoise=true;
|
---|
[3787] | 64 | }
|
---|
[3788] | 65 |
|
---|
| 66 | bool fgcorrbeam=true;
|
---|
[3789] | 67 | double tbeamarcmin=15.;
|
---|
[3788] | 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 | }
|
---|
[3787] | 78 |
|
---|
[3788] | 79 | TArray<r_4> maplss, mapsync;
|
---|
| 80 | const char * tits[2]={"LSS", "Sync/RadioSrc"};
|
---|
[3784] | 81 | for(int ks=0; ks<2; ks++) {
|
---|
| 82 | string& ppfname=inppflss;
|
---|
| 83 | r_4 rfac=rfaclss;
|
---|
[3788] | 84 | TArray<r_4>* inmap=&maplss;
|
---|
| 85 | if (ks==1) { ppfname=inppfsync; rfac=rfacsync; inmap=&mapsync; }
|
---|
[3784] | 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 | }
|
---|
[3787] | 97 |
|
---|
[3788] | 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 |
|
---|
[3787] | 108 | if (fgaddnoise) {
|
---|
[3788] | 109 | cout << " calcpk2: adding noise to skycube cube ... " << endl;
|
---|
| 110 | BeamEffect::AddNoise(skycube, pixsignoise);
|
---|
[3787] | 111 | }
|
---|
| 112 |
|
---|
[3784] | 113 | double mean, sigma;
|
---|
[3788] | 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();
|
---|
[3789] | 121 | Four2DResponse arep(2, InterfArrayDiametre/lambda, InterfArrayDiametre/lambda, lambda);
|
---|
[3788] | 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 | }
|
---|
[3789] | 130 | cout << " calcpk2[3.b] : calling cleaner.CleanNegatives() ... " << endl;
|
---|
| 131 | cleaner.CleanNegatives();
|
---|
[3788] | 132 | if (fgclnsrc) {
|
---|
[3789] | 133 | cout << "calcpk2[3.c] : calling cleaner.CleanPointSources() with threshold NSigma=" << nsigsrc << endl;
|
---|
[3788] | 134 | cleaner.CleanPointSources(nsigsrc);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | cout << "calcpk2[4] : calling cleaner.extractLSSCube(...) " << endl;
|
---|
| 138 | TArray<r_4> synctemp, specidx;
|
---|
| 139 | TArray<r_4> exlss = cleaner.extractLSSCube(synctemp, specidx);
|
---|
| 140 |
|
---|
| 141 | MeanSigma(exlss, mean, sigma);
|
---|
| 142 | cout << " After cleaning/extractLSS: Mean=" << mean << " Sigma=" << sigma << endl;
|
---|
[3784] | 143 | tm.Split(" After CleanForeground");
|
---|
| 144 |
|
---|
[3788] | 145 | cout << "calcpk2[5] : computing 3D Fourier coefficients ... " << endl;
|
---|
[3784] | 146 | FFTWServer ffts;
|
---|
| 147 | TArray< complex<r_4> > four3d;
|
---|
[3788] | 148 | ffts.FFTForward(exlss, four3d);
|
---|
[3784] | 149 | tm.Split(" After FFTForward ");
|
---|
| 150 |
|
---|
[3788] | 151 | cout << "calcpk2[6] : computing power spectrum ... " << endl;
|
---|
[3784] | 152 | RandomGenerator rg;
|
---|
| 153 | Four3DPk pkc(four3d, rg);
|
---|
[3789] | 154 | double dkxmpc = DeuxPI/(double)exlss.SizeX()/XCellSizeMpc;
|
---|
| 155 | double dkympc = DeuxPI/(double)exlss.SizeY()/YCellSizeMpc;
|
---|
| 156 | double dkzmpc = DeuxPI/(double)exlss.SizeZ()/ZCellSizeMpc;
|
---|
| 157 | pkc.SetCellSize(dkxmpc, dkympc, dkzmpc);
|
---|
[3784] | 158 |
|
---|
| 159 | HProf hp = pkc.ComputePk(0.,256);
|
---|
| 160 |
|
---|
| 161 | tm.Split(" Done ComputePk ");
|
---|
| 162 |
|
---|
[3788] | 163 | cout << "calcpk2[7.a] : writing profile P(k) to " << outname << endl;
|
---|
[3784] | 164 | POutPersist po(outname);
|
---|
[3788] | 165 | po << hp;
|
---|
| 166 | outname = "fgm_" + outname;
|
---|
| 167 | cout << "calcpk2[7.b] : writing foreground maps to " << outname << endl;
|
---|
| 168 | POutPersist pom(outname);
|
---|
| 169 | pom << PPFNameTag("Tsync") << synctemp;
|
---|
| 170 | pom << PPFNameTag("async") << specidx;
|
---|
[3784] | 171 |
|
---|
| 172 | } // End of try bloc
|
---|
| 173 | catch (PThrowable & exc) { // catching SOPHYA exceptions
|
---|
| 174 | cerr << " calcpk2.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
| 175 | << "\n...exc.Msg= " << exc.Msg() << endl;
|
---|
| 176 | rc = 99;
|
---|
| 177 | }
|
---|
| 178 | catch (std::exception & e) { // catching standard C++ exceptions
|
---|
| 179 | cerr << " calcpk2.cc: Catched std::exception " << " - what()= " << e.what() << endl;
|
---|
| 180 | rc = 98;
|
---|
| 181 | }
|
---|
| 182 | catch (...) { // catching other exceptions
|
---|
| 183 | cerr << " calcpk2.cc: some other exception (...) was caught ! " << endl;
|
---|
| 184 | rc = 97;
|
---|
| 185 | }
|
---|
[3788] | 186 | cout << " ==== End of calcpk2.cc program Rc= " << rc << endl;
|
---|
[3784] | 187 | return rc;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|