NCAR / wrf-python

A collection of diagnostic and interpolation routines for use with output from the Weather Research and Forecasting (WRF-ARW) Model.
https://wrf-python.readthedocs.io
Apache License 2.0
410 stars 155 forks source link

Behavior of extract_vars inconsistent with documentation #121

Closed irowebbn closed 4 years ago

irowebbn commented 4 years ago

In the documentation for wrf.extract_vars, the details on return say the following:

Returns: A mapping of variable name to an array object. If xarray is enabled and the meta parameter is True, then the array object will be a xarray.DataArray object. Otherwise, the array object will be a numpy.ndarray object with no metadata.

It also says the return type is dict, which confuses me because the previous paragraph just said it would be a xarray or numpy array.

I have xarray enabled and meta set to True, but the return I am getting is not a xarray.DataArray object, just a dict. The dict is not in the correct form to construct a xarray.DataArray using the __init__ or from_dict() functions.

How can I get a xarray DataArray returned from the extract_vars function? If I am misunderstanding how this works please correct me.

irowebbn commented 4 years ago

I misread the documentation. The function returns a dict, which contains one or more variables as keys, and the corresponding arrays as values. You have to index into the dict in order to get the xarray DataArray. I was confused because I was only extracting 1 variable and therefore my dict only had one entry.