def convert_grid_units(array, grid_arc_seconds, units, kpc_per_arcsec):
    """Convert the grid from its input units (arc-seconds) to the input unit (e.g. retain arc-seconds) or convert to     another set of units (pixels or kilo parsecs).

    Parameters
    -----------
    array : ndarray or hyper.array.scaled_array.ScaledArray
        The 2D array of hyper which is plotted, the shape of which is used for converting the grid to units of pixels.
    grid_arc_seconds : ndarray or hyper.array.grid_stacks.RegularGrid
        The (y,x) coordinates of the grid in arc-seconds, in an array of shape (total_coordinates, 2).
    units : str
        The units of the y / x axis of the plots, in arc-seconds ('arcsec') or kiloparsecs ('kpc').
    kpc_per_arcsec : float
        The conversion factor between arc-seconds and kiloparsecs, required to plot the units in kpc.
    """
    if units is 'pixels':
        return array.grid_arc_seconds_to_grid_pixels(grid_arc_seconds=
            grid_arc_seconds)
    elif units is 'arcsec' or kpc_per_arcsec is None:
        return grid_arc_seconds
    elif units is 'kpc':
        return grid_arc_seconds * kpc_per_arcsec
