Healpix: How to convert from data to map?

  • Thread starter bluecrow
  • Start date
Hi.
At first,I am sorry that my English is so bad.

I've just installed Healpix on cxx(c++), and i'm starting to leraning.

then I made txt file containing binary data(RING pixel and corresponding to data like temperture),and I want to make Healpix RING map of the data.

but I don't know which function must be used.

please help me.
 
Last edited:

kimbyd

Science Advisor
Gold Member
2018 Award
964
501
Hi.
At first,I am sorry that my English is so bad.

I've just installed Healpix on cxx(c++), and i'm starting to leraning.

then I made txt file containing binary data(RING pixel and corresponding to data like temperture),and I want to make Healpix RING map of the data.

but I don't know which function must be used.

please help me.
I'm a little unsure what you want to do. Do you want to:

a) Read in the text file to have it as Healpix data so you can do some processing?
b) Convert the binary data to a visual map you can view?

Edit: Also, where are you getting this file from? Most Healpix files are in FITS format, not txt.
 
10,337
3,866

kimbyd

Science Advisor
Gold Member
2018 Award
964
501
Wow, this is an interesting piece of software. I've never heard of it before.
It's honestly really great for spherical data sets. It's ubiquitous for CMB analysis, which is I think what it's designed for. It's a method of efficiently storing spherical data where each pixel corresponds to an identical surface area on the sphere at any resolution, with minimal distortion.
 
I'm a little unsure what you want to do. Do you want to:

a) Read in the text file to have it as Healpix data so you can do some processing?
b) Convert the binary data to a visual map you can view?

Edit: Also, where are you getting this file from? Most Healpix files are in FITS format, not txt.
Thank you for answering my question.
I want to do b, convert the binary data to a visual map I can view.


Now I am calculating the exposure of satellite observation equipment,this file's data have width of several tens of degrees.and I want to depict on celestial sphere map.
 

kimbyd

Science Advisor
Gold Member
2018 Award
964
501
Thank you for answering my question.
I want to do b, convert the binary data to a visual map I can view.


Now I am calculating the exposure of satellite observation equipment,this file's data have width of several tens of degrees.and I want to depict on celestial sphere map.
Okay, great! What you're looking for is in the facilities section of the documentation:
https://healpix.sourceforge.io/doc/html/Healpix_cxx/facilities.html

Basically the way to do it is use Healpix C++ to write to fits (I recommend using the form of write_Healpix_map_to_fits() which takes a string, Healpix_Map<T>, and data type, documented here).

Once you've written it to a file, you can use the "map2tga" utility to create the map from the command line. Example command:

map2tga my_healpix_file.fits my_map.tga

There's lots of options that you can use to customize the resulting output.
 
Wow, this is an interesting piece of software. I've never heard of it before.

Anyway I found this website with api references:

https://healpix.sourceforge.io/documentation.php

https://healpix.sourceforge.io/html/Healpix_cxx/facilities.html

and this HealPix Primer:

https://healpix.jpl.nasa.gov/pdf/intro.pdf
Thank you for answering my question.

I already found their site,but I am beginner of cxx. So I want more detailed solution on cxx.

Reason why I use cxx is that previous research's program data is wrote by cxx. I want to connect two program.
 

kimbyd

Science Advisor
Gold Member
2018 Award
964
501
Thank you for answering my question.

I already found their site,but I am beginner of cxx. So I want more detailed solution on cxx.

Reason why I use cxx is that previous research's program data is wrote by cxx. I want to connect two program.
That's a little bit more challenging, because Healpix C++ really wasn't designed to do that. It was more designed for doing calculations on Healpix maps. Visualization was left to other stuff.

It looks like your best bet is to call the map2tga module from within your code. I recommend doing what is done in the map2tga main function here:

https://sourceforge.net/p/healpix/code/HEAD/tree/trunk/src/cxx/Healpix_cxx/map2tga.cc

Example code:

Code:
#include "levels_facilities.h"
#include "error_handling.h"
  // Lots of code



  // Write Healpix map to .fits file
  PLANCK_DIAGNOSIS_BEGIN
  map2tga_module (argc, argv);
  PLANCK_DIAGNOSIS_END
  // Read image from TGA file using a library
  // Clean up temporary .fits and .tga files
  // Send image to destination


  // Other code
The problem with this is that if you call map2tga from within your C++ code like this, you still have to first output the .fits file to the filesystem, then call it from this module. It also writes the image to a .tga file, which you'd have to load a library to read.

