如何导出导致\uu truediv \uuu错误的xarray数据集?

2024-09-28 01:33:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个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')

Tags: timedsarrayglobdaskxarrayncshape

热门问题