使用Python批量下载IGS测站GNSS原始观测数据,并转换为.rnx格式

本文主要是介绍使用Python批量下载IGS测站GNSS原始观测数据,并转换为.rnx格式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

使用Python批量下载IGS测站GNSS原始观测数据,并转换为.rnx格式


前言

随着全球PPP-AR/PPP-RTK技术的日渐成熟,扩大了大规模使用IGS测站数据的需求,因此有必要开发一种可以直接批量获取IGS原始观测文件的工具

一、IGS测站网络

  1. IGS Network
    可以通过访问IGS官网的“NETWORK RESOURCES”板块查看测站分布及数量(https://igs.org/network-resources),截至2023年08月28日,共有513个IGS测站。
  2. 常用的IGS测站原始观测数据下载地址:
    1)武汉大学:ftp://igs.gnsswhu.cn/pub/gps/data/daily/
    2)CDDIS:https://cddis.nasa.gov/archive/gnss/data/daily/ (需要注册账户)
    3)IGS: ftp://igs.ign.fr/pub/igs/data/campaign/mgex/daily/
    更多下载地址可见:
    1)https://zhuanlan.zhihu.com/p/619226024?utm_id=0
    2)https://blog.csdn.net/qq_35099602/article/details/108183367

二、批量获取IGS测站原始观测数据代码

1.文件准备

根据需要的测站名,构建批量下载文件列表,如下图所示:

在这里插入图片描述


2. crx2rnx.exe准备

准备crx2rnx.exe,便于将下载得到的.crx.gz文件解压后转换为.rnx格式的观测文件。注意:crx2rnx.exe可放置于与.py文件同级目录下(无需再改下面的代码),也可能通过指定路径访问(见第三部分"convert_to_rnx"函数注释)。


3. 源代码

代码如下(示例):

from ftplib import FTP
from datetime import datetime
import os
import subprocess
import shutil
import gzip
def write_to_log(message, log_file):log_file.write(message + "\n")def extract_file(input_file_path):#解压并提取文件try:# 解压 .gz 文件output_file_path = input_file_path[:-3]  # 移除 .gz 扩展名with gzip.open(input_file_path, "rb") as gz_file, open(output_file_path, "wb") as output_file:shutil.copyfileobj(gz_file, output_file)return output_file_pathexcept Exception as e:print(f"Error during extraction: {str(e)}")return Nonedef rename_file_to_xxd(input_file_path,year):#重命名文件try:new_file_path = input_file_path[:-4]new_file_path = new_file_path+"." + year+"d"os.rename(input_file_path, new_file_path)return new_file_pathexcept Exception as e:print(f"Error during renaming: {str(e)}")return Nonedef convert_to_rnx(input_file_path):#转换为.rnx格式文件try:subprocess.run(["crx2rnx.exe", input_file_path])#可以更改.exe的路径return Trueexcept Exception as e:print(f"Error during conversion: {str(e)}")return Falsedef download_file_from_ftp(ftp_host, remote_file_path, local_file_path):#通过访问ftp下载文件with FTP(ftp_host) as ftp:ftp.login()try:with open(local_file_path, "wb") as local_file:ftp.retrbinary("RETR " + remote_file_path, local_file.write)#write_to_log(f"Downloaded {remote_file_path} successfully.",log_file)return Trueexcept Exception as e:#write_to_log(f"Downloaded {remote_file_path} failed.",log_file)return Falsedef download_files_from_list(ftp_host, file_list_path, output_folder,log_file):#根据文件列表下载文件with open(file_list_path, "r") as file_list:logfile=open(log_file, "w")for line in file_list:file_name = line.strip()year=file_name[12:16];doy=file_name[16:19];remote_file_path = f"/pub/gps/data/daily/{year}/{doy}/{year[2:4]}d/{file_name}"  # 替换为实际的远程目录和文件名local_file_path = os.path.join(output_folder, file_name)success = download_file_from_ftp(ftp_host, remote_file_path, local_file_path)timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")  # 获取当前时间戳if success:write_to_log(f"{timestamp} Downloaded {remote_file_path} successfully.",logfile)extracted_file_path = extract_file(local_file_path)if extracted_file_path:write_to_log(f"Processed {file_name} successfully.",logfile)renamed_file_path = rename_file_to_xxd(extracted_file_path,year[2:4])if renamed_file_path:write_to_log(f"Renamed {extracted_file_path} to {renamed_file_path}.",logfile)if convert_to_rnx(renamed_file_path):write_to_log(f"Converted {renamed_file_path} to RINEX format.",logfile)else:write_to_log(f"Conversion of {renamed_file_path} failed.",logfile)else:write_to_log(f"Renaming of {extracted_file_path} failed.",logfile)else:write_to_log(f"Processing of {file_name} failed.",logfile)else:write_to_log(f"{timestamp} Downloaded {remote_file_path} failed.",log_file)if __name__ == "__main__":ftp_host = "igs.gnsswhu.cn"  # 替换为实际的FTP主机名或IP地址file_list_path = "C:/Users/DELL/Desktop/data/file.txt"  # 替换为实际的文件名列表文本文件路径output_folder = "C:/Users/DELL/Desktop/data/"  # 替换为实际的本地保存文件夹路径log_file = "C:/Users/DELL/Desktop/data/download_log.txt"download_files_from_list(ftp_host, file_list_path, output_folder,log_file)

