在GitHub上找到一个GNSSpy库,里面可以实现RINEX以及IONEX等格式文件下载、读取功能,比较实用,下载地址: GNSSpy
为了方便使用,我并没有直接安装这个库(一些函数还是需要修改的),只在这个库基础上做出一些修改方便自己用。在本次绘制电子含量图过程中,只用到了里面readFile.py里面的read_ionFile()函数。
from plotGIM import GIM_plot
GIM_plot("igsg3000.20i")
# -*- encoding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from readFile import read_ionFile
# 主函数
def GIM_plot(ion_file):
# Read VTEC data from ion file
lltec = read_ionFile(ion_file)
lltec = lltec*0.1 #i文件单位为0.1tecu
insti = ion_file[0:4]
day = ion_file[4:7]
yr = int(ion_file[9:11]) + 2000
# Generate a geodetic grid
for i in range(lltec.shape[0]):
ntecs = lltec.shape[0]
nlats = lltec.shape[1]
nlons = lltec.shape[2]
lats = np.linspace(-87.5, 87.5, nlats)
lons = np.linspace(-180, 180, nlons)
lon, lat = np.meshgrid(lons, lats)
tec = lltec[i] # 取第一个记录的tec值
# 设置地图全局属性
plt.rcParams['font.sans-serif'] = ['Times New Roman'] # 设置整体的字体为Times New Roman
plt.figure(figsize=(10, 6), dpi=600) # 设置大小和分辨率
# 创建底图,设置地图投影为World Plate Carrée,分辨率为高分辨率,地图范围为全球
m = Basemap(projection='cyl', resolution='h', llcrnrlon=-180, llcrnrlat=-90, urcrnrlon=180, urcrnrlat=90)
# 设置地图经纬线,并只在左端和底端显示
m.drawmeridians(np.arange(-180, 181, 30), labels=[0, 0, 0, 1], fontsize=10, linewidth=0.3, color='grey', ) # 经线
m.drawparallels(np.arange(-90, 90, 30), labels=[1, 0, 0, 0], fontsize=10, linewidth=0.3, color='grey') # 纬线
# 绘制地图
levels = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50] # 创建分级
color = ['#1e33b8', '#1e5cb3', '#3068a7', '#658d81', '#779a74', '#9ab25b', '#becb42', '#d0d736', '#e1e42a',
'#f3f01d'] # 设置色带
m.contourf(lon, lat, tec, levels=levels, extend='both', colors=color) # 绘图,并设置图例两端显示尖端
m.drawcoastlines(linewidth=0.5)
plt.title('Global Tec Map of ' + str(insti) + ' at ' + str(yr) + '-' + str(day) + '-' + str(2*i) + ':00', fontsize = 10)
# 设置图例
cb = m.colorbar(location='right', pad=0.1, size = 0.2) # 图例在右侧显示
cb.set_ticks(levels) # 设置色带刻度
cb.ax.tick_params(labelsize=10) # 刻度字号大小
cb.set_label('TECU', fontsize=10) # 设置图例名称和字体大小
fig_name = 'Tec Map of ' + str(insti) + ' at ' + str(yr) + '-' + str(day) + '-' + str(2*i) + '.png'
# 保存图片并显示
plt.savefig(fig_name, dpi=300, bbox_inches='tight',
pad_inches=0.1) # 输出地图,并设置边框空白紧密
plt.show() # 显示地图