Exemplo n.º 1
0
void cosmobl::set_ObjectRegion_SubBoxes (catalogue::Catalogue &data, catalogue::Catalogue &random, const int nx, const int ny, const int nz)
{
  vector<double> Lim;
  data.MinMax_var(catalogue::Var::_X_, Lim, 0);
  data.MinMax_var(catalogue::Var::_Y_, Lim, 0);
  data.MinMax_var(catalogue::Var::_Z_, Lim, 0);

  double Cell_X = (Lim[1]-Lim[0])/nx;
  double Cell_Y = (Lim[3]-Lim[2])/ny;
  double Cell_Z = (Lim[5]-Lim[4])/nz;

#pragma omp parallel num_threads(omp_get_max_threads())
  {
    
#pragma omp for schedule(static, 2) 
    for (int i=0; i<data.nObjects(); i++) {
      int i1 = min(int((data.xx(i)-Lim[0])/Cell_X), nx-1);
      int j1 = min(int((data.yy(i)-Lim[2])/Cell_Y), ny-1);
      int z1 = min(int((data.zz(i)-Lim[4])/Cell_Z), nz-1);
      int index = z1+nz*(j1+ny*i1);
      data.catalogue_object(i)->set_region(index);
    }

#pragma omp for schedule(static, 2) 
    for (int i=0; i<random.nObjects(); i++) {
      int i1 = min(int((random.xx(i)-Lim[0])/Cell_X), nx-1);
      int j1 = min(int((random.yy(i)-Lim[2])/Cell_Y), ny-1);
      int z1 = min(int((random.zz(i)-Lim[4])/Cell_Z), nz-1);
      int index = z1+nz*(j1+ny*i1);
      random.catalogue_object(i)->set_region(index);
    }
  }
  
}
Exemplo n.º 2
0
void cosmobl::check_regions (catalogue::Catalogue &data, catalogue::Catalogue &random)
{
  vector<long> data_regions = data.get_region_list();
  vector<long> random_regions = random.get_region_list();
  
  // check if data and random catalogues have the same number of regions
  if (data_regions.size() != random_regions.size()) 
    ErrorMsg("Error in check_regions of Subsample.cpp, data and random have different number of regions");
  
  // check if data and random catalogues have the same regions
  int nRegions = data_regions.size();
  for (int i=0; i<nRegions; i++)
    if (data_regions[i] != random_regions[i])
      ErrorMsg("Error in check_regions of Subsample.cpp, data and random have regions");
  
  // check if regions are consecutives and starting from 0
  bool cons = 1;
  for (int i=0; i<nRegions; i++) 
    if (data_regions[i]!=i)
      cons = 0;
  
  // make regions 
  if (!cons) {
    map<long, long> regions;
    for (long i=0; i<nRegions; i++)
      regions[data_regions[i]] = i;
      
    for (int i=0; i<data.nObjects(); i++) {
      long region = data.catalogue_object(i)->region();
      auto search = regions.find(region);
      data.catalogue_object(i)->set_region(search->second);
    }
      
    for (int i=0; i<random.nObjects(); i++) {
      long region = random.catalogue_object(i)->region();
      auto search = regions.find(region);
      random.catalogue_object(i)->set_region(search->second);
    } 
  }

}
Exemplo n.º 3
0
void cosmobl::set_ObjectRegion_mangle (catalogue::Catalogue &data, catalogue::Catalogue &random, const int nSamples, const string polygonfile, const string dir)
{
  string temp_dir = dir+"temp/";
  string mangle_dir = par::DirCosmo+"/CatalogueAnalysis/RandomCatalogue/mangle/";
  string cmd = "mkdir -p "+temp_dir; if(system(cmd.c_str())){}
  
  string out_cat = temp_dir+"data";
  string out_ran = temp_dir+"ran";

  ofstream fout(out_cat.c_str()); checkIO(out_cat, 0); fout.precision(10);
  
  for (int i=0; i<data.nObjects(); i++)
    fout << data.ra(i) << " " << data.dec(i) << endl;
  fout.clear(); fout.close();
   
  fout.open(out_ran.c_str()); checkIO(out_ran, 0);
  for (int i=0; i<random.nObjects(); i++)
    fout << random.ra(i) << " " << random.dec(i) << endl;
  fout.clear(); fout.close();
  
  cmd = mangle_dir+"bin/polyid -ur "+polygonfile+" "+out_cat+" "+out_cat+".id";
  if (system(cmd.c_str())) {}
  cmd = mangle_dir+"bin/polyid -ur "+polygonfile+" "+out_ran+" "+out_ran+".id";
  if (system(cmd.c_str())) {}
   
   
  vector<int> poly_data, poly_random, poly_list;

  string line;
  string in_cat = out_cat+".id";
  string in_ran = out_ran+".id";

  ifstream fin(in_cat.c_str()); checkIO(in_cat, 1); 
  getline(fin, line);
  while (getline(fin, line)) {
    stringstream ss(line); double NUM; int pp=-100;
    ss >> NUM; 
    ss >> NUM; 
    ss >> pp;
    if (pp==-100) ErrorMsg("Error in cosmobl::set_ObjectRegion_mangle!");
    poly_data.push_back(pp);
  }
  fin.clear(); fin.close();

  fin.open(in_ran.c_str()); checkIO(in_ran, 1); 
  getline(fin, line);
  while (getline(fin, line)) {
    stringstream ss(line); double NUM; int pp = -100;
    ss >> NUM; 
    ss >> NUM; 
    ss >> pp;
    if (pp==-100) ErrorMsg("Error in cosmobl::set_ObjectRegion_mangle!");
    poly_random.push_back(pp);
    poly_list.push_back(pp);
  }
  fin.clear(); fin.close();

  vector<int>::iterator it = poly_list.begin();
  sort(poly_list.begin(), poly_list.end());
  it = unique(poly_list.begin(), poly_list.end());
  poly_list.resize(distance(poly_list.begin(), it));

  int nPoly = poly_list.size();

  vector<int> boundaries(nSamples+1, 0);
  boundaries[0] = Min(poly_list); boundaries[nSamples] = Max(poly_list)+100;

  for (int i=1; i<nSamples; i++)
    boundaries[i] = poly_list[i*int(nPoly/(nSamples))];
  
  for (size_t i=1; i<boundaries.size(); i++) {
    for (size_t j=0; j<poly_data.size(); j++) 
      if (poly_data[j]>=boundaries[i-1] && poly_data[j] <boundaries[i])
	data.catalogue_object(j)->set_region(i-1);
    
    for (size_t j=0; j<poly_random.size(); j++) 
      if (poly_random[j]>=boundaries[i-1] && poly_random[j]<boundaries[i]) 
	random.catalogue_object(j)->set_region(i-1);
  }
  
  string RM = "rm -rf "+dir+"temp/";
  if (system(RM.c_str())) {}
}
Exemplo n.º 4
0
void cosmobl::set_ObjectRegion_RaDec (catalogue::Catalogue &data, catalogue::Catalogue &random, const double Cell_size)
{
  vector<double> Lim;
  
  double Cell_sz = radians(Cell_size);

  vector<double> data_x = data.var(catalogue::Var::_RA_);
  vector<double> data_y = data.var(catalogue::Var::_Dec_);

  vector<double> random_x = random.var(catalogue::Var::_RA_);
  vector<double> random_y = random.var(catalogue::Var::_Dec_);

  for (int i=0; i<data.nObjects(); i++)
    data_x[i] *= cos(data_y[i]);

  for (int i=0; i<random.nObjects(); i++)
    random_x[i] *= cos(random_y[i]);

  Lim.push_back(Min(data_x));
  Lim.push_back(Max(data_x));

  Lim.push_back(Min(data_y));
  Lim.push_back(Max(data_y));

  const int nDec = (Lim[3]-Lim[2])/Cell_sz;

  vector<double> cell_size_x(nDec);
  vector<int> n_cells_x(nDec);
  vector<vector<int>> cells;
  int n = 0;

  for (int i=0; i<nDec; i++) {
    
    double cd = Lim[2]+(i+0.5)*Cell_sz;
    n_cells_x[i] = ceil((Lim[1]-Lim[0])*cos(cd)/Cell_sz);
    cell_size_x[i] = (Lim[1]-Lim[0])/n_cells_x[i];

    vector<int> vv(n_cells_x[i]);
    for (int j=0; j<n_cells_x[i]; j++) {
      vv[j] = n;
      n ++;
    }
    
    cells.push_back(vv);
  }

  
#pragma omp parallel num_threads(omp_get_max_threads())
  {
    
#pragma omp for schedule(static, 2) 
    for (int i=0; i<data.nObjects(); i++) {
      int j1 = min(int((data_y[i]-Lim[2])/Cell_sz), nDec-1);
      int i1 = min(int((data_x[i]-Lim[0])/cell_size_x[j1]), n_cells_x[j1]-1);
      data.catalogue_object(i)->set_region(cells[j1][i1]);
    }

#pragma omp for schedule(static, 2) 
    for (int i=0; i<random.nObjects(); i++) {
      int j1 = min(int((random_y[i]-Lim[2])/Cell_sz), nDec-1);
      int i1 = min(int((random_x[i]-Lim[0])/cell_size_x[j1]), n_cells_x[j1]-1);
      random.catalogue_object(i)->set_region(cells[j1][i1]);
    }
  }

  cosmobl::check_regions(data, random);
}
void cosmobl::reconstruction_fourier_space (const catalogue::Catalogue data, const catalogue::Catalogue random, const cosmology::Cosmology cosmology, const double redshift, const double bias, const double cell_size, const double smoothing_radius, const int interpolation_type)
{
  double ff = cosmology.linear_growth_rate(redshift);
  double beta = ff/bias;
  
  //double rsd_term = 3*ff/(7+3*ff);
  double rsd_term = (ff-beta)/(1+beta);

  data::ScalarField3D density_field = data.density_field(cell_size, interpolation_type, smoothing_radius);
  density_field.FourierTransformField();

  data::VectorField3D displacement_field(density_field.nx(), density_field.ny(), density_field.nz(), density_field.MinX(), density_field.MaxX(), density_field.MinY(), density_field.MaxY(), density_field.MinZ(), density_field.MaxZ()); 

  data::VectorField3D displacement_field_RSD(density_field.nx(), density_field.ny(), density_field.nz(), density_field.MinX(), density_field.MaxX(), density_field.MinY(), density_field.MaxY(), density_field.MinZ(), density_field.MaxZ()); 

  
  // convert the grid to the displacement field (in Fourier space)

  double xfact = 2.*par::pi/(density_field.deltaX()*density_field.nx());
  double yfact = 2.*par::pi/(density_field.deltaY()*density_field.ny());
  double zfact = 2.*par::pi/(density_field.deltaZ()*density_field.nz());

  for (int i=0; i<density_field.nx(); i++) {
    double kx = (i<=density_field.nx()/2) ? xfact*i : -(density_field.nx()-i)*xfact;
    for (int j=0; j<density_field.ny(); j++) {
      double ky =(j<=density_field.ny()/2) ? yfact*j : -(density_field.ny()-j)*yfact;
      for (int k=0; k<density_field.nzFourier(); k++) {
	double kz = zfact*k;
	double kk = pow(kx*kx+ky*ky+kz*kz, 0.5);

	vector<double> gridK = {density_field.ScalarField_FourierSpace_real (i, j, k), density_field.ScalarField_FourierSpace_complex (i, j, k) };

	if (kk!=0){
	  displacement_field.set_VectorField_FourierSpace_real({kx*gridK[1]/(kk*kk)/bias, ky*gridK[1]/(kk*kk)/bias, kz*gridK[1]/(kk*kk)/bias} ,i ,j ,k);

	  displacement_field.set_VectorField_FourierSpace_complex({-kx*gridK[0]/(kk*kk)/bias, -ky*gridK[0]/(kk*kk)/bias, -kz*gridK[0]/(kk*kk)/bias} ,i , j, k);
	}

      }
    }
  }
  
  displacement_field.FourierAntiTransformField();

  
  // apply the RSD correction (in Fourier space)
  
  for (int i=0; i<density_field.nx(); i++)
    for (int j=0; j<density_field.ny(); j++)
      for (int k=0; k<density_field.nz(); k++) {

	double rx = i*density_field.deltaX()+density_field.MinX(), ry = j*density_field.deltaY()+density_field.MinY(), rz = k*density_field.deltaZ()+density_field.MinZ();
	double rr = (sqrt(rx*rx+ry*ry+rz*rz)==0) ? 1 : sqrt(rx*rx+ry*ry+rz*rz);

	vector<double> displ = displacement_field.VectorField(i, j, k);
	double scalar_product = (rr==0) ? 0. : (displ[0]*rx+displ[1]*ry+displ[2]*rz)/rr;

	double displ_x_rsd = displ[0]+rsd_term*scalar_product*rx/rr; 
	double displ_y_rsd = displ[1]+rsd_term*scalar_product*ry/rr; 
	double displ_z_rsd = displ[2]+rsd_term*scalar_product*rz/rr; 

	displacement_field_RSD.set_VectorField({displ_x_rsd, displ_y_rsd, displ_z_rsd}, i, j, k);
      }

  
  // set the displacement

  for (size_t i=0; i<data.nObjects(); i++) {
    int i1 = min(int((data.xx(i)-density_field.MinX())/density_field.deltaX()), density_field.nx()-1);
    int j1 = min(int((data.yy(i)-density_field.MinY())/density_field.deltaY()), density_field.ny()-1);
    int k1 = min(int((data.zz(i)-density_field.MinZ())/density_field.deltaZ()), density_field.nz()-1);

    vector<double> displacement = displacement_field_RSD.VectorField(i1, j1, k1);

    data.catalogue_object(i)->set_x_displacement(displacement[0]);
    data.catalogue_object(i)->set_y_displacement(displacement[1]);
    data.catalogue_object(i)->set_z_displacement(displacement[2]);
  }

  for (size_t i=0; i<random.nObjects(); i++) {
    int i1 = min(int((random.xx(i)-density_field.MinX())/density_field.deltaX()), density_field.nx()-1);
    int j1 = min(int((random.yy(i)-density_field.MinY())/density_field.deltaY()), density_field.ny()-1);
    int k1 = min(int((random.zz(i)-density_field.MinZ())/density_field.deltaZ()), density_field.nz()-1);

    vector<double> displacement = displacement_field_RSD.VectorField(i1, j1, k1);

    random.catalogue_object(i)->set_x_displacement(displacement[0]);
    random.catalogue_object(i)->set_y_displacement(displacement[1]);
    random.catalogue_object(i)->set_z_displacement(displacement[2]);
  }
}