ValueError: Could not convert tuple of form (dims, data[, attrs, encoding]):
I have a problem building this dataset and I couldn't know how to solve it, I try many solutions and it gives me the same error
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)
You may have find your answer by now. If not, try to reshape the coordinate values and see if that helps.