def sum_all_but_dims(dims_to_keep, da):
  """Sum a xr.DataArray along all dimensions except those specified."""
  dims_to_sum = [dim for dim in da.dims if dim not in dims_to_keep]
  return da.sum(dim=dims_to_sum)