def rebin(d, n_x, n_y=None):
if d.ndim == <NUM_LIT:2>:<EOL><INDENT>if n_y is None:<EOL><INDENT>n_y = <NUM_LIT:1><EOL><DEDENT>if n_x is None:<EOL><INDENT>n_x = <NUM_LIT:1><EOL><DEDENT>d = d[:int(d.shape[<NUM_LIT:0>] // n_x) * n_x, :int(d.shape[<NUM_LIT:1>] // n_y) * n_y]<EOL>d = d.reshape((d.shape[<NUM_LIT:0>] // n_x, n_x, d.shape[<NUM_LIT:1>] // n_y, n_y))<EOL>d = d.mean(axis=<NUM_LIT:3>)<EOL>d = d.mean(axis=<NUM_LIT:1>)<EOL><DEDENT>elif d.ndim == <NUM_LIT:1>:<EOL><INDENT>d = d[:int(d.shape[<NUM_LIT:0>] // n_x) * n_x]<EOL>d = d.reshape((d.shape[<NUM_LIT:0>] // n_x, n_x))<EOL>d = d.mean(axis=<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>return d<EOL>
Rebin data by averaging bins together

    Args:
    d (np.array): data
    n_x (int): number of bins in x dir to rebin into one
    n_y (int): number of bins in y dir to rebin into one

    Returns:
    d: rebinned data with shape (n_x, n_y)