爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 280|回复: 0

有朋友用过xeofs库的mv-eof吗?有如下问题

[复制链接]

新浪微博达人勋

发表于 2024-5-20 14:43:43 | 显示全部楼层 |阅读模式
Python
系统平台: Python
问题截图: -
问题概况: 这是官方给出的例子,但是只对海温进行了分解,且是将全球按经度分成4份,我想用海平面气压、850hpa,500hpa气压等不同要素进行多变量eof分解,将每个变量组合在一起以后形成了(n,lat,lon)的数组,但是在使用pca.fit()时出现了报错MergeError: conflicting values for variable 'level' on objects to be combined. You can skip this check by specifying compat='override'.,除此之外还想求问如何计算各个变量的贡献率呢?
我看过提问的智慧: 看过
自己思考时长(天): 1

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

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

x
官方例子
"""
Multivariate EOF analysis
============================================

Multivariate EOF analysis.
"""

# Load packages and data:
import xarray as xr
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from cartopy.crs import PlateCarree

from xeofs.models import EOF

# Create four different dataarrayss
sst = xr.tutorial.open_dataset("ersstv5")["sst"]
subset1 = sst.isel(lon=slice(0, 45))
subset2 = sst.isel(lon=slice(46, 90))
subset3 = sst.isel(lon=slice(91, 135))
subset4 = sst.isel(lon=slice(136, None))
multivariate_data = [subset1, subset2, subset3, subset4]

# %%
# Perform the actual analysis

pca = EOF(n_modes=10, standardize=False, use_coslat=True)
pca.fit(multivariate_data, dim="time")
components = pca.components()
scores = pca.scores()

# %%
# Plot mode 1

mode = 5
proj = PlateCarree()
kwargs = {
    "cmap": "RdBu",
    "vmin": -0.05,
    "vmax": 0.05,
    "transform": proj,
    "add_colorbar": False,
}

fig = plt.figure(figsize=(7.3, 6))
fig.subplots_adjust(wspace=0)
gs = GridSpec(2, 4, figure=fig, width_ratios=[1, 1, 1, 1])
ax = [fig.add_subplot(gs[0, i], projection=proj) for i in range(4)]
ax_pc = fig.add_subplot(gs[1, :])

# PC
scores.sel(mode=mode).plot(ax=ax_pc)
ax_pc.set_xlabel("")
ax_pc.set_title("")

# EOFs
for i, (a, comps) in enumerate(zip(ax, components)):
    a.coastlines(color=".5")
    comps.sel(mode=mode).plot(ax=a, **kwargs)
    a.set_xticks([], [])
    a.set_yticks([], [])
    a.set_xlabel("")
    a.set_ylabel("")
    a.set_title("Subset {:}".format(i + 1))
ax[0].set_ylabel("EOFs")
fig.suptitle("Mode {:}".format(mode))
plt.savefig("multivariate-eof-analysis.jpg")


密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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