如何解决如何组合我在下面定义的 3 个数组?
我有一个关于全世界土壤湿度水平 (mrso) 的大型数据文件。我想限制这些数据,使其仅涵盖欧洲。
mrso 数据具有维度(时间、纬度、经度)。因此,为了将其限制在欧洲,我想将纬度和经度维度限制为欧洲的维度。问题是 0 经度线位于欧洲。由于经度维度从 0 到 360,我需要将 mrso 经度从 330 限制到 360,然后从 0 到 45,然后以某种方式将它们组合起来,为我提供整个欧洲的 mrso。
以下是一些代理数据,试图澄清问题:
# Proxy data for latitude,longitude,time and soil moisture (mrso)
lat = np.linspace(-90,90,181)
lon = np.linspace(0,360,181)
time = np.linspace(0,70,71)
mrso = np.random.rand(len(time),len(lat),len(lon))
我尝试了以下代码来尝试将 mrso 数据限制在欧洲:
def findNearestIndex(vals,target):
# Finds the value within an array that is closest to the target value
minIndex = -1
minDiff = None
# Loop over all the values in the given list
for i in range(len(vals)):
# Find the absolute difference between this value and the target
diff = abs(vals[i] - target)
# If this is the first time,or if the difference is smaller than
# the smallest difference found so far,remember the difference and
# the index
if minDiff is None or diff < minDiff:
minDiff = diff
minIndex = i
return minIndex
def EU_Restrict(lat,lon,mrso):
# Find min and max lat and lon of Europe
max_lat = findNearestIndex(lat,75)
min_lat = findNearestIndex(lat,35)
max_lon = findNearestIndex(lon,45)
min_lon = findNearestIndex(lon,330)
end_lon = findNearestIndex(lon,360) #closest point corresponding to 360/0 lon
# Restrict mrso data to Europe
EU_mrso = np.concatenate((mrso[:,min_lat:max_lat,min_lon:end_lon],mrso[:,0:max_lon]))
return EU_mrso
但是,它返回以下错误消息: ValueError 回溯(最近一次调用) 在 () 第49话 50 ---> 51 map_EU_Restrict(5,r1i1p1f1_hist_path2000)
1 帧 在 EU_Restrict(model) 30 31 # 将 mrso 数据限制在欧洲 ---> 32 EU_mrso = np.concatenate((mrso[:,0:max_lon])) 33 返回 EU_mrso 34
array_function internals> in concatenate(*args,**kwargs)
ValueError: 串联轴的所有输入数组维度必须完全匹配,但沿维度 2,索引 0 处的数组大小为 12,索引 1 处的数组大小为 17
是 concatenate 函数不起作用,但我不知道实现我想要的另一种方法。有人有什么想法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。