def _ion_mass(field, data):
    """
    Creates the function for a derived field to follow the total mass of an
    ion over a dataset given that the specified ion's density field exists
    in the dataset.
    """
    if isinstance(field.name, tuple):
        ftype = field.name[0]
        field_name = field.name[1]
    else:
        ftype = 'gas'
        field_name = field.name
    prefix = field_name.split('_mass')[0]
    suffix = field_name.split('_mass')[-1]
    density_field_name = '%s_density%s' % (prefix, suffix)
    if data.ds.field_info[ftype, density_field_name
        ].sampling_type == 'particle':
        fraction_field_name = '%s_ion_fraction%s' % (prefix, suffix)
        return data[ftype, fraction_field_name] * data[ftype, 'particle_mass']
    else:
        return data[ftype, density_field_name] * data[ftype, 'cell_volume']
