Commit 322f8157 authored by Réza Ansari's avatar Réza Ansari
Browse files

Classe P4gnuGain completee (constructeur, applyGain(), ...), Reza 18/9/2017

parent e6dcf35c
......@@ -53,6 +53,39 @@ void P4gnuGain::computeSaveGain(SOPHYA::TMatrix< complex<r_4> > & vismtx_mean, s
return;
}
P4gnuGain::P4gnuGain(string const & gainfilename, double gthr)
: gainfilename_(gainfilename), vmtxgains_(P4AVisiNumEncoder::getTotalNbVisibilities(), P4FreqBand::getP4NbFreqChannels())
{
P4AVisiNumEncoder venc;
double GAINTHR = gthr; // limite inferieur du gain avant faire 1/G
cout<<"P4gnuGain::P4gnuGain() reading input gain file: "<<gainfilename<<" with GAINTHR= "<<GAINTHR<<endl;
PInPersist pin(gainfilename_);
pin>>PPFNameTag("gains")>>gains_;
pin>>PPFNameTag("gn")>>gnorm_;
if ((gains_.NRows() != venc.getTotalNbFeeds())||(gains_.NCols() != P4FreqBand::getP4NbFreqChannels()))
throw SzMismatchError("P4gnuGain::P4gnuGain()/ERROR bad size for gains matrix");
if (gnorm_.Size() != venc.getTotalNbFeeds())
throw SzMismatchError("P4gnuGain::P4gnuGain()/ERROR bad size for gains normalisation vector ");
cout<<" ... Gain normalisation:"<<endl;
for (int p=0; p<8; p++) cout<<"gn["<<p<<"]="<<gnorm_(p)<<" ";
cout<<endl;
// on transforme gains en facteur multiplicatif
for(sa_size_t r=0;r<gains_.NRows();r++) {
for(sa_size_t c=0; c<gains_.NCols(); c++) gains_(r,c)=((gains_(r,c)>GAINTHR)?1./gains_(r,c):0.);
}
for(sa_size_t r=0; r<vmtxgains_.NRows(); r++) {
std::pair<sa_size_t , sa_size_t> pij = venc.getFeedPair(r);
sa_size_t i=pij.first;
sa_size_t j=pij.second;
for(sa_size_t c=0; c<vmtxgains_.NCols(); c++) {
if (i == j ) vmtxgains_(r,c) = complex< r_4 >( (r_4)gains_(i,c), 0.);
else vmtxgains_(r,c) = complex< r_4 >( sqrt(gains_(i,c)*gains_(j,c)) , 0.);
}
}
return;
}
// ----- adaptation de la fonction de calcul de gain, ecrit par cmv pour l'analyse Amas (Aout 2013)
/* --- fonction de calcul de gain avec fit de spline qui flag tout seul
les mauvais points du spectre - calcule la moyenne par fenetre (en
......
......@@ -20,14 +20,37 @@ public:
\b vismtx_mean is a visibility matrix averaged over few minutes, from which the gains g(nu)
is determined. The 8 g_i(nu) gains are saved as a matrix, as well as overall nomalisation
to the PPF file \b gainfile.
*/
to the PPF file \b gainfile. */
static void computeSaveGain(SOPHYA::TMatrix< complex<r_4> > & vismtx_mean, std::string const & gainfile);
/*! \brief constructor from a gain PPF file.
\b gainfilename is the name of the PPF file containg the gain matrix g(ia, nu)
where 0 <= ia < 8 are the 8 feeds, 1H, 2H ... 4H, 1V ... 4V .
The gain_ matrix for the 8 feeds correspond to a multiplicative gain, the inverse of the values in file
1/gain_in_file. gain_(ia,nu) is put to zero for gain_in_file values < \b gthr.
*/
P4gnuGain(string const & gainfilename, double gthr=0.005);
//! apply the gain correction factor to the full visibility matrix - the input visibility matrix is changed
inline void applyGain(SOPHYA::TMatrix< complex<r_4> > & vismtx)
{ vismtx.Mul(vmtxgains_); }
//! return the multiplicative gain_ matrix, g(ia, nu) with 0 <= ia < 8 , for the 8 auto-correlation signals
inline SOPHYA::Matrix const & getGainMatrix() const { return gains_; }
//! return the multiplicative complex gain matrix, applicable to the full visibility matrix.
inline SOPHYA::TMatrix< complex<r_4> > const & getVisiGainMatrix() const { return vmtxgains_; }
protected:
// ----- adaptation de la fonction de calcul de gain, ecrit par cmv pour l'analyse Amas (Aout 2013)
static SOPHYA::Matrix computeGain2(SOPHYA::Matrix & acs, int SZW=96, float frackeep=0.75);
// ----- fonction pour normaliser les gains
static SOPHYA::Vector normalizeGain2(SOPHYA::Matrix & gain);
std::string gainfilename_;
SOPHYA::TMatrix<r_8> gains_;
SOPHYA::TVector<r_8> gnorm_;
SOPHYA::TMatrix< complex<r_4> > vmtxgains_;
};
#endif
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