def METHOD_NAME(
      work_params,
      spots,
      good_i_seqs,
      miller_indices,
      unit_cell,
      crystal_rotation):
  from scitbx.array_family import flex
  spots_xy0 = flex.vec3_double()
  for spot in spots.select(good_i_seqs):
    x,y = spot.ctr_mass_x()+0.5, spot.ctr_mass_y()+0.5
    spots_xy0.append((x,y,0))
  refined = refinery(
    work_params=work_params,
    spots_xy0=spots_xy0,
    miller_indices=miller_indices,
    unit_cell=unit_cell,
    crystal_rotation_uq=crystal_rotation
      .r3_rotation_matrix_as_unit_quaternion())
  refined.show_summary().show_distances()
  print()
  while True:
    remaining_sel = refined.outlier_removal()
    if (remaining_sel is None):
      break
    print("Removing one outlier and re-refining.")
    print()
    refined = refinery(
      work_params=refined.work_params,
      spots_xy0=refined.spots_xy0.select(remaining_sel),
      miller_indices=refined.miller_indices.select(remaining_sel),
      unit_cell=refined.unit_cell,
      crystal_rotation_uq=refined.crystal_rotation
        .r3_rotation_matrix_as_unit_quaternion())
    refined.show_summary().show_distances()
    print()
  return refined