好奇心Log 发表于 2024-3-8 00:36:21

python绘图 | 多种台风路径可视化实现方法


台风是重大灾害性天气,台风引起的直接灾害通常由三方面造成,狂风、暴雨、风暴潮,除此以外台风的这些灾害极易诱发城市内涝、房屋倒塌、山洪、泥石流等次生灾害。正因如此,台风在科研和业务工作中是研究的重点。希望这次台风路径可视化可以给予大家一点点帮助。

台风路径的获取


中国气象局(CMA)


中国气象局(CMA)的台风最佳路径数据集(BST),BST是之后对历史台风路径进行校正后发布的,其经纬度、强度、气压具有更高的可靠性,但是时间分辨率为6小时,部分3小时,这一点不如观测数据。下载地址:http://tcdata.typhoon.org.cn/

温州台风网

温州台风网的数据是实时发布数据的记录,时间分辨率最高达1小时,对于台风轨迹具有更加精细化的表述。下载地址:http://www.wztf121.com/

示例
导入模块并读取数据,使用BST的2018年台风路径数据作为示例,已经将原始的txt文件转换为xls文件。

import os, glob
import pandas as pd
import numpy as np
import shapely.geometry as sgeom
import matplotlib.pyplot as plt
from matplotlib.image import imread
from matplotlib.animation import FuncAnimation
import matplotlib.lines as mlines
import cartopy.crs as ccrs
import cartopy.feature as cfeat
from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
import cartopy.io.shapereader as shpreader
import cartopy.io.img_tiles as cimgt
from PIL import Image
import warnings
warnings.filterwarnings('ignore')
df = pd.read_csv('./2018typhoon.csv')
定义等级色标

def get_color(level):
    global color
    if level == '热带低压' or level == '热带扰动':
      color='#FFFF00'
    elif level == '热带风暴':
      color='#6495ED'
    elif level == '强热带风暴':
      color='#3CB371'
    elif level == '台风':
      color='#FFA500'
    elif level == '强台风':
      color='#FF00FF'
    elif level == '超强台风':
      color='#DC143C'
    return color
定义底图函数

def create_map(title, extent):
    fig = plt.figure(figsize=(12, 8))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    url = 'http://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi'
    layer = 'BlueMarble_ShadedRelief'
    ax.add_wmts(url, layer)
    ax.set_extent(extent,crs=ccrs.PlateCarree())

    gl = ax.gridlines(draw_labels=False, linewidth=1, color='k', alpha=0.5, linestyle='--')
    gl.xlabels_top = gl.ylabels_right = False
    ax.set_xticks(np.arange(extent, extent+5, 5))
    ax.set_yticks(np.arange(extent, extent+5, 5))
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.xaxis.set_minor_locator(plt.MultipleLocator(1))
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.yaxis.set_minor_locator(plt.MultipleLocator(1))
    ax.tick_params(axis='both', labelsize=10, direction='out')

    a = mlines.Line2D([],[],color='#FFFF00',marker='o',markersize=7, label='TD',ls='')
    b = mlines.Line2D([],[],color='#6495ED', marker='o',markersize=7, label='TS',ls='')
    c = mlines.Line2D([],[],color='#3CB371', marker='o',markersize=7, label='STS',ls='')
    d = mlines.Line2D([],[],color='#FFA500', marker='o',markersize=7, label='TY',ls='')
    e = mlines.Line2D([],[],color='#FF00FF', marker='o',markersize=7, label='STY',ls='')
    f = mlines.Line2D([],[],color='#DC143C', marker='o',markersize=7, label='SSTY',ls='')
    ax.legend(handles=, numpoints=1, handletextpad=0, loc='upper left', shadow=True)
    plt.title(f'{title} Typhoon Track', fontsize=15)
    return ax
定义绘制单个台风路径方法,并绘制2018年第18号台风温比亚。