Overall, it's going to be messy. Your only other option is to modify the map2tga code itself to create a new function which doesn't require file reads or writes. That won't be terribly easy to do. The place to start would be the module code, but I suspect it might be difficult for you if you're a beginner at C++:
https://sourceforge.net/p/healpix/code/HEAD/tree/trunk/src/cxx/Healpix_cxx/map2tga_module.cc
 
Okay, great! What you're looking for is in the facilities section of the documentation:
https://healpix.sourceforge.io/doc/html/Healpix_cxx/facilities.html

Basically the way to do it is use Healpix C++ to write to fits (I recommend using the form of write_Healpix_map_to_fits() which takes a string, Healpix_Map<T>, and data type, documented here).

Once you've written it to a file, you can use the "map2tga" utility to create the map from the command line. Example command:

map2tga my_healpix_file.fits my_map.tga

There's lots of options that you can use to customize the resulting output.

Sorry for late reply.
Beased on your advice,I do something.But yet I don't understand way from data to map.
Please look my code.


lot code...
C:
       double NSIDE=pow(2,6);
       double NPIX=12*NSIDE*NSIDE;
       Healpix_Base map(6,RING);

       for(int i=1;i<=NPIX;i++){
       pointing pnt=map.pix2ang(i);
//
       clat = pnt.theta;
       clon = pnt.phi;
       //cout << clon << endl;
       cu = cos(clat)*cos(clon);
       cv = cos(clat)*sin(clon);
       cw = sin(clat);
       sep = acos(cu*u+cv*v+cw*w)*raddeg;
       ss = 0.;
 
       if(sep>=0.&& sep<60.){
           SSOMEGA(a,b,c,sep,ene,&somega);//icase
           // ss = somega/(1-cos(sep*degrad))/(2*M_PI);
           ss = somega;
             /* cout << " Somega j="<< j <<" k="<< k <<" "<< ss <<" "<<sep<< endl; */
             cel= cel+ss*timedif;
           /*     cout << clat <<" "<<clon<<" " <<sep<<" "<<somega<<" "<<ss*timedif<<endl; */
       }
   }
}
 
  cout << "step1end"<<endl;

  ofstream ccc("exp_16010100_1TeV.dat");
  double NPIX=12*pow(2,6)*pow(2,6);
  for(i=1; i<=NPIX;i++){
 
 
      ccc << i <<" "
       << cel << endl;   //cel is defined cel[50000]
 

      celsum=celsum+cel;
      if(cel>celmax){
 
   celmax=cel;
   }
  }

Healpix_Map<double> G(cel,RING);
write_Healpix_map_to_fits("result.fits",G,PDT);


    return 0;
}
error:
[@localhost RADEC→exp]$ g++ cexp.cc -g -lhealpix_cxx -lcxxsupport -lsharp -lfftpack -lc_utils -lcfitsio
cexp.cc: ‘int main()’ 内:
cexp.cc:251:46: エラー: expected primary-expression before ‘)’ token
write_Healpix_map_to_fits("result.fits",G,PDT);
^
[@localhost RADEC→exp]$
I want to make MAP with cel(i) and want to make map2fits or map2tga ,but not going well.
if you want to know more information,please tell me.
<mentor: add code code tags>
 
Last edited by a moderator:

kimbyd

Science Advisor
Gold Member
2018 Award
964
501
Sorry for late reply.
Beased on your advice,I do something.But yet I don't understand way from data to map.
Please look my code.


lot code...

double NSIDE=pow(2,6);
double NPIX=12*NSIDE*NSIDE;
Healpix_Base map(6,RING);

for(int i=1;i<=NPIX;i++){
pointing pnt=map.pix2ang(i);
//
clat = pnt.theta;
clon = pnt.phi;
//cout << clon << endl;
cu = cos(clat)*cos(clon);
cv = cos(clat)*sin(clon);
cw = sin(clat);
sep = acos(cu*u+cv*v+cw*w)*raddeg;
ss = 0.;

if(sep>=0.&& sep<60.){
SSOMEGA(a,b,c,sep,ene,&somega);//icase
// ss = somega/(1-cos(sep*degrad))/(2*M_PI);
ss = somega;
/* cout << " Somega j="<< j <<" k="<< k <<" "<< ss <<" "<<sep<< endl; */
cel= cel+ss*timedif;
/* cout << clat <<" "<<clon<<" " <<sep<<" "<<somega<<" "<<ss*timedif<<endl; */
}
}
}

cout << "step1end"<<endl;

ofstream ccc("exp_16010100_1TeV.dat");
double NPIX=12*pow(2,6)*pow(2,6);
for(i=1; i<=NPIX;i++){


ccc << i <<" "
<< cel << endl; //cel is defined cel[50000]


celsum=celsum+cel;
if(cel>celmax){

celmax=cel;
}
}

Healpix_Map<double> G(cel,RING);
write_Healpix_map_to_fits("result.fits",G,PDT);


return 0;
}


error:
[@localhost RADEC→exp]$ g++ cexp.cc -g -lhealpix_cxx -lcxxsupport -lsharp -lfftpack -lc_utils -lcfitsio
cexp.cc: ‘int main()’ 内:
cexp.cc:251:46: エラー: expected primary-expression before ‘)’ token
write_Healpix_map_to_fits("result.fits",G,PDT);
^
[@localhost RADEC→exp]$


I want to make MAP with cel(i) and want to make map2fits or map2tga ,but not going well.
if you want to know more information,please tell me.
1) Your compile error is occurring because PDT is a type rather than a value. The compiler is expecting a value, specifically one of the values defined between lines 122 and 134 of this file:
https://healpix.sourceforge.io/doc/html/cxxsupport/datatypes_8h_source.html

For Healpix_Map<double>, the value would be PLANCK_FLOAT64. So the call would be:
write_Healpix_map_to_fits("result.fits", G, PDT);

2) You write "6" many times. Store that in a variable (I recommend MAP_ORDER).

3) Store the values like "NSIDE and NPIX" in "const int" variables instead. They are integers, and they shouldn't change. So const int is the way to go.

4) It looks like you're generating a bunch of data, trying to store it in an array, then converting it to Healpix_Map, then writing it to FITS. Don't do this. Just create the Healpix_Map<double> from scratch. You can use code similar to the following:

Healpix_Map<double> map(MAP_ORDER, RING);


Okay. It looks like you're attempting to generate some data, store it in "cel", then write the data to the Healpix_Map? If so, then there are definitely a few errors here. First, what are you attempting to store in the map?

With that said:
1) You should be storing values like NSIDE and NPIX as integers, as that's what they logically are. Definitely avoid using values like the number 6 in multiple places (makes it hard to change the code in the future). I would suggest creating a new variable, but it's probably not necessary to use this more than once.
2) You really shouldn't be storing data outside the Healpix_Map variable, then converting it to Healpix_Map. Write to the Healpix_Map directly.

With that out of the way, your compile error appears to be a result of "PDT". PDT is a type, not a value. The compiler is expecting a value, specifically one of the values defined between lines 122 and 134 of this file:
https://healpix.sourceforge.io/doc/html/cxxsupport/datatypes_8h_source.html

For Healpix_Map<double>, the value would be PLANCK_FLOAT64. So the call would be:
write_Healpix_map_to_fits("result.fits", G, PDT);

However, you're treating cel like a variable rather than an array. That's going to cause some problems. However, it probably makes sense to just get rid of "cel" entirely. Instead, after you set up the NSIDE and NPIX values, go ahead and define a Healpix_Map<double> object. I recommend doing something like:
Code:
const int NSIDE=pow(2,6);

Healpix_Map<double> hp_map(NSIDE, RING, SET_NSIDE);
for (int i = 0; i < hp_map.Npix(); i++) {
  pointing vec = hp_map.pix2vec(i);
  // Calculate pixel value from vec.theta and vec.phi.
  hp_map[i] = computed_value;
}
write_Healpix_map_to_fits("results.fits", healpix_map, PLANCK_FLOAT64);
If you'd also like to write the values to a text file for debugging (it looks like that's what you're attempting above, but I doubt it works properly), you can also include:

Code:
ofstream ccc("exp_16010100_1TeV.dat");
for(i=1; i<=hp_map.Npix(); i++){
  ccc << i <<" "<< hp_map[i] << endl;
}
 
I can never thank you enough,It happened without a hitch.
by this case and your advice,I was able to learn how to use of healpix a little.
You gave me examples and it was easy to understand.
Thank you.
 

kimbyd

Science Advisor
Gold Member
2018 Award
964
501
I can never thank you enough,It happened without a hitch.
by this case and your advice,I was able to learn how to use of healpix a little.
You gave me examples and it was easy to understand.
Thank you.
Wonderful, I'm glad to hear it!
 

Want to reply to this thread?

"Healpix: How to convert from data to map?" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top