def process_one(data, axis): if isinstance(data, xray.DataArray): name, attrs, coords, dims = meta(data) if axis is not None: dims_del = utils.makelist(axis) else: # All singleton dimensions dims_del = np.where(np.array(data.shape) == 1)[0] squeezed = np.squeeze(data.values, axis=dims_del) # Update metadata dims = list(dims) dimnames_del = [dims[d] for d in dims_del] for nm in dimnames_del: attrs[nm] = coords[nm].values coords = utils.odict_delete(coords, nm) dims.remove(nm) # Squeeze and pack into DataArray squeezed = xray.DataArray(np.squeeze(data.values, axis=dims_del), dims=dims, coords=coords, name=name, attrs=attrs) else: squeezed = np.squeeze(data, axis) return squeezed
def latlon_labels(vals, latlon='lat', fmt='%.0f', deg_symbol=True, join_str=None): """Return a label string for list of latitudes or longitudes.""" if latlon.lower() == 'lat': pos, neg = 'N', 'S' elif latlon.lower() == 'lon': pos, neg = 'E', 'W' else: raise ValueError('Invalid input latlon = ' + latlon) vals = utils.makelist(vals) labels = [] for num in vals: if num >= 0: suffix = pos x = fmt % num else: suffix = neg x = fmt % abs(num) if deg_symbol: labels.append(x + degree_sign() + suffix) else: labels.append(x + suffix) if len(vals) == 1: labels = labels[0] elif join_str is not None: labels = join_str.join(labels) return labels