def draw_single(df):
    ax = create_map(df['名字'].iloc, )
    for i in range(len(df)):
      ax.scatter(list(df['经度'])<i>, list(df['纬度'])<i>, marker='o', s=20, color=get_color(list(df['强度'])<i>))

    for i in range(len(df)-1):
      pointA = list(df['经度'])<i>,list(df['纬度'])<i>
      pointB = list(df['经度']),list(df['纬度'])
      ax.add_geometries()], color=get_color(list(df['强度'])),crs=ccrs.PlateCarree())
    plt.savefig('./typhoon_one.png')
draw_single(df==1818])</i></i></i></i></i>

定义绘制多个台风路径方法,并绘制2018年全年的全部台风路径。

def draw_multi(df):
    L = list(set(df['编号']))
    L.sort(key=list(df['编号']).index)
    ax = create_map('2018', )
    for number in L:
      df1 = df==number]
      for i in range(len(df1)-1):
            pointA = list(df1['经度'])<i>,list(df1['纬度'])<i>
            pointB = list(df1['经度']),list(df1['纬度'])
            ax.add_geometries()], color=get_color(list(df1['强度'])),crs=ccrs.PlateCarree())
    plt.savefig('./typhoon_multi.png')
draw_multi(df)</i></i>

定义绘制单个台风gif路径演变方法,并绘制2018年第18号台风的gif路径图。

def draw_single_gif(df):
    for state in range(len(df.index))[:]:
      ax = create_map(f'{df["名字"].iloc} {df["时间"].iloc}', )
      for i in range(len(df[:state])):
            ax.scatter(df['经度'].iloc<i>, df['纬度'].iloc<i>, marker='o', s=20, color=get_color(df['强度'].iloc<i>))
      for i in range(len(df[:state])-1):
            pointA = df['经度'].iloc<i>,df['纬度'].iloc<i>
            pointB = df['经度'].iloc,df['纬度'].iloc
            ax.add_geometries()], color=get_color(df['强度'].iloc),crs=ccrs.PlateCarree())
      print(f'正在绘制第{state}张轨迹图')
      plt.savefig(f'./{df["名字"].iloc}{str(state).zfill(3)}.png', bbox_inches='tight')
    # 将图片拼接成动画
    imgFiles = list(glob.glob(f'./{df["名字"].iloc}*.png'))
    images =
    im = images
    filename = f'./track_{df["名字"].iloc}.gif'
    im.save(fp=filename, format='gif', save_all=True, append_images=images, duration=500)
draw_single_gif(df==1818])</i></i></i></i></i>


获取方法
示例数据、代码、图片获取,在「好奇心Log」公众号后台留言:台风路径

本文转自微信公众号:好奇心Log

FrankJScott 发表于 2024-9-26 21:24:27

Awesome Pshot Men Sarasota Website

In response to the lady talking about spa med, face beauty med spa, rejuvenation spa near me, radiance medspa reviews, reveal med spa, rejuvenate medical spa, med spa services, medical laser spa, beauty facial spa near me, pa med spa,I highly suggest this cool pshot men Sarasota info or med spa review, body beauty spa, lip facial near me, medical spa, medical aesthetics & laser, restoration medical, advanced aesthetics & med spa, beauty medical aesthetics, microneedling and botox together, st aesthetics, bearing in mind this more info for penis rejuvenation Sarasota site on top of med spa owner, med spa in, body laser spa, skin and body, o skin spa, home visit botox, best spa treatment for wrinkles, harmony medical aesthetics, face rejuvenation treatment, advanced aesthetics med spa, which is worth considering with this this site on penis botox injections in Sarasota forum which is also great. Also, have a look at this more bonuses about pshot Sarasota url on top of me time medspa, best injector near me, med spa close to me, full face rejuvenation, beauty medical aesthetics, aesthetics treatments, medical aesthetics treatments, aesthetics med spa, best place to get facial fillers near me, thera med spa, together with this her response on pshot men Sarasota url and don't forget sarasota microneedling, rejuvenate laser and med spa, face rejuvenation treatment, medspa botox near me, medical beauty spa near me,my website for on top of restoration spa, new skin med spa, be beautiful facial aesthetics, new medi spa, med spa sarasota fl,for good measure. Check more @ Cool Tajir4D Login Info c2cdecb
页: [1]
查看完整版本: python绘图 | 多种台风路径可视化实现方法