def main():
    """Main function... makes 'forward declarations' of helper functions unnecessary"""
    # Constants
    satnum = 25544  # ISS = 25544
    saturl = "http://www.celestrak.com/NORAD/elements/stations.txt"
    our_tzname = 'US/Eastern'

    # Times we need
    now = datetime.now()
    our_tz = timezone(our_tzname)
    our_now = our_tz.localize(datetime(now.year, now.month, now.day, \
                                       now.hour, now.minute, now.second))

    st = SatelliteTle(satnum, tle_url=saturl)
    print_tle_data(st)

    point = st.compute_ephemeris_point(our_now)
    print_ephemeris_point_now(st, point)

    llap = st.compute_lonlatalt_point(our_now)
    print_lonlatalt_now(st, llap)

    sun_state = st.get_satellite_sun_state(our_now)
    if (sun_state == st.InSun):
        in_sun = "in sun"
    elif (sun_state == st.InPenumbra):
        in_sun = "in penumbra"
    else:
        in_sun = "in umbra"

    print "Satellite is %s" % in_sun
Exemplo n.º 2
0
def main():
    """Main function... makes 'forward declarations' of helper functions unnecessary"""
    parser = argparse.ArgumentParser()
    parser.add_argument("-s", "--satnum", help="Specify satellite number (e.g. 25544=ISS, 43852=STF-1)", \
            type=int, metavar="[1-99999]", choices=range(1,99999), default=43852)
    parser.add_argument("-t",
                        "--time",
                        help="Specify date/time (UTC)",
                        type=ArgValidator.validate_datetime,
                        metavar="YYYY-MM-DDTHH:MM:SS",
                        default=datetime.now())
    parser.add_argument("-r", "--endtime", help="Specify date time range with this end date/time (UTC)", \
            type=ArgValidator.validate_datetime, metavar="YYYY-MM-DDTHH:MM:SS", default=None)
    parser.add_argument("-d", "--timestep", help="Specify time step (delta) in seconds for tabular data", \
            type=int, metavar="[1-86400]", choices=range(1,86400), default=60)
    parser.add_argument("-p",
                        "--tle",
                        help="Print TLE information",
                        action="store_true")
    parser.add_argument("-u",
                        "--sun",
                        help="Print sun/umbra/penumbra information",
                        action="store_true")
    parser.add_argument("-e",
                        "--ecef",
                        help="Print ECEF ephemeris",
                        action="store_true")
    parser.add_argument("-i",
                        "--eci",
                        help="Print ECI ephemeris",
                        action="store_true")
    parser.add_argument(
        "-l",
        "--lla",
        help=
        "Print latitude, longitude, altitude (geodetic degrees, altitude in km above WGS-84 ellipsoid) ephemeris",
        action="store_true")
    parser.add_argument(
        "-f",
        "--file",
        help="TLE file to use (instead of looking up the TLE on CelesTrak)",
        type=ArgValidator.validate_file,
        default=None)
    parser.add_argument("-m",
                        "--mag",
                        help="Print geomagnetic data",
                        action="store_true")
    parser.add_argument("-a",
                        "--aer",
                        help="Print az/el/range from ground station",
                        action="store_true")
    parser.add_argument("-x", "--longitude", help="Specify longitude (degrees) of ground station", \
            type=float, default=-79.825518056)
    parser.add_argument("-y", "--latitude", help="Specify latitude (degrees) of ground station", \
            type=float, default=38.43685028)
    parser.add_argument("-z", "--elevation", help="Specify elevation (meters) of ground station", \
            type=float, default=842.0)
    parser.add_argument("-v",
                        "--iirv",
                        help="Print improved interrange vector (IIRV) format",
                        action="store_true")
    args = parser.parse_args()

    if (args.file is not None):
        st = SatelliteTle(args.satnum, tle_file=args.file)
    else:
        saturl = "http://www.celestrak.com/cgi-bin/TLE.pl?CATNR=%s" % args.satnum
        st = SatelliteTle(args.satnum, tle_url=saturl)

    if (args.tle):
        print_tle_data(st)

    if (args.eci):
        if (args.endtime is None):
            point = st.compute_ephemeris_point(args.time)
            print_ephemeris_point(st, point)
        else:
            table = st.compute_ephemeris_table(args.time, args.endtime,
                                               args.timestep)
            print_ephemeris_table(st, table)

    if (args.ecef):
        #print "ECEF is not implemented"
        if (args.endtime is None):
            point = st.compute_ephemeris_point(args.time)
            print_ephemeris_point(st, point, False)
        else:
            table = st.compute_ephemeris_table(args.time, args.endtime,
                                               args.timestep)
            print_ephemeris_table(st, table, False)

    if (args.lla):
        if (args.endtime is None):
            llap = st.compute_lonlatalt_point(args.time)
            print_lonlatalt(st, llap)
        else:
            table = st.compute_lonlatalt_table(args.time, args.endtime,
                                               args.timestep)
            print_lonlatalt_table(st, table)

    if (args.mag):
        if (args.endtime is None):
            llap = st.compute_lonlatalt_point(args.time)
            print_mag(st, llap)
        else:
            table = st.compute_lonlatalt_table(args.time, args.endtime,
                                               args.timestep)
            print_mag_table(st, table)

    if (args.aer):
        gs = GroundStation(lat=args.latitude,
                           lon=args.longitude,
                           el_meters=args.elevation)
        ic = InviewCalculator(gs, st)
        if (args.endtime is None):
            args.endtime = args.time
        azels = ic.compute_azels(args.time, args.endtime, args.timestep)
        print_azelrange_table(azels)

    if (args.sun):
        if (args.endtime is None):
            sun_state = st.get_satellite_sun_state(args.time)
            if (sun_state == st.InSun):
                in_sun = "in sun"
            elif (sun_state == st.InPenumbra):
                in_sun = "in penumbra"
            else:
                in_sun = "in umbra"
            print("===== SUN =====")
            print("Satellite is %s" % in_sun)
        else:
            tables = st.compute_sun_times(args.time, args.endtime)
            print_sun_times_table(st, args.time, args.endtime, tables)

    if (args.iirv):
        if (args.endtime is None):
            point = st.compute_ephemeris_point(args.time)
            print_iirv_point(st, point)
        else:
            table = st.compute_ephemeris_table(args.time, args.endtime,
                                               args.timestep)
            print_iirv_points(st, table)