The transition from natural convection to thermomagnetic convection of a magnetic fluid in a non-uniform magnetic field