MCPcopy Create free account
hub / github.com/NCAR/wrf-python / _get_coord_names

Function _get_coord_names

src/wrf/util.py:1131–1219  ·  view source on GitHub ↗
(wrfin, varname)

Source from the content-addressed store, hash-verified

1129
1130
1131def _get_coord_names(wrfin, varname):
1132
1133 # Need only the first real file
1134 if is_multi_file(wrfin):
1135 if not is_mapping(wrfin):
1136 wrfnc = next(iter(wrfin))
1137 else:
1138 entry = wrfin[next(iter(viewkeys(wrfin)))]
1139 return _get_coord_names(entry, varname)
1140 else:
1141 wrfnc = wrfin
1142
1143 lat_coord = None
1144 lon_coord = None
1145 time_coord = None
1146
1147 var = wrfnc.variables[varname]
1148
1149 # WRF variables will have a coordinates attribute. MET_EM files have
1150 # a stagger attribute which indicates the coordinate variable.
1151 try:
1152 # WRF files
1153 coord_attr = getattr(var, "coordinates")
1154 except AttributeError:
1155
1156 if is_coordvar(varname):
1157 # Coordinate variable (most likely XLAT or XLONG)
1158 lat_coord, lon_coord = get_coord_pairs(varname)
1159 time_coord = None
1160
1161 if has_time_coord(wrfnc):
1162 time_coord = "XTIME"
1163
1164 elif is_time_coord_var(varname):
1165 lon_coord = None
1166 lat_coord = None
1167 time_coord = None
1168 else:
1169 try:
1170 # met_em files or old WRF files
1171 stag_attr = getattr(var, "stagger")
1172 except AttributeError:
1173 lon_coord = None
1174 lat_coord = None
1175
1176 # Let's just check for xlat and xlong in this case
1177 if "XLAT" in wrfnc.variables:
1178 lat_coord = "XLAT"
1179 lon_coord = "XLONG"
1180 else:
1181 # For met_em files, use the stagger name to get the lat/lon var
1182 lat_coord = "XLAT_{}".format(stag_attr)
1183 lon_coord = "XLONG_{}".format(stag_attr)
1184
1185 # If this coord name is missing, it might be an old WRF file
1186 if lat_coord not in wrfnc.variables:
1187 lat_coord = None
1188 lon_coord = None

Callers 2

_build_data_arrayFunction · 0.85
geo_boundsFunction · 0.85

Calls 7

is_multi_fileFunction · 0.85
is_mappingFunction · 0.85
viewkeysFunction · 0.85
is_coordvarFunction · 0.85
get_coord_pairsFunction · 0.85
has_time_coordFunction · 0.85
is_time_coord_varFunction · 0.85

Tested by

no test coverage detected