Reading in a sequence of WRF files and extracting variables

334 views
Skip to first unread message

Michael Murphy

unread,
Apr 9, 2018, 9:55:32 PM4/9/18
to wrfpython-talk
I'm trying to use the wrf.getvar function to extract variables from a sequence of wrfinput files I opened with netcdf4.MFDataset.

I get failures every time, e.g.

Traceback (most recent call last):
  File "plot-rms-model-analyses-uwind-ensMean.py", line 66, in <module>
    print rawSLP
  File "/u/mjmurph4/anaconda2/envs/default-pfe/lib/python2.7/site-packages/xarray/core/common.py", line 97, in __repr__
    return formatting.array_repr(self)
  File "/u/mjmurph4/anaconda2/envs/default-pfe/lib/python2.7/site-packages/xarray/core/formatting.py", line 395, in array_repr
    summary.append(attrs_repr(arr.attrs))
  File "/u/mjmurph4/anaconda2/envs/default-pfe/lib/python2.7/site-packages/xarray/core/formatting.py", line 299, in _mapping_repr
    summary += [summarizer(k, v, col_width) for k, v in mapping.items()]
  File "/u/mjmurph4/anaconda2/envs/default-pfe/lib/python2.7/site-packages/xarray/core/formatting.py", line 262, in summarize_attr
    v_str = unicode_type(value).replace(u'\t', u'\\t').replace(u'\n', u'\\n')
  File "netCDF4/_netCDF4.pyx", line 1905, in netCDF4._netCDF4.Dataset.__unicode__ (netCDF4/_netCDF4.c:14151)
AttributeError: 'NoneType' object has no attribute 'keys'


Is this feature not supported by wrf-python?  Does anyone know of a working method of reading in a sequence of WRF output (or input) netcdf files and getting wrf.getvar to extract variables from them?

Any advice will be appreciated.

Thanks,
Michael

Bill Ladwig

unread,
Apr 10, 2018, 12:40:59 PM4/10/18
to Michael Murphy, wrfpython-talk
Hi Michael,

WRF-Python doesn't currently work natively with MFDataset. In the future, I'm going to be doing an overhaul to the front end to support this, along with xarray and other input types, but you can make this work now by doing:

from netCDF4 import Dataset, MFDataset
from wrf import getvar, ALL_TIMES
 
my_pattern = "wrfout_d02_*"
 
ds = MFDataset(my_pattern)
wrfin = [Dataset(x) for x in ds._files]
 
slp = getvar(wrfin, "slp", ALL_TIMES)

Hope this helps,

Bill

--
You received this message because you are subscribed to the Google Groups "wrfpython-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wrfpython-talk+unsubscribe@ucar.edu.
To post to this group, send email to wrfpyth...@ucar.edu.
Visit this group at https://groups.google.com/a/ucar.edu/group/wrfpython-talk/.

Reply all
Reply to author
Forward
0 new messages