Changeset 1479 in Sophya


Ignore:
Timestamp:
Apr 27, 2001, 2:52:15 AM (24 years ago)
Author:
ansari
Message:

debug deglitcher - Ajout Filtre Fourier (SimpleFourierFilter) - Reza 27/4/2001

Location:
trunk/ArchTOIPipe
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc

    r1478 r1479  
    55#include "pexceptions.h"
    66#include "ctimer.h"
    7 
    8 SimpleDeglitcher::SimpleDeglitcher(int wsz, double ns, int maxnpt)
     7#include "fftpserver.h"
     8
     9SimpleDeglitcher::SimpleDeglitcher(int wsz, double ns, int maxnpt, int minnpt)
    910{
    1011  SetWSize(wsz);
    11   SetDetectionParam(ns, ns/2., maxnpt);
     12  SetDetectionParam(ns, ns/2., maxnpt, minnpt);
    1213  SetRange(-9.e39, 9.e39);
    1314  RepBadSamples(true, true);
     
    2425}
    2526
    26 void SimpleDeglitcher::SetDetectionParam(double ns, double ns2, int maxnpt, int wszrec)
     27void SimpleDeglitcher::SetDetectionParam(double ns, double ns2, int maxnpt,
     28                                         int minnpt, int wszrec)
    2729{
    2830  nsig = (ns > 0.01) ? ns : 1.;
    2931  nsig2 = (ns2 > 0.01) ? ns2 : nsig/2.;
    3032  maxpoints = ((maxnpt > 0) && (maxnpt <= wsize)) ? maxnpt : 5;
     33  minpoints = ((minnpt > 0) && (minnpt <= maxpoints)) ? minnpt : maxpoints/2;
    3134  wrecsize = ((wszrec > 0) && (wszrec <= wsize)) ? wszrec : 2*maxpoints;
    3235}
     
    4245  os << "\n ------------------------------------------------------ \n"
    4346     << " SimpleDeglitcher::PrintStatus() - WindowSize=" << WSize()
    44      << "  NbSigmas=" << NbSigmas() << " MaxPoints=" << MaxPoints() << endl;
    45   os << "  NbSigmas2=" << NbSigmas2() << "  WRecSize= " << WRecSize()
     47     << " MaxPoints=" << MaxPoints() << " MinPoints=" << MinPoints() << endl;
     48  os << " NbSigmas=" << NbSigmas()
     49     << "  NbSigmas2=" << NbSigmas2() << "  WRecSize= " << WRecSize()
    4650     << "  Range_Min= " << range_min << " Range_Max= " << range_max << endl;
    4751  os << "  RepOutOfRangeSamples: " << _Bool2YesNo(rec_out_range_samples)
     
    117121      getData(0, k+snb, vin(k), vfg(k));
    118122
    119     int nokdebut = 0.;
     123    int nokdebut = 0;
    120124    double s = 0.;   
    121125    double mean = 0.;
     
    236240      if (valcur < mean+curnsig*sigma) {  // inferieur au seuil
    237241        if (fgglitch) { 
    238           if (k-kgl < maxpoints) {   // On vient de detecter un glitch
     242          if ( (k-kgl <= maxpoints) && (k-kgl >= minpoints) ) {   
     243            // On vient de detecter un glitch
    239244            glcount++;
    240245            if (rec_gl_samples) { // On change la valeur des samples
     
    253258            lastput = snb+k-1;
    254259          }  // - Fin de detection de glitch
    255           else {  // Trop long - ce n'est pas un glitch ...
     260          else {  // Trop long ou trop court - ce n'est pas un glitch ...
    256261            for(ii=kgl; ii<k; ii++) {
    257262              putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
     
    267272      else {  // Superieur au seuil
    268273        if (fgglitch) {
    269           if (k-kgl+1 >= maxpoints) {  // serie de points > seuil
     274          if (k-kgl+1 > maxpoints) {  // serie de points > seuil
    270275            for(ii=kgl; ii<=k; ii++)   // -> Donc pas glitch
    271276              putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
     
    600605}
    601606
     607// ----------------------------------------------------------------------
     608//   Classe SimpleFourierFilter : Filtre simple ds le domaine de Fourier
     609// ----------------------------------------------------------------------
     610
     611SimpleFourierFilter::SimpleFourierFilter(Vector const & vc)
     612{
     613  ffcoef = vc;
     614  wsize = (ffcoef.Size()-1)*2;
     615  if (wsize < 16)
     616    throw ParmError("SimpleFourierFilter::SimpleFourierFilter() WSize<16 !");
     617  KeepSpectra(0);
     618}
     619
     620SimpleFourierFilter::~SimpleFourierFilter()
     621{
     622}
     623
     624
     625void SimpleFourierFilter::PrintStatus(ostream & os)
     626{
     627  os << "\n ------------------------------------------------------ \n"
     628     << " SimpleFourierFilter::PrintStatus() - WindowSize="
     629     << WSize() << endl;
     630  TOIProcessor::PrintStatus(os);
     631  os << " Coeff= " << ffcoef << endl;
     632  os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
     633  os << " ------------------------------------------------------ " << endl;
     634}
     635
     636void SimpleFourierFilter::init() {
     637  cout << "SimpleFourierFFilter::init" << endl;
     638  declareInput("in");
     639  declareOutput("out");
     640  declareOutput("incopie");
     641  name = "SimpleFourierFilter";
     642  //  upExtra = 1;
     643}
     644
     645
     646void SimpleFourierFilter::run() {
     647  //  TOIManager* mgr = TOIManager::getManager();
     648  int snb = getMinIn();
     649  int sne = getMaxIn();
     650
     651  bool fgout = checkOutputTOIIndex(0);
     652  bool fgincopie = checkOutputTOIIndex(1);
     653
     654  if (!checkInputTOIIndex(0)) {
     655    cerr << " SimpleFourierFilter::run() - Input TOI (in) not connected! "
     656         << endl;
     657    throw ParmError("SimpleFourierFilter::run() Input TOI (in) not connected!");
     658  }
     659  if (!fgout) {
     660    cerr << " SimpleFourierFilter::run() - No Output TOI connected! "
     661         << endl;
     662    throw ParmError("SimpleFourierFilter::run() No output TOI connected!");
     663  }
     664
     665  cout << " SimpleFourierFilter::run() SNRange=" << snb << " - " << sne << endl;
     666 
     667
     668  try {
     669    Timer tm("SimpleFourierFilter::run()");
     670    // Le debut
     671    Vector vin(wsize);
     672    Vector vout(wsize);
     673    TVector<int_8> vfg(wsize);
     674    TVector< complex<r_8> > vfft;
     675    TVector< complex<r_8> > zcoef(ffcoef.Size());
     676    zcoef = ffcoef;
     677
     678
     679    FFTPackServer ffts;
     680    ffts.setNormalize(true);
     681    // Boucle sur les sampleNum
     682
     683    int k,i,klast;
     684    int nks = 0;
     685
     686    klast = snb-1;
     687    // 1er partie, on traite par paquets de wsize
     688    for(k=snb;k<=sne-wsize+1;k+=wsize) {
     689      for(i=0; i<wsize; i++)
     690        getData(0, k+i, vin(i), vfg(i));
     691      ffts.FFTForward(vin, vfft);
     692      if (nks < nb_keep) {
     693        string dbgfile = "ffiltdbg" + (string)MuTyV(nks) + ".ppf";
     694        POutPersist po(dbgfile);
     695        po << vfft;
     696        nks++;
     697      }
     698      vfft.MulElt(zcoef);
     699      ffts.FFTBackward(vfft, vout);
     700      for(i=0; i<wsize; i++)
     701        putData(0,k+i,vout(i),vfg(i));
     702      if (fgincopie)
     703        for(i=0; i<wsize; i++)
     704          putData(1, k+i, vin(i), vfg(i));
     705      klast+=wsize;
     706      totnscount+=wsize;
     707    }
     708   
     709
     710    // 2eme partie, on traite la fin du bloc d'echantillons si necessaire
     711    double inval;
     712    int_8 inflg;
     713    if (klast < sne)
     714      for(k=klast+1; k<=sne; k++) {
     715        getData(0, k, inval, inflg);
     716        putData(0, k, inval, inflg);
     717        if (fgincopie)
     718          putData(1, k, inval, inflg);
     719        totnscount++;
     720      }
     721    cout << " SimpleFourierFilter::run() - End of processing " << endl;
     722  }  // Bloc try
     723
     724  catch (PException & exc) {
     725    cerr << "SimpleFourierFilter: Catched Exception " << (string)typeid(exc).name()
     726         << "\n .... Msg= " << exc.Msg() << endl;
     727  }                                                                             
     728}
    602729
    603730// ---------------------------------------------------------------
     
    659786  out_index = -1;
    660787  int nbconin = 0;
    661   bool fggin = false;
    662788  char buff[64];
    663789  for(int ki=0;ki<nb_input;ki++) {
  • trunk/ArchTOIPipe/ProcWSophya/simtoipr.h

    r1478 r1479  
    1414class SimpleDeglitcher : public TOIProcessor {
    1515public:
    16                 SimpleDeglitcher(int wsz=64, double ns=3, int maxnpt=5);
     16                SimpleDeglitcher(int wsz=64, double ns=3,
     17                                 int maxnpt=5, int minnpt=2);
    1718  virtual       ~SimpleDeglitcher();
    1819
     
    2627
    2728
    28   void          SetDetectionParam(double ns, double ns2, int maxnpt, int wszrec=0);
     29  void          SetDetectionParam(double ns, double ns2, int maxnpt,
     30                                  int minnpt, int wszrec=0);
    2931   
    3032  inline void   RepBadSamples(bool gl_samples, bool out_range_samples, bool use_wrec=true)
     
    4042  inline double NbSigmas2() const { return nsig2; }
    4143  inline int    MaxPoints() const { return maxpoints; }
     44  inline int    MinPoints() const { return minpoints; }
    4245 
    4346  inline int_8  ProcessedSampleCount() const { return totnscount; }
     
    6164  double nsig2;     // Seuil en nb de sigmas, pour les points suivants le 1er
    6265  int maxpoints;    // Nb maxi de points > ns sigmas
     66  int minpoints;    // Nb mini de points > ns sigmas pour avoir un glitch
    6367  double range_min, range_max;  // Range acceptable pour in
    6468
     
    136140
    137141
     142//  Un filtre simple, dans le domaine de Fourier
     143//  InverseFFT ( FFT(Vecteur(in)) * FilterCoefficient )
     144
     145class SimpleFourierFilter : public TOIProcessor {
     146public:
     147                SimpleFourierFilter(Vector const & vc); 
     148                ~SimpleFourierFilter();
     149
     150  inline int    WSize() const { return wsize; }
     151  inline int_8  ProcessedSampleCount() const { return totnscount; }
     152  inline Vector FilterCoefficients() const
     153                { Vector rcv; rcv = ffcoef; return(rcv); }
     154
     155  virtual void  PrintStatus(ostream & os) ; // const plus tard
     156
     157  virtual void  init(); 
     158  virtual void  run();
     159
     160  inline  void  KeepSpectra(int nb=0)
     161                { nb_keep = nb; }
     162protected:
     163  int_8 totnscount;   // Nombre total d'echantillon processe
     164  int wsize;         // Taille de fenetre de travail
     165  Vector ffcoef;     // Coefficients du filtre
     166  int nb_keep;
     167};
     168
     169
    138170//  Classe SimpleFanOut
    139 //  Transforme recopie chaque entree sur M lignes de sortie
     171//  Recopie chaque entree sur M lignes de sortie
    140172
    141173class SimpleFanOut : public TOIProcessor {
     
    159191};
    160192
     193
    161194#endif
  • trunk/ArchTOIPipe/TestPipes/simtst.cc

    r1478 r1479  
    3333  else {
    3434    cout << "\n Usage : simtst [-dbg] [-start snb] [-end sne] \n"
    35          << "         [-wtoi sz] [-w2 sz] inFitsName outFitsName ppfFileName \n"
     35         << "         [-wtoi sz] [-wdegli sz] [-wfft sz] [-keepfft n] \n"
     36         << "         inFitsName outFitsName  \n"
    3637         << "   -dbg : sets TOISeqBuffered debug level to 1 \n"
    3738         << "   -start snb : sets the start sample num \n"
     
    4243         << "   -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
    4344         << "   -wdegli sz : sets deglitcher window size (def= 512) \n"
     45         << "   -wfft sz : Activate Fourier filter and sets its width \n"
     46         << "   -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
    4447         << endl;
    4548    exit(0);
     
    5457
    5558  bool fgdbg = false;
    56   int w1 = 8192;
    57   int w2 = 512;
     59  int wtoi = 8192;
     60  int wdegli = 512;
     61  int wfft = 4096;
     62  int keepfft = 0;
    5863  int nmax = 10;
    59   int istart = 104121000+w1*5;
     64  int istart = 104121000+wtoi*5;
    6065  int iend = 0;
    6166  double range_min = -16000;
     
    6368  string infile;
    6469  string outfile;
    65   string ppffile;
    6670  string intoi = "boloMuV_27";
     71  bool fg_f_filt = false;
    6772
    6873  if (narg < 4) Usage(true);
     
    8085    else if (strcmp(arg[ia],"-wtoi") == 0) {
    8186      if (ia == narg-1) Usage(true); 
    82       w1 = atoi(arg[ia+1]); ia++;
     87      wtoi = atoi(arg[ia+1]); ia++;
    8388    }   
    8489    else if (strcmp(arg[ia],"-wdegli") == 0) {
    8590      if (ia == narg-1) Usage(true); 
    86       w2 = atoi(arg[ia+1]); ia++;
     91      wdegli = atoi(arg[ia+1]); ia++;
     92    }   
     93    else if (strcmp(arg[ia],"-wfft") == 0) {
     94      if (ia == narg-1) Usage(true); 
     95      wfft = atoi(arg[ia+1]); ia++;
     96      fg_f_filt = true;
     97    }   
     98    else if (strcmp(arg[ia],"-keepfft") == 0) {
     99      if (ia == narg-1) Usage(true); 
     100      keepfft = atoi(arg[ia+1]); ia++;
    87101    }   
    88102    else if (strcmp(arg[ia],"-range") == 0) {
     
    100114  }
    101115
    102   if (iend < istart) iend = istart+w1*(nmax+5);
    103   if ((narg-ko) < 3)  Usage(true);
     116  if (iend < istart) iend = istart+wtoi*(nmax+5);
     117  if ((narg-ko) < 2)  Usage(true);
    104118  infile = arg[ko];
    105119  outfile = arg[ko+1];
    106   ppffile = arg[ko+2];
    107120
    108121  cout << " Initializing SOPHYA ... " << endl;
     
    110123  InitTim();
    111124
    112   cout << ">>>> tstrztoi: Infile= " << infile << " outFile=" << outfile
    113        << " ppfFile= " << ppffile << endl;
    114   cout << ">>>> Window Size W1= " << w1 << " W2= " << w2
     125  cout << ">>>> tstrztoi: Infile= " << infile << " outFile="
     126       << outfile << endl;
     127  cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
    115128       << "  iStart= " << istart << " iEnd= " << iend << endl;
    116129  cout << ">>>> InTOIName= " << intoi << endl;
     130
    117131  try {
    118132    TOIManager* mgr = TOIManager::getManager();
     
    131145
    132146
     147    int w1 = wtoi;
     148    int w2 = (fg_f_filt && (wfft > w1)) ? wfft : w1;
     149
    133150    //    char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
    134151    //    char * toiname[5] = {"MJD", "UTC","bolo11","magneto","pivot"};
     
    139156    TOISeqBuffered * toimean = new TOISeqBuffered("mean", w1);
    140157    if (fgdbg) toimean->setDebugLevel(1);
    141     TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w1);
     158    TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w2);
    142159    if (fgdbg) toisig->setDebugLevel(1);
    143160    TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w1);
     
    160177
    161178    cout << " Creating SimpleDeglitcher() " << endl;
    162     SimpleDeglitcher degl(w2);
     179    SimpleDeglitcher degl(wdegli);
     180    degl.SetDetectionParam(3.,1.5, 4, 2, 10);
    163181    cout << " Setting Range for deglitcher: " << range_min
    164182         << " - " << range_max << endl;
     183
    165184    degl.SetRange(range_min, range_max);
    166185    degl.addInput("in", toiin);
     
    174193    TOISeqBuffered * toidegli0 = new TOISeqBuffered("degli0", w1);
    175194    if (fgdbg) toidegli0->setDebugLevel(1);
    176     TOISeqBuffered * toidegli1 = new TOISeqBuffered("degli1", w1);
     195    TOISeqBuffered * toidegli1 = new TOISeqBuffered("degli1", w2);
    177196
    178197    TOISeqBuffered * toimean0 = new TOISeqBuffered("mean0", w1);
    179198    if (fgdbg) toimean0->setDebugLevel(1);
    180     TOISeqBuffered * toimean1 = new TOISeqBuffered("mean1", w1);
     199    TOISeqBuffered * toimean1 = new TOISeqBuffered("mean1", w2);
    181200    if (fgdbg) toimean1->setDebugLevel(1);
    182201   
     
    206225    TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
    207226    if (fgdbg) toiout->setDebugLevel(1);
    208     TOISeqBuffered * toideglioffcopie = new TOISeqBuffered("deglioffcopie", w1);
     227    TOISeqBuffered * toideglioffcopie = new TOISeqBuffered("deglioffcopie", w2);
    209228    if (fgdbg) toideglioffcopie->setDebugLevel(1);
    210229    filt.addOutput("out", toiout);
    211230    filt.addOutput("incopie", toideglioffcopie);
    212    
     231
     232    Vector fcoef(wfft/2);
     233    fcoef = RegularSequence(1., -2./wfft);
     234    cout << " Creating Fourier Filter ... " << endl;
     235    SimpleFourierFilter sfft(fcoef);
     236    sfft.KeepSpectra(keepfft);
     237    TOISeqBuffered * toifft = NULL;
     238    TOISeqBuffered * toifiltcopie = NULL;
     239
     240    if (fg_f_filt) {
     241      cout << " Connecting Fourier Filter ... " << endl;
     242      toifft = new TOISeqBuffered("fftout", w1);
     243      toifiltcopie = new TOISeqBuffered("filtcopie", w1);
     244      sfft.addInput("in",toiout);
     245      sfft.addOutput("out", toifft);
     246      sfft.addOutput("incopie", toifiltcopie);
     247    }
    213248
    214249    cout << " Connecting to output (FitsWriter) " << endl;
     
    216251    w.setOutFlags(true);
    217252    w.addInput("in", toiincopie);
    218     w.addInput("out", toiout);
     253    if (fg_f_filt) {
     254      w.addInput("filtout", toifiltcopie);
     255      w.addInput("fftout", toifft);
     256    }
     257    else   w.addInput("out", toiout);
    219258    w.addInput("degli", toidegli1);
    220259    w.addInput("deglioff", toideglioffcopie);
     
    239278    adder.start();
    240279    filt.start();
     280    if (fg_f_filt) sfft.start();
    241281    w.start();
    242282
     
    268308    cout << filt;
    269309    cout << adder;
     310    if (fg_f_filt) cout << sfft ;
    270311
    271312  }
Note: See TracChangeset for help on using the changeset viewer.