吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1914|回复: 12
上一主题 下一主题
收起左侧

[Python 原创] 500hPa高度场绘制(多年平均图月平均,并形成动画)

[复制链接]
跳转到指定楼层
楼主
wsy11 发表于 2022-12-2 18:26 回帖奖励
最近在研究天气图
下载了1991-2020的多年月平均数据
按照月份绘制500hPa高度场
并绘制了动画,以便于分析

结果如下:



源文件:
链接:https://pan.quark.cn/s/49ce3534cc14
提取码:jZA1


代码如下:
[Python] 纯文本查看 复制代码
import cmaps
import netCDF4 as nc
from netCDF4 import Dataset
import matplotlib.pyplot as plt
import matplotlib.patches as mpt
import numpy as np

import xarray as xr
import cartopy.feature as cf
import pandas as pd
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
from cartopy.util import add_cyclic_point
import imageio

frames = []
for i in range(12):
    #1、地图设置
    fig =plt.figure(figsize=(8,6))
    crs= ccrs.PlateCarree(central_longitude=180)
    box=[-180,180,-90,90]
    resolution ='50m'
    xstep,ystep =60,30
    ax= plt.axes(projection=crs)
    #设定范围
    ax.set_extent(box,crs=crs)
    
    #附加元素(陆地、河流、湖泊)
    # ax.add_feature(cfeature.LAND)
    # ax.add_feature(cfeature.LAKES,alpha=0.5)
    #添加河流
    # ax.add_feature(cfeature.RIVERS)
    #国界线
    ax.add_feature (cfeature.BORDERS,linestyle=':')
    #显示国界线
    # ax.coastlines(resolution)
    # ax.stock_img()
    
    #2、坐标设置
    ax.set_xticks(np.arange(box[0],box[1]+xstep,xstep),crs=crs)
    ax.set_yticks(np.arange(box[2],box[3]+ystep,ystep),crs=crs)
    #zero direction label用来设置经度的0度加不加E和w
    lon_formatter=LongitudeFormatter(zero_direction_label=False)
    lat_formatter=LatitudeFormatter()
    ax.xaxis.set_major_formatter(lon_formatter)
    ax.yaxis.set_major_formatter(lat_formatter)
    #添加海岸线
    ax.coastlines('110m',lw=1,ls='--')
    # ax.stock_img()
    
    nc_obj = Dataset('hgt.mon.ltm.1991-2020.nc')
    #['level', 'lat', 'lon', 'time', 'climatology_bounds', 'hgt', 'valid_yr_count']
    # print(nc_obj.variables.keys())
    
    # 3、读取数据值
    #深度: level(level),,[1000.  925.  850.  700.  600.  500.  400.  300.  250.  200.  150.  100. 70.   50.   30.   20.   10.]
    # print(nc_obj.variables['level'])
    level = (nc_obj.variables['level'][:])
    #lat(lat),[ 90. -90.]
    # print(nc_obj.variables['lat'])
    lat = (nc_obj.variables['lat'][:])
    #lon(lon),[  0.  357.5]
    # print(nc_obj.variables['lon'])
    lon= np.array(nc_obj.variables['lon'][:])-180
    #hgt(time, level, lat, lon),[ -700. 35000.]
    # print(nc_obj.variables['hgt'])
    
    hgt = nc_obj.variables['hgt'][i][5]
    
    #消除白线
    hgt,lon=add_cyclic_point(hgt,coord=lon)
    lon,lat=np.meshgrid(lon,lat)
    
    #4、绘图
    levels=np.arange(5000,6000,40)
    levels2=np.arange(5000,6000,40)
    ac1=ax.contour(lon,lat,hgt,transform=crs,levels=levels,extend='both',colors='k',linewidths=0.5)
    ax.clabel(ac1,inline=True,levels=levels2,fontsize=4,fmt='%.0f')
    ac2=ax.contourf(lon,lat,hgt,transform =crs,levels=levels,cmap=cmaps.matlab_jet,extend='both')
    fig.colorbar(ac2,ax=ax,extend='both',shrink=0.60)
    plt.rcParams['font.sans-serif']=['microsoft YaHei']
    plt.rcParams['axes.unicode_minus']=False#负号
    ax.set_title(str(i+1)+'月多年平均(1991-2020)500hPa高度场')
    plt.savefig(str(i+1)+'月多年平均(1991-2020)500hPa高度场',dpi=300,bbox_inches = 'tight')
    frames.append(imageio.imread(str(i+1)+'月多年平均(1991-2020)500hPa高度场.png'))
    plt.show()

gif_name='多年平均(1991-2020)500hPa高度场.gif'
imageio.mimsave(gif_name, frames, fps=1)

免费评分

参与人数 3吾爱币 +11 热心值 +2 收起 理由
smile1110 + 3 + 1 热心回复!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
woaita + 1 用心讨论,共获提升!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
绿叶红花 发表于 2022-12-5 11:10
wsy11 发表于 2022-12-2 23:16
https://psl.noaa.gov/data/gridded/data.ncep.reanalysis.html
网站是这个,数据网站漏发了

想问的是天气数据,如降雨量等等
推荐
 楼主| wsy11 发表于 2022-12-2 23:16 |楼主
绿叶红花 发表于 2022-12-2 20:25
请问数据那里下载??

https://psl.noaa.gov/data/gridded/data.ncep.reanalysis.html
网站是这个,数据网站漏发了
3#
绿叶红花 发表于 2022-12-2 20:25
4#
MrRight929 发表于 2022-12-2 20:26
感谢楼主无私分享,万分感谢~~~
5#
MrRight929 发表于 2022-12-2 20:28
感谢楼主无私分享,万分感谢~~~
6#
runfog 发表于 2022-12-2 21:01
多年月平均数据看不知道
7#
qinghuayuan 发表于 2022-12-2 23:58
谢谢分享!!!
8#
wan456 发表于 2022-12-3 00:26
按月到按年简单,反推到按日,无法实现
9#
lfordch 发表于 2022-12-3 03:54
感谢分享,学习学习!
10#
chc 发表于 2022-12-3 07:55
久违了500hpa高度场,有一种又见老朋友的感觉!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-19 14:44

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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