Changeset 3430 in Sophya


Ignore:
Timestamp:
Dec 11, 2007, 10:32:45 AM (18 years ago)
Author:
ansari
Message:

Ajout commande errorellipse (fait pour these de S. Bargot) a sopiamodule.cc - Reza 11/12/2007

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/ProgPI/sopiamodule.cc

    r2925 r3430  
    3232}
    3333
     34// --- fonctions pour faire FFT
    3435void SophyaFFT_forw(string& nom, string& nomout, string dopt);
    3536void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8=false);
     
    3738void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec=false);
    3839
     40//--- fonctions pour trace d'ellipse d'erreur
     41int  diag_ellipse(double s1, double s2, double c,
     42                  double &a, double &b, double& tet, double& phi, int prt=0);
     43
     44void ellipse2vec(double a, double b, double tet, Vector& evx, Vector& evy,
     45                 double scale=1., int nbpoints=101);
     46
     47//--- Declaration du CmdExecutor du module
    3948class sopiamoduleExecutor : public CmdExecutor {
    4049public:
     
    4453};
    4554
    46 //  Classe pour trace de grille en projection spherique Mollweide
     55//---  Classe pour trace de grille en projection spherique Mollweide
    4756class MollweideGridDrawer : public PIDrawer {
    4857public:
     
    188197  SetLimits(x0-xlarg/2., x0+xlarg/2., y0-ylarg/2., y0+ylarg/2.);
    189198}
    190 
     199// Cette fonction calcule les parametres de l'ellipse des erreurs
     200// a,b 1/2 grand, petit axe ; tet : Angle du grand axe / Ox
     201// A partir de s1 = Sigma_1^2 , s2 = Sigma_2^2 , c = Covar_1_2 = Sigma_1 x Sigma_2 x Rho
     202
     203//---------------------------------------------------------------------------
     204//--- Fonctions de trace d'ellipses d'erreur
     205//---------------------------------------------------------------------------
     206
     207/* Nouvelle-Fonction */
     208int  diag_ellipse(double s1, double s2, double c,
     209                  double &a, double &b, double& tet, double& phi, int prt)
     210{
     211  int rc = 0;
     212  // On calcule les valeurs propres de la matrice
     213  // | s1  c  |
     214  // | c   s2 |
     215  a = b = 0.;  // Demi axes de l'ellipse
     216  tet = 0.;     // Cos theta de l'angle de l'axe de l'ellipse
     217  phi = 0.;
     218  double det = (s1-s2)*(s1-s2) + 4*c*c;
     219  if (det < 0.) {
     220    if (prt > 0)
     221      cout << "ERREUR : diag_ellipse, ERREUR det = " << det << " <0. s1="
     222           << s1 << " s2=" << s2 << " c=" << c << endl;
     223    return 99;
     224  }
     225  // les deux valeurs propres l1, l2
     226  double l1 = 0.5*((s1+s2)+sqrt(det));
     227  double l2 = 0.5*((s1+s2)-sqrt(det));
     228  if (l1 < 0.) {
     229    if (prt > 1)
     230      cout << "diag_ellipse/Warning l1 < 0. -> a = -sqrt(l1)" << endl;
     231    a = -sqrt(-l1);
     232    rc += 2;
     233  }
     234  else   a = sqrt(l1);
     235  if (l2 < 0.) {
     236    if (prt > 1)
     237      cout << "diag_ellipse/Warning l2 < 0. -> b = -sqrt(l2)" << endl;
     238    b = -sqrt(-l2);
     239    rc += 4;
     240  }
     241  else b = sqrt(l2);
     242 
     243  if (fabs(c) > 1.e-9)  tet = atan2((l1-s1), c);
     244  else {
     245    if (prt > 2)
     246      cout << "diag_ellipse/Warning c (Correlation) = 0. -> Tet=0 " << endl;
     247  }
     248  // Calcul de tan(2 phi)
     249  double t2phi = 0.;
     250  if (fabs(s1-s2) > 1.e-9) {
     251    t2phi = 2.*c/(s1-s2);
     252    phi = atan(t2phi)/2.;
     253  }
     254  else {
     255    if (prt > 3)
     256      cout << "diag_ellipse/Warning fabs(s1-s2)=" << fabs(s1-s2)
     257           << " -> Phi=Pi/4 ... " << endl;
     258    phi = 0.25*M_PI;
     259  }
     260  if (prt > 0)
     261    cout << "diag_ellipse/Info: s1=" << s1 << " s2=" << s2
     262         << " c=" << c << " ---> l1=" << l1 << " l2=" << l2
     263         << "\n a= " << a << " b=" << b << " Theta= " << tet
     264         << "( " << tet*2/M_PI << " xPi/2)  Phi= " << phi
     265         << "( " << phi*2/M_PI << " x Pi/2) " << endl;
     266  return rc;
     267}
     268
     269/* Nouvelle-Fonction */
     270void ellipse2vec(double a, double b, double tet, Vector& evx, Vector& evy,
     271                 double scale, int nbpoints)
     272{
     273  a *= scale;
     274  b *= scale;
     275 
     276  int npt = nbpoints;
     277  double pas = M_PI*2./(npt-1);
     278  evx.SetSize(npt+1);
     279  evy.SetSize(npt+1);
     280  for(int i=0; i<=npt; i++) {
     281    double t = i*pas;
     282    double xr = a*cos(t);
     283    double yr = b*sin(t);
     284    double ar = atan2(yr, xr);
     285    double r = sqrt(xr*xr+yr*yr);
     286    evx(i) = r*cos(ar+tet);
     287    evy(i) = r*sin(ar+tet);
     288  }
     289  return;
     290}
     291
     292//---------------------------------------------------------------------------
     293//--- Classe sopiamoduleExecutor
     294//---------------------------------------------------------------------------
    191295/* --Methode-- */
    192296sopiamoduleExecutor::sopiamoduleExecutor()
     
    251355usage = "Set default value for Molleweide projection of spherical maps (outside maps)";
    252356usage += "\n Usage: setprjmoldefval OutOfMapValue ";
     357mpiac->RegisterCommand(kw, usage, this, hgrp);
     358
     359//--- Trace d'ellipse d'erreur
     360hgrp = "SophyaCmd";
     361kw = "errorellipse";
     362usage = " Error ellipse plotter \n";
     363usage += "Usage: errellipse [-fill] xc yc sx2 sy2 cov [scale=1] [gr_opt] [npt=128] \n";
     364usage = "   Adds an error ellipse, specified by its center (xc,yc) \n";
     365usage += "  and error matrix (covariance) parameters  SigX^2,SigY^2,Covar \n" ;
     366usage += "  A global scaling parameters scale , graphic attributes and \n";
     367usage += "   nomber of points can optionnaly be specified\n";
     368usage += "  if the -fill flag specified, plots a filled ellipse \n" ;
    253369mpiac->RegisterCommand(kw, usage, this, hgrp);
    254370
     
    358474   wrsid = omg.GetImgApp()->DispScDrawer(mollgrid, name, dopt);
    359475 }
     476else if (kw == "errorellipse") {
     477  if ((tokens.size()<5) || ((tokens.size()>0)&&(tokens[0]=="-fill")&&(tokens.size()<6))) {
     478    cout << "Usage: errorellipse [-fill] xc yc sx2 sy2 cov [scale=1 gropt npt=128]" << endl;
     479    return(1);
     480  }
     481  bool fgfill = false;
     482  unsigned int offtok = 0;
     483  if (tokens[0] == "-fill") {
     484    offtok = 1;  fgfill = true;
     485  }
     486  double xc = atof(tokens[0+offtok].c_str());
     487  double yc = atof(tokens[1+offtok].c_str());
     488  double sx = atof(tokens[2+offtok].c_str());
     489  double sy = atof(tokens[3+offtok].c_str());
     490  double cov = atof(tokens[4+offtok].c_str());
     491  double scale = 1.;
     492  if (tokens.size() > (5+offtok)) scale = atof(tokens[5+offtok].c_str());
     493  string gropt;
     494  if (tokens.size() > (6+offtok)) gropt = tokens[6+offtok];
     495  int npt = 128;
     496  if (tokens.size() > (7+offtok)) npt = atoi(tokens[7+offtok].c_str());
     497
     498  double a,b,tet,phi;
     499  diag_ellipse(sx, sy, cov, a, b, tet, phi, 1);
     500  Vector evx, evy;
     501  ellipse2vec(a,b,tet,evx, evy, scale, npt+1);
     502  vector<double> vx, vy;
     503  for(int k=0; k<evx.Size(); k++) {
     504    vx.push_back(evx(k)+xc);
     505    vy.push_back(evy(k)+yc);
     506  }
     507  NamedObjMgr omg;
     508  omg.GetImgApp()->AddPoly(vx, vy, gropt, fgfill, false);
     509}
    360510
    361511return(0);
Note: See TracChangeset for help on using the changeset viewer.