Exemplo n.º 1
0
def rnx2snr(obsfile, navfile, snrfile, snroption, year, month, day, dec_rate,
            log):
    """
    inputs are obsfile - RINEX 2.11
    navfile, which can be nav message or sp3 file
    snrfile: where the results go
    snroption: integer
    year,month,day:  what it sounds like, integer
    dec_rate: integer I think, decimation rate. For fortran users, this is done with teqc

    no output - the output is the snrfile that is created

    This only works for rinex v2.11.  
    Kristine M. Larson August 2020
    This relies on Joakim's rinex reading code
    """
    station = obsfile[0:4]
    #logname = 'logs/' + station + 'python.txt'
    #log = open(logname, 'w+')
    last3 = navfile[-3::]
    # figure out if you have a nav file or a sp3 file
    orbtype = 'sp3'  # assume it is sp3
    if (last3 != 'SP3') and (last3 != 'sp3'):
        orbtype = 'nav'
    log.write("Orbit type {0:4s} \n".format(orbtype))
    log.write("File name {0:50s} \n".format(navfile))
    # these are the elevation angle limits I have been using for the various SNR formats
    emin, emax = elev_limits(snroption)

    exitQ = False
    obsdata, systemsatlists, prntoidx, obstypes, header, obstimes, gpstime = rinpy.processrinexfile(
        obsfile)
    obsdata = rinpy.separateobservables(obsdata, obstypes)
    obslist = obstypes['G'][:]
    # need to check to see what happens without coordinates
    key = 'APPROX POSITION XYZ'
    if key in header.keys():
        log.write('Cartesian coordinates are in the RINEX Header \n')
    else:
        log.write('RINEX file does not have station coordinates. Exiting \n')
        print(
            'RINEX file does not have station coordinates. This is illegal. Exiting'
        )
        return
    rv = header['APPROX POSITION XYZ']
    recv = [float(i) for i in rv.split()]
    recv = np.array(recv)
    log.write("XYZ from header {0:15.5f} {1:15.5f} {2:15.5f} \n".format(
        recv[0], recv[1], recv[2]))
    if np.sum(np.abs(recv)) < 5:
        print(
            'Your receiver coordinates are in the middle of the Earth. Exiting.'
        )
        exitQ = True
        return

    lat, lon, h = g.xyz2llh(recv, 1e-8)  # returns lat/lon in radians
    up, East, North = g.up(lat, lon)  # returns unit vector for UP

    # set defaults
    s5exist = False
    s1exist = False
    s2exist = False
    if 'S1' in obslist:
        s1exist = True
    if 'S2' in obslist:
        s2exist = True
    if 'S5' in obslist:
        s5exist = True
    if not s1exist and not s2exist:
        log.write(
            'There are no S1 and no S2 data - this file is not useful for reflectometry \n'
        )
        exitQ = True
    if (orbtype == 'nav'):
        gpssatlist = systemsatlists['G'][:]
        #print('GPS satellite list', gpssatlist)
        navorbits(navfile, obstimes, obsdata, obslist, prntoidx, gpssatlist,
                  snrfile, s1exist, s2exist, s5exist, up, East, North, emin,
                  emax, recv, dec_rate, log)
    else:
        log.write('Read the sp3 file \n')
        sp3 = g.read_sp3file(navfile)
        testing_sp3(gpstime, sp3, systemsatlists, obsdata, obstypes, prntoidx,
                    year, month, day, emin, emax, snrfile, up, East, North,
                    recv, dec_rate, log)
Exemplo n.º 2
0
def rnx2snr(obsfile, navfile, snrfile, snroption, year, month, day, dec_rate):
    """
    inputs are obsfile - RINEX 2.11
    navfile, which can be nav message or sp3 file
    snrfile: where the results go
    snroption: integer
    year,month,day:  what it sounds like, integer
    dec_rate: integer I think, decimation rate. For fortran users, this is done with teqc

    no output - the output is the snrfile that is created

    This only works for rinex v2.11.  
    Kristine M. Larson August 2020
    This relies on Joakim's rinex reading code
    """
    # figure out if you have a nav file or a sp3 file
    last3 = navfile[-3::]
    orbtype = 'sp3'  # assume it is sp3
    if (last3 != 'SP3') and (last3 != 'sp3'):
        orbtype = 'nav'
    print('orbit type ', orbtype, navfile)
    # these are the elevation angle limits I have been using for the various SNR formats
    emin, emax = elev_limits(snroption)

    exitQ = False
    obsdata, systemsatlists, prntoidx, obstypes, header, obstimes, gpstime = rinpy.processrinexfile(
        obsfile)
    obsdata = rinpy.separateobservables(obsdata, obstypes)
    obslist = obstypes['G'][:]
    # need to check to see what happens without coordinates
    key = 'APPROX POSITION XYZ'
    if key in header.keys():
        print('has Cartesian coordinates in the RINEX Header')
    else:
        print('RINEX file does not have station coordinates. Exiting')
        return
    rv = header['APPROX POSITION XYZ']
    recv = [float(i) for i in rv.split()]
    recv = np.array(recv)
    print('XYZ from header', recv)
    if np.sum(np.abs(recv)) < 5:
        print(
            'Your receiver coordinates are in the middle of the Earth. Exiting.'
        )
        exitQ = True
        return

    lat, lon, h = g.xyz2llh(recv, 1e-8)  # returns lat/lon in radians
    up, East, North = g.up(lat, lon)  # returns unit vector for UP

    # set defaults
    s5exist = False
    s1exist = False
    s2exist = False
    if 'S1' in obslist:
        s1exist = True
    if 'S2' in obslist:
        s2exist = True
    if 'S5' in obslist:
        s5exist = True
    if not s1exist and not s2exist:
        print(
            'hard to know why you are translating this RINEX file as there are no S1 and S2 data'
        )
        exitQ = True
    if (orbtype == 'nav'):
        gpssatlist = systemsatlists['G'][:]
        print('GPS satellite list', gpssatlist)
        navorbits(navfile, obstimes, obsdata, obslist, prntoidx, gpssatlist,
                  snrfile, s1exist, s2exist, s5exist, up, East, North, emin,
                  emax, recv, dec_rate)
    else:
        print('read the sp3 file')
        sp3 = g.read_sp3file(navfile)
        test_sp3(gpstime, sp3, systemsatlists, obsdata, obstypes, prntoidx,
                 year, month, day, emin, emax, snrfile, up, East, North, recv,
                 dec_rate)