def flux_to_total(cube):
    """Convert a flux (i.e. per second quantity) to total"""

    assert 'days' in str(cube.coord('time').units)
    time_span_days = cube.coord('time').bounds[:, 1] - cube.coord('time').bounds[:, 0]
    time_span_seconds = time_span_days * 60 * 60 * 24
    cube.data = cube.data * time_span_seconds
    units = str(cube.units)
    assert ('s-1' in units) or ('W' in units), 'input units must be a flux per second'
    if 's-1' in units:    
        cube.units = units.replace('s-1', '')
    elif 'W' in units:
        cube.units = units.replace('W', 'J')
        
    return cube