  Magnetic field uniformity is of the utmost importance in experiments to
measure the electric dipole moment of the neutron. A general parametrization of
the magnetic field in terms of harmonic polynomial modes is proposed, going
beyond the linear-gradients approximation. We review the main undesirable
effects of non-uniformities: depolarization of ultracold neutrons, and Larmor
frequency shifts of neutrons and mercury atoms. The theoretical predictions for
these effects were verified by dedicated measurements with the single-chamber
nEDM apparatus installed at the Paul Scherrer Institute.
