def map_palette(station):
    """
    Function that returns the colour of a given station to use on the map, depending on the relationship between latest level and typical range.

    Args:
        station (MonitoringStation): The station.

    Returns:
        str: One of

            * 'gray' - typical range not consistent
            * 'red' - above the typical range
            * 'green' - below the typical range
            * 'blue' - within the typical range

    """
    if station.typical_range_consistent() is False or station.latest_level is None:
        return 'gray'
    if station.latest_level > station.typical_range[1]:
        return 'red'
    if station.latest_level < station.typical_range[0]:
        return 'green'
    return 'blue'