def fitimageslice(img, res_x, res_y, xslice, yslice, avg_e_func=None, h5file=None, plot=False):
<EOL>x_start = xslice[<NUM_LIT:0>]<EOL>x_end   = xslice[<NUM_LIT:1>]<EOL>y_start = yslice[<NUM_LIT:0>]<EOL>y_end   = yslice[<NUM_LIT:1>]<EOL>y_low = _np.round(y_start-<NUM_LIT:0.5>) + <NUM_LIT:0.5><EOL>y_high = _np.round(y_end-<NUM_LIT:0.5>) + <NUM_LIT:0.5><EOL>y_px = linspacestep(<NUM_LIT:1>, img.shape[<NUM_LIT:0>])<EOL>y_bool = _np.logical_and(y_low < y_px, y_px < y_high)<EOL>strip = img[y_bool, x_start:x_end]<EOL>histdata = _np.sum(strip, <NUM_LIT:0>)<EOL>xbins = len(histdata)<EOL>x = _np.linspace(<NUM_LIT:1>, xbins, xbins)*res_x<EOL>varbool  = True<EOL>gaussout = _sp.GaussResults(<EOL>x,<EOL>histdata,<EOL>sigma_y    = _np.ones(xbins),<EOL>variance   = varbool,<EOL>background = True,<EOL>p0         = [<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT:0>]<EOL>)<EOL>if avg_e_func is not None:<EOL><INDENT>relcounts = _np.sum(strip, <NUM_LIT:1>) / _np.float(_np.sum(strip))<EOL>Eavg = <NUM_LIT:0><EOL>for i, val in enumerate(linspacestep(y_low, y_high-<NUM_LIT:1>)):<EOL><INDENT>Eavg = Eavg + avg_e_func(val, val+<NUM_LIT:1>, h5file, res_y)*relcounts[i]<EOL><DEDENT>return Eavg, gaussout<EOL><DEDENT>else:<EOL><INDENT>return gaussout<EOL><DEDENT>
Fits a gaussian to a slice of an image *img* specified by *xslice* x-coordinates and *yslice* y-coordinates. *res_x* and *res_y* specify image resolution in x and y. *avg_e_func* is a function that returns the energy of the image as a function of x. It should have the form:

*avg_e_func(x_1, x_2, h5file, res_y)*

Fits a gaussian to a slice of an image.

Parameters
----------

img : array
    Image to be fitted.
res_x : int
    Image resolution in :math:`x`.
res_y : int
    Image resolution in :math:`y`.
xslice : (int, int)
    Slice coordinates in :math:`x`
yslice : (int, int)
    Slice coordinates in :math:`y`
avg_e_func : function
    Of the form *avg_e_func(x_1, x_2, h5file, res_y)*, returns the energy of the image as a function of :math:`x`.
h5file : h5file
    Instance from dataset.
plot : boolean
    Whether to plot or not.