示例#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
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
示例#3
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
示例#4
0
def getdata(nfile, ofile, strsat=None):  #one week data
    f1, f2 = gpstk.L1_FREQ_GPS, gpstk.L2_FREQ_GPS
    alfa = 1.0 / ((f1**2 / f2**2) - 1)
    t = []  #observation epoch on code and phase
    Iphase, Icode, IPPS = {}, {}, {
    }  #dicc: key=time observer; values=iono delay and IPP
    VTECphase, VTECcode, ELEV = {}, {}, {}
    PhaseL1, PhaseL2 = {}, {}
    CodeL1, CodeL2 = {}, {}

    oheader, odata = gpstk.readRinex3Obs(ofile, strict=True)
    nheader, ndata = gpstk.readRinex3Nav(nfile)

    bcestore = gpstk.GPSEphemerisStore()

    for ndato in ndata:
        ephem = ndato.toGPSEphemeris()
        bcestore.addEphemeris(ephem)
    bcestore.SearchNear()

    for observation in odata:
        sats = [
            satID for satID, datumList in observation.obs.iteritems()
            if str(satID).split()[0] == "GPS"
        ]
        obs_types = np.array([i for i in oheader.R2ObsTypes])
        if 'C1' and 'P2' and 'L1' and 'L2' in obs_types:
            for sat in sats:
                if str(sat) == strsat:  #Return for a specific satellite
                    eph = bcestore.findEphemeris(sat, observation.time)
                    Tgd = eph.Tgd
                    sat_pos = eph.svXvt(observation.time)
                    rec_pos = gpstk.Position(
                        oheader.antennaPosition[0], oheader.antennaPosition[1],
                        oheader.antennaPosition[2]).asECEF()
                    elev = oheader.antennaPosition.elvAngle(sat_pos.x)
                    azim = oheader.antennaPosition.azAngle(sat_pos.x)
                    time = observation.time
                    R = 6.378e6  #earth radius
                    mapp = 1 / np.cos(
                        np.arcsin(R / (R + 350000)) * np.sin(elev))
                    IPP = rec_pos.getIonosphericPiercePoint(
                        elev, azim, 350000).asECEF()
                    t.append(np.trunc(gpstk.YDSTime(time).sod))

                    if np.size(np.where(obs_types == 'C1')) > 0 and np.size(
                            np.where(obs_types == 'P2')) > 0 and np.size(
                                np.where(obs_types == 'L1')) > 0 and np.size(
                                    np.where(obs_types == 'L2')) > 0:

                        C1_idx = np.where(obs_types == 'C1')[0][0]
                        P2_idx = np.where(obs_types == 'P2')[0][0]
                        R1 = observation.getObs(sat, C1_idx).data
                        R2 = observation.getObs(sat, P2_idx).data

                        L1_idx = np.where(obs_types == 'L1')[0][0]
                        L2_idx = np.where(obs_types == 'L2')[0][0]
                        L1 = observation.getObs(
                            sat, L1_idx).data * gpstk.L1_WAVELENGTH_GPS
                        L2 = observation.getObs(
                            sat, L2_idx).data * gpstk.L2_WAVELENGTH_GPS

                        if R2 < 3e7 and R1 < 3e7 and L2 < 3e7 and L1 < 3e7:  #Distances should be in order of 1e7 meters, more than that is considered an error

                            iono_delay_c = alfa * (R2 - R1)
                            iono_delay_p = alfa * (L1 - L2)

                            vtec_C = iono_delay_c / mapp
                            vtec_P = iono_delay_p / mapp

                            VTECcode[np.trunc(
                                gpstk.YDSTime(time).sod)] = vtec_C
                            VTECphase[np.trunc(
                                gpstk.YDSTime(time).sod)] = vtec_P
                            Icode[np.trunc(
                                gpstk.YDSTime(time).sod)] = iono_delay_c
                            Iphase[np.trunc(
                                gpstk.YDSTime(time).sod)] = iono_delay_p
                            ELEV[np.trunc(gpstk.YDSTime(time).sod)] = elev
                            IPPS[np.trunc(gpstk.YDSTime(time).sod)] = IPP
                            PhaseL1[np.trunc(gpstk.YDSTime(time).sod)] = L1
                            PhaseL2[np.trunc(gpstk.YDSTime(time).sod)] = L2
                            CodeL1[np.trunc(gpstk.YDSTime(time).sod)] = R1
                            CodeL2[np.trunc(gpstk.YDSTime(time).sod)] = R2

                            #stec=(iono_delay_p*f1**2)/(-40.3) #STEC delay on phase [mm]
                            #vtec=stec/mapp #vertical delay!
        else:
            print "Needs both L1 and L2 frequencies to compute delay"
            break

    return t, Icode, Iphase, VTECphase, ELEV, IPPS, PhaseL1, PhaseL2, CodeL1, CodeL2, Tgd
示例#5
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)
示例#6
0
# 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("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)