coordconvert.py

python script for converting between galactic & celestial coordinates - Cardenzana Josh, 07/02/2017 09:38 AM

Download (1.22 KB)

 
1

    
2
import gammalib as gl
3
import argparse
4

    
5
#__________________________________________________________
6
# MAIN FUNCTION
7
if __name__=="__main__":
8
    # Get the command line options
9
    parser = argparse.ArgumentParser()
10
    parser.add_argument("--incoordsys", help="Input coordinate system <GAL|CEL>",
11
                        type=str)
12
    parser.add_argument("--xref", help="X Coordinate (RA or Galactic longitude)",
13
                        type=float)
14
    parser.add_argument("--yref", help="Y Coordinate (DEC ro GLAT)",
15
                        type=float)
16
    opts = parser.parse_args()
17

    
18
    # Create coordinate object
19
    coords = gl.GSkyDir()
20
    
21
    # Convert GAL -> CEL
22
    if opts.incoordsys == "GAL":
23
        coords.lb_deg( opts.xref, opts.yref )
24
        print("\nConverting GAL -> CEL:")
25
        print("   RA : {0}\n   DEC: {1}\n".format(coords.ra_deg(), coords.dec_deg()))
26
    # Convert CEL -> GAL
27
    elif opts.incoordsys == "CEL":
28
        coords.radec_deg( opts.xref, opts.yref )
29
        print("\nConverting CEL -> GAL:")
30
        print("   glon: {0}\n   glat: {1}\n".format(coords.l_deg(), coords.b_deg()))
31
    # Unknown coordinate system (or none) supplied
32
    else:
33
        print("\nERROR: incoordsys param must be either GAL or CEL.\n")
34