Commit 57258d1c authored by perdereau's avatar perdereau
Browse files

to handle skipping some corupted files

parent 1f1438ce
......@@ -67,6 +67,8 @@ def viewtfmap(folder,num,mvmin=0.,mvmax=0.,save=False, raplot=False,timeplot=F
nfre = np.size(freqs)
ntim = np.size(times)
timin = min(times)/3600.
if timin ==0. :
timin=times[0]/3600.
timax = max(times)/3600.
if ramod :
timin = min(ras)
......
......@@ -190,13 +190,18 @@ int main(int narg, const char* arg[])
vector <TimeStamp> vtimes ;
vector <double> med_chan ;
long serialnum;
size_t rdidx, lastrdidx=0;
while (fgok) {
//reads next visibility matrix window
fgok = wreader.Shift();
fgok = wreader.Shift(rdidx, serialnum);
//DBG cout << " read "<< wreader.getNbReads()<<" ok "<< fgok<<":"<<endl;
if (!fgok) break;
if ((rdidx <= lastrdidx)&&(lastrdidx>0)) throw ForbiddenError("BAD wreader.Shift(rdidx) rdidx <= lastrdidx"); // BUG si ca arrive !
lastrdidx=rdidx;
for (size_t k=0 ; k<wreader.getWindowSize() ; k++){
TMatrix< complex<r_4> > vmtx = wreader.getVisMtx(k);
......
......@@ -103,11 +103,16 @@ int main(int narg, const char* arg[])
sa_size_t TFMtmidx=0;
sa_size_t tfmSX, tfmSY;
long serialnum;
size_t rdidx, lastrdidx=0;
bool fgok=true;
while (fgok) {
//reads next visibility matrix window
fgok = wreader.Shift();
fgok = wreader.Shift(rdidx, serialnum);
if (!fgok) break;
if ((rdidx <= lastrdidx)&&(lastrdidx>0)) throw ForbiddenError("BAD wreader.Shift(rdidx) rdidx <= lastrdidx"); // BUG si ca arrive !
if ((rdidx-lastrdidx)>1) TFMtmidx+=(rdidx-lastrdidx-1)/deltaIavg;;
lastrdidx=rdidx;
TMatrix< complex<r_4> > vismtx = wreader.getAverageVisMtx(cfdate);
......
......@@ -169,11 +169,16 @@ int main(int narg, const char* arg[])
sa_size_t ramSX, ramSY;
long serialnum;
size_t rdidx, lastrdidx=0;
while (fgok) {
//reads next visibility matrix window
fgok = wreader.Shift();
fgok = wreader.Shift(rdidx, serialnum);
if (!fgok) break;
if ((rdidx <= lastrdidx)&&(lastrdidx>0)) throw ForbiddenError("BAD wreader.Shift(rdidx) rdidx <= lastrdidx"); // BUG si ca arrive !
lastrdidx=rdidx;
vismtx = wreader.getAverageVisMtx(cfdate);
if (cnt==0) { //resizing matrices for sum of auto-correlations and sum of 6 cross-correlations
......
......@@ -157,11 +157,19 @@ int main(int narg, const char* arg[])
TArray< r_4 > racntmap((sa_size_t)ram.getMapSize());
sa_size_t kt=0; //-- time index
long serialnum;
size_t rdidx, lastrdidx=0;
while (fgok) {
//reads next visibility matrix window
fgok = wreader.Shift();
fgok = wreader.Shift(rdidx, serialnum);
if (!fgok) break;
if ((rdidx <= lastrdidx)&&(lastrdidx>0)) throw ForbiddenError("BAD wreader.Shift(rdidx) rdidx <= lastrdidx"); // BUG si ca arrive !
lastrdidx=rdidx;
TMatrix< complex<r_4> > vismtx = wreader.getAverageVisMtx(cfdate);
if (cnt==0) {
......
......@@ -155,7 +155,7 @@ int main(int narg, const char* arg[])
TMatrix< r_4 > cxsum_hv_sq_rp;
TMatrix< r_4 > cxsum_hv_sq_ip;
TimeStamp dateobs, cfdate,datestart;
TimeStamp dateobs, cfdate,datestart,datused;
TimeStamp dateorg(2015,1,1,12,0,0.); // Date origine 1 jan 2015
double mttag;
int cnt=0, cntnt=0, pcntnt=0;
......@@ -188,13 +188,20 @@ int main(int narg, const char* arg[])
//---- for the time-freqency map filling
sa_size_t TFMtmidx=0;
sa_size_t tfmSX, tfmSY;
long serialnum;
size_t rdidx, lastrdidx=0;
while (fgok) {
//reads next visibility matrix window
fgok = wreader.Shift();
fgok = wreader.Shift(rdidx, serialnum);
if (!fgok) break;
if ( (rdidx <= lastrdidx)&&(lastrdidx>0)) throw ForbiddenError("BAD wreader.Shift(rdidx) rdidx <= lastrdidx"); // BUG si ca arrive !
if ((rdidx-lastrdidx)>1 ){
TFMtmidx+=(rdidx-lastrdidx-1)/deltaIavg;
cout<<" visiavg : skipped some data "<< (rdidx-lastrdidx-1) << endl;
}
lastrdidx=rdidx;
vismtx = wreader.getAverageVisMtx(cfdate);
if (cnt==0) { //resizing matrices for sum of auto-correlations and sum of 6 cross-correlations
......@@ -271,7 +278,7 @@ int main(int narg, const char* arg[])
// recupere le jour de depart @ 0h
datestart = TimeStamp(cfdate.DaysPart(),0.);
} // end if cnt==0
if (I==0) { // start filling a new time bin
......@@ -302,7 +309,7 @@ int main(int narg, const char* arg[])
cxsum_hv_sq_ip = 0.;
}
}
}
}// end if(I==0)
// sum (integration) along the time axis
for(size_t k=0; k<KVAC.size(); k++) acsum.Row(k) += vismtx.Row(KVAC[k]); // Les auto-correlations
......@@ -434,20 +441,28 @@ int main(int narg, const char* arg[])
} //----- end of loop over the 16 Xcor HV
} // end HV option
double tdif = cfdate.TimeDifferenceSeconds(cfdate,dateobs)/2.;
timevec(TFMtmidx) = dateobs.TimeDifferenceSeconds(dateobs.ShiftSeconds (tdif ),datestart); // centre du bin
double tdif = cfdate.TimeDifferenceSeconds(cfdate,dateobs)/2.; // 1/2 largeur du bin en temps
double mytime = dateobs.TimeDifferenceSeconds(dateobs.ShiftSeconds (tdif ),datestart); // centre du bin
if ( mytime == 0.) {
cout<<"visiavg/PROBLEME : time=0 ?!? " <<cntnt<<endl;
}
timevec(TFMtmidx) = mytime ;
ravec(TFMtmidx) = P4Coords::RAFromTimeTU(dateobs.ShiftSeconds (tdif ));
TFMtmidx++;
// ... done
I=0; cntnt++;
}
cnt++;
if ((cnt>0)&&(cntnt%10==0)&&(cntnt>pcntnt)) {
cout<<"visiavg/Info: TFM-Map fill cnt="<<cntnt<<" VisMtxCount="<<cnt
if ((cnt>0)&&(cntnt%10==0)&&(cntnt>pcntnt))
{
cout<<"visiavg/Info: TFM-Map fill cnt="<<cntnt<<" VisMtxCount="<<cnt<<" tfmidx "<< TFMtmidx
<<" /Max="<<wreader.getTotalNbWindows()<<" DateObs="<<dateobs<<endl;
pcntnt=cntnt;
}
}
}
}// end while(fgok)
cout<<"visiavg/Info: count="<<cnt*wreader.getWindowSize()<<" Visibility Matrices read "<<endl;
// --- Sauvegarde cartes temps-frequence en fits
......
......@@ -51,6 +51,8 @@ public:
inline long getSerialLast() const { return ser_last_; }
//! return the visibility matrix serial number (or sequence number) step
inline long getSerialStep() const { return ser_step_; }
//! return the current visibility matrix serial number (or sequence number)
inline long getCurrentSerial() const { return cur_serialnum_; }
//! Activate or deactivate frequency reordering when reading visibility matrices
inline void setFreqReordering(bool fg)
......
......@@ -11,7 +11,7 @@
VisiP4WindowReader::VisiP4WindowReader(vector<string> const& vpath, size_t wsz, bool fgrdthRFI)
: wsz_(wsz), fgreadthermRFI_(fgrdthRFI), p4vreaderp_(NULL), vtu_(wsz),
p4gnu_(NULL), p4gvf_(NULL), p4phc_(NULL),
fgown_p4gnu_(false), fgown_p4gvf_(false), fgown_p4phc_(false), fggpcor_(wsz)
fgown_p4gnu_(false), fgown_p4gvf_(false), fgown_p4phc_(false), fggpcor_(wsz), firstread_serial_num(-1)
{
cout << " VisiP4WindowReader - Creating Reader with window size= " << wsz_ << endl;
BaseArray::SetDefaultMemoryMapping(BaseArray::CMemoryMapping);
......@@ -29,7 +29,7 @@ VisiP4WindowReader::VisiP4WindowReader(vector<string> const& vpath, size_t wsz,
VisiP4WindowReader::VisiP4WindowReader(P4AnaParams & params, bool fgrdthRFI)
: wsz_(params.inwsz_), fgreadthermRFI_(fgrdthRFI), p4vreaderp_(NULL), vtu_(params.inwsz_),
p4gnu_(NULL), p4gvf_(NULL), p4phc_(NULL),
fgown_p4gnu_(false), fgown_p4gvf_(false), fgown_p4phc_(false), fggpcor_(params.inwsz_)
fgown_p4gnu_(false), fgown_p4gvf_(false), fgown_p4phc_(false), fggpcor_(params.inwsz_), firstread_serial_num(-1)
{
cout << " VisiP4WindowReader(P4AnaParams & params) - Creating Reader with window size= " << wsz_ << endl;
BaseArray::SetDefaultMemoryMapping(BaseArray::CMemoryMapping);
......@@ -126,8 +126,10 @@ void VisiP4WindowReader::setPhaseCorrector(P4PhaseCor& phc)
/* --Methode-- */
bool VisiP4WindowReader::Shift()
bool VisiP4WindowReader::Shift(size_t & rdidx, long & serialnum)
{
serialnum=-1;
rdidx=0;
for(size_t ii=0; ii<wsz_; ii++) fggpcor_[ii]=false; cntfgcor_=0;
size_t k0 = 0;
TimeStamp dateobs;
......@@ -156,6 +158,12 @@ bool VisiP4WindowReader::Shift()
vtu_[k]=dateobs;
}
if (nbreads_ == 0 ) return false;
serialnum=getReader().getCurrentSerial();
if (firstread_serial_num<0) firstread_serial_num=serialnum;
else {
long lidx=(serialnum-firstread_serial_num)/getSerialNumStepWhenShift();
if (lidx>=0) rdidx=lidx;
}
return true;
}
......
......@@ -59,6 +59,8 @@ public:
//! return the window size
inline size_t getWindowSize() const { return wsz_; }
//! return the visibility matrix sequence number step, for each call to shift
inline long getSerialNumStepWhenShift() const { return ((long)p4vreaderp_->getSerialStep()*(long)wsz_); }
//! return total number of windows to be read
size_t getTotalNbWindows();
......@@ -70,8 +72,13 @@ public:
//! \brief Set/change the phase correction P4PhaseCor object.
void setPhaseCorrector(P4PhaseCor& phc);
//! Reads the visibility matrices corresponding to the next time window - return true if OK, false otherwise
bool Shift();
/*! \brief Reads the visibility matrices corresponding to the next time window -
return true if OK, false otherwise
\param rdidx : integer index representing the read window index, taking into account missing or skipped visibility matrix
equal to (last_read_serial-first_read_serial)/getSerialNumStepWhenShift()
\param serialnum : the sequence (or serial number) of the last visibility matrix read
*/
bool Shift(size_t & rdidx, long & serialnum);
//! Returns the visibiliy matrix with the index k in the window, gain and phase corrected if \b fgcor is true
TMatrix< complex<r_4> > getVisMtx(size_t k, bool fgcor=true);
/*! \brief Returns the average visibiliy matrix of the window, gain and phase corrected
......@@ -99,7 +106,7 @@ protected:
bool fgown_p4gnu_, fgown_p4gvf_, fgown_p4phc_; // true->the corresponding pointer is owned by the VisiP4WindowReader object
vector<bool> fggpcor_; // flag indicating if gain/phase correction have (true-> correction applied)
size_t cntfgcor_; // count of true in fggpcor_
long firstread_serial_num; // The serial number after the first read
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment