Healpix: How to convert from data to map?

In summary: Healpix data.In summary, the conversation is about the user wanting to convert binary data into a Healpix RING map using C++ and looking for help on which function to use. They also mention being a beginner in C++ and wanting a more detailed solution. The expert suggests using the facilities section of the Healpix documentation and using the "map2tga" utility to create the map. They also mention the option of calling the module from within the code, but warn that it may be messy.
  • #1
bluecrow
5
0
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:
Technology news on Phys.org
  • #2
bluecrow said:
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.
 
  • #5
jedishrfu said:
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.
 
  • Like
Likes Klystron and jedishrfu
  • #6
kimbyd said:
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.
 
  • #7
bluecrow said:
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.
 
  • #8
jedishrfu said:
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.
 
  • #9
bluecrow said:
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
 
  • Like
Likes jedishrfu
  • #10
kimbyd said:
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:
  • #11
bluecrow said:
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;
}
 
  • Like
Likes bluecrow
  • #12
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.
 
  • #13
bluecrow said:
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!
 

1. What is Healpix and how does it relate to data and maps?

Healpix is a software package designed for analyzing and visualizing data on the sphere, particularly for astronomical applications. It uses a hierarchical pixelization scheme to convert data points on a sphere into a map, allowing for efficient analysis and visualization.

2. How do I convert my data into a Healpix map?

The first step is to format your data into a specific file format that Healpix recognizes, such as a FITS or ASCII file. Then, you can use the Healpix software to convert this data into a map using a specific pixelization scheme and projection method.

3. What are some common challenges when converting data to a Healpix map?

One challenge is choosing the appropriate pixelization scheme for your data, as different schemes may be better suited for different types of data. Another challenge is determining the optimal resolution for your map, as higher resolutions may result in longer processing times and larger file sizes.

4. Can I visualize my Healpix map in different projections?

Yes, Healpix supports several projection methods, including cylindrical, conical, and azimuthal projections. You can choose the appropriate projection based on the type of data you have and the desired visualization.

5. Is Healpix only used for astronomical data?

No, while Healpix was initially developed for astronomical applications, it can also be used for other types of data on the sphere, such as climate data or 3D scans of the earth's surface. It is a versatile tool for visualizing and analyzing spherical data.

Similar threads

  • Cosmology
Replies
16
Views
6K
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
Replies
2
Views
928
  • Programming and Computer Science
Replies
19
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
174
  • Programming and Computer Science
Replies
10
Views
2K
  • Electrical Engineering
Replies
14
Views
741
  • Programming and Computer Science
Replies
6
Views
2K
  • Astronomy and Astrophysics
Replies
1
Views
3K
Back
Top