Exemple #1
0
def main():
    # In the GPSTk there are multiple classes to manage time, depending
    # on the specific operation that we want to carry out. This modular
    # approach eases handling the many different time systems used in the
    # modern Global Navigation Satellite Systems.

    # Note, however, that in the GPSTk the unifying class to do time
    # Computations is the 'CommonTime' class.

    # Read current time from system clock
    systime = gpstk.SystemTime()

    # Convert to 'CommonTime', the standard way to handle time at GPSTk
    comtime = systime.toCommonTime()

    # This is the typical way to handle civil time
    civtime = gpstk.CivilTime(comtime)

    # The YDSTime class is very useful for common GNSS tasks
    ydstime = gpstk.YDSTime(comtime)

    # This is a typical class to handle time in GPS system
    gpstime = gpstk.GPSWeekSecond(comtime)

    # Class to handle Modified Julian Date
    mjd = gpstk.MJD(comtime)

    print "Hello world!"
    print "   The current civil time is", civtime
    print "   The current year is", ydstime.year
    print "   The current day of year is", ydstime.doy
    print "   The current second of day is", ydstime.sod
    print "   The current full GPS week is", gpstime.week
    print "   The current short GPS week is", gpstime.getModWeek()
    print "   The current day of GPS week is", gpstime.getDayOfWeek()
    print "   The current second of GPS week is", gpstime.sow
    print "   The current Modified Julian Date is", mjd
Exemple #2
0
def main(args=sys.argv[1:]):
    program_description = ("Converts from a given input time specification to "
                           "other time formats. Include the quotation marks. "
                           "All year values are four digit years.")
    parser = argparse.ArgumentParser(description=program_description)

    group = parser.add_mutually_exclusive_group()
    group.add_argument("-A", "--ansi", help='"ANSI-Second"')
    group.add_argument(
        "-c",
        "--civil",
        help='"Month(numeric) DayOfMonth Year Hour:Minute:Second"')
    group.add_argument(
        "-R",
        "--rinex",
        help='"Year(2-digit) Month(numeric) DayOfMonth Hour Minute Second"')
    group.add_argument("-o",
                       "--ews",
                       help='"GPSEpoch 10bitGPSweek SecondOfWeek"')
    group.add_argument("-f", "--ws", help='"FullGPSWeek SecondOfWeek"')
    group.add_argument("-w", "--wz", help='"FullGPSWeek Zcount"')
    group.add_argument("--z29", help='"29bitZcount"')
    group.add_argument("-Z", "--z32", help='"32bitZcount"')
    group.add_argument("-j", "--julian", help='"JulianDate"')
    group.add_argument("-m", "--mjd", help='"ModifiedJulianDate"')
    group.add_argument("-u",
                       "--unixtime",
                       help='"UnixSeconds UnixMicroseconds"')
    group.add_argument("-y", "--doy", help='"Year DayOfYear SecondsOfDay"')

    parser.add_argument("-F",
                        "--output_format",
                        help="Time format to use on output")

    parser.add_argument("-a",
                        "--add_offset",
                        type=int,
                        nargs="+",
                        help="add NUM seconds to specified time")
    parser.add_argument("-s",
                        "--sub_offset",
                        type=int,
                        nargs="+",
                        help="subtract NUM seconds to specified time")
    args = parser.parse_args(args)

    # these format keys must match the long arg names
    formats = {
        "ansi": "%K",
        "civil": "%m %d %Y %H:%M:%f",
        "rinex": "%y %m %d %H %M %S",
        "ews": "%E %G %g",
        "ws": "%F %g",
        "wz": "%F %Z",
        "z29": "%E %c",
        "z32": "%C",
        "julian": "%J",
        "mjd": "%Q",
        "unixtime": "%U",
        "doy": "%Y %j %s",
    }

    time_found = False
    for key in formats:
        input_time = getattr(args, key)  # args.ansi, args.civil, etc.
        if input_time is not None:
            try:
                ct = gpstk.scanTime(input_time, formats[key])
                time_found = True
            except gpstk.exceptions.InvalidRequest:
                raise gpstk.exceptions.InvalidRequest(
                    "Input could not be parsed."
                    "\nCheck formatt, ensure that the input is both valid and in quotes."
                    "\nCheck if time is too early/late for these formats.")

    if not time_found:
        ct = gpstk.SystemTime().toCommonTime()

    ct.setTimeSystem(gpstk.TimeSystem("GPS"))

    if args.add_offset is not None:
        for t in args.add_offset:
            ct.addSeconds(float(t))
    if args.sub_offset is not None:
        for t in args.sub_offset:
            ct.addSeconds(-float(t))

    if args.output_format is not None:
        print((gpstk.printTime(ct, args.output_format)))
    else:

        def left_align(txt: str):
            spacing = " " * 8
            return spacing + txt.ljust(31)

        print("")  # newline

        print(left_align("Month/Day/Year H:M:S"), end=" ")
        print(gpstk.CivilTime(ct))

        print(left_align("Modified Julian Date"), end=" ")
        print(gpstk.MJD(ct))

        print(left_align("GPSweek DayOfWeek SecOfWeek"), end=" ")
        print(gpstk.GPSWeekSecond(ct).printf("%G %w % 13.6g"))

        print(left_align("FullGPSweek Zcount"), end=" ")
        print(gpstk.GPSWeekZcount(ct).printf("%F % 6z"))

        print(left_align("Year DayOfYear SecondOfDay"), end=" ")
        print(gpstk.YDSTime(ct).printf("%Y %03j % 12.6s"))

        print(left_align("Unix: Second Microsecond"), end=" ")
        print(gpstk.UnixTime(ct).printf("%U % 6u"))

        print(left_align("Zcount: 29-bit (32-bit)"), end=" ")
        print(gpstk.GPSWeekZcount(ct).printf("%c (%C)"))

        print("")  # newline
