问题描述
我有一个 NetCDF 数据集,我正在尝试从我的数据变量中删除纬度和经度数据,以便它们可以被正确索引。每个数据变量的形状始终为 (x,1,1),其中 x 是我的数据点数,1 代表静态经度和纬度。我试过 xarray.Dataset.squeeze
和 xarray.Dataset.drop
和 xarray.DataArray.drop_vars
定位纬度和经度。我还用熊猫数据框尝试了它,纬度和经度仍然粘在我的变量上并阻止正确索引。如果您复制下面的代码,您将看到变量 'wave_height'
显示的形状为 (3411,1)。我想要一个使这个形状只是 (3411,) 的函数。
url = 'https://dods.ndbc.noaa.gov/thredds/fileServer/data/stdmet/46077/46077h2021.nc'
reqSpectra = urllib.request.Request(url)
with urllib.request.urlopen(reqSpectra) as respS:
ds_s = xr.open_dataset(io.BytesIO(respS.read()))
wh = ds_s.variables['wave_height']
wh
解决方法
我会使用 NumPy 的挤压来去除额外的维度。
class _Sigh extends _Vector {
anotherMethod() {
}
}
type Sigh<N extends number> = Vector<N> & { anotherMethod(): void };
interface SighConstructor { new <N extends number>(...init: Tuple<number,N>): Sigh<N>; }
const Sigh = _Sigh as SighConstructor;