def MaskField(**kwargs):
    """Create a new field for a :py:class:`~.KeyspacesRegion` that will write
    out a mask value from a keyspace.

    Parameters
    ----------
    field : string
        The name of the keyspace field to store the mask for.
    tag : string
        The name of the keyspace tag to store the mask for.

    Raises
    ------
    TypeError
        If both or neither field and tag are specified.

    Returns
    -------
    function
        A function which can be used in the `fields` argument to
        :py:class:`~.KeyspacesRegion` that will include a specified mask in the
        region data.
    """
    # Process the arguments
    field = kwargs.get("field")
    tag = kwargs.get("tag")

    # Create the field method
    if field is not None and tag is None:
        def mask_getter(keyspace, **kwargs):
            return keyspace.get_mask(field=field)

        return mask_getter
    elif tag is not None and field is None:
        def mask_getter(keyspace, **kwargs):
            return keyspace.get_mask(tag=tag)

        return mask_getter
    else:
        raise TypeError("MaskField expects 1 argument, "
                        "either 'field' or 'tag'.")