[3959] | 1 | // Utilisation de SOPHYA pour faciliter les tests ...
|
---|
| 2 | #include "sopnamsp.h"
|
---|
| 3 | #include "machdefs.h"
|
---|
| 4 |
|
---|
| 5 | /* ----------------------------------------------------------
|
---|
| 6 | Projet BAORadio - (C) LAL/IRFU 2011
|
---|
| 7 |
|
---|
| 8 | Programme de lecture des fichiers matrices de visibilites
|
---|
| 9 | au format fits pour ecrire une DataTable de visib_moyenne(temps)
|
---|
| 10 | Fichier de visibilites produits par le prog vismf
|
---|
| 11 | R. Ansari, C. Magneville - LAL/Irfu
|
---|
| 12 | V : Mai 2009
|
---|
| 13 | ---------------------------------------------------------- */
|
---|
| 14 |
|
---|
| 15 | // include standard c/c++
|
---|
| 16 | #include <math.h>
|
---|
| 17 | #include <stdio.h>
|
---|
| 18 | #include <stdlib.h>
|
---|
| 19 | #include <string.h>
|
---|
| 20 |
|
---|
| 21 | #include <iostream>
|
---|
| 22 | #include <string>
|
---|
| 23 |
|
---|
| 24 | #include "pexceptions.h"
|
---|
| 25 | #include "tvector.h"
|
---|
| 26 | #include "fioarr.h"
|
---|
| 27 | // #include "tarrinit.h"
|
---|
| 28 | #include "ntuple.h"
|
---|
| 29 | #include "datatable.h"
|
---|
| 30 | #include "histinit.h"
|
---|
| 31 | #include "matharr.h"
|
---|
| 32 | #include "timestamp.h"
|
---|
| 33 | #include <utilarr.h>
|
---|
| 34 | #include "fitsarrhand.h"
|
---|
| 35 | #include "fitshdtable.h"
|
---|
| 36 |
|
---|
| 37 | // include sophya mesure ressource CPU/memoire ...
|
---|
| 38 | #include "resusage.h"
|
---|
| 39 | #include "ctimer.h"
|
---|
| 40 | #include "timing.h"
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | //--------------------------- Fonctions de ce fichier -------------------
|
---|
| 44 | int Usage(bool fgshort=true);
|
---|
| 45 |
|
---|
| 46 | int DecodeProc(int narg, char* arg[]);
|
---|
| 47 | int ProcVisMtxFiles(string& inoutpath, int imin, int imax, int istep, int jf1, int jf2, int nfreq,
|
---|
| 48 | vector<sa_size_t> tfrlist);
|
---|
| 49 | int FillVisDTable(BaseDataTable& visdt_, TMatrix< r_4 > vismtx_, TVector< int_4> chanum_,
|
---|
| 50 | sa_size_t jf1_, sa_size_t jf2_, sa_size_t djf_) ;
|
---|
| 51 |
|
---|
| 52 | //------------------------------------------------------------------------------------------------------------
|
---|
| 53 |
|
---|
| 54 | /* --Fonction-- */
|
---|
| 55 | int Usage(bool fgshort)
|
---|
| 56 | {
|
---|
| 57 | cout << " --- visfits2dt : Read fits visibility matrices produced by visfmib to make \n"
|
---|
| 58 | << " time-frequency matrices and Visibilites=f(time) datatable " << endl;
|
---|
[3962] | 59 | cout << " Usage: visfits2dt InOutPath Imin,Imax,step NumFreq1,NumFreq2,NBinFreq VisMtxRowList [DT] \n" << endl;
|
---|
[3959] | 60 | if (fgshort) {
|
---|
| 61 | cout << " svv2mtx -h for detailed instructions" << endl;
|
---|
| 62 | return 1;
|
---|
| 63 | }
|
---|
| 64 | cout << " InOutPath : Input/Output directory name \n"
|
---|
| 65 | << " Imin,Imax,IStep: Input FITS files sequence number (vismtxII.fits) \n"
|
---|
| 66 | << " FileNames=InOutPath/vismtxII.fits Imin<=II<=Imax II+=IStep \n"
|
---|
| 67 | << " NumFreq1,NumFreq2,NBinFreq: Freq Zone and number of frequency bins for DataTable\n"
|
---|
[3962] | 68 | << " VisMtxRowList : List of visibiliy matrix rows (0,2,...) -> time-freq map \n"
|
---|
| 69 | << " DT : Fill datatable if DT arg specified " << endl;
|
---|
[3959] | 70 | return 1;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | //----------------------------------------------------
|
---|
| 74 | //----------------------------------------------------
|
---|
| 75 | int main(int narg, char* arg[])
|
---|
| 76 | {
|
---|
| 77 | if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false);
|
---|
[3962] | 78 | if (narg<5) return Usage(true);
|
---|
[3959] | 79 | HiStatsInitiator _inia;
|
---|
| 80 | // TArrayInitiator _inia;
|
---|
| 81 |
|
---|
| 82 | int rc = 0;
|
---|
| 83 | try {
|
---|
| 84 | bool fgvjun09=false;
|
---|
| 85 | ResourceUsage resu;
|
---|
| 86 | DecodeProc(narg-1, arg+1);
|
---|
| 87 | resu.Update();
|
---|
| 88 | cout << resu;
|
---|
| 89 | }
|
---|
| 90 | catch (PException& exc) {
|
---|
| 91 | cerr << " visfits2dt.cc catched PException " << exc.Msg() << endl;
|
---|
| 92 | rc = 77;
|
---|
| 93 | }
|
---|
| 94 | catch (std::exception& sex) {
|
---|
| 95 | cerr << "\n visfits2dt.cc std::exception :"
|
---|
| 96 | << (string)typeid(sex).name() << "\n msg= "
|
---|
| 97 | << sex.what() << endl;
|
---|
| 98 | rc = 78;
|
---|
| 99 | }
|
---|
| 100 | catch (...) {
|
---|
| 101 | cerr << " visfits2dt.cc catched unknown (...) exception " << endl;
|
---|
| 102 | rc = 79;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | cout << ">>>> visfits2dt.cc ------- END ----------- RC=" << rc << endl;
|
---|
| 106 | return rc;
|
---|
| 107 |
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | //--------------------------------------------------------------------
|
---|
| 111 | // Traitement fichiers produits par vismfib (V Nov09)
|
---|
| 112 | /* --Fonction-- */
|
---|
[3962] | 113 | static bool fgfilldt=false;
|
---|
| 114 |
|
---|
[3959] | 115 | int DecodeProc(int narg, char* arg[])
|
---|
| 116 | {
|
---|
| 117 | // Decodage des arguments et traitement
|
---|
| 118 | string inoutpath = arg[0];
|
---|
| 119 | int imin=0;
|
---|
| 120 | int imax=0;
|
---|
| 121 | int istep=1;
|
---|
| 122 | sscanf(arg[1],"%d,%d,%d",&imin,&imax,&istep);
|
---|
| 123 | int jf1=0;
|
---|
| 124 | int jf2=0;
|
---|
| 125 | int nfreq=0;
|
---|
| 126 | sscanf(arg[2],"%d,%d,%d",&jf1,&jf2,&nfreq);
|
---|
| 127 | int card=1;
|
---|
| 128 | vector<sa_size_t> rowlist;
|
---|
[3962] | 129 | EnumeratedSequence es;
|
---|
| 130 | int nbad;
|
---|
| 131 | es.Append(arg[3], nbad, ",");
|
---|
| 132 | for(int j=0; j<es.Size(); j++) rowlist.push_back((int)es.Value(j));
|
---|
| 133 | fgfilldt=false;
|
---|
| 134 | if ((narg>4)&&(strcmp(arg[4],"DT")==0)) fgfilldt=true;
|
---|
[3960] | 135 | // if (rowlist.size()<1) rowlist.push_back(0);
|
---|
[3959] | 136 |
|
---|
| 137 | cout << " ----- visfits2dt/DecodeProc - Start - InOutPath= " << inoutpath << " IMin,Max,Step="
|
---|
| 138 | << imin << "," << imax << "," << istep << " Card=" << card << endl;
|
---|
| 139 | cout << "Frequency num range JF=" << jf1 << "," << jf2 << "," << nfreq << " ------- " << endl;
|
---|
| 140 | cout << " RowList: " ;
|
---|
| 141 | for(int j=0; j<rowlist.size(); j++) cout << rowlist[j] << " , " ;
|
---|
| 142 | cout << endl;
|
---|
| 143 | int rc=ProcVisMtxFiles(inoutpath, imin, imax, istep, jf1, jf2, nfreq, rowlist);
|
---|
| 144 | return rc;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
|
---|
| 148 | /* --Fonction-- */
|
---|
| 149 | int ProcVisMtxFiles(string& inoutpath, int imin, int imax, int istep, int jf1, int jf2, int nfreq,
|
---|
| 150 | vector<sa_size_t> rowlist)
|
---|
| 151 | {
|
---|
| 152 | Timer tm("ProcVisMtxFiles");
|
---|
| 153 |
|
---|
| 154 | DataTable visdt;
|
---|
| 155 | visdt.AddDoubleColumn("mfc");
|
---|
| 156 | visdt.AddDoubleColumn("mtt");
|
---|
| 157 | visdt.AddIntegerColumn("jfreq");
|
---|
| 158 | visdt.AddIntegerColumn("numch");
|
---|
| 159 | visdt.AddFloatColumn("vre");
|
---|
| 160 | visdt.AddFloatColumn("vim");
|
---|
| 161 |
|
---|
| 162 | vector< TMatrix< r_4 > > vmtf;
|
---|
| 163 |
|
---|
| 164 | if (jf1<1) jf1=1;
|
---|
| 165 | if ((jf2<1)||(jf2<jf1)) jf2=jf1;
|
---|
| 166 | if (nfreq<1) nfreq=1;
|
---|
| 167 | int djf=(jf2-jf1)/nfreq;
|
---|
| 168 | if (djf<1) djf=1;
|
---|
| 169 |
|
---|
[3962] | 170 | cout << " --- ProcVisMtxFiles Frequency binng Start=" << jf1 << " End= " << jf2 << " DFreq=" << djf << " NBinFreq=" << nfreq << endl;
|
---|
[3959] | 171 | char fname[1024];
|
---|
| 172 |
|
---|
| 173 | cout << " ---- ProcVisMtxFiles()-Begin - Reading chanum vector" << endl;
|
---|
| 174 | TVector< int_4 > chanum;
|
---|
| 175 | {
|
---|
| 176 | sprintf(fname, "%s/chanum.fits",inoutpath.c_str());
|
---|
| 177 | FitsInOutFile fic(fname, FitsInOutFile::Fits_RO);
|
---|
| 178 | fic.MoveAbsToHDU(3);
|
---|
| 179 | fic >> chanum;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | cout << " ---- ProcVisMtxFiles()-Read chanum done " << endl;
|
---|
| 183 | sa_size_t nrows = (imax-imin+1)/istep;
|
---|
[3962] | 184 | sa_size_t ktime=0;
|
---|
[3959] | 185 |
|
---|
[3962] | 186 | // sa_size_t mtf_binfreq=25;
|
---|
| 187 | sa_size_t mtf_bintime=1;
|
---|
[3959] | 188 |
|
---|
| 189 | sa_size_t ncols=1;
|
---|
| 190 |
|
---|
| 191 | for(int ifile=imin; ifile<=imax; ifile+=istep) {
|
---|
| 192 | sprintf(fname, "%s/vismtx%d.fits",inoutpath.c_str(),ifile);
|
---|
| 193 | cout << " ProcVisMtxFiles[" << ifile << "] opening file " << fname << endl;
|
---|
| 194 | FitsInOutFile fin(fname, FitsInOutFile::Fits_RO);
|
---|
| 195 | TMatrix< r_4 > vismtx;
|
---|
| 196 | fin >> vismtx;
|
---|
| 197 | // cout << vismtx.Info();
|
---|
| 198 |
|
---|
[3960] | 199 | if ((ifile==imin)&&(rowlist.size()>0)) {
|
---|
[3959] | 200 | ncols = vismtx.NCols();
|
---|
| 201 | cout << " ProcVisMtxFiles/Info: Output Time-Frequency matrices NRows(time) "
|
---|
[3962] | 202 | << nrows/mtf_bintime+1 << " NCols(freq) =" << nfreq << endl;
|
---|
[3959] | 203 | for(size_t j=0; j<rowlist.size(); j++)
|
---|
[3962] | 204 | vmtf.push_back(TMatrix< r_4 >(nrows/mtf_bintime+1, nfreq));
|
---|
[3959] | 205 | }
|
---|
| 206 |
|
---|
[3960] | 207 | if (rowlist.size()>0) {
|
---|
[3962] | 208 | for(size_t j=0; j<rowlist.size(); j++) {
|
---|
| 209 | sa_size_t jfreb=0;
|
---|
| 210 | for(sa_size_t jf=jf1; jf<jf2; jf+=djf) {
|
---|
| 211 | sa_size_t jfreb=(jf-jf1)/djf;
|
---|
| 212 | if (jfreb>=nfreq) break;
|
---|
| 213 | vmtf[j](ktime/mtf_bintime,jfreb)+=vismtx(rowlist[j],jf);
|
---|
[3960] | 214 | }
|
---|
[3962] | 215 | }
|
---|
[3959] | 216 | }
|
---|
| 217 | // cout << " DBG* kr=" << kr << " kr/mtf_bintime=" << kr/mtf_bintime
|
---|
| 218 | // << " ncols/2/mtf_binfreq=" << ncols/2/mtf_binfreq << endl;
|
---|
[3962] | 219 | ktime++;
|
---|
[3959] | 220 |
|
---|
| 221 |
|
---|
| 222 | // Calcul moyenne dans des bandes en frequence
|
---|
[3962] | 223 | if (fgfilldt) FillVisDTable(visdt, vismtx, chanum, jf1, jf2, djf);
|
---|
[3959] | 224 | }
|
---|
| 225 |
|
---|
| 226 | if (rowlist.size()>0) {
|
---|
| 227 | sprintf(fname, "!%s/vistfreqmtx.fits",inoutpath.c_str());
|
---|
| 228 | cout << "ProcVisMtxFiles: Opening file " << fname << " for writing Visi(Freq,Time) matrices" << endl;
|
---|
| 229 | FitsInOutFile fo(fname, FitsInOutFile::Fits_Create);
|
---|
[3962] | 230 | for(size_t j=0; j<rowlist.size(); j++) {
|
---|
[3964] | 231 | cout << " Writing Time-Freq visibility matrix[" << j << "] for VisIJ= " << chanum(rowlist[j]) << endl;
|
---|
[3959] | 232 | fo << vmtf[j];
|
---|
[3962] | 233 | }
|
---|
[3959] | 234 | }
|
---|
[3962] | 235 | if (fgfilldt) {
|
---|
| 236 | cout << visdt;
|
---|
| 237 | sprintf(fname, "!%s/visidt.fits",inoutpath.c_str());
|
---|
| 238 | cout << "ProcVisMtxFiles: writing visibility datatable to file " << fname << endl;
|
---|
| 239 | FitsInOutFile fod(fname, FitsInOutFile::Fits_Create);
|
---|
| 240 | fod << visdt;
|
---|
| 241 | }
|
---|
[3959] | 242 | return 0;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | /* --Fonction-- */
|
---|
| 246 | int FillVisDTable(BaseDataTable& visdt_, TMatrix< r_4 > vismtx_, TVector< int_4> chanum_,
|
---|
| 247 | sa_size_t jf1_, sa_size_t jf2_, sa_size_t djf_)
|
---|
| 248 | {
|
---|
| 249 | double xnt_[20];
|
---|
| 250 | xnt_[0]=(double)vismtx_.Info()["MEANFC"];
|
---|
| 251 | xnt_[1]=(double)vismtx_.Info()["MEANTT"]/1.25e8;
|
---|
| 252 |
|
---|
| 253 | uint_4 nmean_=vismtx_.Info()["NPAQSUM"];
|
---|
| 254 | if (djf_<2) {
|
---|
| 255 | for(sa_size_t rv=0; rv<vismtx_.NRows(); rv++) {
|
---|
| 256 | for(sa_size_t jf=jf1_; jf<jf2_; jf++) {
|
---|
| 257 | xnt_[2]=jf;
|
---|
| 258 | xnt_[3]=chanum_(rv);
|
---|
| 259 | xnt_[4]=vismtx_(rv,jf*2)/(r_4)(nmean_);
|
---|
| 260 | xnt_[5]=vismtx_(rv,jf*2+1)/(r_4)(nmean_);
|
---|
| 261 | visdt_.AddRow(xnt_);
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | }
|
---|
| 265 | else {
|
---|
| 266 | for(sa_size_t rv=0; rv<vismtx_.NRows(); rv++) {
|
---|
| 267 | for(sa_size_t jf=jf1_; jf<jf2_; jf+=djf_) {
|
---|
| 268 | r_4 moyreal=0.;
|
---|
| 269 | r_4 moyimag=0.;
|
---|
| 270 | sa_size_t jjfmx=jf+djf_;
|
---|
| 271 | if (jjfmx > vismtx_.NCols()) jjfmx=vismtx_.NCols();
|
---|
| 272 | for(sa_size_t jjf=jf; jjf<jjfmx; jjf++) {
|
---|
| 273 | moyreal+=vismtx_(rv,jjf*2);
|
---|
| 274 | moyimag+=vismtx_(rv,jjf*2+1);
|
---|
| 275 | }
|
---|
| 276 | xnt_[2]=jf+djf_/2;
|
---|
| 277 | xnt_[3]=chanum_(rv);
|
---|
| 278 | xnt_[4]=moyreal/(r_4)(nmean_*djf_);
|
---|
| 279 | xnt_[5]=moyimag/(r_4)(nmean_*djf_);
|
---|
| 280 | visdt_.AddRow(xnt_);
|
---|
| 281 | }
|
---|
| 282 | }
|
---|
| 283 | }
|
---|
| 284 | return 0;
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 |
|
---|
| 289 |
|
---|