lagsht_spheregeom.cc 6.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226

#include "lagsht_spheregeom.h" 
#include "lagsht_exceptions.h"
#include "lagsht_healpixhelper.h"

namespace LagSHT {


//------------------------- ECP/Fejer1 Geom ---------------------

  int ECPGeometry::PixIndexSph(r_8 theta, r_8 phi) const {

    int stride_phi=1;         //this migth be also a memeber data
    int stride_theta=Nphi_;  //"
    r_8 phi0 = 0.; //for the time beeing

    int itheta=int(Nrings_*theta/M_PI);
    int iphi = int(Nphi_+ Nphi_*(phi-phi0)/(2*M_PI)+0.5)%Nphi_;

    return stride_phi*iphi+stride_theta*itheta;

  }//PixIndexSph

  void ECPGeometry::PixThetaPhi(int k, r_8& theta, r_8& phi) const {

    //JEC if is not the case change the code       int stride_phi=1;         //this migth be also a memeber data
    //JEC if is not the case change the code      int stride_theta=Nphi_;  //"
    r_8 phi0 = 0.;

    int iphi=k%Nphi_;
    int itheta=k/Nphi_;
    phi=phi0 + iphi*2*M_PI/Nphi_;
    theta=(itheta+0.5)*M_PI/Nrings_;
    
  }//PixThetaPhi

  void ECPGeometry::SetMap(int nrings, int nphi) {

      geomType_ = "ECP";

      if(geomDone_){
	cout << "-------------------------------------------------" <<endl;
	cout << "---------------  New ECP Geometry  ------------- " <<endl;
	cout << "-------------------------------------------------" <<endl;
	geomDone_ = false;
      }
      
      //dans sharp_testsuite.c Fejer's 1st rule
      //nrings = 2Lmax+1
      //npixper ring = 2Mmax+1
      
      Nrings_ = (nrings == -1) ? 2*L_-1 : nrings;
      Nphi_   = (nphi == -1) ?  2*M_-1 : nphi;
      
      sharpjob_.set_ECP_geometry(Nrings_,Nphi_);
      
      
      //do the common features
      SetCommonMapFeatures();

      geomDone_=true;

  }//SetMap
  
//------------------------- Gauss Geom ---------------------

int GaussGeometry::PixIndexSph(r_8 theta, r_8 phi) const {
  int stride_phi=1;         //this migth be also a memeber data
    int stride_theta=Nphi_;  //"
    r_8 phi0 = 0.; //for the time beeing

    int itheta = std::min_element(thetaPix_.begin(),thetaPix_.end(), closer_to(theta)) - thetaPix_.begin();
    int iphi = int(Nphi_+ Nphi_*(phi-phi0)/(2*M_PI)+0.5)%Nphi_;
    
    return stride_phi*iphi+stride_theta*itheta;

}//PixIndexSph

void GaussGeometry::PixThetaPhi(int k, r_8& theta, r_8& phi) const {
  //Nb this is the same code as ECPGeometry
//JEC if is not the case change the code       int stride_phi=1;         //this migth be also a memeber data
//JEC if is not the case change the code      int stride_theta=Nphi_;  //"
      r_8 phi0 = 0.;

      int iphi=k%Nphi_;
      int itheta=k/Nphi_;
      phi=phi0 + iphi*2*M_PI/Nphi_;
      theta=(itheta+0.5)*M_PI/Nrings_;

}//PixThetaPhi


void GaussGeometry::SetMap(int nrings, int nphi) {
      geomType_ = "Gauss";

      if(geomDone_){
	cout << "-------------------------------------------------" <<endl;
	cout << "---------------  New Gauss Geometry  ------------- " <<endl;
	cout << "-------------------------------------------------" <<endl;
	geomDone_ = false;
      }

      //dans sharp_testsuite.c Gauss
      //nrings = Lmax+1
      //npixper ring = 2Mmax+1

      Nrings_ = (nrings == -1) ? L_ : nrings;
      Nphi_   = (nphi == -1) ?  2*M_-1 : nphi;

      sharpjob_.set_Gauss_geometry(Nrings_,Nphi_);

      //do the common features
      SetCommonMapFeatures();

      geomDone_=true;


}//SetMap



//------------------------- HEALPIX Geom ---------------------

