Dask 延迟慢:如何在两个数据集之间快速选择/插值

Dask 延迟慢:如何在两个数据集之间快速选择/插值,dask,python-xarray,dask-delayed,Dask,Python Xarray,Dask Delayed,我有两个数据集(称为satdata和atmosdata)。大气数据在纬度和经度上均匀网格化。Atmosdata具有维度(纬度:713,级别:37,经度:1440,时间:72),总大小为12GB。大气数据有几个变量,如温度、湿度等。湿度的形状为(时间、水平、纬度、经度) Satdata包含卫星观测数据,其尺寸为(跨轨道:90,通道:3,时间:32195),90*3*32195=8692650个数据点。交叉轨道是指卫星FOV交叉轨道位置。Satdata在纬度/经度上不是均匀网格化的。例如,satda

我有两个数据集(称为satdata和atmosdata)。大气数据在纬度和经度上均匀网格化。Atmosdata具有维度(纬度:713,级别:37,经度:1440,时间:72),总大小为12GB。大气数据有几个变量,如温度、湿度等。湿度的形状为(时间、水平、纬度、经度)

Satdata包含卫星观测数据,其尺寸为(跨轨道:90,通道:3,时间:32195),90*3*32195=8692650个数据点。交叉轨道是指卫星FOV交叉轨道位置。Satdata在纬度/经度上不是均匀网格化的。例如,satdata.latitude的维度为(时间、通道、跨_轨道),与satdata.longitude、satdata.sft的维度相同

Atmosdata和satdata中的“time”变量包含同一天内的时间,但这两个数据集中的值不同。我需要找到大气数据(例如湿度和温度),它与卫星数据具有相同的纬度、经度和时间

为了实现这一点,我迭代satdata以找到每次观测的位置和时间;然后找到相应的大气数据(首先是距离卫星数据位置最近的网格,然后插值到卫星时间)。最后,我将所有迭代的结果数据连接到一个数据集中

通过使用一小段数据,我的代码的一部分如下所示

import xarray as xr
import numpy as np
import dask
import pandas as pd

# define a simple satdata dataset
lon = np.array([[18.717, 18.195, 17.68  ], [18.396, 17.87 , 17.351, ]])
lat = np.array([[-71.472, -71.635, -71.802],
   [-71.52 , -71.682, -71.847]])
sft = np.array([[1, 1, 1],
   [1, 1, 1]])
time = np.array(['2010-09-07T00:00:01.000000000', '2010-09-07T00:00:03.000000000'],dtype='datetime64[ns]')
satdata = xr.Dataset({'sft': (['time','across_track'], sft)}, coords = {'longitude': (['time','across_track'], lon), 'latitude': (['time','across_track'], lat), 'time':time })

# atmosdata
atmoslat = np.array([-71.75, -71.5 , -71.25, -71.  , -70.75, -70.5 , -70.25, -70.  , -69.75 ])
atmoslon = np.array([17.25, 17.5 , 17.75, 18.  , 18.25, 18.5 , 18.75, 19.  , 19.25])
atmostime = np.array(['2010-09-07T00:00:00.000000000', '2010-09-07T01:00:00.000000000'],dtype='datetime64[ns]')

atmosq = np.random.rand(2,9,9)
atmosdata = xr.Dataset({'q': (['time', 'latitude', 'longitude'], atmosq)}, coords={'longitude':(['longitude'], atmoslon), 'latitude': (['latitude'], atmoslat), 'time':(['time'], atmostime)})

# do the matching:
matched = dask.compute(match(atmosdata, satdata),scheduler='processes',  num_workers=20)[0]
匹配功能如下:

@dask.delayed
def match(atmosdata, satdata):
    newatmos = []
    newind = 0
    # iterate over satdata
    for i in np.ndenumerate(satdata.sft):
        if i[1] != np.nan:
           # find one latitude and longitude of satellite data
           temp_lat = satdata.latitude.isel(time=[i[0][0]], across_track=[i[0][1]])
           temp_lon = satdata.longitude.isel(time=[i[0][0]],  across_track=[i[0][1]])
           # find the atmosdata in the grid nearest to this location
           temp_loc  =  atmosdata.sel(latitude =temp_lat.values.ravel()[0], longitude = temp_lon.values.ravel()[0], method='nearest')
           if temp_loc.q.all() > 0:
               # find atmosdata at the satellite time by interpolation
               temp_time = satdata.time.isel(time=[i[0][0]])
               newatmos.append(temp_loc.interp( time = temp_time.data.ravel() ))
               newind += 1

    return xr.concat(newatmos,dim=pd.Index(range(newind), name='NewInd'))
1) 当我启动代码时,它就工作了。但是如果我不在代码中使用较小的数据量,而是使用我的原始数据(具有上面提到的维度),那么我启动计算并得到错误

---> 52 matched = dask.compute(match(ecmwfdata, ssmis_land), scheduler='processes', num_workers=20 )
error: 'i' format requires -2147483648 <= number <= 2147483647
-->52 matched=dask.compute(match(ecmwfdata,ssmis_land),scheduler='processs',num_workers=20)

错误:“i”格式需要-2147483648我不确定我是否能提供帮助,只是说我认为您需要使用使用距离树的重采样包

Pyresample有一个条带网格,它可以做您想要做的事情


我曾经找到最近的点

嗨,小尼,欢迎光临。你介意和我共用一个房间吗?我想有一种比for循环更好的方法来过滤数据。嗨,我试着缩短帖子,希望它更好。如果你能提供一个数据集的样本会更好。即使是它的虚拟版本也很好用。是的,我创建了一个非常小的数据集来测试代码。提前谢谢!如果您还将atmosdata定义为一个简单的虚拟数据集,那么人们就可以测试您的功能了。