ó
šßÈ[c           @` sU   d  d l  m Z m Z m Z m Z d d l m Z d g Z d e f d „  ƒ  YZ	 d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   logu   NDSlicingMixint   NDSlicingMixinc           B` s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   uÒ  Mixin to provide slicing on objects using the `NDData`
    interface.

    The ``data``, ``mask``, ``uncertainty`` and ``wcs`` will be sliced, if
    set and sliceable. The ``unit`` and ``meta`` will be untouched. The return
    will be a reference and not a copy, if possible.

    Examples
    --------
    Using this Mixin with `~astropy.nddata.NDData`:

        >>> from astropy.nddata import NDData, NDSlicingMixin
        >>> class NDDataSliceable(NDSlicingMixin, NDData):
        ...     pass

    Slicing an instance containing data::

        >>> nd = NDDataSliceable([1,2,3,4,5])
        >>> nd[1:3]
        NDDataSliceable([2, 3])

    Also the other attributes are sliced for example the ``mask``::

        >>> import numpy as np
        >>> mask = np.array([True, False, True, True, False])
        >>> nd2 = NDDataSliceable(nd, mask=mask)
        >>> nd2slc = nd2[1:3]
        >>> nd2slc[nd2slc.mask]
        NDDataSliceable([3])

    Be aware that changing values of the sliced instance will change the values
    of the original::

        >>> nd3 = nd2[1:3]
        >>> nd3.data[0] = 100
        >>> nd2
        NDDataSliceable([  1, 100,   3,   4,   5])

    See also
    --------
    NDDataRef
    NDDataArray
    c         C` s=   |  j  j d k r! t d ƒ ‚ n  |  j | ƒ } |  j |   S(   Nu   scalars cannot be sliced.(    (   t   datat   shapet	   TypeErrort   _slicet	   __class__(   t   selft   itemt   kwargs(    (    s>   lib/python2.7/site-packages/astropy/nddata/mixins/ndslicing.pyt   __getitem__8   s    c         C` sn   i  } |  j  | | d <|  j | ƒ | d <|  j | ƒ | d <|  j | ƒ | d <|  j | d <|  j | d <| S(   uÍ  Collects the sliced attributes and passes them back as `dict`.

        It passes uncertainty, mask and wcs to their appropriate ``_slice_*``
        method, while ``meta`` and ``unit`` are simply taken from the original.
        The data is assumed to be sliceable and is sliced directly.

        When possible the return should *not* be a copy of the data but a
        reference.

        Parameters
        ----------
        item : slice
            The slice passed to ``__getitem__``.

        Returns
        -------
        dict :
            Containing all the attributes after slicing - ready to
            use them to create ``self.__class__.__init__(**kwargs)`` in
            ``__getitem__``.
        u   datau   uncertaintyu   masku   wcsu   unitu   meta(   R   t   _slice_uncertaintyt   _slice_maskt
   _slice_wcst   unitt   meta(   R   R   R   (    (    s>   lib/python2.7/site-packages/astropy/nddata/mixins/ndslicing.pyR	   A   s    c         C` sJ   |  j  d  k r d  Sy |  j  | SWn t k
 rB t j d ƒ n X|  j  S(   Nu   uncertainty cannot be sliced.(   t   uncertaintyt   NoneR   R   t   info(   R   R   (    (    s>   lib/python2.7/site-packages/astropy/nddata/mixins/ndslicing.pyR   b   s    c         C` sJ   |  j  d  k r d  Sy |  j  | SWn t k
 rB t j d ƒ n X|  j  S(   Nu   mask cannot be sliced.(   t   maskR   R   R   R   (   R   R   (    (    s>   lib/python2.7/site-packages/astropy/nddata/mixins/ndslicing.pyR   m   s    c         C` sJ   |  j  d  k r d  Sy |  j  | SWn t k
 rB t j d ƒ n X|  j  S(   Nu   wcs cannot be sliced.(   t   wcsR   R   R   R   (   R   R   (    (    s>   lib/python2.7/site-packages/astropy/nddata/mixins/ndslicing.pyR   v   s    (   t   __name__t
   __module__t   __doc__R   R	   R   R   R   (    (    (    s>   lib/python2.7/site-packages/astropy/nddata/mixins/ndslicing.pyR      s   +			!			N(
   t
   __future__R    R   R   R   t    R   t   __all__t   objectR   (    (    (    s>   lib/python2.7/site-packages/astropy/nddata/mixins/ndslicing.pyt   <module>   s   "	