Commit 0bab08e0 authored by Reza  ANSARI's avatar Reza ANSARI
Browse files

Introduction de la gestion de bande frequence a masquer (killfreq) dans...

Introduction de la gestion de bande frequence a masquer (killfreq) dans P4FreqSelectorFilterMgr et adaptation de visamm.cc - A TESTER, Reza 19/08/2018
parent c16a82d8
......@@ -21,41 +21,88 @@
#include "p4freqselmgr.h"
P4FreqSelectorFilterMgr::P4FreqSelectorFilterMgr()
: fgdomask_(true)
{
mask_.SetSize1D(P4FreqBand::getP4NbFreqChannels());
mask_ = complex<float>(1., 0.);
}
P4FreqSelectorFilterMgr::P4FreqSelectorFilterMgr(string const & filename)
P4FreqSelectorFilterMgr::P4FreqSelectorFilterMgr(P4AnaParams & params)
: fgdomask_(true)
{
readFreqBandDefinitioFile(filename);
mask_.SetSize1D(P4FreqBand::getP4NbFreqChannels());
mask_ = complex<float>(1., 0.);
for(size_t i=0; i<params.fbands_.size(); i++) {
cout << "P4FreqSelectorFilterMgr(params) Adding Band["<<i<<"] "<<params.fbands_[i]<<endl;
addBand(params.fbands_[i]);
}
for(size_t i=0; i<params.kill_fbands_.size(); i++) {
cout << "P4FreqSelectorFilterMgr(params) Masking Band["<<i<<"] "<<params.fbands_[i]<<endl;
addMaskBand(params.kill_fbands_[i]);
}
}
size_t P4FreqSelectorFilterMgr::readFreqBandDefinitioFile(string const & filename)
{
// Il faut coder cette methode
throw ForbiddenError("P4FreqSelectorFilterMgr::readFreqBandDefinitioFile() NOT YET IMPLEMENTED");
}
size_t P4FreqSelectorFilterMgr::addBand(P4FreqBand& fb)
{
v_bands_.push_back( pair<sa_size_t , sa_size_t>(fb.getFirstFreqChannel() , fb.getLastFreqChannel() ) );
weight_bands_.push_back(complex<float>((float)(1./(double)(fb.getLastFreqChannel()-fb.getFirstFreqChannel()+1)), 0.));
v_band_mask_.push_back( TArray< complex<float> >((sa_size_t)(fb.getLastFreqChannel()-fb.getFirstFreqChannel()+1)) );
weight_bands_.push_back(complex<float>(1., 0.));
norm_bands_.push_back(complex<float>(1., 0.));
v_freqbands_.push_back(fb);
fgdomask_=true;
return v_bands_.size();
}
P4FreqBand P4FreqSelectorFilterMgr::getBand(size_t i)
P4FreqBand P4FreqSelectorFilterMgr::getBand(size_t i, float& weight)
{
if (i >= v_bands_.size()) throw RangeCheckError("P4FreqSelectorFilterMgr::getBand() Out of Range band number");
weight=weight_bands_[i].real();
return v_freqbands_[i];
}
vector< complex<float> > P4FreqSelectorFilterMgr::getAverage( TVector< complex<float> > & vis)
size_t P4FreqSelectorFilterMgr::addMaskBand(P4FreqBand& fb)
{
if (vis.Size() != P4FreqBand::getP4NbFreqChannels())
throw ParmError("P4FreqSelectorFilterMgr::getAverage() Bad input visibility vector size ");
v_maskfreqbands_.push_back(fb);
fgdomask_=true;
return v_maskfreqbands_.size();
}
P4FreqBand P4FreqSelectorFilterMgr::getMaskBand(size_t i)
{
if (i >= v_maskfreqbands_.size()) throw RangeCheckError("P4FreqSelectorFilterMgr::getMaskBand() Out of Range band number");
return v_maskfreqbands_[i];
}
vector< complex<float> > P4FreqSelectorFilterMgr::getAverage( TArray< complex<float> > & vis)
{
if (fgdomask_) ComputeMaskWeights();
vis.CompactAllDimensions();
if (vis.SizeX() != mask_.SizeX())
throw ParmError("P4FreqSelectorFilterMgr::getAverage() Bad input visibility 1D array size ");
vector< complex<float> > rvec(size());
for (size_t i=0; i<size(); i++) {
rvec[i] = vis(Range(v_bands_[i].first, v_bands_[i].second)).Sum()*weight_bands_[i];
complex<float> mskwv=v_band_mask_[i].DotProduct(vis(Range(v_bands_[i].first, v_bands_[i].second), Range::all(), Range::all()));
rvec[i] = mskwv*norm_bands_[i];
}
return rvec;
}
void P4FreqSelectorFilterMgr::ComputeMaskWeights()
{
mask_ = complex<float>(1., 0.);
for (size_t i=0; i<v_maskfreqbands_.size(); i++) {
sa_size_t j1=v_maskfreqbands_[i].getFirstFreqChannel();
sa_size_t j2=v_maskfreqbands_[i].getLastFreqChannel();
for(sa_size_t j=j1; j<=j2; j++) mask_(j)=complex<float>(0.,0.);
}
for (size_t i=0; i<v_freqbands_.size(); i++) {
v_band_mask_[i] = mask_(Range(v_bands_[i].first, v_bands_[i].second), Range::all(), Range::all());
complex<float> w = v_band_mask_[i].Sum();
weight_bands_[i]=w;
if (w.real()>0.1) norm_bands_[i]=complex<float>(1./w.real(),0.);
else norm_bands_[i]=complex<float>(0.,0.);
}
fgdomask_=false;
}
......@@ -28,33 +28,46 @@ class P4FreqSelectorFilterMgr {
public:
//! Default constructor, No frequency band defined
P4FreqSelectorFilterMgr();
//! \brief Constructor with the specification of the name of file containing definition of frequency bands
P4FreqSelectorFilterMgr(string const & filename);
//! \brief read the file containing the definition of frequency bands
size_t readFreqBandDefinitioFile(string const & filename);
//! \brief Constructor, getting band and mask definition from the P4AnaParams \b params object
P4FreqSelectorFilterMgr(P4AnaParams & params);
//! \brief return the number of bands defined
inline size_t getNbBands() const { return v_bands_.size(); }
//! \brief return the number of bands defined
inline size_t size() const { return v_bands_.size(); }
//! \brief return the band i
P4FreqBand getBand(size_t i);
//! \brief Add a simple, without masked frequency band
//! \brief Add a frequency band
size_t addBand(P4FreqBand& fb);
//! \brief return the band i and the corresponding weight
P4FreqBand getBand(size_t i, float& weight);
//! \brief return the band i
inline P4FreqBand getBand(size_t i)
{ float w; return getBand(i,w); }
//! \brief Add a frequency band to be masked / killed
size_t addMaskBand(P4FreqBand& fb);
//! \brief return the number of bands defined
inline size_t getNbMaskBands() const { return v_maskfreqbands_.size(); }
//! \brief return the masked band i
P4FreqBand getMaskBand(size_t i);
//! \brief return averaged visibilities in the defined bands ...
vector< complex<float> > getAverage( TVector< complex<float> > & vis);
/*! \brief return averaged visibilities in the defined bands ...
\warning Note that \b vis should be a 1D array on which CompactAllDimensions() would be called */
vector< complex<float> > getAverage( TArray< complex<float> > & vis);
protected:
// Definition of simple bands, without masked frequencies
void ComputeMaskWeights();
// Frequency band definition for averaging/filtering
std::vector< std::pair<sa_size_t , sa_size_t> > v_bands_;
std::vector< complex<float> > weight_bands_;
std::vector< P4FreqBand > v_freqbands_;
std::vector< complex<float> > weight_bands_; // the weight for each band (sum of the mask in the band)
std::vector< complex<float> > norm_bands_; // Normalisation factor for each band (1/weight)
std::vector< TArray< complex<float> > > v_band_mask_; // mask vector for each frequency band
// Definition of masked frequency bands
std::vector< P4FreqBand > v_maskfreqbands_;
TArray< complex<float> > mask_; // the full frequency band mask itself
bool fgdomask_; // true -> mask & weights needs to be computed
};
......
......@@ -110,12 +110,8 @@ int main(int narg, const char* arg[])
ResourceUsage resu;
// Frequency band definition
P4FreqSelectorFilterMgr freqbands;
cout << "visamm/Info : Computing Visibility array for " << params.fbands_.size() << " Frequency bands"<<endl;
for(size_t i=0; i<params.fbands_.size(); i++) {
cout << "Band["<<i<<"] "<<params.fbands_[i]<<endl;
freqbands.addBand(params.fbands_[i]);
}
P4FreqSelectorFilterMgr freqbands(params);
cout << "visamm/Info : Computing Visibility array for " << freqbands.size() << " Frequency bands"<<endl;
P4AVisiNumEncoder visiencod;
vector<sa_size_t> KVAC = visiencod.getAllAutoCor();
......@@ -187,8 +183,8 @@ int main(int narg, const char* arg[])
for(size_t i=0; i<avgac.size(); i++) avgac[i]=complex<float>(0.,0.);
// Getting the 4 H auto-correlations
for(size_t i=0; i<4; i++) {
TVector< complex<r_4> > vir = vismtx.Row(KVAC[i]);
vector< complex<float> > vacm = freqbands.getAverage(vir);
TArray< complex<r_4> > vira = vismtx.Row(KVAC[i]);
vector< complex<float> > vacm = freqbands.getAverage(vira);
for(size_t j=0; j<vacm.size(); j++) {
TArray<r_4> & arr = vammac[j];
arr(idxra, (sa_size_t)i) += vacm[j].real();
......@@ -203,8 +199,8 @@ int main(int narg, const char* arg[])
}
// Getting the 6 H-H cross-correlations and updating the corresponding component in the output visibility array
for(size_t i=0; i<KVCXHH.size(); i++) {
TVector< complex<r_4> > vir = vismtx.Row(KVCXHH[i]);
vector< complex<float> > vcxm = freqbands.getAverage(vir);
TArray< complex<r_4> > vira = vismtx.Row(KVCXHH[i]);
vector< complex<float> > vcxm = freqbands.getAverage(vira);
for(size_t j=0; j<vcxm.size(); j++) {
TArray< complex<r_4> > & arrZ = vamm[j];
arrZ(idxra, (sa_size_t)i+1) += vcxm[j];
......
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