BSRN地表基准辐射网数据批量下载
1. BSRN数据介绍
BSRN(https://bsrn.awi.de/)是来自全球能源和水交换(GEWEX)的数据和分析面板的一个项目,因此旨在检测地球表面的地球辐射场的重要变化,这可能与气候变化有关。
- LR 0100 基本测量(全球,直射,漫射,上行长波,空气温度,相对湿度,压力)
- LR 0300 其他测量值(上行短波,上行长波,净辐射)
- LR 0500 紫外测量(UV-A,UB-B)
- LR 1000 表面SYNOPS
- LR 1100 辐射测量
- LR 1200 臭氧测量
- LR 1300 用仪器(总云量,云碱基高,云液体水)扩展的测量值
- LR 3nnn 高度在nnn米处的其他测量值(全球,上行短波,下行长波,上行长波,空气温度,相对湿度)
- LR 4000 净辐射和仪器温度(圆顶和身体)
- LR 4nnn 在nnn米高度处仪器温度(圆顶和身体)
2. 数据存储格式
按级别、年份存储,未提供批量筛选下载方式,具体数据存储页面如下(https://dataportals.pangaea.de/bsrn/?q=LR0100)。
3. 数据下载方式
3.1 手动下载
根据数据需求,选择相应的级别和年份,单独点击数据doi页面进行下载。
3.2 批量下载
若下载的年份较多,需要用代码实现批量下载。
3.2.1 将所有需要下载的数据的网页整理到txt文档,如下图所示。
3.2.2 利用python代码,将doi整理成下载的网页链接。
import re# 设置输入输出文件路径
input_file = r"E:\SXF_up.txt" # 原始文本文件路径
output_file = r'E:\output_links.txt' # 生成的下载链接文件路径# 读取原始文本
with open(input_file, 'r', encoding='utf-8') as f:text = f.read()# 提取所有 DOI 链接
doi_urls = re.findall(r'https://doi\.org/10\.1594/PANGAEA\.\d+', text)# 转换为 PANGAEA 下载链接
download_links = [url.replace('https://doi.org', 'https://doi.pangaea.de') + '?format=textfile&charset=UTF-8'for url in doi_urls
]# 去重并排序(可选)
download_links = sorted(set(download_links))# 写入输出文件
with open(output_file, 'w', encoding='utf-8') as f:for link in download_links:f.write(link + '\n')print(f"{len(download_links)} links written to {output_file}")
整理后的文档如下所示:
3.2.3 运行批量下载的代码
import os
import requests
from urllib.parse import unquote# 输入链接文件路径和输出目录
link_file = r"E:\output_links.txt"
output_dir = r"E:\BSRN\PSU\up"# 创建保存目录
os.makedirs(output_dir, exist_ok=True)# 读取所有下载链接
with open(link_file, 'r', encoding='utf-8') as f:links = [line.strip() for line in f if line.strip()]# 下载文件
for url in links:try:print(f"Downloading: {url}")response = requests.get(url, allow_redirects=True)response.raise_for_status()# 提取服务器返回的原始文件名(Content-Disposition 头)cd = response.headers.get('Content-Disposition', '')filename = Noneif 'filename=' in cd:filename = cd.split('filename=')[-1].strip().strip('"')filename = unquote(filename) # 处理URL编码else:# 如果服务器没返回,就用最后路径部分filename = url.split('/')[-1].split('?')[0] + '.txt'file_path = os.path.join(output_dir, filename)# 保存文件with open(file_path, 'wb') as f_out:f_out.write(response.content)print(f"Saved as: {file_path}")except Exception as e:print(f"❌ Failed to download {url}: {e}")
最后,就可以在相应的文件夹中检查下载的数据了。