运用python读取CMA的台风路径数据(txt格式),绘制台风路径,并有所经过的附近区域的全球地图作底图、经纬度划分。
数据集在此
链接:https://pan.baidu.com/s/1pYvefPpyHw0Nr3s_J-7PKA
提取码:93yz
运用python读取CMA的台风路径数据(txt格式),绘制台风路径,并有所经过的附近区域的全球地图作底图、经纬度划分。
数据集在此
链接:https://pan.baidu.com/s/1pYvefPpyHw0Nr3s_J-7PKA
提取码:93yz
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
# 读取并解析数据
with open('CH2021BST.txt', 'r') as f:
lines = f.readlines()
data = []
temp_data = []
for line in lines:
if '66666' in line:
if temp_data:
data.append(pd.DataFrame(temp_data, columns=['date', 'lat', 'lon', 'pressure', 'wind']))
temp_data = []
continue
split_line = line.split()
date = split_line[0]
lat = float(split_line[2]) / 10 # convert to standard degrees
lon = float(split_line[3]) / 10 # convert to standard degrees
pressure = split_line[4]
wind = split_line[5]
temp_data.append([date, lat, lon, pressure, wind])
# 在全球地图上绘制台风路径
fig = plt.figure(figsize=(12,9))
m = Basemap(projection='cyl', resolution='c', llcrnrlon=0, urcrnrlon=360, llcrnrlat=-90, urcrnrlat=90)
m.drawcoastlines()
m.drawparallels(range(-90,91,30), labels=[1,0,0,0])
m.drawmeridians(range(0,360,60), labels=[0,0,0,1])
m.fillcontinents(color='coral',lake_color='aqua')
m.drawmapboundary(fill_color='aqua')
# 绘制每个台风的路径
for typhoon in data:
m.plot(typhoon['lon'], typhoon['lat'], latlon=True)
plt.show()