Mekong River Basin Precipitation Analysis: Comparing BCC and ERA5 Data
import xarray as xr import geopandas as gpd import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter
加载bcc数据
dataset = xr.open_dataset(r'I:\CMIP6HR\highresSST-present\bcc.nc') pr_mean = dataset['pr_mean'] pr_frequency = dataset['pr_frequency'] pr_intensity = dataset['pr_intensity']
加载ERA5数据
era5_dataset = xr.open_dataset(r'I:\ERA5\era5.nc') tp_average = era5_dataset['tp_average'] tp_frequency = era5_dataset['tp_frequency'] tp_intensity = era5_dataset['tp_intensity']
加载shp文件
shapefile = gpd.read_file(r'I:\MekongRiverBasin_whole\MekongRiverBasin.shp') lat_min, lat_max = shapefile.bounds['miny'].min(), shapefile.bounds['maxy'].max() lon_min, lon_max = shapefile.bounds['minx'].min(), shapefile.bounds['maxx'].max()
筛选出shpfile内部的经纬度范围
pr_mean = pr_mean.sel(lat=slice(lat_min, lat_max), lon=slice(lon_min, lon_max)) pr_frequency = pr_frequency.sel(lat=slice(lat_min, lat_max), lon=slice(lon_min, lon_max)) pr_intensity = pr_intensity.sel(lat=slice(lat_min, lat_max), lon=slice(lon_min, lon_max))
计算每一行格点的平均值
pr_mean_avg = pr_mean.mean(dim='lon') pr_frequency_avg = pr_frequency.mean(dim='lon') pr_intensity_avg = pr_intensity.mean(dim='lon')
创建Figure和Axes对象
fig, axes = plt.subplots(1, 3, figsize=(12, 5), sharey=True)
绘制pr_mean变量的纬度变化曲线
axes[0].plot(pr_mean_avg.coords['lat'], pr_mean_avg) axes[0].set_xlabel('', fontsize=12) axes[0].set_ylabel('precipitation average/(mm/d)', fontsize=12) axes[0].set_title('', fontsize=12) axes[0].xaxis.set_major_formatter(FormatStrFormatter('%d°N')) axes[0].set_yticks([0, 100, 200, 300, 400]) # 设置y轴刻度标签
绘制pr_frequency变量的纬度变化曲线
axes[1].plot(pr_frequency_avg.coords['lat'], pr_frequency_avg) axes[1].set_xlabel('', fontsize=12) axes[1].set_ylabel('precipitation frequency/%', fontsize=12) axes[1].set_title('', fontsize=12) axes[1].xaxis.set_major_formatter(FormatStrFormatter('%d°N')) axes[1].set_yticks([0, 10, 20, 30, 40]) # 设置y轴刻度标签
绘制pr_intensity变量的纬度变化曲线
axes[2].plot(pr_intensity_avg.coords['lat'], pr_intensity_avg) axes[2].set_xlabel('', fontsize=12) axes[2].set_ylabel('precipitation intensity/(mm/h)', fontsize=12) axes[2].set_title('', fontsize=12) axes[2].xaxis.set_major_formatter(FormatStrFormatter('%d°N')) axes[2].set_yticks([0, 5, 10, 15, 20]) # 设置y轴刻度标签
绘制ERA5数据
axes[0].plot(pr_mean_avg.coords['lat'], tp_average.mean(dim='lon')) axes[1].plot(pr_frequency_avg.coords['lat'], tp_frequency.mean(dim='lon')) axes[2].plot(pr_intensity_avg.coords['lat'], tp_intensity.mean(dim='lon'))
plt.tight_layout() plt.show()
原文地址: https://www.cveoy.top/t/topic/bFTj 著作权归作者所有。请勿转载和采集!