python气象可视化第二弹-黄河流域白化
生活随笔
收集整理的這篇文章主要介紹了
python气象可视化第二弹-黄河流域白化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
提示:文章寫完后,目錄可以自動生成,如何生成可參考右邊的幫助文檔
文章目錄
- 前言
- 在學習了氣象家園平流層的蘿卜首發、晉陵小生優化的 maskout 模塊白化功能之后。利用九大流域的shp文件,我對九大流域中黃河流域的降水分布進行了繪制。
- 一、使用maskout程序包的要點?
- 二、使用步驟
- 1.引入庫
- 2.繪制黃河流域降水分布圖
- 總結
前言
在學習了氣象家園平流層的蘿卜首發、晉陵小生優化的 maskout 模塊白化功能之后。利用九大流域的shp文件,我對九大流域中黃河流域的降水分布進行了繪制。
一、使用maskout程序包的要點?
maskout是比較python+cartopy實現白化功能的一個比較好用的子程序。(1)在應用的過程中要注意相關的shp文件應該是地理坐標系,如果不是的話要轉化坐標系。(詳情參考:如何使用arcmap轉換shp文件坐標系)(2)注意選擇合適的region,盡量選擇具有代表性的record。
相應的maskout_hhriver里應該修改為下圖所示:
二、使用步驟
1.引入庫
代碼如下(示例):
import os import shapefile as shp SHP = r'F:\mapshp\china_shp' import numpy as np import matplotlib import matplotlib.pyplot as plt import matplotlib.ticker as mticker import xarray as xr import cartopy.crs as ccrs import cartopy.feature as cfeature from cartopy.io.shapereader import Reader from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter import numpy import pandas as pd import mask_hhriver #設定新字體2.繪制黃河流域降水分布圖
代碼如下(示例):
#設定新字體 from matplotlib.font_manager import FontProperties lpfont = matplotlib.font_manager.FontProperties(fname='F:\python可視化\font\SimSun.ttf') plt.rcParams.update({'font.size':16})region=[95,120,32,42] df=xr.open_dataset(r'E:\testdataset\precip.mon.mean.nc') lat = df.lat lon = df.lon # lat = df['lat'] # lon = df['lon'] pre0 = df['precip'] #含缺測值 pre1 = np.array(pre0) pre_clim=np.nanmean(pre1,axis=0) fig=plt.figure(dpi=600,figsize=(12,6)) proj=ccrs.PlateCarree() ax = plt.axes(projection = proj) ax.set_extent(region, crs = proj) ax.set_xticks(np.arange(region[0], region[1] + 1, 5), crs = proj) ax.set_yticks(np.arange(region[-2], region[-1] + 1, 2), crs = proj) ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=False)) ax.yaxis.set_major_formatter(LatitudeFormatter()) # Add 黃河流域&干流shp c11=ax.contourf(lon,lat,pre_clim,np.arange(0,3,0.01),extend='both',transform=ccrs.PlateCarree(),cmap='gist_rainbow') ax.add_geometries(Reader(r'F:/mapshp/hhriver/jichu/黃河干流epsg4324.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='k',linewidth=0.5) clip=mask_hhriver.shp2clip(c11,ax,shpfile=os.path.join(SHP, 'China_nine_basinepsg4324.shp'),region=['Yellow River Basin'],proj= proj) cbar=plt.colorbar(c11,shrink=0.75,aspect=20,fraction=.03,pad=0.02) #aspect控制bar寬度,fraction控制大小比例,pad控制與圖的距離 cbar.set_ticks(np.arange(0,3,0.3)) #設置colorbar范圍和刻度標記間隔 cbar.ax.tick_params(labelsize=12, direction='in', right=False) #出圖 plt.savefig('prehh.png',dpi=600) plt.show()總結
最后還可以對圖片進行潤色,例如添加標題等等。參考氣象水文科研貓發布的Python可視化中國區域地面氣象要素驅動數據集—以黃河流域為例。基本實現了黃河流域的白化功能。
j
總結
以上是生活随笔為你收集整理的python气象可视化第二弹-黄河流域白化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: signature=d0108467db
- 下一篇: android+多米音乐+自动播放,an