예제 #1
0
int main(void)
{
/*
	// define particulars 
	Healpix_Map<double> map1;
	std::string const filename1("/share/data1/manera/4sree/Y1A1_SPT_frac_o.256_t.32768_EQU_z_V2.fits");
	
	// read the map
	read_Healpix_map_from_fits(filename1,map1);
	
	for(int i=0;i<100;++i)
	{
		std::cout<<i<<"\t"<<map1[i]<<std::endl;
	}
*/	
	Healpix_Map<double> map2;
	std::string const filename2("/share/data1/manera/4sree/Y1A1_SPT_maskfootprint_o.256_t.32768_EQU_all_V2new.fits");
	
	// read the map
	read_Healpix_map_from_fits(filename2,map2);
	
	for(int i=0;i<100;++i)
	{
		std::cout<<i<<"\t"<<map2[i]<<std::endl;
	}
	
	return 0;
}
int main (int argc, char *argv[])
{
  if ((argc < 5) || (argc > 6)) usage (argv[0]);
  std::string quad_list_prefix = argv[1];
  std::string alm_dir = argv[2];
  size_t Nstart, Nend;
  if (! Npoint_Functions::from_string (argv[3], Nstart)) {
    std::cerr << "Could not parse Nstart\n";
    usage (argv[0]);
  }
  if (! Npoint_Functions::from_string (argv[4], Nend)) {
    std::cerr << "Could not parse Nend\n";
    usage (argv[0]);
  }
  bool have_mask = false;
  Healpix_Map<double> mask;
  if (argc == 6) {
    read_Healpix_map_from_fits (argv[5], mask);
    have_mask = true;
  }

  // Figure out how many bins there are by trying to open files.
  std::vector<std::string> quad_list_files
    = Npoint_Functions::get_range_file_list(quad_list_prefix, 0, 400);
  if (quad_list_files.size() == 0) {
    std::cerr << "No quad list files found!\n";
    usage (argv[0]);
  }

  int Lmax;
  std::vector<Healpix_Map<double> > maps (Nend-Nstart);
  // Make maps
  {
    Npoint_Functions::Quadrilateral_List_File<int> qlf;
    qlf.initialize (quad_list_files[0]);
    if (have_mask) {
      if (static_cast<size_t>(mask.Nside()) != qlf.Nside()) {
        std::cerr << "Mask and quadrilateral lists do not have"
                  << " the same Nside: " << mask.Nside() 
                  << " != " << qlf.Nside() << std::endl;
        std::exit(1);
      }
      if (mask.Scheme() != qlf.Scheme()) mask.swap_scheme();
    }
    Lmax = std::min(200UL, 4*qlf.Nside()+1);
    //#pragma omp parallel shared(qlf, maps)
    {
      Alm<xcomplex<double> > alm (Lmax, Lmax);
      //#pragma omp for schedule(static)
      for (size_t k=0; k < maps.size(); ++k) {
        read_Alm_from_fits (dirtree::filename(alm_dir, "alm_T_", ".fits",
                                              k+Nstart),
                            alm, Lmax, Lmax);
        maps[k].SetNside (qlf.Nside(), RING);
        alm2map (alm, maps[k]);
        if (maps[k].Scheme() != qlf.Scheme()) maps[k].swap_scheme();
      }
    }
  }

  std::vector<double> bin_list(quad_list_files.size());
  /* We will generate this by bin for each map so make the bin number the
   * first index. */
  std::vector<std::vector<double> > Corr(quad_list_files.size());

#pragma omp parallel shared(Corr, bin_list, quad_list_files, maps, mask)
  {
    Npoint_Functions::Quadrilateral_List_File<int> qlf;
    
#pragma omp for schedule(dynamic,2)
    for (size_t k=0; k < quad_list_files.size(); ++k) {
      if (! qlf.initialize (quad_list_files[k])) {
        std::cerr << "Error initializing quadrilateral list from "
                  << quad_list_files[k] << std::endl;
        std::exit(1);
      }

      bin_list[k] = qlf.bin_value();
      if (have_mask) {
        Npoint_Functions::calculate_masked_fourpoint_function_list
          (maps, mask, qlf, Corr[k]);
      } else {
        Npoint_Functions::calculate_fourpoint_function_list
          (maps, qlf, Corr[k]);
      }
    }
  }
  
  std::cout << "# LCDM four point function from " << quad_list_prefix
            << std::endl;
  std::cout << "# First line is bin values, rest are the four point function.\n";
  for (size_t k=0; k < bin_list.size(); ++k) {
    std::cout << bin_list[k] << " ";
  }
  std::cout << std::endl;

  for (size_t j=0; j < maps.size(); ++j) {
    for (size_t k=0; k < bin_list.size(); ++k) {
      std::cout << Corr[k][j] << " ";
    }
    std::cout << std::endl;
  }

  return 0;
}
int main (int argc, char *argv[])
{
  if ((argc < 3) || (argc > 4)) usage (argv[0]);
  std::string mapfile = argv[1];
  std::string quad_list_prefix = argv[2];

  Healpix_Map<double> map;
  read_Healpix_map_from_fits (mapfile, map);
  bool have_mask = false;
  Healpix_Map<double> mask;
  if (argc == 4) {
    read_Healpix_map_from_fits (argv[3], mask);
    have_mask = true;
  }

  // Figure out how many bins there are by trying to open files.
  std::vector<std::string> quad_list_files
    = Npoint_Functions::get_range_file_list(quad_list_prefix, 0, 180);

  std::vector<double> bin_list(quad_list_files.size());
  std::vector<double> Corr(quad_list_files.size());

#pragma omp parallel shared(Corr, bin_list, quad_list_files)
  {
    Npoint_Functions::Quadrilateral_List_File<int> qlf;

#pragma omp for schedule(dynamic,2)
    for (size_t k=0; k < quad_list_files.size(); ++k) {

      if (! qlf.initialize (quad_list_files[k])) {
        std::cerr << "Error initializing quadrilateral list from "
                  << quad_list_files[k] << std::endl;
        std::exit(1);
      }
      if (static_cast<size_t>(map.Nside()) != qlf.Nside()) {
        std::cerr << "Map has Nside = " << map.Nside()
                  << " but quad list has Nside = " << qlf.Nside()
                  << "\nGiving up!\n";
        std::exit(1);
      }
      if (map.Scheme() != qlf.Scheme()) map.swap_scheme();
      if (have_mask) {
        if (static_cast<size_t>(mask.Nside()) != qlf.Nside()) {
          std::cerr << "Mask and quadrilateral lists do not have"
                    << " the same Nside: " << mask.Nside() 
                    << " != " << qlf.Nside() << std::endl;
          std::exit(1);
        }
        if (mask.Scheme() != qlf.Scheme()) mask.swap_scheme();
      }

#pragma omp critical
      {
        std::cerr 
#ifdef OMP
          << omp_get_thread_num() << " "
#endif       
          << k << std::endl;
      }

      bin_list[k] = qlf.bin_value();
      if (have_mask) {
        Corr[k] = calculate_masked_fourpoint_function (map, mask, qlf);
      } else {
        Corr[k] = calculate_fourpoint_function (map, qlf);
      }
    }
  }
  
  for (size_t k=0; k < bin_list.size(); ++k) {
    // Same format as spice
    std::cout << bin_list[k]*M_PI/180 << " " 
              << cos(bin_list[k]*M_PI/180) << " "
              << Corr[k] << std::endl;
  }

  return 0;
}
예제 #4
0
int main (int argc, char *argv[]) {
  const double FullSky = 4.0*M_PI*(180.0/M_PI)*(180.0/M_PI); // In degrees.
  bool GetArea=0;
  std::string infile, outfile, areafile;
  int l, m, lmax;
  Healpix_Map<MAP_PRECISION> Map, Test;
  double **winClTable, area;
  std::ofstream outstream;
  printf("\n");

  /*
  // Create quadrilateral window function:
  if (argc!=3) {
    printf("Input is: <Map FITS output file> <Nside>\n");
    printf("Exiting...\n\n");
    return 1;
  }
  outfile.assign(argv[1]);
  m = atoi(argv[2]);
  CreateWindow(outfile, m);
  return 0;
  */


  // Check if number of input parameters is correct:
  if (argc!=3 && argc!=4) {
    printf("Input is: <Map FITS file> <W^2_l .dat file> <Window area file (optional)>\n");
    printf("Exiting...\n\n");
    return 1;
  }
  
  // Get input:
  infile.assign(argv[1]);
  outfile.assign(argv[2]);
  if (argc==4) {
    GetArea=1;
    areafile.assign(argv[3]);
  }

  // Load map:
  Announce("Loading Healpix map from "+infile+"... ");
  read_Healpix_map_from_fits(infile, Map); 
  Announce();
  lmax = (5*Map.Nside())/2; // LMAX hard-coded to 2.5 Nside, limit mentioned by Franz Elsner, 08/2015.


  // If requested, set pixels values to either 0 or 1:
  if (BINARIZE==1) {
    Announce("Setting pixels values to 1 or 0... ");
    l = 12*Map.Nside()*Map.Nside();
#pragma omp parallel for
    for (m=0; m<l; m++) {
      if (Map[m]<1.0) Map[m]=0.0;
      else Map[m]=1.0;
    }
    Announce();
  }
  
  // If requested, compute the effective window area by adding pixel values:
  if (GetArea==1) {
    Announce("Computing window effective area... ");
    l    = 12*Map.Nside()*Map.Nside();
    area = 0.0;
#pragma omp parallel for reduction(+:area)
    for (m=0; m<l; m++) area += Map[m];
    area = area/((double)l)*FullSky;
    outstream.open(areafile.c_str());
    if (!outstream.is_open()) warning("Cannot write to file "+outfile);
    else {
      outstream << "# Window "<<infile<<" effective area (deg^2):\n";
      outstream << area << std::endl; 
    }
    outstream.close();    
    Announce();
  }

  // Allocate and clean memory for alm's:
  Announce("Allocating memory for harmonic coefficients... ");
  Alm<xcomplex <ALM_PRECISION> > alm(lmax,lmax);
#pragma omp parallel for schedule(dynamic) private(m)
  for(l=0; l<=lmax; l++) {
    for (m=0; m<=l; m++) alm(l,m).Set(0,0);
  }
  Announce();

  // Prepare Healpix weights:
  arr<double> weight(2*Map.Nside());
  PrepRingWeights(1, weight, Map.Nside());

  // Transform to alm:
  Announce("Getting harmonic coefficients... ");
  map2alm_iter(Map, alm, NITER, weight);
  Announce();

  // Compute Sum_m|alm|^2
  Announce("Summing squares over m... ");
  winClTable=matrix<double>(0,lmax, 0,1);
#pragma omp parallel for schedule(dynamic) private(m)
  for(l=0; l<=lmax; l++) {
    winClTable[l][0] = (double)l;
    winClTable[l][1] = alm(l,0).norm();
    for(m=1; m<=l; m++) winClTable[l][1] += 2.0*alm(l,m).norm();     
  }
  Announce();

  // Output to ASCII file:
  Announce("Writing Cl window function to "+outfile+"... ");
  outstream.open(outfile.c_str());
  if (!outstream.is_open()) warning("Cannot write to file "+outfile);
  else PrintTable(winClTable, lmax+1, 2, &outstream);
  outstream.close();
  Announce();
  
  // Exit program:
  printf("\n");
  return 0;

  /*
  // Test recovery of input map:
  Announce("Go back... ");
  Test.SetNside(Map.Nside(), RING);
  alm2map(alm, Test);
  Announce();
  Announce("Writing to fits file "+outfile+"... ");
  write_Healpix_map_to_fits("!"+outfile, Test, planckType<MAP_PRECISION>()); // Filename prefixed by ! to overwrite.
  Announce();
  */  
}