Skip to content

Can't access variables in the subgroup #2731

Closed
@zxdawn

Description

@zxdawn

Code Sample

import xarray as xr 
from netCDF4 import Dataset

rootgrp = Dataset("test.nc", "w", format="NETCDF4")
fcstgrp = rootgrp.createGroup("forecasts")

lat = rootgrp.createDimension("lat", 73)
lon = rootgrp.createDimension("lon", 144)
latitudes = rootgrp.createVariable("lat","f4",("lat",))
longitudes = rootgrp.createVariable("lon","f4",("lon",))

temp = rootgrp.createVariable("temp","f4",("lat","lon",))
ftemp = rootgrp.createVariable("/forecasts/temp","f4","lat","lon",)
rootgrp.close()

ds = xr.open_dataset('test.nc')
print (ds['temp'])
print (ds['/forecasts/temp'])

Problem description

The temp variable in the / group can be accessed successfully, but temp in the /forecasts group not.
It says:

KeyError: '/forecasts/temp'

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.8.final.0 python-bits: 64 OS: Linux OS-release: 4.9.0-8-amd64 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_US.utf8 LOCALE: en_US.UTF-8

xarray: 0.11.0
pandas: 0.23.4
numpy: 1.15.4
scipy: 1.1.0
netCDF4: 1.4.2
h5netcdf: 0.5.1
h5py: 2.8.0
Nio: None
zarr: None
cftime: 1.0.0
PseudonetCDF: None
rasterio: None
iris: 2.2.0
bottleneck: 1.2.1
cyordereddict: None
dask: 0.16.1
distributed: 1.20.2
matplotlib: 3.0.2
cartopy: 0.17.0
seaborn: 0.8.1
setuptools: 38.4.0
pip: 18.1
conda: 4.6.1
pytest: 3.3.2
IPython: 6.2.1
sphinx: 1.6.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions