[英]How can I export an xarray dataset that is leading to a __truediv__ error?
我有一個由一堆文件連接而成的xarray數據集。
<xarray.Dataset>
Dimensions: (hru: 17, time: 233)
Coordinates:
* hru (hru) int64 9 17 11 8 3 2 6 4 7 12 1 13 10 16 15 5 14
* time (time) datetime64[ns] 2010-01-01 ... 2010-01-30
Data variables:
pptrate (time, hru) float64 9.241e-05 9.241e-05 ... 2.717e-09
hruId (hru) int64 dask.array<shape=(17,), chunksize=(1,)>
averageInstantRunoff (time, hru) float64 9.241e-05 9.241e-05 ... 2.717e-09
nSnow (time, hru) int32 dask.array<shape=(233, 17), chunksize=(233, 1)>
nSoil (time, hru) int32 dask.array<shape=(233, 17), chunksize=(233, 1)>
nLayers (time, hru) int32 dask.array<shape=(233, 17), chunksize=(233, 1)>
當我嘗試導出ds.to_netcdf('test.nc')
我收到此錯誤消息:
TypeError: cannot perform __truediv__ with this index type: <class 'pandas.core.indexes.datetimes.DatetimeIndex'>
不知道是什么問題。
這是生成ds
的代碼
import xarray as xr
import glob, os
NCDIR = './output/out/'
finalfile = 'summaout.nc'
outfilelist = glob.glob((NCDIR+'/*{}*.nc').format('basin_*timestep'))
ds=xr.open_mfdataset(outfilelist, concat_dim='hru')
replace = ds['pptrate']
runoff = ds['averageInstantRunoff'].values
runoff = np.squeeze(runoffdata, axis=2)
runoff = runoff.transpose()
replace.values = runoff
ncconvert = ds.drop('averageInstantRunoff')
runoffarray = xr.DataArray(runoff, dims=['time','hru'])
ds['averageInstantRunoff'] = runoffarray
ds.to_netcdf('test.nc')
已將Pandas從Numpy更新到最新版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.