Closed Timothy-W-Hilton closed 6 years ago
This is a bug and I'll have it fixed for the next release. You can get around the problem for now by setting 'meta=False' in either getvar or extract_vars. This will disable the metadata, but you'll still get the values as a regular numpy array. Thanks for reporting the issue.
thanks, both for the bug fix and suggesting the workaround (which had not occurred to me for some reason).
(For my own reference)
ZS and DZS do not contain the south_north or west_east dimensions, which needs to be handled. The ncdump for both is below:
float ZS(Time, soil_layers_stag) ; ZS:FieldType = 104 ; ZS:MemoryOrder = "Z " ; ZS:description = "DEPTHS OF CENTERS OF SOIL LAYERS" ; ZS:units = "m" ; ZS:stagger = "Z" ;
float DZS(Time, soil_layers_stag) ; DZS:FieldType = 104 ; DZS:MemoryOrder = "Z " ; DZS:description = "THICKNESSES OF SOIL LAYERS" ; DZS:units = "m" ; DZS:stagger = "Z" ;
The KeyError in the initial issue has already been fixed when compatibility was improved for pre-3.x WRF files (not yet released), but instead a new error is thrown:
Traceback (most recent call last): File "
", line 1, in File "/Users/ladwig/miniconda2/envs/test_env/lib/python2.7/site-packages/wrf/routines.py", line 275, in getvar method, squeeze, cache, meta, _key)[varname] File "/Users/ladwig/miniconda2/envs/test_env/lib/python2.7/site-packages/wrf/util.py", line 2213, in extract_vars for var in varlist} File "/Users/ladwig/miniconda2/envs/test_env/lib/python2.7/site-packages/wrf/util.py", line 2213, in for var in varlist} File "/Users/ladwig/miniconda2/envs/test_env/lib/python2.7/site-packages/wrf/util.py", line 2136, in _extract_var multifile, _key) File "/Users/ladwig/miniconda2/envs/test_env/lib/python2.7/site-packages/wrf/util.py", line 1322, in _build_data_array attrs=attrs) File "/Users/ladwig/miniconda2/envs/test_env/lib/python2.7/site-packages/xarray/core/dataarray.py", line 224, in init coords, dims = _infer_coords_and_dims(data.shape, coords, dims) File "/Users/ladwig/miniconda2/envs/test_env/lib/python2.7/site-packages/xarray/core/dataarray.py", line 81, in _infer_coords_and_dims 'dimensions %s' % (k, v.dims, dims)) ValueError: coordinate XLONG has dimensions (u'south_north', u'west_east'), but these are not a subset of the DataArray dimensions (u'Time', u'soil_layers_stag')
After the change to support pre-3.x WRF files, if coordinate variables aren't found, it defaults to XLAT and XLONG, which isn't applicable for these two products.
Using either
extract_vars()
orgetvar()
to retrieve soil layer thicknesses (netCDF variables DZS and ZS) from a WRF output file fails with "KeyError: u'XLONG_Z'".The same command retrieves variable SMOIS successfully.