【发布时间】:2019-04-03 08:49:09
【问题描述】:
我有一个大的Dataset,数据组装中心想要添加一个新变量idstring,带有一个新维度idstring_len。 (我不知道他们为什么要把它作为一个新变量,而不是一个属性,但是......)
所以我有
import xarray as xr
import numpy as np
ds = xr.Dataset()
ds['time'] = ('time', np.arange(1000))
ds['boo'] = ('time', np.randome.randn(1000))
# File is saved in here, then `open_dataset` to get it again.
ds['idstr_len'] = ('idstr_len', 50)
ds['idstring'] = ('idstr_len', 'my_helpful_ID_string')
但这给了我ds['idstr_len'] = ...:
ValueError: dimensions ('idstr_len',) must have the same length as the number of data dimensions, ndim=0
所以我确信有一种好方法可以事后向数据集添加维度,但我不确定它是什么。
编辑:有关更多上下文,他们建议在原始 netcdf 中执行此操作的方式是:
TRAJECTORY_STRING = 'glider-YYYYmmddTHHMM'
trajectory = nc.createDimension('traj_strlen', len(TRAJECTORY_STRING))
trajectory = nc.createVariable('trajectory',
'S1',
('traj_strlen',))
我想我可以在事后使用原始 netcdf 接口完成所有这些工作。
【问题讨论】:
标签: python-xarray