σ
ίΘ[c           @   sb   d  Z  d d l m Z d d l m Z d d g Z d e f d     YZ d e f d     YZ d	 S(
   s    
Special models useful for complex compound models where control is needed over
which outputs from a source model are mapped to which inputs of a target model.
i   (   t   FittableModeli   (   t   ranget   Mappingt   Identityc           B   st   e  Z d  Z e Z d d d d  Z e d    Z e d    Z	 e d    Z
 d   Z d   Z e d    Z RS(	   s¬  
    Allows inputs to be reordered, duplicated or dropped.

    Parameters
    ----------
    mapping : tuple
        A tuple of integers representing indices of the inputs to this model
        to return and in what order to return them.  See
        :ref:`compound-model-mappings` for more details.
    n_inputs : int
        Number of inputs; if `None` (default) then ``max(mapping) + 1`` is
        used (i.e. the highest input index used in the mapping).
    name : str, optional
        A human-friendly name associated with this model instance
        (particularly useful for identifying the individual components of a
        compound model).
    meta : dict-like
        Free-form metadata to associate with this model.

    Raises
    ------
    TypeError
        Raised when number of inputs is less that ``max(mapping)``.

    Examples
    --------

    >>> from astropy.modeling.models import Polynomial2D, Shift, Mapping
    >>> poly1 = Polynomial2D(1, c0_0=1, c1_0=2, c0_1=3)
    >>> poly2 = Polynomial2D(1, c0_0=1, c1_0=2.4, c0_1=2.1)
    >>> model = (Shift(1) & Shift(2)) | Mapping((0, 1, 0, 1)) | (poly1 & poly2)
    >>> model(1, 2)  # doctest: +FLOAT_CMP
    (17.0, 14.2)
    c         C   s¨   | d  k r8 t d   t t |  d  D  |  _ n t d   t |  D  |  _ t d   t t |   D  |  _ | |  _ t t	 |   j
 d | d |  d  S(   Nc         s   s   |  ] } d  t  |  Vq d S(   t   xN(   t   str(   t   .0t   idx(    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pys	   <genexpr>4   s   i   c         s   s   |  ] } d  t  |  Vq d S(   R   N(   R   (   R   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pys	   <genexpr>7   s   c         s   s   |  ] } d  t  |  Vq d S(   R   N(   R   (   R   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pys	   <genexpr>9   s    t   namet   meta(   t   Nonet   tupleR   t   maxt   _inputst   lent   _outputst   _mappingt   superR   t   __init__(   t   selft   mappingt   n_inputsR   R	   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyR   2   s    	#	%	c         C   s   |  j  S(   sU   
        The name(s) of the input variable(s) on which a model is evaluated.
        (   R   (   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyt   inputs=   s    c         C   s   |  j  S(   s*   The name(s) of the output(s) of the model.(   R   (   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyt   outputsE   s    c         C   s   |  j  S(   s,   Integers representing indices of the inputs.(   R   (   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyR   K   s    c         C   s9   |  j  d  k r d j |  j  Sd j |  j |  j   Sd  S(   Ns   <Mapping({0})>s   <Mapping({0}, name={1})>(   R   R
   t   formatR   (   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyt   __repr__Q   s    c            s   t     |  j k rZ |  j d  k	 r- |  j n d } t d j | |  j t        n  t   f d   |  j D  } |  j d k r | d S| S(   NR   s   {0} expects {1} inputs; got {2}c         3   s   |  ] }   | Vq d  S(   N(    (   R   R   (   t   args(    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pys	   <genexpr>^   s    i   i    (	   R   R   R   R
   t	   TypeErrorR   R   R   t	   n_outputs(   R   R   R   t   result(    (   R   s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyt   evaluateW   s    	c            s   y) t    f d   t   j  D  } Wn) t k
 rT t d j   j    n X  j |  }   j | _	   j	 | _ | S(   s)  
        A `Mapping` representing the inverse of the current mapping.

        Raises
        ------
        `NotImplementedError`
            An inverse does no exist on mappings that drop some of its inputs
            (there is then no way to reconstruct the inputs that were dropped).
        c         3   s!   |  ] }   j  j |  Vq d  S(   N(   R   t   index(   R   R   (   R   (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pys	   <genexpr>r   s   s[   Mappings such as {0} that drop one or more of their inputs are not invertible at this time.(
   R   R   R   t
   ValueErrort   NotImplementedErrorR   R   t	   __class__R   R   (   R   R   t   inv(    (   R   s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyt   inversee   s    N(   t   __name__t
   __module__t   __doc__t   Truet   linearR
   R   t   propertyR   R   R   R   R   R$   (    (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyR      s   "		c           B   s;   e  Z d  Z e Z d d d  Z d   Z e d    Z	 RS(   sα  
    Returns inputs unchanged.

    This class is useful in compound models when some of the inputs must be
    passed unchanged to the next model.

    Parameters
    ----------
    n_inputs : int
        Specifies the number of inputs this identity model accepts.
    name : str, optional
        A human-friendly name associated with this model instance
        (particularly useful for identifying the individual components of a
        compound model).
    meta : dict-like
        Free-form metadata to associate with this model.

    Examples
    --------

    Transform ``(x, y)`` by a shift in x, followed by scaling the two inputs::

        >>> from astropy.modeling.models import (Polynomial1D, Shift, Scale,
        ...                                      Identity)
        >>> model = (Shift(1) & Identity(1)) | Scale(1.2) & Scale(2)
        >>> model(1,1)  # doctest: +FLOAT_CMP
        (2.4, 2.0)
        >>> model.inverse(2.4, 2) # doctest: +FLOAT_CMP
        (1.0, 1.0)
    c         C   s8   t  t |   } t t |   j | d | d | d  S(   NR   R	   (   R   R   R   R   R   (   R   R   R   R	   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyR       s    c         C   s9   |  j  d  k r d j |  j  Sd j |  j |  j   Sd  S(   Ns   <Identity({0})>s   <Identity({0}, name={1})>(   R   R
   R   R   (   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyR   €   s    c         C   s   |  S(   sl   
        The inverse transformation.

        In this case of `Identity`, ``self.inverse is self``.
        (    (   R   (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyR$   ͺ   s    N(
   R%   R&   R'   R(   R)   R
   R   R   R*   R$   (    (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyR      s
   	N(   R'   t   coreR    t   extern.six.movesR   t   __all__R   R   (    (    (    s8   lib/python2.7/site-packages/astropy/modeling/mappings.pyt   <module>   s
   r