Commit 467afa37 authored by Réza Ansari's avatar Réza Ansari
Browse files

Ajout de la classe P4AVisiNumEncoder, permettant de convertir les noms de...

Ajout de la classe P4AVisiNumEncoder, permettant de convertir les noms de visibilites (du style 3H-4V) en numero de ligne de matrice et l'inverse, Reza 16/09/2017
parent 2f5efd3b
...@@ -3,18 +3,153 @@ ...@@ -3,18 +3,153 @@
Classes et fonctions utilitaires pour les programmes d'analyse PAON4 Classes et fonctions utilitaires pour les programmes d'analyse PAON4
R. Ansari, C. Magneville Fevrier-Mars 2017 R. Ansari, C. Magneville Fevrier-Mars 2017
MAJ : Automne 2017
---------------------------------------------------------- */ ---------------------------------------------------------- */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <map>
#include <iomanip>
#include "p4autils.h" #include "p4autils.h"
//---------------------------------------------------------------------
//---- declaration des constantes (static) de la classe P4FreqBand --- //---- declaration des constantes (static) de la classe P4FreqBand ---
const int P4FreqBand::nbnufft_ = 4096; // 4096 frequences const int P4FreqBand::nbnufft_ = 4096; // 4096 frequences
const double P4FreqBand::deltanufft_ = 250./4096.; // 250 MHz en 4096 frequences const double P4FreqBand::deltanufft_ = 250./4096.; // 250 MHz en 4096 frequences
const double P4FreqBand::freqstart_ = 1250.; // Bande de 1250-1500 MHz const double P4FreqBand::freqstart_ = 1250.; // Bande de 1250-1500 MHz
//---------------------------------------------------------------------
//---------------------- classe P4AVisNumEncoder ---------------------
//---------------------------------------------------------------------
std::map<std::string, sa_size_t> visname_num_;
std::vector<std::string> visnames_;
bool fg_visnames_done = false;
void P4AVisNumEncoder_toupper(std::string & name)
{
if (name.length()<5) return;
if (name[1]=='h') name[1]='H';
else if (name[1]=='v') name[1]='V';
if (name[4]=='h') name[4]='H';
else if (name[4]=='v') name[4]='V';
return;
}
static void P4AVisNumEncoder_Init()
{
if (fg_visnames_done) return;
const char * chnames[8]={"1H","2H","3H","4H","1V","2V","3V","4V"};
char buff[32];
sa_size_t cnt=0;
for(int i=0; i<8; i++)
for(int j=i; j<8; j++) {
sprintf(buff,"%s-%s",chnames[i],chnames[j]);
string vn=buff;
visname_num_[vn]=cnt;
visnames_.push_back(vn);
cnt++;
}
fg_visnames_done=true;
return;
}
P4AVisiNumEncoder::P4AVisiNumEncoder()
{
P4AVisNumEncoder_Init();
}
ostream& P4AVisiNumEncoder::PrintAll(ostream & os) const
{
os << "----- P4AVisiNumEncoder::PrintAll() - List of "<<visnames_.size()<<" PAON4 Visibility names -----"<<endl;
for(size_t i=0; i<visnames_.size(); i++) {
if ((i>0) && (i%6 == 0)) os << endl;
os << setw(3) << i << ": " << visnames_[i] << " ";
if (visnames_[i] != this->Convert2VisiName(i)) os << "\n BUG visnames_[i] != "<<this->Convert2VisiName(i)<<endl;
}
os << endl;
os << "-----------------------------------------------------------------------------"<<endl;
return os;
}
std::vector<sa_size_t> P4AVisiNumEncoder::Convert2VisiNumber(std::vector<std::string> & visnm)
{
if (!fg_visnames_done) P4AVisNumEncoder_Init();
std::vector<sa_size_t> rv;
for(size_t i=0; i<visnm.size(); i++) {
P4AVisNumEncoder_toupper(visnm[i]);
std::map<std::string, sa_size_t>::const_iterator it = visname_num_.find(visnm[i]);
if (it != visname_num_.end()) rv.push_back(it->second);
}
return rv;
}
std::vector<std::string> P4AVisiNumEncoder::Convert2VisiName(std::vector<sa_size_t> const & visnum)
{
if (!fg_visnames_done) P4AVisNumEncoder_Init();
std::vector<std::string> rv;
for(size_t i=0; i<visnum.size(); i++) {
if ((visnum[i]>=0)&&(visnum[i]<visnames_.size())) rv.push_back(visnames_[visnum[i]]);
}
return rv;
}
sa_size_t P4AVisiNumEncoder::Convert2VisiNumber(std::string & name)
{
if (!fg_visnames_done) P4AVisNumEncoder_Init();
P4AVisNumEncoder_toupper(name);
std::map<std::string, sa_size_t>::const_iterator it = visname_num_.find(name);
if (it != visname_num_.end()) return it->second;
return -1;
}
sa_size_t P4AVisiNumEncoder::Convert2VisiNumber(const char * name)
{
std::string str(name);
sa_size_t vn = P4AVisiNumEncoder::Convert2VisiNumber(str);
return vn;
}
std::string P4AVisiNumEncoder::Convert2VisiName(sa_size_t visnum)
{
if (!fg_visnames_done) P4AVisNumEncoder_Init();
if ((visnum>=0)&&(visnum<visnames_.size())) return visnames_[visnum];
return string("");
}
std::vector<sa_size_t> P4AVisiNumEncoder::getAllAutoCor()
{
const char * acornm[8]={"1H-1H","2H-2H","3H-3H","4H-4H", "1V-1V","2V-2V","3V-3V","4V-4V" };
std::vector<std::string> nms;
for(size_t i=0; i<8; i++) {
nms.push_back(std::string(acornm[i]));
}
return P4AVisiNumEncoder::Convert2VisiNumber(nms);
}
std::vector<sa_size_t> P4AVisiNumEncoder::getAllHCrossCor()
{
const char * hcxnm[6]={"1H-2H","1H-3H","1H-4H","2H-3H", "2H-4H","3H-4H" };
std::vector<std::string> nms;
for(size_t i=0; i<6; i++) {
nms.push_back(std::string(hcxnm[i]));
}
return P4AVisiNumEncoder::Convert2VisiNumber(nms);
}
std::vector<sa_size_t> P4AVisiNumEncoder::getAllVCrossCor()
{
const char * vcxnm[6]={"1V-2V","1V-3V","1V-4V","2V-3V", "2V-4V","3V-4V" };
std::vector<std::string> nms;
for(size_t i=0; i<6; i++) {
nms.push_back(std::string(vcxnm[i]));
}
return P4AVisiNumEncoder::Convert2VisiNumber(nms);
}
//---------------------------------------------------------------------
//------------------------ classe P4AnaParams ------------------------
//---------------------------------------------------------------------
P4AnaParams::P4AnaParams() P4AnaParams::P4AnaParams()
: inpath5_("bao5/"), inpath6_("bao6/"), Imin_(0), Imax_(10), Istep_(1), : inpath5_("bao5/"), inpath6_("bao6/"), Imin_(0), Imax_(10), Istep_(1),
fgreorderfreq_(false), gain_gnu_file_("gain.ppf"), fgreorderfreq_(false), gain_gnu_file_("gain.ppf"),
...@@ -129,3 +264,4 @@ ostream& P4AnaParams::Print(ostream& os) const ...@@ -129,3 +264,4 @@ ostream& P4AnaParams::Print(ostream& os) const
else for(size_t i=0; i<fbands_.size(); i++) os<<"FreqBand["<<i<<"]: "<<fbands_[i]<<endl; else for(size_t i=0; i<fbands_.size(); i++) os<<"FreqBand["<<i<<"]: "<<fbands_[i]<<endl;
return os; return os;
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Classes et fonctions utilitaires pour les programmes d'analyse PAON4 Classes et fonctions utilitaires pour les programmes d'analyse PAON4
R. Ansari, C. Magneville Fevrier-Mars 2017 R. Ansari, C. Magneville Fevrier-Mars 2017
MAJ : Automne 2017
---------------------------------------------------------- */ ---------------------------------------------------------- */
#ifndef P4AUTILS_SEEN #ifndef P4AUTILS_SEEN
...@@ -19,10 +20,13 @@ ...@@ -19,10 +20,13 @@
#include "sopnamsp.h" #include "sopnamsp.h"
#include "pexceptions.h" #include "pexceptions.h"
//---------------------------------------------------------------------------------
//---- Classe definition de bande de frequence, frequence centrale et largeur //---- Classe definition de bande de frequence, frequence centrale et largeur
/*! \brief a simple utility class to convert a frequency band in MHz to frequency PAON-4 channel */
class P4FreqBand { class P4FreqBand {
public: public:
// definition de la bande de frequence, specification frequence centrale f0 et largeur df en MHz // definition de la bande de frequence, specification frequence centrale f0 et largeur df en MHz
//! Constructor with definition of the frequency band, specified as central frequency f0 and bandwidth df in MHz
P4FreqBand(double f0=1420., double df=1.) P4FreqBand(double f0=1420., double df=1.)
: f0_(f0), df_(df) : f0_(f0), df_(df)
{ {
...@@ -33,11 +37,28 @@ public: ...@@ -33,11 +37,28 @@ public:
throw ParmError("P4FreqBand(f0,df) Out of range (0...4095) jfmin,jfmax"); throw ParmError("P4FreqBand(f0,df) Out of range (0...4095) jfmin,jfmax");
} }
} }
//! copy constructor
P4FreqBand(P4FreqBand const& a) P4FreqBand(P4FreqBand const& a)
: f0_(a.f0_), df_(a.df_), jfmin_(a.jfmin_), jfmax_(a.jfmax_) : f0_(a.f0_), df_(a.df_), jfmin_(a.jfmin_), jfmax_(a.jfmax_)
{ } { }
//! copy (equal) operator
P4FreqBand& operator = (P4FreqBand const& a) P4FreqBand& operator = (P4FreqBand const& a)
{ f0_=a.f0_; df_=a.df_; jfmin_=a.jfmin_; jfmax_=a.jfmax_; return *this; } { f0_=a.f0_; df_=a.df_; jfmin_=a.jfmin_; jfmax_=a.jfmax_; return *this; }
//! return the central frequency in MHz
inline double getCentralFreq() const { return f0_; }
//! return the frequency bandwidth in MHz
inline double getBandwidth() const { return df_; }
//! return the first frequency channel number
inline sa_size_t getFirstFreqChannel() const { return jfmin_; }
//! return the last frequency channel number
inline sa_size_t getLastFreqChannel() const { return jfmax_; }
//! return PAON4 frequency resolution in MHz
static inline double getP4FreqResolution() { return deltanufft_; }
//! return PAON4 total number of frequency channels
static inline int getP4NbFreqChannels() { return nbnufft_; }
double f0_, df_; // frequence centrale et largeur en MHz , f0_-df_/2 <= f <= f0_+df_/2 double f0_, df_; // frequence centrale et largeur en MHz , f0_-df_/2 <= f <= f0_+df_/2
sa_size_t jfmin_, jfmax_; // numero de colonne de frequence dans la matrice de visibilite sa_size_t jfmin_, jfmax_; // numero de colonne de frequence dans la matrice de visibilite
...@@ -50,6 +71,53 @@ public: ...@@ -50,6 +71,53 @@ public:
inline ostream& operator << (ostream& os, P4FreqBand const& a) inline ostream& operator << (ostream& os, P4FreqBand const& a)
{ os<<a.f0_<<" +/- "<<a.df_<<" MHz (jf="<<a.jfmin_<<"-"<<a.jfmax_<<")"; return os; } { os<<a.f0_<<" +/- "<<a.df_<<" MHz (jf="<<a.jfmin_<<"-"<<a.jfmax_<<")"; return os; }
//---------------------------------------------------------------------------------
/*! \brief Class to help conversion between visibility names and corresponding row numbers in PAON-4
visibility matrices.
Visibility names are specified as a dash separated pair of feed identifier. A feed identifier is composed of a dish number,
from 1 to 4 and the feed polarisation, H or V. Example of visibility names: 2V-2V , 1H-2H , 3H-4V.
There are 36 visibilities in total. Visibility numbers (visibility matrix row ) runs from 0 <= VisiNum <= 35
\warning: Visibility names with second dish number smaller than the first one, or or V-H type polarisation are invalid.
Valid names: 3H-4H , 3H-4V , 2V-3V
Invalid names: 4H-3H , 4V-3H , 3V-2V
*/
class P4AVisiNumEncoder {
public:
P4AVisiNumEncoder();
/*! \brief return the row numbers in the Visibility matrix corresponding to the visibilities identified by their names
\warning The visibility names might be modified to convert lower case characters to upper case: 1h-3v is converted to 1H-3V
*/
static std::vector<sa_size_t> Convert2VisiNumber(std::vector<std::string> & visnm);
//! return visibility names corresponding to list of visibility numbers given as argument
static std::vector<std::string> Convert2VisiName(std::vector<sa_size_t> const & visnum);
//! return row number in the visibility matrix corresponding to the visibility name \b name , -1 if invalide name
static sa_size_t Convert2VisiNumber(std::string & name);
//! return row number in the visibility matrix corresponding to the visibility name \b name , -1 if invalide name
static sa_size_t Convert2VisiNumber(const char * name);
//! return the Visibility name corresponding to row number \b rnum
static std::string Convert2VisiName(sa_size_t visnum);
//! return a vector with visibility number (VisiMatrix rows) for all auto-correlations (8 auto-corr)
static std::vector<sa_size_t> getAllAutoCor();
//! return a vector with visibility number (VisiMatrix rows) for all H-H type cross correlations ( 6 cx-corr)
static std::vector<sa_size_t> getAllHCrossCor();
//! return a vector with visibility number (VisiMatrix rows) for all V-V type cross correlations ( 6 cx-corr)
static std::vector<sa_size_t> getAllVCrossCor();
//! prints a list of all visibility names and corresponding row numbers
ostream& PrintAll(ostream & os) const;
};
inline ostream& operator << (ostream& os, P4AVisiNumEncoder const& a)
{ return a.PrintAll(os); }
//---------------------------------------------------------------------------------
/*! \brief Class to decode various parameters of PAON4 data analysis programs, in particular
the input visibility data set (data paths and data set selection criteria) */
class P4AnaParams { class P4AnaParams {
public: public:
P4AnaParams(); P4AnaParams();
...@@ -86,4 +154,6 @@ public: ...@@ -86,4 +154,6 @@ public:
inline ostream& operator << (ostream& os, P4AnaParams const& a) inline ostream& operator << (ostream& os, P4AnaParams const& a)
{ return a.Print(os); } { return a.Print(os); }
#endif #endif
...@@ -79,7 +79,9 @@ int main(int narg, const char* arg[]) ...@@ -79,7 +79,9 @@ int main(int narg, const char* arg[])
<<"Imin,max,step="<<Imin<<","<<Imax<<","<<Istep<<"\n" <<"Imin,max,step="<<Imin<<","<<Imax<<","<<Istep<<"\n"
<<"PrtLev="<<prtlev<<" OutFile:"<<outfile<<endl; <<"PrtLev="<<prtlev<<" OutFile:"<<outfile<<endl;
if(fgrdmean) cout<<"Trying to read also the FFT mean coef matrix"<<endl; if(fgrdmean) cout<<"Trying to read also the FFT mean coef matrix"<<endl;
P4AVisiNumEncoder vencod;
cout << vencod;
// --- // ---
HiStatsInitiator _inia; HiStatsInitiator _inia;
int rc = 0; int rc = 0;
......
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