- 积分
- 2005
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-4-7
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 LemonTree007 于 2019-3-28 16:10 编辑
- import netCDF4
- import matplotlib.pyplot as plt
- import numpy as np
- from mpl_toolkits.basemap import Basemap
- from eofs.standard import Eof
- # read uwind
- nc_obj = netCDF4.Dataset('D:\\wind_u_v\\ERA\\u.mon.mean.1958.2016.nc', 'r')
- print(nc_obj.variables.keys())
- lon = nc_obj.variables['longitude'][:]
- lat = nc_obj.variables['latitude'][:]
- time = nc_obj.variables['time'][:]
- level = nc_obj.variables['level'][2]
- u = nc_obj.variables['u'][:, :, :]
- nc_obj.close()
- # 截取研究区域和时段u风数据
- lat_bounds = [-5, 40]
- lon_bounds = [80, 130]
- # latitude lower and upper index
- lat_li = np.argmin(np.abs(lat - lat_bounds[0])) # argmin(array):返回范围内最小值的位置索引号
- lat_ui = np.argmin(np.abs(lat - lat_bounds[1]))
- # longitude lower and upper index
- lon_li = np.argmin(np.abs(lon - lon_bounds[0]))
- lon_ui = np.argmin(np.abs(lon - lon_bounds[1]))
- <b><font color="#008080">uSubset = u[:, lat_ui:lat_li, lon_li:lon_ui]</font></b>
- # 处理缺测数据
- u[u <= -32767] = np.nan
- # 计算u风夏季平均值
- u_JJA = np.zeros((59, lat_li-lat_ui, lon_ui-lon_li), dtype=np.float32)
- for i in range(59):
- for j in range(5, 8):
- u_JJA[i, :, :] = u_JJA[i, :, :] + uSubset[12*i+j, :, :]
- u_JJA[i, :, :] = u_JJA[i, :, :]/3.
复制代码 Traceback (most recent call last):
File "C:/Python_course/pygrads/test_eof.py", line 35, in <module>
u_JJA[i, :, :] = u_JJA[i, :, :] + uSubset[12*i+j, :, :]
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\ma\core.py", line 4077, in __radd__
return add(other, self)
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\ma\core.py", line 1019, in __call__
result = self.f(da, db, *args, **kwargs)
ValueError: operands could not be broadcast together with shapes (18,20) (3,20,144)
大概明白是因为两个数组之间的维数不同无法进行运算,但感觉维数都是三维,一样的呀
|
|