def fluximage3(ri, li, rs, v, x, y, N, wBx, wBy, Ntest):
    '\n    A Monte Carlo approach to creating a flux image out of a perpendicular deflection field. \n    \n    Args:\n        ri:\n        li:\n        rs:\n        v:\n        N: Number of protons in reality\n        x (array): Perpendicular deflection field x-coordinates.\n        y (array): Perpendicular deflection field y-coordinates.\n        wBx (array): Perpendicular deflection field x-component.\n        wBy (array): Perpendicular deflection field y-component.\n        Ntest: Number of test protons (Monte Carlo)\n\n    Returns:\n        flux_image (array): Generated flux image.\n    '
    magnify = (((rs + li) + ri) / (ri + (0.5 * li)))
    xgv = x[:, 0].flatten()
    ygv = y[0, :].flatten()
    xmin = np.min(xgv)
    xmax = np.max(xgv)
    ymin = np.min(ygv)
    ymax = np.max(ygv)
    dx = np.mean(np.diff(xgv))
    dy = np.mean(np.diff(ygv))
    x_edges = np.append((xgv - (dx / 2.0)), (xgv[(- 1)] + (dx / 2.0)))
    y_edges = np.append((ygv - (dy / 2.0)), (ygv[(- 1)] + (dy / 2.0)))
    xd = np.random.uniform(xmin, xmax, size=(Ntest,))
    yd = np.random.uniform(ymin, ymax, size=(Ntest,))
    xyd = np.stack((xd, yd), axis=1)
    wBxd = sp.interpolate.interpn((xgv, ygv), wBx, xyd, method='linear')
    wByd = sp.interpolate.interpn((xgv, ygv), wBy, xyd, method='linear')
    xfd = (xd + ((rs / (magnify * v)) * wBxd))
    yfd = (yd + ((rs / (magnify * v)) * wByd))
    print('Histogramming reference...')
    (flux_ref, _, _) = np.histogram2d(xd, yd, bins=[x_edges, y_edges])
    flux_ref = ((flux_ref * N) / Ntest)
    print('Histogramming signal...')
    (flux_image, _, _) = np.histogram2d(xfd, yfd, bins=[x_edges, y_edges])
    flux_image = ((flux_image * N) / Ntest)
    print('DONE')
    return (flux_image, flux_ref)
A Monte Carlo approach to creating a flux image out of a perpendicular deflection field. 

Args:
    ri:
    li:
    rs:
    v:
    N: Number of protons in reality
    x (array): Perpendicular deflection field x-coordinates.
    y (array): Perpendicular deflection field y-coordinates.
    wBx (array): Perpendicular deflection field x-component.
    wBy (array): Perpendicular deflection field y-component.
    Ntest: Number of test protons (Monte Carlo)

Returns:
    flux_image (array): Generated flux image.
def fluximage3(ri, li, rs, v, x, y, N, wBx, wBy, Ntest):
    '\n    A Monte Carlo approach to creating a flux image out of a perpendicular deflection field. \n    \n    Args:\n        ri:\n        li:\n        rs:\n        v:\n        N: Number of protons in reality\n        x (array): Perpendicular deflection field x-coordinates.\n        y (array): Perpendicular deflection field y-coordinates.\n        wBx (array): Perpendicular deflection field x-component.\n        wBy (array): Perpendicular deflection field y-component.\n        Ntest: Number of test protons (Monte Carlo)\n\n    Returns:\n        flux_image (array): Generated flux image.\n    '
    magnify = (((rs + li) + ri) / (ri + (0.5 * li)))
    xgv = x[:, 0].flatten()
    ygv = y[0, :].flatten()
    xmin = np.min(xgv)
    xmax = np.max(xgv)
    ymin = np.min(ygv)
    ymax = np.max(ygv)
    dx = np.mean(np.diff(xgv))
    dy = np.mean(np.diff(ygv))
    x_edges = np.append((xgv - (dx / 2.0)), (xgv[(- 1)] + (dx / 2.0)))
    y_edges = np.append((ygv - (dy / 2.0)), (ygv[(- 1)] + (dy / 2.0)))
    xd = np.random.uniform(xmin, xmax, size=(Ntest,))
    yd = np.random.uniform(ymin, ymax, size=(Ntest,))
    xyd = np.stack((xd, yd), axis=1)
    wBxd = sp.interpolate.interpn((xgv, ygv), wBx, xyd, method='linear')
    wByd = sp.interpolate.interpn((xgv, ygv), wBy, xyd, method='linear')
    xfd = (xd + ((rs / (magnify * v)) * wBxd))
    yfd = (yd + ((rs / (magnify * v)) * wByd))
    print('Histogramming reference...')
    (flux_ref, _, _) = np.histogram2d(xd, yd, bins=[x_edges, y_edges])
    flux_ref = ((flux_ref * N) / Ntest)
    print('Histogramming signal...')
    (flux_image, _, _) = np.histogram2d(xfd, yfd, bins=[x_edges, y_edges])
    flux_image = ((flux_image * N) / Ntest)
    print('DONE')
    return (flux_image, flux_ref)