0

ValueError: 无法转换形式的元组 (dims, data[, attrs, encoding]):

我在构建这个数据集时遇到问题,我不知道如何解决它,我尝试了很多解决方案,它给了我同样的错误

import cfgrib
import glob
import xarray as xr
import pandas as pd 


folder = input('Folder Path:')
val = input('Variable Name:')

files = glob.glob(rf'{folder}/*.grib2')

data_conc=[]

for file in files:

     data = xr.open_dataset(file,engine='cfgrib',
     backend_kwargs={'filter_by_keys':{'typeOfLevel': 'hybrid'}})
 
 
     lon  = data.variables['longitude'].values
     lat  = data.variables['latitude'].values
     hyb  = data.variables['hybrid'].values
     time = pd.Timestamp(data.time.values) + pd.to_timedelta(data.step.values,'H')
 
     X = xr.Dataset(
                    data_vars = { 
                    'data':(['Alt','lat','lon'], data[val].values)
                                 },
                    coords = {
                              'Alt':(['lat','lon'],hyb),
                              'lat':(['lat','lon'],lat),
                              'lon':(['lat','lon'],on),
                              'time':time
                               },
     
                    )

 
     data_conc.append(X) 
4

1 回答 1

0

你现在可能已经找到答案了。如果没有,请尝试重塑坐标值,看看是否有帮助。

import numpy as np
     lon  = np.reshape(data.variables['longitude'].values, (1, -1))
     lat  = np.reshape(data.variables['latitude'].values, (1, -1))
     hyb  = np.reshape(data.variables['hybrid'].values, (1, -1))
于 2021-08-24T17:28:27.960 回答