def main(args=sys.argv[1:]):
    program_description = ('Converts from a given input time specification to '
                           'other time formats. Include the quotation marks. '
                           'All year values are four digit years.')
    parser = argparse.ArgumentParser(description=program_description)

    group = parser.add_mutually_exclusive_group()
    group.add_argument('-A', '--ansi', help='\"ANSI-Second\"')
    group.add_argument('-c', '--civil',
                       help='\"Month(numeric) DayOfMonth Year Hour:Minute:Second\"')
    group.add_argument('-R', '--rinex',
                       help='\"Year(2-digit) Month(numeric) DayOfMonth Hour Minute Second\"')
    group.add_argument('-o', '--ews', help='\"GPSEpoch 10bitGPSweek SecondOfWeek\"')
    group.add_argument('-f', '--ws', help='\"FullGPSWeek SecondOfWeek\"')
    group.add_argument('-w', '--wz', help='\"FullGPSWeek Zcount\"')
    group.add_argument('--z29', help='\"29bitZcount\"')
    group.add_argument('-Z', '--z32', help='\"32bitZcount\"')
    group.add_argument('-j', '--julian', help='\"JulianDate\"')
    group.add_argument('-m', '--mjd', help='\"ModifiedJulianDate\"')
    group.add_argument('-u', '--unixtime', help='\"UnixSeconds UnixMicroseconds\"')
    group.add_argument('-y', '--doy', help='\"Year DayOfYear SecondsOfDay\"')

    parser.add_argument('-F', '--output_format', help='Time format to use on output')

    parser.add_argument('-a', '--add_offset', type=int, nargs='+',
                        help='add NUM seconds to specified time')
    parser.add_argument('-s', '--sub_offset', type=int, nargs='+',
                        help='subtract NUM seconds to specified time')
    args = parser.parse_args(args)

    # these format keys must match the long arg names
    formats = {
        'ansi': '%K',
        'civil': '%m %d %Y %H:%M:%f',
        'rinex': '%y %m %d %H %M %S',
        'ews': '%E %G %g',
        'ws': '%F %g',
        'wz': '%F %Z',
        'z29': '%E %c',
        'z32': '%C',
        'julian': '%J',
        'mjd': '%Q',
        'unixtime': '%U',
        'doy': '%Y %j %s'
    }

    time_found = False
    for key in formats:
        input_time = getattr(args, key)  # args.ansi, args.civil, etc.
        if input_time is not None:
            try:
                ct = gpstk.scanTime(input_time, formats[key])
                time_found = True
            except gpstk.exceptions.InvalidRequest:
                raise gpstk.exceptions.InvalidRequest('Input could not be parsed.'
                                                      '\nCheck formatt, ensure that the input is both valid and in quotes.'
                                                      '\nCheck if time is too early/late for these formats.')

    if not time_found:
        ct = gpstk.SystemTime().toCommonTime()

    ct.setTimeSystem(gpstk.TimeSystem('GPS'))

    if args.add_offset is not None:
        for t in args.add_offset:
            ct.addSeconds(float(t))
    if args.sub_offset is not None:
        for t in args.sub_offset:
            ct.addSeconds(-float(t))

    if args.output_format is not None:
        print((gpstk.printTime(ct, args.output_format)))
    else:
        def left_align(str):
            spacing = ' ' * 8
            return spacing + str.ljust(31)

        print('')  # newline

        print(left_align('Month/Day/Year H:M:S'), end=' ')
        print(gpstk.CivilTime(ct))

        print(left_align('Modified Julian Date'), end=' ')
        print(gpstk.MJD(ct))

        print(left_align('GPSweek DayOfWeek SecOfWeek'), end=' ')
        print(gpstk.GPSWeekSecond(ct).printf('%G %w % 13.6g'))

        print(left_align('FullGPSweek Zcount'), end=' ')
        print(gpstk.GPSWeekZcount(ct).printf('%F % 6z'))

        print(left_align('Year DayOfYear SecondOfDay'), end=' ')
        print(gpstk.YDSTime(ct).printf('%Y %03j % 12.6s'))

        print(left_align('Unix: Second Microsecond'), end=' ')
        print(gpstk.UnixTime(ct).printf('%U % 6u'))

        print(left_align('Zcount: 29-bit (32-bit)'), end=' ')
        print(gpstk.GPSWeekZcount(ct).printf('%c (%C)'))

        print('')  # newline
Exemple #4
0
Usage:
  python example1.py
"""
from __future__ import print_function
import gpstk

# In the GPSTk there are multiple classes to manage time, depending
# on the specific operation that we want to carry out. This modular
# approach eases handling the many different time systems used in the
# modern Global Navigation Satellite Systems.

# Note, however, that in the GPSTk the unifying class to do time
# Computations is the 'CommonTime' class.

# Read current time from system clock
systime = gpstk.SystemTime()

# Convert to 'CommonTime', the standard way to handle time at GPSTk
comtime = systime.toCommonTime()

# This is the typical way to handle civil time
civtime = gpstk.CivilTime(comtime)

# The YDSTime class is very useful for common GNSS tasks
ydstime = gpstk.YDSTime(comtime)

# This is a typical class to handle time in GPS system
gpstime = gpstk.GPSWeekSecond(comtime)

# Class to handle Modified Julian Date
mjd = gpstk.MJD(comtime)