'A helper function to support reading either a pair of arrays
or a single Nx2 array.'

def _array_converter(self, func, sky, *args, **kwargs):

    ra_dec_order = kwargs.pop(u'ra_dec_order', False)
    if len(kwargs):
        raise TypeError(u'Unexpected    keyword    argument    {0!r}'.format(kwargs.keys()[0]))
    def _return_list_of_arrays(axes, origin):
        try:
            axes = np.broadcast_arrays(*axes)
        except ValueError:
            raise ValueError(u'Coordinate    arrays    are    not    broadcastable    to    each    other')
        xy = np.hstack([x.reshape((x.size, 1)) for x in axes])
        if (ra_dec_order and (sky == u'input')):
            xy = self._denormalize_sky(xy)
        output = func(xy, origin)
        if (ra_dec_order and (sky == u'output')):
            output = self._normalize_sky(output)
            return (output[:, 0].reshape(axes[0].shape), output[:, 1].reshape(axes[0].shape))
        return [output[:, i].reshape(axes[0].shape) for i in range(output.shape[1])]
    def _return_single_array(xy, origin):
        if (xy.shape[(-1)] != self.naxis):
            raise ValueError(u'When    providing    two    arguments,    the    array    must    be    of    shape    (N,    {0})'.format(self.naxis))
        if (ra_dec_order and (sky == u'input')):
            xy = self._denormalize_sky(xy)
        result = func(xy, origin)
        if (ra_dec_order and (sky == u'output')):
            result = self._normalize_sky(result)
        return result
    if (len(args) == 2):
        try:
            (xy, origin) = args
            xy = np.asarray(xy)
            origin = int(origin)
        except Exception:
            raise TypeError(u'When    providing    two    arguments,    they    must    be    (coords[N][{0}],    origin)'.format(self.naxis))
        if ((self.naxis == 1) and (len(xy.shape) == 1)):
            return _return_list_of_arrays([xy], origin)
        return _return_single_array(xy, origin)
    elif (len(args) == (self.naxis + 1)):
        axes = args[:(-1)]
        origin = args[(-1)]
        try:
            axes = [np.asarray(x) for x in axes]
            origin = int(origin)
        except Exception:
            raise TypeError((u'When    providing    more    than    two    arguments,    they    must    be    ' + u'a    1-D    array    for    each    axis,    followed    by    an    origin.'))
        return _return_list_of_arrays(axes, origin)
    raise TypeError(u'WCS    projection    has    {0}    dimensions,    so    expected    2    (an    Nx{0}    array    and    the    origin    argument)    or    {1}    arguments    (the    position    in    each    dimension,    and    the    origin    argument).    Instead,    {2}    arguments    were    given.'.format(self.naxis, (self.naxis + 1), len(args)))