4. 结果

在这里插入图片描述
在这里插入图片描述


总结

以上就是一个简单的、可直接运行的IGS测站观测数据批量下载小工具,欢迎交流讨论!

这篇关于使用Python批量下载IGS测站GNSS原始观测数据,并转换为.rnx格式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/245748

相关文章

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

SpringBoot中六种批量更新Mysql的方式效率对比分析

《SpringBoot中六种批量更新Mysql的方式效率对比分析》文章比较了MySQL大数据量批量更新的多种方法,指出REPLACEINTO和ONDUPLICATEKEY效率最高但存在数据风险,MyB... 目录效率比较测试结构数据库初始化测试数据批量修改方案第一种 for第二种 case when第三种

python生成随机唯一id的几种实现方法

《python生成随机唯一id的几种实现方法》在Python中生成随机唯一ID有多种方法,根据不同的需求场景可以选择最适合的方案,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习... 目录方法 1:使用 UUID 模块(推荐)方法 2:使用 Secrets 模块(安全敏感场景)方法

一文详解如何使用Java获取PDF页面信息

《一文详解如何使用Java获取PDF页面信息》了解PDF页面属性是我们在处理文档、内容提取、打印设置或页面重组等任务时不可或缺的一环,下面我们就来看看如何使用Java语言获取这些信息吧... 目录引言一、安装和引入PDF处理库引入依赖二、获取 PDF 页数三、获取页面尺寸(宽高)四、获取页面旋转角度五、判断

MyBatis-Plus通用中等、大量数据分批查询和处理方法

《MyBatis-Plus通用中等、大量数据分批查询和处理方法》文章介绍MyBatis-Plus分页查询处理,通过函数式接口与Lambda表达式实现通用逻辑,方法抽象但功能强大,建议扩展分批处理及流式... 目录函数式接口获取分页数据接口数据处理接口通用逻辑工具类使用方法简单查询自定义查询方法总结函数式接口

C++中assign函数的使用

《C++中assign函数的使用》在C++标准模板库中,std::list等容器都提供了assign成员函数,它比操作符更灵活,支持多种初始化方式,下面就来介绍一下assign的用法,具有一定的参考价... 目录​1.assign的基本功能​​语法​2. 具体用法示例​​​(1) 填充n个相同值​​(2)

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

SQL server数据库如何下载和安装

《SQLserver数据库如何下载和安装》本文指导如何下载安装SQLServer2022评估版及SSMS工具,涵盖安装配置、连接字符串设置、C#连接数据库方法和安全注意事项,如混合验证、参数化查... 目录第一步:打开官网下载对应文件第二步:程序安装配置第三部:安装工具SQL Server Manageme

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

深入理解Go语言中二维切片的使用

《深入理解Go语言中二维切片的使用》本文深入讲解了Go语言中二维切片的概念与应用,用于表示矩阵、表格等二维数据结构,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧... 目录引言二维切片的基本概念定义创建二维切片二维切片的操作访问元素修改元素遍历二维切片二维切片的动态调整追加行动态