Reading GPS RINEX data with Pandas

徘徊边缘 提交于 2019-12-05 07:41:26

Here is what I ended up doing

df = readObs(indir, filename)
df.set_index(['%_GPST', 'satID'])

Note that I just set the new MultiIndex at the end after building it.

def readObs(dir, file):
    df = pd.DataFrame()
    #Grab header
    header = ''
    with open(dir + file) as handler:
        for i, line in enumerate(handler):
            header += line
            if 'END OF HEADER' in line:
                break
    #Grab Data
    with open(dir + file) as handler:
        for i, line in enumerate(handler):
            #Check for a Timestamp lable
            if '> ' in line:
                #Grab Timestamp
                links = line.split()
                index = datetime.strptime(' '.join(links[1:7]), '%Y %m %d %H %M %S.%f0')
                #Identify number of satellites
                satNum = int(links[8])
                #For every sat
                for j in range(satNum):
                    #just save the data as a string for now
                    satData = handler.readline()
                    #Fix the names
                    satdId = satData.replace("G ", "G0").split()[0]
                    #Make a dummy dataframe
                    dff = pd.DataFrame([[index,satdId,satData]], columns=['%_GPST','satID','satData'])
                    #Tack it on the end
                    df = df.append(dff)
    return df, header

Using a dummy data-frame just doesn't seem the most elegant though.

I suggest to write a custom parser, read the file line by line.

The space inebtween "G 5" is a further hint to write a custom parser.
In that case you cannot split the arguments simply by space,
you have to read all 3 chars at once, and remove the first char, and convert the remaining two (" 5") to a sattelite number.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!