Example #1
0
def navorbits(navfile, obstimes, observationdata, obslist, prntoidx,
              gpssatlist, snrfile, s1exist, s2exist, s5exist, up, East, North,
              emin, emax, recv, dec_rate, log):
    """
    This is for GPS only files !
    navfile is nav broadcast ephemeris in RINEX format
    inputs are rinex info, obstimes, observationdata,prntoidx,gpssatlist
    various bits about SNR existence
    snrfile is output name
    log is for screen outputs - now going to a file
    """
    log.write('reading the ephemeris data \n')
    ephemdata = g.myreadnav(navfile)
    if len(ephemdata) == 0:
        log.write("Empty ephemeris or the file does not exist \n")
        return

    # change variable name to save typing
    a = obstimes
    if True:
        log.write('Opening output file for the SNR data \n')
        fout = open(snrfile, 'w+')
        K = len(obstimes)
        log.write('Number of epochs in the RINEX file {0:6.0f} \n '.format(K))
        log.write('Decimation rate {0:3.0f} \n'.format(dec_rate))

        for i in range(0, K):
            if np.remainder(i, 1000) == 0:
                log.write('Epoch {0:6.0f} \n'.format(i))
            # sod is seconds of the day
            sod = 3600 * a[i].hour + 60 * a[i].minute + a[i].second
            if dec_rate > 0:
                rem = sod % dec_rate
            else:
                rem = 0
            if (rem == 0):
                gweek, gpss = g.kgpsweek(a[i].year, a[i].month, a[i].day,
                                         a[i].hour, a[i].minute, a[i].second)
                for sat in gpssatlist:
                    s1, s2, s5 = readSNRval(s1exist, s2exist, s5exist,
                                            observationdata, prntoidx, sat, i)
                    if (s1 > 0):
                        closest = g.myfindephem(gweek, gpss, ephemdata, sat)
                        if len(closest) > 0:
                            satv = satorb_prop(gweek, gpss, sat, recv, closest)
                            r = np.subtract(
                                satv, recv)  # satellite minus receiver vector
                            eleA = g.elev_angle(up, r) * 180 / np.pi
                            azimA = g.azimuth_angle(r, East, North)
                            if (eleA >= emin) and (eleA <= emax):
                                fout.write(
                                    "{0:3.0f} {1:10.4f} {2:10.4f} {3:10.0f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f} {8:7.2f} \n"
                                    .format(sat, eleA, azimA, sod, 0, 0, s1,
                                            s2, s5))
        fout.close()
    else:
        log.write(
            'There was some kind of problem with your file, exiting ...\n')
        print('There was some kind of problem with your file, exiting ...')
Example #2
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument("year", help="year ", type=int)
    parser.add_argument("month", help="month", type=int)
    parser.add_argument("day", help="day", type=int)

    args = parser.parse_args()
    year = args.year
    month = args.month
    day = args.day

    wk, swk = g.kgpsweek(year, month, day, 0, 0, 0)
    #doy,cdoy,cyyyy,cyy = g.ymd2doy(year, month, day )
    print('WEEK:', wk, ' DAY:', int(swk / 86400))
