def exact_volume_sphere(rvec, pos, radius, zscale=<NUM_LIT:1.0>, volume_error=<NUM_LIT>,<EOL>function=sphere_analytical_gaussian, max_radius_change=<NUM_LIT>, args=()):
vol_goal = <NUM_LIT>/<NUM_LIT:3>*np.pi*radius**<NUM_LIT:3> / zscale<EOL>rprime = radius<EOL>dr = inner(rvec, pos, rprime, zscale=zscale)<EOL>t = function(dr, rprime, *args)<EOL>for i in range(MAX_VOLUME_ITERATIONS):<EOL><INDENT>vol_curr = np.abs(t.sum())<EOL>if np.abs(vol_goal - vol_curr)/vol_goal < volume_error:<EOL><INDENT>break<EOL><DEDENT>rprime = rprime + <NUM_LIT:1.0>*(vol_goal - vol_curr) / (<NUM_LIT:4>*np.pi*rprime**<NUM_LIT:2>)<EOL>if np.abs(rprime - radius)/radius > max_radius_change:<EOL><INDENT>break<EOL><DEDENT>dr = inner(rvec, pos, rprime, zscale=zscale)<EOL>t = function(dr, rprime, *args)<EOL><DEDENT>return t<EOL>
Perform an iterative method to calculate the effective sphere that perfectly
(up to the volume_error) conserves volume.  Return the resulting image