lagsht_spheregeom.cc 5.97 KB
Newer Older
1 2 3 4 5 6 7

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

namespace LagSHT {

8
//----------------- Base Class of Geometry ----------------------
9

10 11 12 13 14 15 16
void BaseGeometry::SetCommonMapFeatures() {
        
  //sharp initialization
  sharpjob_.set_triangular_alm_info(L_-1,M_-1); 
  
  Npix_ = get_npix(sharpjob_.get_geom_info());    
  Nalm_ = get_nalms(sharpjob_.get_alm_info());
17

18 19 20 21 22 23 24 25 26 27
  SetPixelPositions();
    
  cout << "SetThetaPhiMap: Geom, Nring, Nphi, Npix, Nalm: " << geomType_ << ", "
       << Nrings_ << ", " 
       << Nphi_ << ", "
       << Npix_ << ", "
       << Nalm_ 
       << endl;
  
}//SetThetaPhiMap
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
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
59 60


61
//------------------------- ECP/Fejer1 Geom ---------------------
62

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

65 66 67 68 69 70 71 72 73 74 75 76
  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 {
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
  //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_);
108
      
109 110 111 112 113 114
  //do the common features
  SetCommonMapFeatures();
  
  geomDone_=true;
  
}//SetMap
115 116 117 118 119
  
//------------------------- Gauss Geom ---------------------

int GaussGeometry::PixIndexSph(r_8 theta, r_8 phi) const {
  int stride_phi=1;         //this migth be also a memeber data
120 121 122 123 124 125 126 127
  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;
  
128 129 130 131
}//PixIndexSph

void GaussGeometry::PixThetaPhi(int k, r_8& theta, r_8& phi) const {
  //Nb this is the same code as ECPGeometry
132 133 134 135 136 137 138 139 140
  //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_;
  
141
}//PixThetaPhi
142
  
143 144

void GaussGeometry::SetMap(int nrings, int nphi) {
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
  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;
167 168 169 170 171

}//SetMap

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

172
int HealpixGeometry::PixIndexSph(r_8 theta, r_8 phi) const {
173
  
174 175
  if(theta<=0 || theta>=M_PI)  LagSHTError("BaseLagSphTransform::PixIndexSph: Healpix theta out of range");
  return HEALPIX::ang2pix_ring_z_phi(Nrings_,cos(theta),phi);
176
  
177
}//PixIndexSph
178
  
179
void HealpixGeometry::PixThetaPhi(int k, r_8& theta, r_8& phi) const {
180

181 182 183 184 185
  r_8 z;
  HEALPIX::pix2ang_ring_z_phi (Nrings_,k,&z,&phi);
  theta = acos(z);
  
}//PixThetaPhi
186

187 188 189 190 191 192 193 194 195
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;
196
  }
197 198 199 200 201 202 203 204 205 206 207 208 209 210
  
  //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
211 212 213 214



}// Fin de namespace