  int HealpixGeometry::PixIndexSph(r_8 theta, r_8 phi) const {

    if(theta<=0 || theta>=M_PI)  LagSHTError("BaseLagSphTransform::PixIndexSph: Healpix theta out of range");
    return HEALPIX::ang2pix_ring_z_phi(Nrings_,cos(theta),phi);

  }//PixIndexSph

  void HealpixGeometry::PixThetaPhi(int k, r_8& theta, r_8& phi) const {

    r_8 z;
    HEALPIX::pix2ang_ring_z_phi (Nrings_,k,&z,&phi);
    theta = acos(z);

  }//PixThetaPhi

  void HealpixGeometry::SetMap(int nsides, int DUMMY) { //second argument not used

      geomType_ = "Healpix";

      if(geomDone_){
	cout << "-------------------------------------------------" <<endl;
	cout << "---------------  New Healpix Geometry  --------- " <<endl;
	cout << "-------------------------------------------------" <<endl;
	geomDone_ = false;
      }
      
      //dans sharp_testsuite.c Healpix
      //nside = Lmax/2;
      Nrings_ = (nsides == -1 ) ? (L_ -1)/2: nsides; // this is the nside argument in fact
      Nphi_ = -1; // is not used
      
      sharpjob_.set_Healpix_geometry(Nrings_);

      //do the common features
      SetCommonMapFeatures();

      geomDone_=true;

  }//SetMap

  //---------------------------------------

  void BaseGeometry::SetCommonMapFeatures() {
  
      
  
  sharpjob_.set_triangular_alm_info(L_-1,M_-1); 
  
  Npix_ = get_npix(sharpjob_.get_geom_info());    
  Nalm_ = get_nalms(sharpjob_.get_alm_info());

  //fill the ANN-kdTree to prepare the filling of the 2D spheres
  //  geom_t vecPix;
  SetPixelPositions();

    
  cout << "SetThetaPhiMap: Geom, Nring, Nphi, Npix, Nalm: " << geomType_ << ", "
       << Nrings_ << ", " 
       << Nphi_ << ", "
       << Npix_ << ", "
       << Nalm_ 
       << endl;

}//SetThetaPhiMap



  //----------------------------------------------------------

void BaseGeometry::SetPixelPositions() {
  const sharp_geom_info *ginfo; 
  ginfo = sharpjob_.get_geom_info();
  for (int i=0; i<ginfo->npairs; ++i) {
      double theta1 = ginfo->pair[i].r1.theta;
      thetaPix_.push_back(theta1);
      // and so on for nph, phi0
      int nph1 = ginfo->pair[i].r1.nph;
      double phi0 = ginfo->pair[i].r1.phi0;
      for(int j=0; j<nph1; j++) {
	double phi1 = phi0 + j*(2.0*M_PI/nph1);
	//	cout << "vecPix_s ( "<< theta1 << ", " << phi1 << ")" << endl;
	vecPix_.push_back(make_pair(theta1,phi1));
      }
      if (ginfo->pair[i].r2.nph>0) {// the second ring in this pair exists
	double theta2 = ginfo->pair[i].r2.theta;
	thetaPix_.push_back(theta2);
	int nph2 = ginfo->pair[i].r2.nph;
	double phi0 = ginfo->pair[i].r2.phi0;
	for(int j=0; j<nph2; j++) {
	  double phi2 = phi0 + j*(2.0*M_PI/nph2);
	  //	  cout << "vecPix_s ( "<< theta2 << ", " << phi2 << ")" << endl;
	  vecPix_.push_back(make_pair(theta2,phi2));
	}
      }
  }

  sort(vecPix_.begin(),vecPix_.end()); //See if it is necessary...
  sort(thetaPix_.begin(), thetaPix_.end()); //mandatory for PixIndexSph

}//SetPixelPositions


}// Fin de namespace