'Return a dictionary containing all non-None metadata fields, including
the custom ones.'

def all_non_none_fields(self):

    result = {}
    _data = object.__getattribute__(self, '_data')
    for attr in STANDARD_METADATA_FIELDS:
        v = _data.get(attr, None)
        if (v is not None):
            result[attr] = v
    for attr in TOP_LEVEL_IDENTIFIERS:
        v = self.get(attr, None)
        if (v is not None):
            result[attr] = v
    for attr in _data['user_metadata'].iterkeys():
        v = self.get(attr, None)
        if (v is not None):
            result[attr] = v
            if (_data['user_metadata'][attr]['datatype'] == 'series'):
                result[(attr + '_index')] = _data['user_metadata'][attr]['#extra#']
    return result
