def check_spatial_dim(spatial_dim, data):
    """Check that a valid spatial dimension is specified."""
    # Check type
    if not isinstance(spatial_dim, str):
        raise TypeError("Specify 'spatial_dim' as a string.")  
    # Check validity
    coords = list(data.coords.keys())
    if spatial_dim not in coords:
        raise ValueError("'spatial_dim' must be a coordinate of the xarray object.") 
    # Return spatial_dim as a list of strings     
    return spatial_dim