Python】RTKLIB rnx2rtkp.exe ppp批处理

Edited by LZCUMT
使用方法:将文件与rnx2rtkp.exe以及相关的GNSS数据与产品放在同一路径下,打开命令行窗口,运行python文件即可进行PPP批处理

#!/usr/bin/python
# coding=utf-8
'''
RTKLIB后处理批量调用
Version:1.1
Author:LZ_CUMT

新增以下功能:
1、修改了文件夹遍历方法
2、使用正则表达式进行观测文件和配置文件匹配
3、优化了精密轨道和钟差匹配方法

cmd打印示例:
* Processing the1 th obs file: cut01800.15o with the conf: MyCfg.conf
rnx2rtkp.exe cut01800.15o brdm1800.15p igs18511.sp3 igs18511.clk -k MyCfg.conf -o cut01800.MyCfg.pos -x 3

'''


import os
import re
import subprocess


# 找目录下含该关键词的文件名及其路径
def find_content(key_word):
    filename = []
    for files in os.listdir():  # 遍历目录文件名
        if (key_word == 'o' ):
            if re.match(r'[A-Za-z0-9]+\.\d\do',files):
                filename.append(files)  # 文件名及其路径添加到数组
        elif (key_word == 'conf'):
            if re.match(r'[A-Za-z0-9]+\.conf',files):
                filename.append(files)  # 文件名及其路径添加到数组
    return filename  # 返回数组


def time_transmit(year, doy):
    JD = int(365.25 * (int(year) + 2000 - 1)) + int(30.6001 * 14) + 1720981.5 + int(doy)
    # 年份与年纪日转换为儒略历
    week = (JD - 2444244.5) / 7  # 儒略日转换为GPS周
    day = (week - int(week)) * 7  # GPS周内天数
    if int(week) < 1000:
        timetag = '0' + str(int(week)) + str(int(day+ 0.5))
    else:
        timetag = str(int(week)) +str(int(day+ 0.5))
        # 以精密产品命名字符串输出,例如‘19645’
        return timetag


def match_beph(year, doy):
    filename = []
    for files in os.listdir():  # 遍历目录文件名
        if doy in files:  # 文件内容是否包含关键字
            if year + 'p' in files:  # 'p文件'
                filename.append(files)  # 文件名及路径添加到数组
            elif year + 'n' in files:  # 'n文件'
                filename.append(files)
    if filename == []:
        print('* Error in beph matching')
    return filename


def match_sp3clk(timetag,sp3clk):
    filename = []
    # 精密产品提供机构
    acs = ['igs', 'esa', 'cod', 'gfz', 'grg', 'jpl', 'gbm', 'com', 'grm', 'wum']
    for files in os.listdir():  # 遍历目录文件名
        for ac in acs:
            peph = ac + timetag + '.' + sp3clk
            if peph == files:
                filename.append(files)  # 文件名及路径添加到数组
                break

    if filename == []:
        print('* Error in sp3clk matching')
    return filename


if __name__ == '__main__':
    obsfilelist = find_content('o')  # 找到观测文件
    if obsfilelist == []:
        print('* Error in obs matching')
    conffilelist = find_content('conf')  # 找到配置文件
    if obsfilelist == []:
        print('*Error in conf matching')
    for j in range(0, len(conffilelist)):
        for i in range(0, len(obsfilelist)):
            obsfile = obsfilelist[i]
            conffile = conffilelist[j]
            # 输出当前观测文件与配置文件信息
            print('* Processing the' + str(i + 1) + ' th obs file: ' + obsfile + ' with the conf: ' + conffile)
            year = obsfile[9:11]
            doy = obsfile[4:7]
            timetag = time_transmit(year, doy)  # 观测文件与年纪日转为精密产品的GPS周与周天数
            beph = match_beph(year, doy)  # 广播星历匹配
            sp3 = match_sp3clk(timetag,'sp3')  # 精密星历钟差匹配
            clk = match_sp3clk(timetag,'clk')  # 精密星历钟差匹配

            obs = obsfile.split('.', 1)
            conf = conffile.split('.', 1)
            pos = obs[0] + '.' + conf[0] + '.pos'  # 定位文件命名
            argv = ' ' + beph[0] + ' ' + sp3[0] + ' ' + clk[0]
            cmd = 'rnx2rtkp.exe ' + obsfile + argv + ' -k ' + conffile + ' -o ' + pos +' -x 1'
            print(cmd)  # 输出完整命令行
            subprocess.call(cmd, shell=True)

命令行结果输出示例:
在这里插入图片描述

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