def apply_schema(ds, schema):
    """Apply a metadata schema on a dataset.

    Args:
        ds (xarray.Dataset): Dataset.
        schema (dict): Axiom schema dictionary.

    Returns:
        xarray.Dataset : Dataset with schema-defined metadata applied.
    """
    # Apply the global metadata, if available
    for key, _schema in schema['_global'].items():
        if 'allowed' in _schema.keys():
            ds.attrs[key] = _schema['allowed'][0]

    # Loop through each variable on the dataset
    for variable in list(ds.data_vars.keys()) + list(ds.coords.keys()):

        # If the variable is define
        if variable in schema['variables'].keys():

            # Extract the schema for the variable itself
            var_schema = schema['variables'][variable]

            # Loop through attributes
            for key, _schema in var_schema.items():

                # Apply if there is an expected value
                if 'allowed' in _schema.keys():
                    ds[variable].attrs[key] = _schema['allowed'][0]

    # Return the updated schema
    return ds