From f9dd771b158680e0a4d994dac2f18932cfaf41db Mon Sep 17 00:00:00 2001 From: Bill Ladwig Date: Thu, 5 Oct 2017 11:28:53 -0600 Subject: [PATCH] Now handles WRF files that are missing coordinate attributes for variables (old WRF files). Fixes #29. --- src/wrf/util.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wrf/util.py b/src/wrf/util.py index 6ac841f..6c520e1 100644 --- a/src/wrf/util.py +++ b/src/wrf/util.py @@ -1117,15 +1117,29 @@ def _get_coord_names(wrfin, varname): time_coord = None else: try: - # met_em files + # met_em files or old WRF files stag_attr = getattr(var, "stagger") except AttributeError: lon_coord = None lat_coord = None + + # Let's just check for xlat and xlong in this case + if "XLAT" in wrfnc.variables: + lat_coord = "XLAT" + lon_coord = "XLONG" else: # For met_em files, use the stagger name to get the lat/lon var lat_coord = "XLAT_{}".format(stag_attr) lon_coord = "XLONG_{}".format(stag_attr) + + # If this coord name is missing, it might be an old WRF file + if lat_coord not in wrfnc.variables: + lat_coord = None + lon_coord = None + + if "XLAT" in wrfnc.variables: + lat_coord = "XLAT" + lon_coord = "XLONG" else: coord_names = coord_attr.split() lon_coord = coord_names[0]