Example #3
0
def testing_sp3(gpstime, sp3, systemsatlists, obsdata, obstypes, prntoidx,
                year, month, day, emin, emax, outputfile, up, East, North,
                recv, dec_rate, log):
    """
    inputs are gpstime( numpy array with week and sow)
    sp3 is what has been read from the sp3 file
    columsn are satNu, week, sow, x, y, z (in meters)
    log is for comments
    """
    checkD = False
    if dec_rate > 0:
        checkD = True
        log.write('You are decimating \n')
    # epoch at the beginning of the day of your RINEX file
    gweek0, gpssec0 = g.kgpsweek(year, month, day, 0, 0, 0)

    ll = 'quadratic'
    #   will store in this variable, then sort it before writing out to a file
    saveit = np.empty(shape=[0, 11])
    fout = open(outputfile, 'w+')
    NsatT = 0
    # make a dictionary for constellation name
    sname = {}
    sname['G'] = 'GPS'
    sname['R'] = 'GLONASS'
    sname['E'] = 'GALILEO'
    sname['C'] = 'BEIDOU'
    for con in ['G', 'E', 'R', 'C']:
        if con in obstypes:
            satL = len(systemsatlists[con][:])
            satS = 'Processing ' + sname[con]
            with Bar(satS, max=satL, fill='@', suffix='%(percent)d%%') as bar:
                log.write(
                    'Good news - found data for constellation {0:s} \n'.format(
                        con))
                obslist = obstypes[con][:]
                satlist = systemsatlists[con][:]
                for prn in satlist:
                    bar.next()
                    addon = g.findConstell(
                        con)  # 100,200,or 300 for R,E, and C
                    log.write(
                        'Constellation {0:1s} Satellite {1:2.0f}  Addon {2:3.0f} \n'
                        .format(con, prn, addon))
                    # window out the data for this satellite
                    m = sp3[:, 0] == prn + addon
                    x = sp3[m, 3]
                    if len(x) > 0:
                        sp3_week = sp3[m, 1]
                        sp3_sec = sp3[m, 2]
                        x = sp3[m, 3]
                        y = sp3[m, 4]
                        z = sp3[m, 5]
                        # fit the orbits for this satellite
                        t = sp3_sec
                        iX = interp1d(t,
                                      x,
                                      ll,
                                      bounds_error=False,
                                      fill_value='extrapolate')
                        iY = interp1d(t,
                                      y,
                                      ll,
                                      bounds_error=False,
                                      fill_value='extrapolate')
                        iZ = interp1d(t,
                                      z,
                                      ll,
                                      bounds_error=False,
                                      fill_value='extrapolate')
                        # get the S1 data for this satellite
                        if 'S1' in obslist:
                            s1 = obsdata[con]['S1'][:, prntoidx[con][prn]]

        # indices when there are no data for this satellite
                        ij = np.isnan(s1)
                        # indices when there are data in the RINEX file - this way you do not compute
                        # orbits unless there are data.
                        not_ij = np.logical_not(ij)
                        Tp = gpstime[
                            not_ij,
                            1]  # only use the seconds of the week for now
                        s1 = s1[not_ij]
                        #print(s1.shape)
                        emp = np.zeros(shape=[len(s1), 1], dtype=float)
                        # get the rest of the SNR data in a function
                        s2, s5, s6, s7, s8 = extract_snr(
                            prn, con, obslist, obsdata, prntoidx, not_ij, emp)
                        # make sure there are no nan values in s2 or s5

                        nepochs = len(Tp)
                        for ij in range(0, nepochs):
                            TT = 0  # default value
                            if checkD:
                                TT = Tp[ij] % dec_rate  # get the modulus
                            if TT == 0:
                                SatOrb = satorb_prop_sp3(
                                    iX, iY, iZ, recv, Tp, ij)
                                r = np.subtract(SatOrb, recv)
                                azimA = g.azimuth_angle(r, East, North)
                                eleA = g.elev_angle(up, r) * 180 / np.pi
                                if (eleA >= emin) and (eleA <= emax):
                                    fout.write(
                                        "{0:3.0f} {1:10.4f} {2:10.4f} {3:10.0f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f} {8:7.2f} {9:7.2f} {10:7.2f} \n"
                                        .format(prn + addon, eleA, azimA,
                                                Tp[ij] - gpssec0, 0,
                                                float(s6[ij]), s1[ij],
                                                float(s2[ij]), float(s5[ij]),
                                                float(s6[ij]), float(s7[ij])))
                    else:
                        log.write(
                            'This satellite is not in the orbit file. {0:3.0f} \n'
                            .format(prn))
        else:
            log.write('No data for constellation {0:1s} \n'.format(con))
    log.write('write SNR data to file \n')
    fout.close()
