예제 #1
0
 def test(self):
     a = gpstk.ANSITime()
     a.scanf("1234567789", "%K")
     a.setTimeSystem(gpstk.TimeSystem('GLO'))
     b = a.toCommonTime()
     c = gpstk.MJD(b)
     d = gpstk.GPSWeekSecond(b)
     e = gpstk.CivilTime(b)
     f = gpstk.QZSWeekSecond(b)
     self.assertEqual('1234567789 GLO', str(a))
     self.assertEqual('2454876 84589000 0.000000000000000 GLO', str(b))
     self.assertEqual('54875.979039352 GLO', str(c))
     self.assertEqual('1518 516589.000000 GLO', str(d))
     self.assertEqual('02/13/2009 23:29:49 GLO', str(e))
     self.assertEqual('1518 516589.000000 GLO', str(f))
예제 #2
0
def compute_raim_position(gps_week, gps_sow, prns, prns_pos, pranges,
                          bcestore):
    if len(prns) == 0 or len(prns_pos) == 0:
        return np.array([0, 0, 0])
    t = gpstk.GPSWeekSecond(gps_week, gps_sow).toCommonTime()
    prnList = [gpstk.SatID(int(i[3:])) for i in prns]
    satVector = gpstk.seqToVector(list(prnList), outtype='vector_SatID')
    rangeVector = gpstk.seqToVector([float(i) for i in pranges])
    noTropModel = gpstk.ZeroTropModel()
    raimSolver = gpstk.PRSolution2()
    raimSolver.RAIMCompute(t, satVector, rangeVector, bcestore, noTropModel)
    r = np.array([
        raimSolver.Solution[0], raimSolver.Solution[1], raimSolver.Solution[2]
    ])
    return r
예제 #3
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
예제 #4
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(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
예제 #5
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
예제 #6
0
def rinex_to_dataframe(obsfile, navfile):
    c = 299792458.

    #observation_types=["P1", "P2", "L1", "L2"]
    observation_types = ["C1", "P2", "L1", "L2"]
    obsHeader, obsData = gpstk.readRinex3Obs(obsfile)
    navHeader, navData = gpstk.readRinex3Nav(navfile)
    # setup ephemeris store to look for satellite positions
    bcestore = gpstk.GPSEphemerisStore()
    for navDataObj in navData:
        ephem = navDataObj.toGPSEphemeris()
        bcestore.addEphemeris(ephem)
    bcestore.SearchNear()
    navData.close()

    rec_pos = [
        obsHeader.antennaPosition[0], obsHeader.antennaPosition[1],
        obsHeader.antennaPosition[2]
    ]
    requested_obstypes = observation_types
    obsidxs = []
    obstypes = []
    obsdefs = np.array([i for i in obsHeader.R2ObsTypes])
    for i in requested_obstypes:
        w = np.where(obsdefs == i)[0]
        if len(w) != 0:
            obsidxs.append(w[0])
            obstypes.append(i)
        else:
            print("WARNING! observation `" + i + "` no present in file")
    obsidxs, obstypes
    print obsdefs  #que tipos hay

    r = []
    for obsObject in obsData:
        prnlist = []
        obsdict = {}
        prnspos = []
        prns_clockbias = []
        prns_relcorr = []
        prnselev = []
        prnsaz = []
        for i in obstypes:
            obsdict[i] = []

        gpsTime = gpstk.GPSWeekSecond(obsObject.time)

        for satID, datumList in obsObject.obs.iteritems():
            if satID.system == satID.systemGPS:
                prnlist.append("".join(str(satID).split()))
                try:
                    eph = bcestore.findEphemeris(satID, obsObject.time)
                except:
                    print "no encontrada!"

                for i in range(len(obsidxs)):
                    obsdict[obstypes[i]].append(
                        obsObject.getObs(satID, obsidxs[i]).data)

                P1 = obsObject.getObs(satID, obsidxs[0]).data
                svTime = obsObject.time - P1 / c
                svXvt = eph.svXvt(svTime)
                svTime += -svXvt.getClockBias() + svXvt.getRelativityCorr()
                svXvt = eph.svXvt(svTime)

                prnspos.append([svXvt.x[0], svXvt.x[1], svXvt.x[2]])
                prns_clockbias.append(svXvt.getClockBias())
                prns_relcorr.append(svXvt.getRelativityCorr())

                prnselev.append(
                    obsHeader.antennaPosition.elvAngle(svXvt.getPos()))
                prnsaz.append(obsHeader.antennaPosition.azAngle(
                    svXvt.getPos()))

                correct_sod = np.round(
                    gpstk.YDSTime(obsObject.time).sod / 30.0) * 30  #mod 30s

        r.append([
            gpsTime.getWeek(),
            gpsTime.getSOW(), correct_sod,
            np.array(prnlist),
            np.array(prnspos),
            np.array(prns_clockbias),
            np.array(prns_relcorr),
            np.array(prnselev),
            np.array(prnsaz)
        ] + [np.array(obsdict[i]) for i in obstypes])

    names = [
        "gps_week", "gps_sow", "tod", "prns", "prns_pos", "prns_clockbias",
        "prns_relcorr", "prns_elev", "prns_az"
    ] + obstypes
    r = pd.DataFrame(r, columns=names)
    obsData.close()
    return r, bcestore, np.array(rec_pos)
예제 #7
0
# 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("current civil time is", civtime)
print("current year is", ydstime.year)
print("current day of year is", ydstime.doy)
print("current second of day is", ydstime.sod)
print("current full GPS week is", gpstime.week)
print("current short GPS week is", gpstime.getModWeek())
print("current day of GPS week is", gpstime.getDayOfWeek())
print("current second of GPS week is", gpstime.sow)
print("current Modified Julian Date is {}".format(mjd))