Search code examples
pythonastronomyhealpy

Healpy: Rotator function gives different results


I'm using the following script in order to calculate the Galactical Center (GC) position in galactical coordinates (in degrees) to celestial coordinates:

import healpy as hp
r = hp.Rotator(coord = ['G', 'C'], deg=True)
ri = hp.Rotator(coord = ['C', 'G'], deg=True)
gz, ga = 0., 0.         # position of GC
gz_e, ga_e = r(gz, ga)
print gz_e, ga_e
zg, ag = ri(gz_e, ga_e)
print zg, ag

These are the results I get:

1.09730865695 -2.91715324734  # celestial
0.0 -1.57079632679            # back to galactical

First of all, the numbers are wrong in celestial as well as in galactical coordinates. There is a chance that I'm using the function wrong (which I hope), or something is wrong with the function itself. Does someone know what is going wrong?

Second: it seems, that I get the numbers in radian back, is that right?


Solution

  • deg refers only to the angles in rot, not to the Rotator itself. The Rotator needs theta (colatitude) and phi (longitude) in radians, see:

    import healpy as hp
    import numpy as np
    r = hp.Rotator(coord = ['G', 'C'])
    ri = hp.Rotator(coord = ['C', 'G'])
    gz, ga = np.pi/2, 0.         # position of GC
    gz_e, ga_e = r(gz, ga)
    
    print("Galactic center in Celestial Coordinates")
    print(gz_e, ga_e)
    zg, ag = ri(gz_e, ga_e)
    print("Back to galactic coordinates")
    print(zg, ag)
    

    Output:

    Galactic center in Celestial Coordinates
    2.07582709512 -1.63354890767
    Back to galactic coordinates
    1.57079632679 -1.11022302489e-16