Example #4
0
def test_sp3(gpstime, sp3, systemsatlists, obsdata, obstypes, prntoidx, year,
             month, day, emin, emax, outputfile, up, East, North, recv,
             dec_rate):
    """
    inputs are gpstime( numpy array with week and sow)
    sp3 is what has been read from the sp3 file
    columsn are satNu, week, sow, x, y, z (in meters)
    """
    checkD = False
    if dec_rate > 0:
        checkD = True
        print('decimating')
    # epoch at the beginning of the day of your RINEX file
    gweek0, gpssec0 = g.kgpsweek(year, month, day, 0, 0, 0)

    ll = 'quadratic'
    #   will store in this variable, then sort it before writing out to a file
    saveit = np.empty(shape=[0, 11])
    fout = open(outputfile, 'w+')
    for con in ['G', 'E', 'R', 'C']:
        if con in obstypes:
            print('good news - found data for constellation ', con)
            obslist = obstypes[con][:]
            satlist = systemsatlists[con][:]
            print(satlist)
            for prn in satlist:
                addon = g.findConstell(con)  # 100,200,or 300 for R,E, and C
                print('Constellation ', con, ' satellite ', prn, addon)
                # window out the data for this satellite
                m = sp3[:, 0] == prn + addon
                x = sp3[m, 3]
                if len(x) > 0:
                    sp3_week = sp3[m, 1]
                    sp3_sec = sp3[m, 2]
                    x = sp3[m, 3]
                    y = sp3[m, 4]
                    z = sp3[m, 5]
                    # fit the orbits for this satellite
                    t = sp3_sec
                    iX = interp1d(t,
                                  x,
                                  ll,
                                  bounds_error=False,
                                  fill_value='extrapolate')
                    iY = interp1d(t,
                                  y,
                                  ll,
                                  bounds_error=False,
                                  fill_value='extrapolate')
                    iZ = interp1d(t,
                                  z,
                                  ll,
                                  bounds_error=False,
                                  fill_value='extrapolate')
                    # get the S1 data for this satellite
                    if 'S1' in obslist:
                        s1 = obsdata[con]['S1'][:, prntoidx[con][prn]]

        # indices when there are no data for this satellite
                    ij = np.isnan(s1)
                    # indices when there are data in the RINEX file - this way you do not compute
                    # orbits unless there are data.
                    not_ij = np.logical_not(ij)
                    Tp = gpstime[not_ij,
                                 1]  # only use the seconds of the week for now
                    s1 = s1[not_ij]
                    #print(s1.shape)
                    emp = np.zeros(shape=[len(s1), 1], dtype=float)
                    # get the rest of the SNR data in a function
                    s2, s5, s6, s7, s8 = extract_snr(prn, con, obslist,
                                                     obsdata, prntoidx, not_ij,
                                                     emp)

                    # make sure there are no nan values in s2 or s5

                    nepochs = len(Tp)
                    for ij in range(0, nepochs):
                        TT = 0  # default value
                        if checkD:
                            TT = Tp[ij] % dec_rate  # get the modulus
                        if TT == 0:
                            SatOrb = satorb_prop_sp3(iX, iY, iZ, recv, Tp, ij)
                            r = np.subtract(SatOrb, recv)
                            azimA = g.azimuth_angle(r, East, North)
                            eleA = g.elev_angle(up, r) * 180 / np.pi
                            if (eleA >= emin) and (eleA <= emax):
                                fout.write(
                                    "{0:3.0f} {1:10.4f} {2:10.4f} {3:10.0f} {4:7.2f} {5:7.2f} {6:7.2f} {7:7.2f} {8:7.2f} {9:7.2f} {10:7.2f} \n"
                                    .format(prn + addon, eleA,
                                            azimA, Tp[ij] - gpssec0, 0,
                                            float(s6[ij]), s1[ij],
                                            float(s2[ij]), float(s5[ij]),
                                            float(s6[ij]), float(s7[ij])))
                else:
                    print('this satellite is not in the orbit file.', prn)
        else:
            print('no data for constellation ', con)
    # print('sort by time')
    # tried saving to variable but it was very slow
    #ne = np.array([prn,eleA,azimA,Tp[ij],0,0,s1[ij],s2[ij],s5[ij],0,0])
    #saveit = np.vstack((saveit,ne))
    #i = np.argsort(saveit[:,3])
    # apply that sort to variable with shorter name
    #s = saveit[i,:]
    print('write to file')
    fout.close()
