Next / Previous / Contents / TCC Help System / NM Tech homepage

5.4. main()

As with Section 4.4, “main(), first we check out the command line arguments, then convert from horizon to celestial coordinates and print the result.

aard
# - - - - -   m a i n

def main():
    """Main program for aard.
    """

    #-- 1 --
    # [ if sys.argv contains a valid set of command line
    #   arguments ->
    #     altAz  :=  the azimuth and altitude as
    #                a sidereal.AltAz instance
    #     latLon  :=  the observer's location as a
    #                 sidereal.LatLon instance
    #     dt  :=  the observer's date and time as a
    #             datetime.datetime instance
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    altAz, latLon, dt  =  checkArgs()

    #-- 2 --
    # [ if dt has no time zone information ->
    #     utc  :=  dt
    #   else ->
    #     utc  :=  the UTC equivalent to dt ]
    if  ( (dt.tzinfo is None) or
          (dt.utcoffset() is None) ):
        utc  =  dt
    else:
        utc  =  dt - dt.utcoffset()

Display the local sidereal time in case the observer is interested.

aard
    #-- 3 --
    # [ sys.stdout  +:=  local sidereal time for dt and latLon ]
    gst  =  sidereal.SiderealTime.fromDatetime ( utc )
    lst  =  gst.lst ( latLon.lon )
    print "Horizon coordinates:", altAz
    print "Observer's location:", latLon
    print "Observer's time:", dt
    print "Local sidereal time is", lst

Here is where this script diverges from Section 4.4, “main(). To convert from horizon to equatorial coordinates, you need a local sidereal time and an observer's location.

aard
    #-- 4 --
    # [ raDec  :=  equatorial coordinates of self for local
    #       sidereal time (lst) and location (latLon) ]
    raDec  =  altAz.raDec ( lst, latLon )

    #-- 5 --
    print "Equatorial coordinates:", raDec