请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5502|回复: 3

[经验总结] 天气学诊断与应用实习3

[复制链接]

新浪微博达人勋

发表于 2022-7-2 22:37:57 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 xiaoxiao啊 于 2022-7-2 22:40 编辑

可以参考实习2的函数将*.000格式文件转化为*.txt文件
涡度平流和温度平流同样可以使用metpy函数计算,需要灵活地使用,在这里留给大家自己思考!


import numpy as np
from scipy.interpolate import interp2d
from metpy.units import units
import metpy.calc as mpcalc
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cmaps


plt.rcParams['font.sans-serif'] = ['Times New Roman']
plt.rcParams['axes.unicode_minus'] = False


lon = np.arange(30, 160 + 2.5, 2.5)
lat = np.arange(80, 10 - 2.5, -2.5)
new_lon = np.arange(30, 160 + 0.5, 0.5)
new_lat = np.arange(10, 80 + 0.5, 0.5)


def my_interploate(*, var):
    func = interp2d(lon, lat, var, kind='cubic')
    return func(new_lon, new_lat)


def my_plot(*, level, time, var):
    u = np.loadtxt(f'u/{level}/{time}.txt')
    v = np.loadtxt(f'v/{level}/{time}.txt')
    t = np.loadtxt(f't/{level}/{time}.txt')

    u, v, t = u * units('m/s'), v * units('m/s'), t * units('degC')
    dx, dy = mpcalc.lat_lon_grid_deltas(lon, lat)
    vor = mpcalc.vorticity(u=u, v=v, dx=dx, dy=dy)
    div = mpcalc.divergence(u=u, v=v, dx=dx, dy=dy)
    new_div = my_interploate(var=div)
    new_vor = my_interploate(var=vor)

    fig = plt.figure(figsize=(6, 7), facecolor='w')
    ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
    day = str(time)[4:6]
    ax.set_title(f'2013-05-{day}_20:00:00', loc='right')
    ax.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.3, edgecolor='dimgrey')
    ax.add_feature(cfeature.LAKES.with_scale('110m'), linewidth=0.3, edgecolor='dimgrey', facecolor='none')
    ax.set_extent([90, 130, 20, 50], ccrs.PlateCarree())
    ax.set_xticks(np.arange(90, 140, 10), crs=ccrs.PlateCarree())
    ax.set_yticks(np.arange(20, 60, 10), crs=ccrs.PlateCarree())
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(which='major', width=0.5, length=5)
    ax.spines['geo'].set_linewidth(0.5)

    if var == 'div':
        clevels = np.arange(-7, 8, 1)
        ax.set_title(f'{level}hPa Divergence', loc='left')
        ax.contour(new_lon, new_lat, new_div * 1e+5, colors='k', linewidths=0.2, levels=clevels, transform=ccrs.PlateCarree())
        cf = ax.contourf(new_lon, new_lat, new_div * 1e+5, cmap=cmaps.NCV_blu_red, levels=clevels, transform=ccrs.PlateCarree())

    if var == 'vor':
        clevels = np.arange(-12, 14, 2)
        ax.set_title(f'{level}hPa Vorticity', loc='left')
        ax.contour(new_lon, new_lat, new_vor * 1e+5, colors='k', linewidths=0.2, levels=clevels, transform=ccrs.PlateCarree())
        cf = ax.contourf(new_lon, new_lat, new_vor * 1e+5, cmap=cmaps.NCV_blu_red, levels=clevels, transform=ccrs.PlateCarree())

    cb = fig.colorbar(cf, orientation='horizontal', shrink=0.95, pad=0.1, aspect=20, ticks=clevels)
    cb.outline.set_linewidth(0.1)
    cb.ax.tick_params(length=0)
    plt.savefig(f'{var}_{level}_{day}.png', dpi=300, bbox_inches='tight')


my_plot(level=500, time=13052520, var='div')
my_plot(level=500, time=13052620, var='div')
my_plot(level=850, time=13052520, var='div')
my_plot(level=850, time=13052620, var='div')
my_plot(level=500, time=13052520, var='vor')
my_plot(level=500, time=13052620, var='vor')
my_plot(level=850, time=13052520, var='vor')
my_plot(level=850, time=13052620, var='vor')


div_500_25.png
div_500_26.png
div_850_25.png
div_850_26.png
vor_500_25.png
vor_500_26.png
vor_850_25.png
vor_850_26.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2023-5-8 03:31:08 来自手机 | 显示全部楼层
这个是NCL的图片吧?不太像python画的,楼主上传错了吧?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2023-6-2 16:02:44 | 显示全部楼层
雪域小丹 发表于 2023-5-8 03:31
这个是NCL的图片吧?不太像python画的,楼主上传错了吧?

python画的,NCL画的比我好看
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2023-6-25 14:01:17 | 显示全部楼层
xiaoxiao啊 发表于 2023-6-2 16:02
python画的,NCL画的比我好看

平滑用的是什么呀?效果怎么这么好?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表