def enforce_cf_variable(var, mask_and_scale=True):
var = as_variable(var)<EOL>data = var._data  <EOL>dims = var.dims<EOL>attrs = var.attrs.copy()<EOL>encoding = var.encoding.copy()<EOL>orig_dtype = data.dtype<EOL>if '<STR_LIT>' in attrs:<EOL><INDENT>scale = attrs.pop('<STR_LIT>')<EOL>attrs['<STR_LIT>'] = scale<EOL>encoding['<STR_LIT>'] = scale<EOL>if mask_and_scale:<EOL><INDENT>data = scale*data<EOL><DEDENT><DEDENT>if '<STR_LIT>' in attrs:<EOL><INDENT>unit = attrs.pop('<STR_LIT>')<EOL>unit = get_cfcompliant_units(unit)<EOL>attrs['<STR_LIT>'] = unit<EOL><DEDENT>return Variable(dims, data, attrs, encoding=encoding)<EOL>
Given a Variable constructed from GEOS-Chem output, enforce
    CF-compliant metadata and formatting.

    Until a bug with lazily-loaded data and masking/scaling is resolved in
    xarray, you have the option to manually mask and scale the data here.

    Parameters
    ----------
    var : xarray.Variable
        A variable holding information decoded from GEOS-Chem output.
    mask_and_scale : bool
        Flag to scale and mask the data given the unit conversions provided

    Returns
    -------
    out : xarray.Variable
        The original variable processed to conform to CF standards

    .. note::

        This method borrows heavily from the ideas in ``xarray.decode_cf_variable``