Example #5
0
def _readheader_v21x(lines):
    """ Read rinex version 2.10 and 2.11 
    kristine larson added gps week and second of week outputs
    """

    header = {}
    # Capture header info

    for i, line in enumerate(lines):
        if "END OF HEADER" in line:
            i += 1  # skip to data
            break

        if line[60:80].strip() not in header:  # Header label
            header[line[60:80].strip(
            )] = line[:60]  # don't strip for fixed-width parsers
            # string with info
        else:
            header[line[60:80].strip()] += "\n" + line[:60]
            # concatenate to the existing string

    rowpersat = 1 + (len(header['# / TYPES OF OBSERV'][6:].split()) - 1) // 5

    timeoffirstobs = [part for part in header['TIME OF FIRST OBS'].split()]

    headerlines = []
    headerlengths = []
    obstimes = []
    epochsatlists = []
    # for those of who do not like datetime
    gpstime = np.empty(shape=[0, 2])
    satset = set()

    century = int(timeoffirstobs[0][:2] + '00')
    # This will result in an error if the record overlaps the end of the century. So if someone feels this is a major
    # problem, feel free to fix it. Personally can't bother to do it...

    pattern = re.compile('(\s{2}\d|\s\d{2}){2}')

    while i < len(lines):
        if pattern.match(
                lines[i][:6]):  # then it's the first line in a header record
            if int(lines[i][28]) in (0, 1, 6):  # CHECK EPOCH FLAG  STATUS
                headerlines.append(i)
                year, month, day, hour = lines[i][1:3], lines[i][4:6], lines[
                    i][7:9], lines[i][10:12]
                minute, second = lines[i][13:15], lines[i][16:26]
                obstimes.append(
                    datetime.datetime(year=century + int(year),
                                      month=int(month),
                                      day=int(day),
                                      hour=int(hour),
                                      minute=int(minute),
                                      second=int(float(second)),
                                      microsecond=int(
                                          float(second) % 1 * 100000)))

                week, sow = g.kgpsweek(century + int(year), int(month),
                                       int(day), int(hour), int(minute),
                                       int(float(second)))
                ne = np.array((week, sow))
                gpstime = np.vstack((gpstime, ne))

                numsats = int(
                    lines[i][29:32])  # Number of visible satellites %i3
                headerlengths.append(
                    1 + (numsats - 1) // 12
                )  # number of lines in header, depends on how many svs on view

                if numsats > 12:
                    sv = []
                    for s in range(numsats):
                        if s > 0 and s % 12 == 0:
                            i += 1
                        sv.append(lines[i][32 + (s % 12) * 3:35 +
                                           (s % 12) * 3])
                    epochsatlists.append(sv)

                else:
                    epochsatlists.append([
                        lines[i][32 + s * 3:35 + s * 3] for s in range(numsats)
                    ])

                i += numsats * rowpersat + 1

            else:  # there was a comment or some header info
                flag = int(lines[i][28])
                if flag != 4:
                    print(flag)
                skip = int(lines[i][30:32])
                i += skip + 1
        else:
            # We have screwed something up and have to iterate to get to the next header row, or eventually the end.
            i += 1

    for satlist in epochsatlists:
        satset = satset.union(satlist)

    return header, headerlines, headerlengths, obstimes, epochsatlists, satset, gpstime