Need help getting started w/ HEALPix 2.1 c++

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Michael Burgess
Posts: 1
Joined: June 26 2008
Affiliation: University of Alabama in Huntsville

Need help getting started w/ HEALPix 2.1 c++

Post by Michael Burgess » June 26 2008

I am a beginning grad student working with "diffuse" x-ray data that I would like to map with HEALPix. I have been trying to find some simple example code so that I can get familiar with it's usage.

For example, I'd like to take a line of constant theta in a cartesian grid and then convert that into a HEALPix map. Does anyone know of or have some example code in c++ so that I could look at to get up to speed with this program?

I'm not really concerned with doing any kind of analysis at this moment... just have to figure out how to do the simple stuff first! Thanks

Florian Borchers
Posts: 2
Joined: June 08 2011
Affiliation: National Taiwan University

Need help getting started w/ HEALPix 2.1 c++

Post by Florian Borchers » June 09 2011

I had the same problem finding examples for the Cpp version of Healpix. Here I post one that I compile with
-lhealpix_cxx -lcxxsupport -lpsht -lc_utils -lfftpack
and all the links to the Healpix directories.

Here is the code:

#include <iostream>

#include "healpix_map.h"
#include "healpix_data_io.h"
#include "healpix_map_fitsio.h"

#include <alm.h>
#include <alm_fitsio.h>
#include <alm_healpix_tools.h>

// tools for Cls
#include <powspec.h>
#include <powspec_fitsio.h>
#include <alm_powspec_tools.h>


using namespace std ;


// MAIN ------------------------
int main(int argc,char **argv)
{

// read a HEALPix map from a file -----------------------------
Healpix_Map<double> map ;
read_Healpix_map_from_fits("test.fits", map,1,2);


// prepare the alms -----------------------------
int nside = map.Nside() ;
int nlmax = 2*nside ;
int nmmax = nlmax ;

arr<double> weight ;
weight.alloc(2*nside) ;
weight.fill(1) ;

Alm<xcomplex<double> > alm( nlmax, nmmax) ;


// test the Fourier Transform -----------------------------

// do the FFT
if( map.Scheme()==NEST ) map.swap_scheme() ;
map2alm_iter( map, alm, 1, weight) ;



// test some of the power spectra methods ---------------

//create the Cl array:
PowSpec mySpec(1,nlmax);

//cast the read alm into their power spectrum
extract_powspec(alm,mySpec);

// create the fitshandle to the power spectra file
fitshandle myCl;
myCl.create("myCl.fits");

// write the power spectrum to the file:
write_powspec_to_fits(myCl, mySpec,1);
// remember the last number carries the info on how many spectra: 1 OR 4 OR 6

cout << "done with test program! " << endl;
return 0;
}

Post Reply