'Create a new instance, applying a method to the underlying data.
In typical usage, the method is any of the shape-changing methods for
`~numpy.ndarray` (``reshape``, ``swapaxes``, etc.), as well as those
picking particular elements (``__getitem__``, ``take``, etc.), which
are all defined in `~astropy.utils.misc.ShapedLikeNDArray`. It will be
applied to the underlying arrays in the representation (e.g., ``x``,
``y``, and ``z`` for `~astropy.coordinates.CartesianRepresentation`),
as well as to any frame attributes that have a shape, with the results
used to create a new instance.
Internally, it is also used to apply functions to the above parts
(in particular, `~numpy.broadcast_to`).
Parameters
method : str or callable
If str, it is the name of a method that is applied to the internal
``components``. If callable, the function is applied.
args : tuple
Any positional arguments for ``method``.
kwargs : dict
Any keyword arguments for ``method``.'

def _apply(self, method, *args, **kwargs):

    def apply_method(value):
        if isinstance(value, ShapedLikeNDArray):
            return value._apply(method, *args, **kwargs)
        elif callable(method):
            return method(value, *args, **kwargs)
        else:
            return getattr(value, method)(*args, **kwargs)
    self_frame = self._sky_coord_frame
    try:
        self._sky_coord_frame = self_frame._apply(method, *args, **kwargs)
        out = SkyCoord(self, representation=self.representation, copy=False)
        for attr in self._extra_attr_names:
            value = getattr(self, attr)
            if (getattr(value, u'size', 1) > 1):
                value = apply_method(value)
            elif ((method == u'copy') or (method == u'flatten')):
                value = copy.copy(value)
            setattr(out, (u'_' + attr), value)
        if (u'info' in self.__dict__):
            out.info = self.info
        return out
    finally:
        self._sky_coord_frame = self_frame
