Python 板


LINE

https://imgur.com/a/FADxycQ 如上图所示 档案内座标系统的经度是0-360 cartopy使用的座标系统经度应该是-180到180(我没看错的话) 我原先没有转换座标系统就出问题了 但转换座标系统後後还是有问题 请各位大神帮我看看这个应该怎麽处理 程式如下 import xarray as xr import matplotlib.pyplot as plt import numpy as np from scipy import stats from scipy.signal import detrend import cartopy.crs as ccrs # 读取.nc档案 dataset = xr.open_dataset('D:\PCCU\python\ERA5 monthly averaged data on single levels from 1940 to present.nc') # 选择1979到2020年间的数据 dataset = dataset.sel(time=slice('1979', '2020')) # 选择目标范围 precip_dataset = dataset.sel(longitude=slice(105, 125), latitude=slice(28, 20)) sst_dataset = dataset.sel(longitude=slice(80, 300), latitude=slice(60, -60)) # 将经度资料转换到 -180 到 180 的范围 longitude = sst_dataset.longitude.values longitude[longitude > 180] = longitude[longitude > 180] - 360 sst_dataset = sst_dataset.assign_coords(longitude=longitude) # 提取并转换降水资料单位 precip = precip_dataset['tp'].values * 1000 # 单位转换 # 提取SST资料 sst = sst_dataset['sst'].values # 进行空间平均 precip_mean = precip.mean(axis=(1, 2)) # 降水资料去趋势 precip_detrended = detrend(precip_mean) # 为绘制散布图和回归直线准备资料 time = np.arange(len(precip_detrended)) # 创建一个与 precip_detrended 相同长度的时间数组 # 执行回归并获取斜率和截距 slope, intercept, _, _, _ = stats.linregress(time, precip_detrended) # 绘制散布图和回归直线 plt.figure(figsize=(10, 6)) plt.scatter(time, precip_detrended, label='Detrended Precipitation') # 绘制散布图 plt.plot(time, slope*time + intercept, color='red', label='Regression Line') # 绘制回归直线 plt.xlabel('Time') plt.ylabel('Detrended Precipitation') plt.legend() plt.title('Scatter plot of Detrended Precipitation and Regression Line') plt.show() # 初始化一个空的阵列来存储斜率 (与 sst 没有时间维度的形状相同) slopes = np.empty(sst.shape[1:]) # 对每个网格点进行回归 for i in range(sst.shape[1]): for j in range(sst.shape[2]): finite_mask = np.isfinite(sst[:, i, j]) & np.isfinite(precip_detrended) if finite_mask.sum() > 0: slope, _, _, _, _ = stats.linregress(sst[finite_mask, i, j], precip_detrended[finite_mask]) slopes[i, j] = slope else: slopes[i, j] = np.nan # 绘图 fig = plt.figure(figsize=(12, 6)) ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(central_longitude=180)) #设定图中央位在太平洋上 p = ax.pcolormesh(sst_dataset.longitude, sst_dataset.latitude, slopes, cmap='RdBu_r') ax.coastlines() ax.set_extent([80, -60, -60, 60]) # 将绘图范围设定为东经80度到西经60度,北纬60度到南纬60度 plt.colorbar(p, ax=ax, orientation='vertical', label='Slope') plt.title('Regression slopes of SST and Detrended Precipitation') plt.show() 谢谢 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 101.3.2.161 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1690519180.A.0DF.html
1F:→ lycantrope: ax.contourf(lons,lats,slopes,\ 07/28 22:59
2F:→ lycantrope: transform=ccrs.PlateCarree()) 07/28 23:00







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP