
[c           @` s_  d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l m Z m Z d d l m Z m Z d d l Z d d l m Z m Z m Z d d l m Z d d	 l m Z m Z d d
 l m Z d d l  m! Z! m" Z" m# Z# d d l$ m% Z% d d l m& Z& m' Z' m( Z( m) Z) m* Z* m+ Z+ m, Z, d d l- m. Z. d d l/ m0 Z0 d d l1 m2 Z2 d d l m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 d d l: m; Z; m< Z< d d l= m> Z> m? Z? m@ Z@ d d d d d d g ZA d eB f d     YZC d   ZD d e) e( e jE f d     YZF e jG eF  d  eH f d!     Y ZI d" eI f d#     YZJ d$ eJ f d%     YZK d& eJ f d'     YZL d(   ZM d)   ZN d*   ZO i eM e
 jP  d+ 6eM e
 jQ  d, 6eM e
 jR  d- 6eM e
 jS  d. 6eM e
 jT  d/ 6eN d0 6eO d1 6ZU d0 f d1 f d+ d, f d- d. f d/ f g ZV i  ZW x5 eX eV  D]' \ ZY ZZ x eZ D] Z[ eY eW e[ <qWquW[Y [[ [Z d2 eF f d3     YZ\ e jG e\  d4 eI f d5     Y Z] d6   Z^ e_ d7  Z` e_ e_ d8  Za d9   Zb d:   Zc d;   Zd d<   Ze d=   Zf e jg eF eF jh  e jg e\ e\ jh  d S(>   ud  
This module defines base classes for all models.  The base class of all
models is `~astropy.modeling.Model`. `~astropy.modeling.FittableModel` is
the base class for all fittable models. Fittable models can be linear or
nonlinear in a regression analysis sense.

All models provide a `__call__` method which performs the transformation in
a purely mathematical way, i.e. the models are unitless.  Model instances can
represent either a single model, or a "model set" representing multiple copies
of the same type of model, but with potentially different values of the
parameters in each model making up the set.
i    (   t   absolute_importt   unicode_literalst   divisiont   print_functionN(   t   defaultdictt   OrderedDict(   t   chaint   islicei   (   t   indentt   isinstancemethodt   metadata(   t   six(   t   copyregt   zip(   t   Table(   t   Quantityt
   UnitsErrort   dimensionless_unscaled(   t   quantity_asanyarray(   t   sharedmethodt   find_current_modulet   InheritDocstringst   OrderedDescriptorContainert   check_broadcastt   IncompatibleShapeErrort
   isiterable(   t   make_function_with_signature(   t   suppress(   t	   signaturei   (   t   combine_labelst   make_binary_operator_evalt   ExpressionTreet	   AliasDictt   get_inputs_and_paramst   _BoundingBoxt   _combine_equivalency_dict(   t	   add_arrayt   extract_array(   t	   Parametert   InputParameterErrort   param_repr_onelineu   Modelu   FittableModelu   Fittable1DModelu   Fittable2DModelu   custom_modelu   ModelDefinitionErrort   ModelDefinitionErrorc           B` s   e  Z d  Z RS(   u%   Used for incorrect models definitions(   t   __name__t
   __module__t   __doc__(    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR)   8   s   c         ` s      f d   S(   u  
    Returns a function that evaluates a given Python arithmetic operator
    between two models.  The operator should be given as a string, like ``'+'``
    or ``'**'``.

    Any additional keyword arguments passed in are passed to
    `_CompoundModelMeta._from_operator`.
    c         ` s   t  j  |  |    S(   N(   t   _CompoundModelMetat   _from_operator(   t   leftt   right(   t   kwargst   oper(    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   <lambda>K   s   	(    (   R2   R1   (    (   R1   R2   s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _model_oper<   s    t
   _ModelMetac           B` s4  e  Z d  Z e   Z e Z e   Z d   Z	 d   Z
 d   Z d   Z d   Z e d    Z e d    Z e d    Z e d	    Z d
   Z d   Z d   Z d   Z d   Z e d  Z e d  Z e d  Z e d  Z e d  Z e d  Z e d  Z e  j! r&e d  Z" n  g  d  Z# RS(   u   
    Metaclass for Model.

    Currently just handles auto-generating the param_names list based on
    Parameter descriptors declared at the class-level of Model subclasses.
    c         C` s;   d | k r |  j  | d <n  t t |   j |  | | |  S(   Nu   _is_dynamic(   t   _is_dynamict   superR5   t   __new__(   t   mclst   namet   basest   members(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR8   m   s    c         C` s   t  t |   j | | |  |  j r^ t |  d  rI t |  j  |  _ q^ t |  j  |  _ n  |  j |  |  j	 |  |  j
 |  t j |   r | j d  r |  j j |   n  d  S(   Nu   _param_namesu   _(   R7   R5   t   __init__t   _parameters_t   hasattrt   tuplet   _param_namest   param_namest   _create_inverse_propertyt   _create_bounding_box_propertyt   _handle_special_methodst   inspectt
   isabstractt
   startswitht   registryt   add(   t   clsR:   R;   R<   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR=   t   s    	 c         C` s
   |  j    S(   u3   
        Custom repr for Model subclasses.
        (   t   _format_cls_repr(   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   __repr__   s    c         C` s   | j  t |    d S(   u   
        Repr for IPython's pretty printer.

        By default IPython "pretty prints" classes, so we need to implement
        this so that IPython displays the custom repr for Models.
        N(   t   textt   repr(   RK   t   pt   cycle(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _repr_pretty_   s    c         C` s   |  j  s |  j St |  j  } x- t |  D] } | j d  r, | | =q, q, Wx$ d D] } | | k rV | | =qV qV Wt |   |  j |  j | f f Sd  S(   Nu   _abc_u   __init__u   __call__(   u   __init__u   __call__(   R6   R*   t   dictt   __dict__t   listRH   t   typet	   __bases__(   RK   R<   t   key(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt
   __reduce__   s    	c         C` s   |  j  S(   u   
        The name of this model class--equivalent to ``cls.__name__``.

        This attribute is provided for symmetry with the `Model.name` attribute
        of model instances.
        (   R*   (   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR:      s    	c         C` s   t  |  j  S(   N(   t   lent   inputs(   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   n_inputs   s    c         C` s   t  |  j  S(   N(   RZ   t   outputs(   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt	   n_outputs   s    c         C` s    |  j  j d  p t j |   S(   u   
        A class-level property that determines whether the class is a concrete
        implementation of a Model--i.e. it is not some abstract base class or
        internal implementation detail (i.e. begins with '_').
        u   _(   R*   RH   RF   RG   (   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _is_concrete   s    c         C` s   t  j r- t | t  j  r- | j d  } n  t d  } | rK | j } n d } t | |  f i   } t |  | _	 t
 |  d  r | j	 d k r | | _ q d j | |  | _ n  | S(   u  
        Creates a copy of this model class with a new name.

        The new class is technically a subclass of the original class, so that
        instance and type checks will still work.  For example::

            >>> from astropy.modeling.models import Rotation2D
            >>> SkyRotation = Rotation2D.rename('SkyRotation')
            >>> SkyRotation
            <class '__main__.SkyRotation'>
            Name: SkyRotation (Rotation2D)
            Inputs: ('x', 'y')
            Outputs: ('x', 'y')
            Fittable parameters: ('angle',)
            >>> issubclass(SkyRotation, Rotation2D)
            True
            >>> r = SkyRotation(90)
            >>> isinstance(r, Rotation2D)
            True
        u   asciii   u   __main__u   __qualname__u   {0}.{1}(   R   t   PY2t
   isinstancet	   text_typet   encodeR   R*   RV   t   strR+   R?   t   __qualname__t   format(   RK   R:   t   modt   modnamet   new_cls(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   rename   s    c         C` s`   | j  d  } | d  k s. |  j d t k r2 d  St | t  rM | j } n  | |  _ |  ` d  S(   Nu   inversei    (	   t   gett   NoneRW   t   objectRa   t   propertyt   fgett   _inverset   inverse(   RK   R<   Rq   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRC      s    	c         C` s  | j  d  } | d k s. |  j d t k r2 d St | t  rM | j } n  t |  s y t j	 |  |  } Wq t
 k
 r } t | j d   q Xn6 t |  } t | j  d k r |  j | |  } n  t j r t | t j  r | j } n  | |  _ |  ` d S(   u   
        Takes any bounding_box defined on a concrete Model subclass (either
        as a fixed tuple or a property or method) and wraps it in the generic
        getter/setter interface for the bounding_box attribute.
        u   bounding_boxi    Ni   (   Rk   Rl   RW   Rm   Ra   Rn   Ro   t   callableR"   t   validatet
   ValueErrorR)   t   argsR   RZ   t
   parameterst   _create_bounding_box_subclassR   R`   t   typest
   MethodTypet   __func__t   _bounding_boxt   bounding_box(   RK   R<   R|   t   exct   sig(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRD     s"    
	c         ` s     f d   } g  } x{ t  | j j    D]d \ } } | d k rI q+ n  | j | j k rv t d j |  j    n  | j | j | j f  q+ Wt	 | d |  } t
 t d j |  j   t f i | d 6 S(   u  
        For Models that take optional arguments for defining their bounding
        box, we create a subclass of _BoundingBox with a ``__call__`` method
        that supports those additional arguments.

        Takes the function's Signature as an argument since that is already
        computed in _create_bounding_box_property, so no need to duplicate that
        effort.
        c         ` s     |  j  |  S(   N(   t   _model(   t   selfR1   (   t   func(    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   __call__O  s    i    u   The bounding_box method for {0} is not correctly defined: If defined as a method all arguments to that method (besides self) must be keyword arguments with default values that can be used to compute a default bounding box.u   selfu   _{0}BoundingBoxu   __call__(   u   self(   t	   enumerateRv   t   valuest   defaultt   emptyR)   Rf   R:   t   appendR   RV   Rd   R"   (   RK   R   R~   R   R1   t   idxt   param(    (   R   s4   lib/python2.7/site-packages/astropy/modeling/core.pyRw   8  s    "c         ` s  d   } d | k r d | k r t  | d t  r   f d   } | d } d | } t | | d d t f d t j f d g  } | |    |   _ n  d
 | k rt j	    r  j
 rt d   t j   j
  D  r^d } g  } x~   j D]] }   j
 | j }	   j
 | j }
 |
 d  k	 rDt |	 |
 d t }	 n  | j | |	 f  q Wn d   j } i  }   f d   } t | | | d d } | |    |   _ n  d  S(   Nc         S` sU   | j  |  _  t | |  j  j |  _ t | d  rQ d j | j |  j  |  _ n  d  S(   Nu   __qualname__u   {0}.{1}(   R+   t   getattrR*   R,   R?   Rf   Re   (   t   wrapperRK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   update_wrapperj  s
    u   __call__u   inputsc         ` s   t    |   j | |   S(   u+   Evaluate this model on the supplied inputs.(   R7   R   (   R   R[   R1   (   RK   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR   |  s    u   selfu   model_set_axisu   with_bounding_boxu
   fill_valueu   equivalenciesu   __init__c         s` s   |  ] } | j  d  k	 Vq d  S(   N(   R   Rl   (   t   .0RP   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>  s    t   copyc         ` s   t    |   j | |   S(   N(   R7   R=   (   R   t   paramsR1   (   RK   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR=     s    t	   varkwargsu   kwargs(   u   self(   u   model_set_axisN(   u   equivalenciesN(   u   self(   u   self(   Ra   R@   R   Rl   t   Falset   npt   nanR   RF   RG   R>   t   allR   t
   itervaluesRB   R   t   unitR   R   R=   (   RK   R<   R   R   R[   Ru   t   new_callR1   t
   param_nameR   R   R=   t   new_init(    (   RK   s4   lib/python2.7/site-packages/astropy/modeling/core.pyRE   g  s>    	

			"u   +u   -u   *u   /u   **u   |u   &c         C` s   t  t |   j   g } |  j s) | d Sd   } y d | |   f d |  j f d |  j f g } |  j r | j d |  j f  n  x@ | | D]4 \ } } | d	 k	 r | j d j	 | |   q q Wd j
 |  SWn t k
 r | d SXd	 S(
   u   
        Internal implementation of ``__repr__``.

        This is separated out for ease of use by subclasses that wish to
        override the default ``__repr__`` while keeping the same basic
        formatting.
        i    c         S` s   g  } xb |  j    d D]P } t | t  s2 q n% t j |  sS | j j d  rW Pn  | j | j  q W| r d j	 |  j d j
 |   S|  j Sd  S(   Ni   u   _u	   {0} ({1})u    -> (   t   mrot
   issubclasst   ModelRF   RG   R*   RH   R   R:   Rf   t   join(   RK   R;   t   base(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   format_inheritance  s    u   Nameu   Inputsu   Outputsu   Fittable parametersu   {0}: {1}u   
N(   R7   R5   RM   R_   R[   R]   RB   R   Rl   Rf   R   t	   Exception(   RK   t   keywordst   partsR   t   default_keywordst   keywordt   value(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRL     s"    				 ($   R*   R+   R,   t   setRI   R   R6   R   R>   R8   R=   RM   RR   RY   Rn   R:   R\   R^   R_   Rj   RC   RD   Rw   RE   R4   t   __add__t   __sub__t   __mul__t   __truediv__t   __pow__t   __or__t   __and__R   R`   t   __div__RL   (    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR5   O   s8   						
			/		,	/	N	R   c           B` s  e  Z d  Z e j Z d= Z d> Z d? Z d@ Z	 e
 Z e Z e
 Z e j   Z dA Z dA Z dA Z dA Z d Z e Z e Z dA Z d   Z d   Z d   Z d   Z d   Z e  d	  Z! e  d
  Z" e  d  Z# e  d  Z$ e  d  Z% e  d  Z& e  d  Z' e( j) re  d  Z* n  e+ d    Z, e, j- d    Z, e+ d    Z. e+ d    Z/ e+ d    Z0 e+ d    Z1 e+ d    Z2 e2 j- d    Z2 e+ d    Z3 e+ d    Z4 e+ d    Z5 e+ d    Z6 e+ d    Z7 e+ d    Z8 e8 j- d    Z8 e8 j9 d    Z8 e+ d     Z: e+ d!    Z; e; j- d"    Z; e; j9 d#    Z; e+ d$    Z< d%   Z= d&   Z> e+ d'    Z? e+ d(    Z@ eA jB d)    ZC d*   ZD dA dA d+  ZE e+ d,    ZF eF j- d-    ZF e+ d.    ZG eG j- d/    ZG d0   ZH d1   ZI d2   ZJ eK d3    ZL eK d4    ZM eK d5    ZN d6   ZO d7   ZP d8   ZQ d9   ZR e e d:  ZS g  i  i  d;  ZT g  d<  ZU RS(B   u  
    Base class for all models.

    This is an abstract class and should not be instantiated directly.

    This class sets the constraints and other properties for all individual
    parameters and performs parameter validation.

    The following initialization arguments apply to the majority of Model
    subclasses by default (exceptions include specialized utility models
    like `~astropy.modeling.mappings.Mapping`).  Parametric models take all
    their parameters as arguments, followed by any of the following optional
    keyword arguments:

    Parameters
    ----------
    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, optional
        An optional dict of user-defined metadata to attach to this model.
        How this is used and interpreted is up to the user or individual use
        case.

    n_models : int, optional
        If given an integer greater than 1, a *model set* is instantiated
        instead of a single model.  This affects how the parameter arguments
        are interpreted.  In this case each parameter must be given as a list
        or array--elements of this array are taken along the first axis (or
        ``model_set_axis`` if specified), such that the Nth element is the
        value of that parameter for the Nth model in the set.

        See the section on model sets in the documentation for more details.

    model_set_axis : int, optional
        This argument only applies when creating a model set (i.e. ``n_models >
        1``).  It changes how parameter values are interpreted.  Normally the
        first axis of each input parameter array (properly the 0th axis) is
        taken as the axis corresponding to the model sets.  However, any axis
        of an input array may be taken as this "model set axis".  This accepts
        negative integers as well--for example use ``model_set_axis=-1`` if the
        last (most rapidly changing) axis should be associated with the model
        sets. Also, ``model_set_axis=False`` can be used to tell that a given
        input should be used to evaluate all the models in the model set.

    fixed : dict, optional
        Dictionary ``{parameter_name: bool}`` setting the fixed constraint
        for one or more parameters.  `True` means the parameter is held fixed
        during fitting and is prevented from updates once an instance of the
        model has been created.

        Alternatively the `~astropy.modeling.Parameter.fixed` property of a
        parameter may be used to lock or unlock individual parameters.

    tied : dict, optional
        Dictionary ``{parameter_name: callable}`` of parameters which are
        linked to some other parameter. The dictionary values are callables
        providing the linking relationship.

        Alternatively the `~astropy.modeling.Parameter.tied` property of a
        parameter may be used to set the ``tied`` constraint on individual
        parameters.

    bounds : dict, optional
        A dictionary ``{parameter_name: value}`` of lower and upper bounds of
        parameters. Keys are parameter names. Values are a list or a tuple
        of length 2 giving the desired range for the parameter.

        Alternatively the `~astropy.modeling.Parameter.min` and
        `~astropy.modeling.Parameter.max` or
        ~astropy.modeling.Parameter.bounds` properties of a parameter may be
        used to set bounds on individual parameters.

    eqcons : list, optional
        List of functions of length n such that ``eqcons[j](x0, *args) == 0.0``
        in a successfully optimized problem.

    ineqcons : list, optional
        List of functions of length n such that ``ieqcons[j](x0, *args) >=
        0.0`` is a successfully optimized problem.

    Examples
    --------
    >>> from astropy.modeling import models
    >>> def tie_center(model):
    ...         mean = 50 * model.stddev
    ...         return mean
    >>> tied_parameters = {'mean': tie_center}

    Specify that ``'mean'`` is a tied parameter in one of two ways:

    >>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3,
    ...                        tied=tied_parameters)

    or

    >>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3)
    >>> g1.mean.tied
    False
    >>> g1.mean.tied = tie_center
    >>> g1.mean.tied
    <function tie_center at 0x...>

    Fixed parameters:

    >>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3,
    ...                        fixed={'stddev': True})
    >>> g1.stddev.fixed
    True

    or

    >>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3)
    >>> g1.stddev.fixed
    False
    >>> g1.stddev.fixed = True
    >>> g1.stddev.fixed
    True
    u   eqconsu   ineqconsi   c         O` ss   t  t |   j   | j d d   } | d  k	 r= | |  _ n  | j d d   |  _ |  j |  |  j | |  d  S(   Nu   metau   name(	   R7   R   R=   t   popRl   t   metat   _namet   _initialize_constraintst   _initialize_parameters(   R   Ru   R1   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR=     s    c         C` s
   |  j    S(   N(   t   _format_repr(   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRM     s    c         C` s
   |  j    S(   N(   t   _format_str(   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   __str__  s    c         C` s   |  j  S(   N(   t	   _n_models(   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   __len__  s    c         O` s,  |  j  | |   \ } } t g  | D] } t | t  ^ q"  } |  j d t d t  } | j d t  } | j d t j	  } d }	 | r-y |  j }	 Wn t k
 r d }	 n X|  j d k r |	 d k	 r |	 d d d  }	 n  |	 d k r
|  j t | |    }
 qE|  j d k r%|	 g }	 n  t j | d j d	 t j } xs t |  D]e \ } } t j | j d	 t j } t j | |	 | d k  | |	 | d k d
 | } d | | <qQWt j |  j   } g  } xZ | D]R } | j s| rg  | D] } | ^ q}
 q.| j |  q| j | |  qW|  j t | |    } |  j d k re| g } n  g  t t |   D]  } t j | d j  | ^ qx} xB t |  D]4 \ } } | | j s| | | <q| | | | <qW|  j d k rt j | d  }
 qEg  | D] } t j |  ^ q}
 n |  j t | |    }
 |  j d k r`|
 f }
 n  |  j | |
 |  }
 |  j r| r|  j d k rt |  j  ri |  j |  j d 6} n	 |  j } t  g  t! |
 |  j  D]% \ } } t | | | d t ^ q }
 n  |  j d k r$|
 d S|
 Sd S(   u   
        Evaluate this model using the given input(s) and the parameter values
        that were specified when the model was instantiated.
        t   rawt   unitsu   with_bounding_boxu
   fill_valuei   Nii    t   dtypet   outt   subok("   t   prepare_inputst   anyRa   R   t   _param_setst   TrueR   R   R   R   Rl   R|   t   NotImplementedErrorR\   t   evaluateR   t   zerost   shapet   boolR   t
   logical_ort   logical_nott   nonzeroR   R^   t   rangeRZ   t   asarrayt   prepare_outputst   return_unitsR   R]   R@   R   (   R   R[   R1   t   format_infot   it   inputs_are_quantityRv   t	   with_bboxt
   fill_valuet   bboxR]   t   nan_indt   indt   inpt   axis_indt	   valid_indRu   t   inputt   at   valid_resultt   resultt   rR   R   t   out_name(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     sl    (
4	9%	Au   +u   -u   *u   /u   **u   |u   &c         C` s   |  j  S(   u+   User-provided name for this model instance.(   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR:   6  s    c         C` s   | |  _  d S(   u"   Assign a (new) name to this model.N(   R   (   R   t   val(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR:   <  s    c         C` s   t  |  j  S(   uc   
        The number of inputs to this model.

        Equivalent to ``len(model.inputs)``.
        (   RZ   R[   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR\   B  s    c         C` s   t  |  j  S(   ug   
        The number of outputs from this model.

        Equivalent to ``len(model.outputs)``.
        (   RZ   R]   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR^   L  s    c         C` s   |  j  S(   ug  
        The index of the model set axis--that is the axis of a parameter array
        that pertains to which model a parameter value pertains to--as
        specified when the model was initialized.

        See the documentation on `Model Sets
        <http://docs.astropy.org/en/stable/modeling/models.html#model-sets>`_
        for more details.
        (   t   _model_set_axis(   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   model_set_axisU  s    c         C` s
   |  j    S(   u   
        Return parameters as a pset.

        This is a list with one item per parameter set, which is an array of
        that parameter's values across all parameter sets, with the last axis
        associated with the parameter set.
        (   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt
   param_setsc  s    
c         C` sT   |  j  s |  j S|  j |  j  d d j } |  j |  j  d d j } |  j | | !S(   u   
        A flattened array of all parameter values in all parameter sets.

        Fittable parameters maintain this list and fitters modify it.
        i    u   slicei(   RB   t   _parameterst   _param_metricst   startt   stop(   R   R   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRv   o  s
    	c         C` s   |  j  s d S|  j |  j  d d j } |  j |  j  d d j } y) t j |  j   } | |  j | | +Wn( t k
 r } t	 d j
 |    n Xd S(   ul   
        Assigning to this attribute updates the parameters array rather than
        replacing it.
        Ni    u   sliceiuJ   Input parameter values not compatible with the model parameters array: {0}(   RB   R   R   R   R   t   arrayt   flattenR   Rt   R'   Rf   (   R   R   R   R   t   e(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRv     s    	c         C` s   |  j  d S(   uM   
        A `dict` mapping parameter names to their fixed constraint.
        u   fixed(   t   _constraints(   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   fixed  s    c         C` s   |  j  d S(   uL   
        A `dict` mapping parameter names to their tied constraint.
        u   tied(   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   tied  s    c         C` s   |  j  d S(   u   
        A `dict` mapping parameter names to their upper and lower bounds as
        ``(min, max)`` tuples or ``[min, max]`` lists.
        u   bounds(   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   bounds  s    c         C` s   |  j  d S(   u'   List of parameter equality constraints.u   eqcons(   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   eqcons  s    c         C` s   |  j  d S(   u)   List of parameter inequality constraints.u   ineqcons(   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   ineqcons  s    c         C` s?   |  j  d k	 r |  j  S|  j d k	 r/ |  j   St d   d S(   u  
        Returns a new `~astropy.modeling.Model` instance which performs the
        inverse transform, if an analytic inverse is defined for this model.

        Even on models that don't have an inverse defined, this property can be
        set with a manually-defined inverse, such a pre-computed or
        experimentally determined inverse (often given as a
        `~astropy.modeling.polynomial.PolynomialModel`, but not by
        requirement).

        A custom inverse can be deleted with ``del model.inverse``.  In this
        case the model's inverse is reset to its default, if a default exists
        (otherwise the default is to raise `NotImplementedError`).

        Note to authors of `~astropy.modeling.Model` subclasses:  To define an
        inverse for a model simply override this property to return the
        appropriate model representing the inverse.  The machinery that will
        make the inverse manually-overridable is added automatically by the
        base class.
        uH   An analytical inverse transform has not been implemented for this model.N(   t   _user_inverseRl   Rp   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRq     s
    
c         C` s7   t  | t t d   f  s* t d   n  | |  _ d  S(   Nu   The ``inverse`` attribute may be assigned a `Model` instance or `None` (where `None` explicitly forces the model to have no inverse.(   Ra   R   RV   Rl   Rt   R   (   R   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRq     s    c         C` s
   |  `  d S(   u~   
        Resets the model's inverse to its default (if one exists, otherwise
        the model will have no inverse).
        N(   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRq     s    c         C` s   |  j  d k	 S(   u   
        A flag indicating whether or not a custom inverse model has been
        assigned to this model by a user, via assignment to ``model.inverse``.
        N(   R   Rl   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   has_user_inverse  s    c         C` s   |  j  d k	 r4 |  j  t k r- t d   n  |  j  S|  j d k rR t d   nc t |  j t  rk |  j St |  j t j  r |  j   S|  j d d |    } |  j | d |  Sd S(   u
  
        A `tuple` of length `n_inputs` defining the bounding box limits, or
        `None` for no bounding box.

        The default limits are given by a ``bounding_box`` property or method
        defined in the class body of a specific model.  If not defined then
        this property just raises `NotImplementedError` by default (but may be
        assigned a custom value by a user).  ``bounding_box`` can be set
        manually to an array-like object of shape ``(model.n_inputs, 2)``. For
        further usage, see :ref:`bounding-boxes`

        The limits are ordered according to the `numpy` indexing
        convention, and are the reverse of the model input order,
        e.g. for inputs ``('x', 'y', 'z')``, ``bounding_box`` is defined:

        * for 1D: ``(x_low, x_high)``
        * for 2D: ``((y_low, y_high), (x_low, x_high))``
        * for 3D: ``((z_low, z_high), (y_low, y_high), (x_low, x_high))``

        Examples
        --------

        Setting the ``bounding_box`` limits for a 1D and 2D model:

        >>> from astropy.modeling.models import Gaussian1D, Gaussian2D
        >>> model_1d = Gaussian1D()
        >>> model_2d = Gaussian2D(x_stddev=1, y_stddev=1)
        >>> model_1d.bounding_box = (-5, 5)
        >>> model_2d.bounding_box = ((-6, 6), (-5, 5))

        Setting the bounding_box limits for a user-defined 3D `custom_model`:

        >>> from astropy.modeling.models import custom_model
        >>> def const3d(x, y, z, amp=1):
        ...    return amp
        ...
        >>> Const3D = custom_model(const3d)
        >>> model_3d = Const3D()
        >>> model_3d.bounding_box = ((-6, 6), (-5, 5), (-4, 4))

        To reset ``bounding_box`` to its default limits just delete the
        user-defined value--this will reset it back to the default defined
        on the class:

        >>> del model_1d.bounding_box

        To disable the bounding box entirely (including the default),
        set ``bounding_box`` to `None`:

        >>> model_1d.bounding_box = None
        >>> model_1d.bounding_box  # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          File "astropy\modeling\core.py", line 980, in bounding_box
            "No bounding box is defined for this model (note: the "
        NotImplementedError: No bounding box is defined for this model (note:
        the bounding box was explicitly disabled for this model; use `del
        model.bounding_box` to restore the default bounding box, if one is
        defined for this model).
        u   No bounding box is defined for this model (note: the bounding box was explicitly disabled for this model; use `del model.bounding_box` to restore the default bounding box, if one is defined for this model).u*   No bounding box is defined for this model.R   N(    (	   t   _user_bounding_boxRl   t   NotImplementedR   R{   Ra   R"   Rx   Ry   (   R   R|   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR|     s    ?
c         C` s   | d k r d } t } n6 t |  j t  rK t |  j t  rK |  j } n t } | d k	 r y | j |  |  } Wq t k
 r } t | j	 d   q Xn  | |  _
 d S(   u2   
        Assigns the bounding box limits.
        i    N(   Rl   R   Ra   R{   RV   R   R"   Rs   Rt   Ru   R   (   R   R|   RK   R}   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR|   R  s    	c         C` s   d  |  _ d  S(   N(   Rl   R   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR|   k  s    c         C` s   |  j  d k	 S(   u   
        A flag indicating whether or not a custom bounding_box has been
        assigned to this model by a user, via assignment to
        ``model.bounding_box``.
        N(   R   Rl   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   has_user_bounding_boxo  s    c   	      ` s   |  j    }   f d   |  j D }   f d   |  j D } |  j | |  } xf | j   D]X \ } } t | |  } | j d k	 r] | j j	 |  j
 | _
 | j d d t q] q] W| S(   u  
        Return an instance of the model for which the parameter values have been
        converted to the right units for the data, then the units have been
        stripped away.

        The input and output Quantity objects should be given as keyword
        arguments.

        Notes
        -----

        This method is needed in order to be able to fit models with units in
        the parameters, since we need to temporarily strip away the units from
        the model during the fitting (which might be done by e.g. scipy
        functions).

        The units that the parameters should be converted to are not necessarily
        the units of the input data, but are derived from them. Model subclasses
        that want fitting to work in the presence of quantities need to define a
        _parameter_units_for_data_units method that takes the input and output
        units (as two dictionaries) and returns a dictionary giving the target
        units for each parameter.
        c         ` s9   i  |  ]/ }   | d k	 r t   | d  t  |  q S(   u   unitN(   Rl   R   R   (   R   R   (   R1   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys
   <dictcomp>  s   	c         ` s9   i  |  ]/ }   | d k	 r t   | d  t  |  q S(   u   unitN(   Rl   R   R   (   R   R   (   R1   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys
   <dictcomp>  s   	t   forceN(   R   R[   R]   t   _parameter_units_for_data_unitst   itemsR   R   Rl   t   quantityt   toR   t	   _set_unitR   (	   R   R1   t   modelt   inputs_unitt   outputs_unitt   parameter_unitsR:   R   t	   parameter(    (   R1   s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   without_units_for_data{  s    c   	      ` s   |  j    }   f d   |  j D }   f d   |  j D } |  j | |  } x< | j   D]. \ } } t | |  } | j | d t q] W| S(   u  
        Return an instance of the model which has units for which the parameter
        values are compatible with the data units specified.

        The input and output Quantity objects should be given as keyword
        arguments.

        Notes
        -----

        This method is needed in order to be able to fit models with units in
        the parameters, since we need to temporarily strip away the units from
        the model during the fitting (which might be done by e.g. scipy
        functions).

        The units that the parameters will gain are not necessarily the units of
        the input data, but are derived from them. Model subclasses that want
        fitting to work in the presence of quantities need to define a
        _parameter_units_for_data_units method that takes the input and output
        units (as two dictionaries) and returns a dictionary giving the target
        units for each parameter.
        c         ` s9   i  |  ]/ }   | d k	 r t   | d  t  |  q S(   u   unitN(   Rl   R   R   (   R   R   (   R1   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys
   <dictcomp>  s   	c         ` s9   i  |  ]/ }   | d k	 r t   | d  t  |  q S(   u   unitN(   Rl   R   R   (   R   R   (   R1   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys
   <dictcomp>  s   	R   (   R   R[   R]   R   R   R   R   R   (	   R   R1   R   R   R   R   R:   R   R   (    (   R1   s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   with_units_from_data  s    c         C` s8   x1 |  j  D]" } t |  |  j d  k	 r
 t Sq
 Wt Sd  S(   N(   RB   R   R   Rl   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt
   _has_units  s    c         C` s   t  |  d  S(   Nu   _parameter_units_for_data_units(   R?   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _supports_unit_fitting  s    c         O` s   d S(   u+   Evaluate the model on some input variables.N(    (   R   Ru   R1   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s    c         O` s   d S(   u  
        Evaluate the sum of any implicit model terms on some input variables.
        This includes any fixed terms used in evaluating a linear model that
        do not have corresponding parameters exposed to the user. The
        prototypical case is `astropy.modeling.functional_models.Shift`, which
        corresponds to a function y = a + bx, where b=1 is intrinsically fixed
        by the type of model, such that sum_of_implicit_terms(x) == x. This
        method is needed by linear fitters to correct the dependent variable
        for the implicit term(s) when solving for the remaining terms
        (ie. a = y - bx).
        N(    (   R   Ru   R1   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   sum_of_implicit_terms  s    c         C` sH  y |  j  } Wn t k
 r& d } n X|  j } | d k rc | d k rc | d k rc t d   n  | d k r | d k	 r | g } n  | d k	 r | g } q n  | d k	 r(t j | d t } t |  | k s t	  | d k	 r| d j
 | j
 k r%t d   q%q(t j | d j
  } n  | d k	 rjt j | d t } | j | k rjt d   qjn  | d k	 rt j g  | D]4 } t j |  t j | d | d d  f ^ q j t  j } | \ } } | d k	 r)t | d d  }	 t j g  | D] }
 t |
 |	 |  ^ q } nG g  | j D]* \ } } t | | | | d d  ^ q3} t j | } | d d d	  } | d k r|  |   } qDy t | |  |   |  } WqDt k
 rt d
   qDXng | d k r!| j
 } g  | D] } t |  ^ q} t j | } n  | d d d	  } | |  |   7} | S(   ui  
        Evaluate a model at fixed positions, respecting the ``bounding_box``.

        The key difference relative to evaluating the model directly is that
        this method is limited to a bounding box if the `Model.bounding_box`
        attribute is set.

        Parameters
        ----------
        out : `numpy.ndarray`, optional
            An array that the evaluated model will be added to.  If this is not
            given (or given as ``None``), a new array will be created.
        coords : array-like, optional
            An array to be used to translate from the model's input coordinates
            to the ``out`` array. It should have the property that
            ``self(coords)`` yields the same shape as ``out``.  If ``out`` is
            not specified, ``coords`` will be used to determine the shape of the
            returned array. If this is not provided (or None), the model will be
            evaluated on a grid determined by `Model.bounding_box`.

        Returns
        -------
        out : `numpy.ndarray`
            The model added to ``out`` if  ``out`` is not ``None``, or else a
            new array from evaluating the model over ``coords``.
            If ``out`` and ``coords`` are both `None`, the returned array is
            limited to the `Model.bounding_box` limits. If
            `Model.bounding_box` is `None`, ``arr`` or ``coords`` must be passed.

        Raises
        ------
        ValueError
            If ``coords`` are not given and the the `Model.bounding_box` of this
            model is not set.

        Examples
        --------
        :ref:`bounding-boxes`
        u7   If no bounding_box is set, coords or out must be input.i   R   i    u!   inconsistent shape of the output.u<   the array and model must have the same number of dimensions.i   Niuk   The `bounding_box` is larger than the input out in one or more dimensions. Set `model.bounding_box = None`.(   R|   R   Rl   R\   Rt   R   t
   asanyarrayt   floatRZ   t   AssertionErrorR   R   t   ndimR   t   meant   ceilt   astypet   intt   TR@   R%   t   slicet   mgridR$   (   R   R   t   coordsR   R  t   bbt   pdt   post   deltat	   sub_shapet   ct
   sub_coordsRP   t   dt   limitst   im_shapeR   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   render  s`    )
	$	M	(:	c         ` sx   t  |  d  r |  j St  |  j d  rp |  j j j       j d d    rt t   f d   |  j D  Sn d Sd S(   u  
        This property is used to indicate what units or sets of units the
        evaluate method expects, and returns a dictionary mapping inputs to
        units (or `None` if any units are accepted).

        Model sub-classes can also use function annotations in evaluate to
        indicate valid input units, in which case this property should
        not be overriden since it will return the input units based on the
        annotations.
        u   _input_unitsu   __annotations__u   returnc         3` s   |  ] } |   | f Vq d  S(   N(    (   R   R:   (   t   annotations(    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>v  s    N(	   R?   t   _input_unitsR   t   __annotations__R   R   Rl   RS   R[   (   R   (    (   R  s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   input_unitsc  s     c         C` s   | |  _  d  S(   N(   R  (   R   R  (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  {  s    c         C` sF   t  |  d  r |  j St  |  j d  r> |  j j j d d  Sd Sd S(   u  
        This property is used to indicate what units or sets of units the output
        of evaluate should be in, and returns a dictionary mapping outputs to
        units (or `None` if any units are accepted).

        Model sub-classes can also use function annotations in evaluate to
        indicate valid output units, in which case this property should not be
        overriden since it will return the return units based on the
        annotations.
        u   _return_unitsu   __annotations__u   returnN(   R?   t   _return_unitsR   R  Rk   Rl   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s
    c         C` s   | |  _  d  S(   N(   R   (   R   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s    c         O` s  | j  d d
  } | j  d d
  } | d
 k r< |  j } n  t |   } g  |  j D] } t |  |  ^ qR } g  | D] } t j | d t ^ qt } t	 | |  j
 | | |  j  |  j d
 k	 rt |  j
 | |  j  }	 xt t |   D]}
 |  j
 |
 } |  j j | d
  } | d
 k r%q n  t | |
 t  r| |
 j j | d |	 | rt |	  d k ss|  j r| |
 j | d |	 | | |
 <qq| t k rt d j |  j
 |
 | |
 j | |
 j j    qt d j |  j
 |
 | |
 j | |
 j j | | j    q |  j r | t k	 r | d
 k	 r t j | |
 d k  rt d j |  j
 |
 | | j    qq q Wn  | d	 k rt |  | | |  St |  | | | | |  Sd
 S(   u  
        This method is used in `~astropy.modeling.Model.__call__` to ensure
        that all the inputs to the model can be broadcast into compatible
        shapes (if one or both of them are input as arrays), particularly if
        there are more than one parameter sets. This also makes sure that (if
        applicable) the units of the input will be compatible with the evaluate
        method.
        u   model_set_axisu   equivalenciesR   t   equivalenciesi    uW   Units of input '{0}', {1} ({2}), could not be converted to required dimensionless inputu\   Units of input '{0}', {1} ({2}), could not be converted to required input units of {3} ({4})ub   Units of input '{0}', (dimensionless), could not be converted to required input units of {1} ({2})i   N(   R   Rl   R   RZ   RB   R   R   R  R  t   _validate_input_shapesR[   t   standard_broadcastingR  R#   t   input_units_equivalenciesR   Rk   Ra   R   R   t   is_equivalentt   input_units_strictR   R   R   Rf   t   physical_typet   input_units_allow_dimensionlessR   t   _prepare_inputs_single_modelt   _prepare_inputs_model_set(   R   R[   R1   R   R!  t   n_modelsR:   R   t   _inputR$  R   t
   input_namet
   input_unit(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     sX    %(	 '	

	


	c         O` s6   t  |   d k r" t |  | |  St |  | |  Sd  S(   Ni   (   RZ   t   _prepare_outputs_single_modelt   _prepare_outputs_model_set(   R   R   R]   R1   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s    c         C` s   t  j |   S(   u   
        Return a copy of this model.

        Uses a deep copy so that all model attributes, including parameter
        values, are copied as well.
        (   R   t   deepcopy(   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR   	  s    c         C` s   |  j    } | | _ | S(   u>   
        Return a copy of this model with a new name.
        (   R   R   (   R   R:   t	   new_model(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRj     s    	c         C` s   d S(   ub   
        Return the number of components in a single model, which is
        obviously 1.
        i   (    (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   n_submodels  s    c         C` s(  t  |  t  r: t } d t |  } |  j |  |  }  n t } |  j   }  t t |  j	 |   } i  } x1 |  j
 D]& } | j | } t | |  | | <qt W| |  _ | j |  _ | j |  _ | j |  _ t t  |  _ x1 t j |  D]  \ }	 }
 | j |
 |  j |	 <q W| r$|  j |   n  |  S(   uU  
        Creates a new instance of ``cls`` that shares its underlying parameter
        values with an existing model instance given by ``existing``.

        This is used primarily by compound models to return a view of an
        individual component of a compound model.  ``param_names`` should be
        the names of the parameters in the *existing* model to use as the
        parameters in this new model.  Its length should equal the number of
        parameters this model takes, so that it can map parameters on the
        existing model to parameters on this model one-to-one.
        i    (   i    (   Ra   RV   R   RZ   R8   R   R   RS   R   RB   t   parameter_constraintsR   R    R   R   R   R   R   R   t	   iteritemsR=   (   R   t   existingRB   t   needs_initializationt
   dummy_argst   aliasest   constraintst	   cons_typet   origt   param_at   param_b(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _from_existing%  s*    	c         C` s   t  |  d  r d Si  |  _ x |  j D]} } | j | i   } | j   |  j | <xO |  j D]D } t |  |  } t | |  } | d k	 r[ | |  j | | <q[ q[ Wq& Wx0 |  j D]% } | j | g   } | |  j | <q Wd S(   u   
        Pop parameter constraint values off the keyword arguments passed to
        `Model.__init__` and store them in private instance attributes.
        u   _constraintsN(	   R?   R   R4  R   R   RB   R   Rl   t   model_constraints(   R   R1   t
   constraintR   R   R   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR   V  s    	c         C` s  t  |  d  r d S| j d d  } | d k pR t | t t j f  oR | d k sm t d j |    n  | j d d  } | d k r | d k	 r | d k r d } q t	 } nC | t	 k p t | t  o t | t
  s t d j |    n  i  } t |  t |  j  k rLt d	 j |  j j t |  j  t |     n  | |  _ t t  |  _ xL t |  D]> \ } } | d k rqqn  t | d
 t j | |  j | <qqWx |  j D]| } | | k r| | k rt d j |  j j |    n  | j |  }	 |	 d k rqn  t |	 d
 t j | | <qqW| rux/ | D]$ }
 t d j |  j j |
    qJWn  | t	 k	 r| d k r| rd } | d k  rt |  } n
 | d } x t j |  D] \ } }	 t j |	  } | | k  rt d j | | | |    n  t | |  } | d k rA|	 j | } q|	 j | | k rt d j | | |    qqW|  j | |  n% | d k rd } n  |  j | d  | |  _ |  j  |  d S(   u	  
        Initialize the _parameters array that stores raw parameter values for
        all parameter sets for use with vectorized fitting algorithms; on
        FittableModels the _param_name attributes actually just reference
        slices of this array.
        u   _parametersNu   n_modelsi   u   n_models must be either None (in which case it is determined from the model_set_axis of the parameter initial values) or it must be a positive integer (got {0!r})u   model_set_axisi    u   model_set_axis must be either False or an integer specifying the parameter array axis to map to each model in a set of models (got {0!r}).uA   {0}.__init__() takes at most {1} positional arguments ({2} given)R   u6   {0}.__init__() got multiple values for parameter {1!r}u2   {0}.__init__() got an unrecognized parameter {1!r}u   All parameter values must be arrays of dimension at least {0} for model_set_axis={1} (the value given for {2!r} is only {3}-dimensional)u   Inconsistent dimensions for parameter {0!r} for {1} model sets.  The length of axis {2} must be the same for all input parameter values(!   R?   R   Rl   Ra   R  R   t   integerRt   Rf   R   R   RZ   RB   t	   TypeErrort	   __class__R*   R   R   RS   R   R   R   R  t   absR   R5  R  R'   t   maxR   t   _check_param_broadcastR   t   _initialize_parameter_values(   R   Ru   R1   R+  R   R   R   t   argR   R   t   kwargt   max_ndimt   min_ndimR:   t
   param_ndim(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR   t  s    $			$ 
		c         C` s  |  j  } d } x|  j D]} d  } t |  |  } | j |  d  k r | j } | d  k r t d j |  j j	 |    n  | } | | <| j
 } n+ | | } t | t  r | j
 } n d  } t j |  }	 t j |  }
 t | | |	  } | | | d <|
 | | d <| d  k rM| j
 d  k	 rMt d j |  j j	 |    n  | | | d <d  | | d <| j d  k	 r| j |  } t | t  r| j
 | | d <qd  | | d <n  | |	 7} q W| |  _  t j | d t j |  _ x | j   D] \ } } t |  |  } | j
 } t j |  } | | d } | j d  k	 r| d  k	 rxt j | j | |  j  } q| j |  } n  | j   |  j | | d <qWx- | D]% } t |  |  } | j | j  qWd  S(	   Ni    u3   {0}.__init__() requires a value for parameter {1!r}u   sliceu   shapeu6   {0}.__init__() requires a Quantity for parameter {1!r}u	   orig_unitu   raw_unitR   (   R   RB   Rl   R   Rk   R   RC  Rf   RD  R*   R   Ra   R   R   t   sizeR   R  R'   t   _setterR   t   float64R   R   R   R   R   t   ravelt	   validator(   R   R   t   param_metricst
   total_sizeR:   R   t   param_descrR   R   t
   param_sizet   param_shapet   param_slicet   _valt	   orig_unit(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRH    sb    		
			"c         C` sg  g  } g  } |  j  } x |  j D] } | | k r7 q n  | | } | j |  t j |  } t |  }	 | d k	 r |	 | k  r d | |	 }
 | d k  r |
 | } n | | d  |
 | | d } | |  j | d <| j |  q | j |  q Wy t |   WnZ t	 k
 rb} | j
 \ } } } } | | } | | } t d j | | | |    n Xd S(   u{  
        This subroutine checks that all parameter arrays can be broadcast
        against each other, and determines the shapes parameters must have in
        order to broadcast correctly.

        If model_set_axis is None this merely checks that the parameters
        broadcast and returns an empty dict if so.  This mode is only used for
        single model sets.
        i   i    u   broadcast_shapeu   Parameter {0!r} of shape {1!r} cannot be broadcast with parameter {2!r} of shape {3!r}.  All parameter arrays must have shapes that are mutually compatible according to the broadcasting rules.N(   i   (   R   RB   R   R   R   RZ   Rl   R   R   R   Ru   R'   Rf   (   R   R   RK  t
   all_shapesRB   R   R:   R   RW  RM  t   new_axest   broadcast_shapeR}   t   shape_at   shape_a_idxt   shape_bt   shape_b_idxR=  R>  (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRG  L  s:    	


c         C` s  |  j  } g  } g  } x|  j D]} t |  |  } | rF | j } n	 | j } | | j d  }	 |	 d k	 r | j |	  } n  | j t	 j
 |   t |   d k r t	 j | g  } n  | r| r |  j  | d d k	 r |  j  | d }
 n	 | j }
 |
 d k	 rt | |
  } qn  | j |  q Wt t |   d k sM| rst	 j t |  d t } | | (| St	 j |  S(   u  
        Implementation of the Model.param_sets property.

        This internal implementation has a ``raw`` argument which controls
        whether or not to return the raw parameter values (i.e. the values that
        are actually stored in the ._parameters array, as opposed to the values
        displayed to users.  In most cases these are one in the same but there
        are currently a few exceptions.

        Note: This is notably an overcomplicated device and may be removed
        entirely in the near future.
        u   broadcast_shapei   u   raw_unitR   N(   R   RB   R   t
   _raw_valueR   Rk   Rl   t   reshapeR   R   R   RZ   R   R   R   R   R   Rm   (   R   R   R   RS  R   t   shapesR:   R   R   R]  R   t   psets(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s4    				c         ` s  g  | D] } t  |  ^ q } | j   f d     j D    j d k	 rj | j d j   j   n  xU | j   D]G \ } } | | k r | | | k r qw n  | j d j | |   qw Wt    d k r | j d j t      n  d j   j	 j
 d j |   S(	   u   
        Internal implementation of ``__repr__``.

        This is separated out for ease of use by subclasses that wish to
        override the default ``__repr__`` while keeping the same basic
        formatting.
        c         3` s0   |  ]& } d  j  | t t   |    Vq d S(   u   {0}={1}N(   Rf   R(   R   (   R   R:   (   R   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>  s   u
   name={0!r}u	   {0}={1!r}i   u   n_models={0}u
   <{0}({1})>u   , N(   RO   t   extendRB   R:   Rl   R   Rf   R   RZ   RD  R*   R   (   R   Ru   R1   t   defaultsR   R   RJ  R   (    (   R   s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s    c   	      C` so  d |  j  j f d |  j f d |  j f d |  j f d t |   f g } g  | | D]* \ } } | d k	 rS d j | |  ^ qS } | j d  t |   d k r g  |  j	 D] } t
 |  |  j g ^ q } n( g  |  j	 D] } t
 |  |  j ^ q } | rbt | d	 |  j	 } x* |  j	 D] } t
 |  |  j | | _ qW| j t t |  d
 d  n  d j |  S(   u   
        Internal implementation of ``__str__``.

        This is separated out for ease of use by subclasses that wish to
        override the default ``__str__`` while keeping the same basic
        formatting.
        u   Modelu   Nameu   Inputsu   Outputsu   Model set sizeu   {0}: {1}u   Parameters:i   t   namest   widthi   u   
N(   RD  R*   R:   R[   R]   RZ   Rl   Rf   R   RB   R   R   R   R   R   Rd   R   (	   R   R   R   R   R   R   R:   t   columnst   param_table(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s(    
$+%"(   u   eqconsu   ineqcons(    (    (    N(V   R*   R+   R,   R&   R:  R4  R@  RB   R[   R]   R   R#  R   t   fittablet   linearR
   t   MetaDataR   Rl   Rp   R   R{   R   R   R&  R(  R$  R=   RM   R   R   R   R4   R   R   R   R   R   R   R   R   R`   R   Rn   R:   t   setterR\   R^   R   R   Rv   R   R   R   R   R   Rq   t   deleterR   R|   R   R   R  R  R  t   abct   abstractmethodR   R  R  R  R   R   R   R   R   Rj   R3  R?  R   R   RH  RG  R   R   R   (    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s   z						[	
		
		Y	+	+		q	l		
		1			S	ECt   FittableModelc           B` s&   e  Z d  Z e Z d Z e Z e Z	 RS(   u]   
    Base class for models that can be fitted using the built-in fitting
    algorithms.
    N(
   R*   R+   R,   R   Rm  Rl   t	   fit_derivR   t   col_fit_derivRl  (    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRs    s
   	t   Fittable1DModelc           B` s   e  Z d  Z d Z d Z RS(   u   
    Base class for one-dimensional fittable models.

    This class provides an easier interface to defining new models.
    Examples can be found in `astropy.modeling.functional_models`.
    u   xu   y(   u   x(   u   y(   R*   R+   R,   R[   R]   (    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRv  0  s   t   Fittable2DModelc           B` s   e  Z d  Z d Z d Z RS(   u   
    Base class for two-dimensional fittable models.

    This class provides an easier interface to defining new models.
    Examples can be found in `astropy.modeling.functional_models`.
    u   xu   yu   z(   u   xu   y(   u   z(   R*   R+   R,   R[   R]   (    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRw  <  s   c         ` s     f d   } | S(   Nc         ` s)   t    |  d | d  |  d |  d f S(   Ni    i   i   (   R   (   t   ft   g(   R2   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   opO  s    (    (   R2   Rz  (    (   R2   s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _make_arithmetic_operatorH  s    c         ` s!      f d     d  d f S(   Nc         ` s    d   d |  |  |  S(   Ni    (    (   R[   R   (   Rx  Ry  (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR3   \  s    i   i   (    (   Rx  Ry  (    (   Rx  Ry  s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _composition_operatorU  s    c         ` s1      f d     d  d   d  d f S(   Nc         ` s2     d |    d  |   d |    d |  S(   Ni    i   (    (   R[   R   (   Rx  Ry  (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR3   g  s   i   i   (    (   Rx  Ry  (    (   Rx  Ry  s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _join_operator`  s    u   +u   -u   *u   /u   **u   |u   &R-   c           B` s%  e  Z d Z d Z d Z d  Z d Z d Z d  Z	 d Z
 d Z d Z d   Z d   Z d   Z d   Z d   Z e d    Z e d    Z e d    Z d	   Z e i  d
   Z e d    Z e d    Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! e" d    Z# RS(   i    c         C` sO   |  j  |  } t | t t j f  r5 |  j   | S|  j | j | j  Sd  S(   N(	   t   _normalize_indexRa   R  R   RB  t   _get_submodelst
   _get_sliceR   R   (   RK   t   index(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   __getitem__  s    c         C` sE   |  j  d  k	 r5 | |  j k r5 |  j   t |  |  St |   d  S(   N(   t   _treeRl   RB   t   _init_param_descriptorsR   t   AttributeError(   RK   t   attr(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   __getattr__  s    
c         C` sc   |  j  d  k r |  j   S|  j   } |  j   } d | f d d t |  f g } |  j d |  S(   Nu
   Expressionu
   Componentsu   
R   (   R  Rl   RL   t   _format_expressiont   _format_componentsR   (   RK   t
   expressiont
   componentsR   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRM     s    
	c         C` s   y t  t |   j   } Wn< t k
 rW t t t t |    t |  j    } n X|  j	 d k	 r x |  j D] } | j |  qq W| j   n  | S(   ut   
        Returns a list of attributes defined on a compound model, including
        all of its parameters.
        N(   R7   R-   t   __dir__R  RU   R   t   dirRV   RT   R  Rl   RB   R   t   sort(   RK   t   basedirR:   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR    s    /c         C` sM   t  t |   j   } t | t  rI t t   | d d d =Wd  QXn  | S(   Ni   i   u	   _evaluate(   R7   R-   RY   Ra   R@   R   t   KeyError(   RK   t   rv(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRY     s
    c         C` s   |  j  d  k r i  } g  } x t |  j    D] \ } } t | j  } | | k r | j d j | |   | | d k r | | } d j | | |  | | <d | | <q q. | j |  | | | <q. Wt |  |  _  n  |  j  S(   Nu   {0}_{1}i    i(	   t   _submodel_namesRl   R   R  Rd   R:   R   Rf   R@   (   RK   t   seenRh  R   t   submodelR:   t   jdx(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   submodel_names  s    
c         C` s#   |  j  d  k r |  j   n  |  j  S(   N(   RA   Rl   t   _init_param_names(   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRB     s    c         C` s8   |  j  d  k r1 t d   |  j   D  |  _  n  |  j  S(   Nc         s` s   |  ] } | j  Vq d  S(   N(   Rl  (   R   t   m(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>  s    (   t	   _fittableRl   R   R  (   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRl    s    "c         G` s   |  j  d  k r@ |  j j t d |  j d } t |  |  _  n  | |  j  } t | |  j  } |  j  | |  } |  j	 d k r | d S| Sd  S(   Nt   getteri    i   (
   t	   _evaluateRl   R  R   t   BINARY_OPERATORSt   _model_evaluate_gettert   staticmethodR\   t   iterR^   (   RK   Ru   R   R[   R   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR   	  s    c         C` s  g  } x | | f D]u } t  | t t f  rJ | j t j | j   q t  | t  ru | j t | j     q | j t |   q Wt | d | d d | d } t	 d j
 t j   } t j d 7_ t d  }	 |	 r |	 j }
 n d }
 |  j | | |  \ } } | d k r3| j o-| j } n t } | j oH| j } | } | j i | d 6t d 6| d 6| d 6| d 6| d 6t	 |
  d 6 |  | t f |  } t  | t  rt  | t  r|   } |  j | | |  | _ | j | j k r
| j | _ n t d   | S| S(   u  
        Given a Python operator (represented by a string, such as ``'+'``
        or ``'*'``, and two model classes or instances, return a new compound
        model that evaluates the given operator on the outputs of the left and
        right input models.

        If either of the input models are a model *class* (i.e. a subclass of
        `~astropy.modeling.Model`) then the returned model is a new subclass of
        `~astropy.modeling.Model` that may be instantiated with any parameter
        values.  If both input models are *instances* of a model, a new class
        is still created, but this method returns an *instance* of that class,
        taking the parameter values from the parameters of the input model
        instances.

        If given, the ``additional_members`` `dict` may provide additional
        class members that should be added to the generated
        `~astropy.modeling.Model` subclass.  Some members that are generated by
        this method should not be provided by ``additional_members``.  These
        include ``_tree``, ``inputs``, ``outputs``, ``linear``,
        ``standard_broadcasting``, and ``__module__`.  This is currently for
        internal use only.
        R/   i    R0   i   u   CompoundModel{0}i   u   __main__u   |u   +u   -u   _treeu   _is_dynamicu   inputsu   outputsu   linearu   standard_broadcastingu
   __module__u3   Model sets must have the same number of components.(   u   |u   +u   -(   Ra   R-   t   _CompoundModelR   R   R1  R  R   R   Rd   Rf   t   _nextidR   R*   t   _check_inputs_and_outputsRm  R   R#  t   updateR   t   _make_user_inverseR   R   Rt   (   R9   t   operatorR/   R0   t   additional_memberst   childrent   childt   treeR:   Rg   Rh   R[   R]   Rm  R#  R<   Ri   t   instance(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR.   	  sL    
 		c      	   C` s!  | d k rl | j  } | j } | j | j k rt d j | j | j | j | j | j | j    qn | d k r t | j  | j   } t | j | j  } nr | j  } | j } | j | j k s | j | j k rt d j | | j | j | j | j | j | j    n  | | f S(   Nu   |u   Unsupported operands for |: {0} (n_inputs={1}, n_outputs={2}) and {3} (n_inputs={4}, n_outputs={5}); n_outputs for the left-hand model must match n_inputs for the right-hand model.u   &u   Unsupported operands for {0}: {1} (n_inputs={2}, n_outputs={3}) and {4} (n_inputs={5}, n_outputs={6}); models must have the same n_inputs and the same n_outputs for this operator(   R[   R]   R^   R\   R)   Rf   R:   R   (   R9   R  R/   R0   R[   R]   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  	  s(    				c         C` sm   | d k o | j  p | j  s" d Sy | j } | j } Wn t k
 rL d SX| d k ra | | @S| | BSd S(   u  
        Generates an inverse `Model` for this `_CompoundModel` when either
        model in the operation has a *custom inverse* that was manually
        assigned by the user.

        If either model has a custom inverse, and in particular if another
        `_CompoundModel` has a custom inverse, then none of that model's
        sub-models should be considered at all when computing the inverse.
        So in that case we just compute the inverse ahead of time and set
        it as the new compound model's custom inverse.

        Note, this use case only applies when combining model instances,
        since model classes don't currently have a notion of a "custom
        inverse" (though it could probably be supported by overriding the
        class's inverse property).

        TODO: Consider fixing things so the aforementioned class-based case
        works as well.  However, for the present purposes this is good enough.
        u   &u   |N(   u   &u   |(   R   Rl   Rq   R   (   R9   R  R/   R0   t   left_invt	   right_inv(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  	  s    	c         C` sQ   |  j  d  k	 r |  j  Sg  |  j j   D] } | j r& | j ^ q& } | |  _  | S(   N(   t
   _submodelsRl   R  t   traverse_postordert   isleafR   (   RK   R  t	   submodels(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  	  s    	c      	   ` s   x |  j  D] } |  j | \ } } |  | } t | | d    t | t  rZ   j } n	   j } t   f d   t j	 D  }   j
 d | d | d   j |  } t |  | |  q
 Wd S(   uy  
        This routine sets up the names for all the parameters on a compound
        model, including figuring out unique names for those parameters and
        also mapping them back to their associated parameters of the underlying
        submodels.

        Setting this all up is costly, and only necessary for compound models
        that a user will directly interact with.  For example when building an
        expression like::

            >>> M = (Model1 + Model2) * Model3  # doctest: +SKIP

        the user will generally never interact directly with the temporary
        result of the subexpression ``(Model1 + Model2)``.  So there's no need
        to setup all the parameters for that temporary throwaway.  Only once
        the full expression is built and the user initializes or introspects
        ``M`` is it necessary to determine its full parameterization.
        c         3` s$   |  ] } | t    |  f Vq d  S(   N(   R   (   R   RX   (   t
   orig_param(    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>
  s   R:   R   R   N(   RB   t
   _param_mapR   Rl   Ra   R   R   R   RS   R4  R   R   t   setattr(   RK   R   t   submodel_idxt   submodel_paramR  R   R:  t	   new_param(    (   R  s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  	  s    
		c         C` s   g  } i  } |  j  } xv t |  j    D]b \ } } | j sC q( n  xD | j D]9 } d j | | |  } | j |  | | f | | <qM Wq( Wt |  |  _ | |  _ t	 d   | j
   D  |  _ d S(   u   
        This subroutine is solely for setting up the ``param_names`` attribute
        itself.

        See ``_init_param_descriptors`` for the full parameter setup.
        u   {0}_{1}c         s` s!   |  ] \ } } | | f Vq d  S(   N(    (   R   t   kt   v(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>E
  s    N(   t   _slice_offsetR   R  RB   Rf   R   R@   RA   R  RS   R   t   _param_map_inverse(   RK   Rh  t	   param_mapt   param_suffixR   R   R   R:   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  
  s    			c         C` s   |  j  j t  S(   N(   R  t   format_expressiont   OPERATOR_PRECEDENCE(   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  G
  s    c         C` s#   d j  d   t |  j    D  S(   Nu   

c         s` s'   |  ] \ } } d  j  | |  Vq d S(   u   [{0}]: {1!r}N(   Rf   (   R   R   R  (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>M
  s   (   R   R   R  (   RK   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  L
  s    c         ` s    f d   }   f d   } t  | t j  r: | |  St  | t  r| j d
 k rg t d   n  | j d	 k	 r | j n d } | j d	 k	 r | j n t	   j
  } t  | t t j f  r | |  } n  t  | t t j f  r | |  } n  t  | t j  r| |  } n  t  | t j  r@| |  d } n  | | } | d k rZ| S| d k rut d   n  t | |  St  | t t j f  r| t	   j
  k rt d j |    n  | |  St d j |    d	 S(   u1  
        Converts an index given to __getitem__ to either an integer, or
        a slice with integer start and stop values.

        If the length of the slice is exactly 1 this converts the index to a
        simple integer lookup.

        Negative integers are converted to positive integers.
        c         ` sG   y   j  j |   SWn, t k
 rB t d j   j |     n Xd  S(   Nu6   Compound model {0} does not have a component named {1}(   R  R  Rt   t
   IndexErrorRf   R:   (   R:   (   RK   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   get_index_from_name[
  s    c         ` sP   |  d k  rL t    j  |  } | d k  rC t d j |     qL | }  n  |  S(   Ni    u   Model index {0} out of range.(   RZ   R  R  Rf   (   R  t	   new_index(   RK   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   check_for_negative_indexc
  s    	i   u.   Step not supported for compound model slicing.i    u    Empty slice of a compound model.u   Model index {0} out of range.uQ   Submodels can be indexed either by their integer order or their name (got {0!r}).N(   i   N(   Ra   R   t   string_typesR  t   stepRl   Rt   R   R   RZ   R  R  R   RB  R  Rf   RC  (   RK   R  R  R  R   R   t   length(    (   RK   s4   lib/python2.7/site-packages/astropy/modeling/core.pyR~  P
  s@    
'

c         ` sL   i |  j  | d 6  t   f d   t D  } |  j j | d | d | S(   u  
        Return a new model build from a sub-expression of the expression
        represented by this model.

        Right now this is highly inefficient, as it creates a new temporary
        model for each operator that appears in the sub-expression.  It would
        be better if this just built a new expression tree, and the new model
        instantiated directly from that tree.

        Once tree -> model instantiation is possible this should be fixed to
        use that instead.
        u   _slice_offsetc         3` s'   |  ] } | t  | d    f Vq d S(   R  N(   R4   (   R   R2   (   R<   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>
  s   R   R   (   R  RS   R  R  R   (   RK   R   R   t	   operators(    (   R<   s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  
  s    c         ` s   t   j    j }  j } t  t  ry t   j  ry | d k rd   f d   } q   f d   } n<  j   | d k r    f d   } n    f d   } | | | f S(   Ni   c         ` s4   t  t |    }   |   j t |  |    f S(   N(   R@   R   R   R   (   R[   R   t   param_values(   R   t   n_params(    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRx  
  s    c         ` s1   t  t |    }   |   j t |  |    S(   N(   R@   R   R   R   (   R[   R   R  (   R   R  (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRx  
  s    c         ` s     t  |  t |      f S(   N(   R   R   (   R[   R   (   R   R  (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR3   
  s    c         ` s     t  |  t |      S(   N(   R   R   (   R[   R   (   R   R  (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR3   
  s    (   RZ   RB   R\   R^   Ra   R   R	   R   (   R   R   R\   R^   Rx  (    (   R   R   R  s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  
  s    			N($   R*   R+   Rl   R  R  R  R  RA   R  R  R  R  R  R  R  RM   R  RY   Rn   R  RB   Rl  R   t   classmethodR.   R  R  R  R  R  R  R  R~  R  R  R  (    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR-     s>   			
			
	k$,		1	6			F	R  c           B` s   e  Z d Z e Z d Z d    Z d   Z d   Z	 e
 j d  d k  rR d   Z n  e d    Z e d    Z e d	    Z e d
    Z e d    Z e d    Z e d    Z d   Z RS(   c         C` sS   |  j    } |  j   } d | f d d t |  f g } t t |   j d |  S(   Nu
   Expressionu
   Componentsu   
R   (   R  R  R   R7   R  R   (   R   R  R  R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR   
  s
    	c         C` s=   t  |  j |  } t | d  r9 | j |  |  j  } n  | S(   Nu   __get__(   R   RD  R?   t   __get__(   R   R  R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  
  s    	c         ` sx   |  j  j      |  j    } t   t  r: | j } n. |  j  j  t    f d   | j D  } | j |  |  S(   Nc         3` s   |  ] }    | f Vq d  S(   N(    (   R   R:   (   R  R  (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>
  s   (   RD  R~  Ra   R  RB   R  R@   R?  (   R   R  R   RB   (    (   R  R  s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  
  s    i   i   i   c         C` sA   t  d  t k	 r* t d j |     n t t |   j   Sd  S(   Ni   u   Pickling of compound models is not possible using Python versions less than 2.7.3 due to a bug in Python.  See http://docs.astropy.org/en/v1.0.4/known_issues.html#pickling-error-on-compound-models for more information (tried to pickle {0!r}).(   R   R   t   RuntimeErrorRf   R7   R  RY   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRY   
  s
    c         C` s
   |  j  j S(   N(   RD  R  (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR    s    c         C` s   t  |  j  S(   N(   RZ   R  (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR3    s    c         C` s
   |  j  j S(   N(   RD  RB   (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRB     s    c         C` s
   |  j  j S(   N(   RD  Rl  (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyRl    s    c         G` s   |  j  j |   S(   N(   RD  R   (   R   Ru   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR     s    c         ` sj   d     t    f d   d D  } t j | d <d	   | d
 <d }  f d   }  j j | d | S(   Nc         ` s     f d   } | S(   Nc         ` s   t  d j      d  S(   NuX   The inverse is not currently defined for compound models created using the {0} operator.(   R   Rf   (   t   xt   y(   R2   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _raise'  s    (    (   R2   R  (    (   R2   s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   _not_implemented&  s    c         3` s!   |  ] } |   |  f Vq d  S(   N(    (   R   R2   (   R  (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>-  s   u   +u   -u   *u   /u   **u   &c         S` s   t  j | |   S(   N(   R  t   or_(   R  R  (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR3   1  s    u   |ic         ` s<   y   |  j  SWn& t k
 r7 t d j |    n Xd  S(   Nu   All models in a composite model must have an inverse defined in order for the composite model to have an inverse.  {0!r} does not have an inverse.(   Rq   R   Rf   (   R   R   (   R   (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  5  s    R  (   u   +u   -u   *u   /u   **(   RS   R  t   and_R  R   (   R   R  t   leaf_idxR  (    (   R  R   s4   lib/python2.7/site-packages/astropy/modeling/core.pyRq   $  s    	c         C` s   |  j  j   S(   N(   RD  R  (   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  C  s    c   	      C` sn   i  } xa t  |  j  D]P \ } } | j | |  } x/ | D]' } |  j | | f } | | | | <q; Wq W| S(   N(   R   R  R   R  (	   R   R  t   output_unitst   units_for_datat   imodelR   t   units_for_data_subt	   param_subR   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR   G  s    N(   i   i   i   (   R*   R+   Rl   Rt  R   Ru  R  R   R  R  t   syst   version_infoRY   Rn   R  R   R3  RB   Rl  R   Rq   R  R   (    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR  
  s    					c          O` s}   | j  d d  } t |   d k rK t j |  d  rK t |  d d | S|  sd t j t d | St d j	 t
    d S(   uf  
    Create a model from a user defined function. The inputs and parameters of
    the model will be inferred from the arguments of the function.

    This can be used either as a function or as a decorator.  See below for
    examples of both usages.

    .. note::

        All model parameters have to be defined as keyword arguments with
        default values in the model function.  Use `None` as a default argument
        value if you do not want to have a default value for that parameter.

    Parameters
    ----------
    func : function
        Function which defines the model.  It should take N positional
        arguments where ``N`` is dimensions of the model (the number of
        independent variable in the model), and any number of keyword arguments
        (the parameters).  It must return the value of the model (typically as
        an array, but can also be a scalar for scalar inputs).  This
        corresponds to the `~astropy.modeling.Model.evaluate` method.
    fit_deriv : function, optional
        Function which defines the Jacobian derivative of the model. I.e., the
        derivative with respect to the *parameters* of the model.  It should
        have the same argument signature as ``func``, but should return a
        sequence where each element of the sequence is the derivative
        with respect to the corresponding argument. This corresponds to the
        :meth:`~astropy.modeling.FittableModel.fit_deriv` method.

    Examples
    --------
    Define a sinusoidal model function as a custom 1D model::

        >>> from astropy.modeling.models import custom_model
        >>> import numpy as np
        >>> def sine_model(x, amplitude=1., frequency=1.):
        ...     return amplitude * np.sin(2 * np.pi * frequency * x)
        >>> def sine_deriv(x, amplitude=1., frequency=1.):
        ...     return 2 * np.pi * amplitude * np.cos(2 * np.pi * frequency * x)
        >>> SineModel = custom_model(sine_model, fit_deriv=sine_deriv)

    Create an instance of the custom model and evaluate it::

        >>> model = SineModel()
        >>> model(0.25)
        1.0

    This model instance can now be used like a usual astropy model.

    The next example demonstrates a 2D Moffat function model, and also
    demonstrates the support for docstrings (this example could also include
    a derivative, but it has been omitted for simplicity)::

        >>> @custom_model
        ... def Moffat2D(x, y, amplitude=1.0, x_0=0.0, y_0=0.0, gamma=1.0,
        ...            alpha=1.0):
        ...     """Two dimensional Moffat function."""
        ...     rr_gg = ((x - x_0) ** 2 + (y - y_0) ** 2) / gamma ** 2
        ...     return amplitude * (1 + rr_gg) ** (-alpha)
        ...
        >>> print(Moffat2D.__doc__)
        Two dimensional Moffat function.
        >>> model = Moffat2D()
        >>> model(1, 1)  # doctest: +FLOAT_CMP
        0.3333333333333333
    u	   fit_derivi   i    Rt  u   {0} takes at most one positional argument (the callable/function to be turned into a model.  When used as a decorator it should be passed keyword arguments only (if any).N(   Rk   Rl   RZ   R   Rr   t   _custom_model_wrappert	   functoolst   partialRC  Rf   R*   (   Ru   R1   Rt  (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   custom_modelQ  s    E%c   	      C` s  t  j |   s t d   n  | d k	 rI t  j |  rI t d   n  |  j } t |   \ } } | d k	 r t t  j |   t |  k r t d   n  | r | d j f } n d } t	 d   | D  } t
 d  } | r | j } n d } i t |  d	 6|  j d
 6t d   | D  d 6| d 6t |   d 6} | d k	 r`t |  | d <n  | j |  t | t f |  S(   u7  
    Internal implementation `custom_model`.

    When `custom_model` is called as a function its arguments are passed to
    this function, and the result of this function is returned.

    When `custom_model` is used as a decorator a partial evaluation of this
    function is returned by `custom_model`.
    uD   func is not callable; it must be a function or other callable objectuF   fit_deriv not callable; it must be a function or other callable objectuD   derivative function should accept same number of parameters as func.i    u   xc         s` s0   |  ]& } | j  t | j  d  | j f Vq d S(   R   N(   R:   R&   R   (   R   R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>  s   i   u   __main__u
   __module__u   __doc__c         s` s   |  ] } | j  Vq d  S(   N(   R:   (   R   R  (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pys	   <genexpr>  s    u   inputsu   outputsu   evaluateu	   fit_derivN(   u   x(   R   Rr   R)   Rl   R*   R!   RZ   t   get_function_defaultsR:   RS   R   Rd   R,   R@   R  R  RV   Rs  (	   R   Rt  t
   model_nameR[   R   t   output_namesRg   Rh   R<   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR    s<    	!	
c         C` s  |  j  } | d k | d k @| d k @r8 t d   n  |  j d k rz | d k	 r_ | g } n  | d k	 rz | g } qz n  | d k	 r | j   } | j |  j k r t d   q n  | d k	 rBt j |  } t |  |  j k r t d   n  | d k	 r)| d j	 | j	 k r?t d   q?qBt j
 | d j	  } n  | d k	 rt j g  | D]4 } t j |  t j | d | d d  f ^ q[ j t  j } \ } } | d k	 rt | d d  } t j g  | D] }	 t |	 | |  ^ q }
 nG g  | j D]* \ } } t | | | | d d  ^ q	} t j | }
 |
 d d d	  }
 | d k rt|  |
   } qy t | |  |
   |  } Wqt k
 rt d
   qXna | d k r| j	 } g  | D] } t |  ^ q} t j | } n  | |  | d d d	    7} | S(   u0  
    Evaluates a model on an input array. Evaluation is limited to
    a bounding box if the `Model.bounding_box` attribute is set.

    Parameters
    ----------
    model : `Model`
        Model to be evaluated.
    arr : `numpy.ndarray`, optional
        Array on which the model is evaluated.
    coords : array-like, optional
        Coordinate arrays mapping to ``arr``, such that
        ``arr[coords] == arr``.

    Returns
    -------
    array : `numpy.ndarray`
        The model evaluated on the input ``arr`` or a new array from ``coords``.
        If ``arr`` and ``coords`` are both `None`, the returned array is
        limited to the `Model.bounding_box` limits. If
        `Model.bounding_box` is `None`, ``arr`` or ``coords`` must be passed.

    Examples
    --------
    :ref:`bounding-boxes`
    u7   If no bounding_box is set, coords or arr must be input.i   uD   number of array dimensions inconsistent with number of model inputs.u?   coordinate length inconsistent with the number of model inputs.i    u3   coordinate shape inconsistent with the array shape.i   Niuk   The `bounding_box` is larger than the input arr in one or more dimensions. Set `model.bounding_box = None`.(   R|   Rl   Rt   R\   R   R  R   R   RZ   R   R   R	  R
  R  R  R  R@   R%   R  R  R$   (   R   t   arrR  R   R  R  R  R  R  R  R  RP   R  R  R  R   (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   render_model  sR    	 	W1:	c         K` s  g  } x$t  |  D]\ } } | j } | sD | j d  | | <n  | sS | } n d } x | D] }	 y( |  j r t | |	 j  }
 n | }
 Wn< t k
 r t d j |  j | | |	 j	 |	 j    n Xt
 |
  t
 |  k r |
 } q` t
 |
  t
 |  k r` t | |
  } q` q` W| j |  q W|  j |  j k rt
 t |   d k rft d   q|  j |  j } | s| j d   n  | j | d g |  n  | | f f S(   Ni   ub   Model input argument {0!r} of shape {1!r} cannot be broadcast with parameter {2!r} of shape {3!r}.uL  For models with n_outputs > n_inputs, the combination of all inputs and parameters must broadcast to the same shape, which will be used as the shape of all outputs.  In this case some of the inputs had different shapes, so it is ambiguous how to format outputs for this model.  Try using inputs that are all the same size and shape.i    (   i   (    (   R   R   Rc  R#  R   R   Rt   Rf   R[   R:   RZ   RF  R   R^   R\   R   Rl   Rf  (   R   R   R[   R1   t
   broadcastsR   R,  t   input_shapet   max_broadcastR   t	   broadcastt   extra_outputs(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR)  ?  s@    			
	c         C` s   | d } t  |  } x_ t |  D]Q \ } } | | } | d  k	 r# | s^ | j   | | <qt | j |  | | <q# q# Wt |  S(   Ni    (   RU   R   Rl   t   itemRc  R@   (   R   R]   R   R  R   t   outputR]  (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR/  z  s    

c         K` s  g  } g  } x?t  |  D]1\ } }	 d }
 | d k rb | t k	 rb |	 j |  |	 j | d } n	 |	 j } x | D] } y t | | j  Wn< t k
 r t d j |  j | | | j | j    n Xt	 | j  t	 |
  k rr | j }
 qr qr Wt	 |  } | t k rt	 |
  | k rWd t	 |
  | } d | } | |	 j } |  j
 } n, | t	 |
  } |	 j |  d |	 j | } |	 j |  } n t	 |
  | k r t	 |
  | } |  j
 } d | } |	 j | d  | |	 j | d } |	 j |  } n0 |	 j t	 |
  d } t j |	 | | d  } | j |  | j |  q W|  j |  j k  r| j | g |  j |  j  n  | | f f S(   Ni   ub   Model input argument {0!r} of shape {1!r} cannot be broadcast with parameter {2!r} of shape {3!r}.(    (   i   (   i   (   i   (   R   R   R   R   R   Rt   Rf   R[   R:   RZ   R   Rc  R  R   t   rollaxisR   R\   R^   Rf  (   R   R   R[   R+  R   R1   t   reshapedt   pivotsR   R,  t   max_param_shapeR  R   t
   input_ndimt
   n_new_axesR\  t	   new_shapet   pivott	   new_input(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR*    sX    
	
	
!c         C` s   | d } t  |  } xa t |  D]S \ } } | | } | | j k  r# | |  j k r# t j | | |  j  | | <q# q# Wt |  S(   Ni    (   RU   R   R  R   R   R  R@   (   R   R]   R   R  R   R  R  (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR0    s    

c         C` sX  | d k o | t  k	 } | p! | s( d Sg  } x t |   D] \ } } t j |  }	 |	 r | r t |	  | d k  r t d j | | d    q |	 | | k r t d j | | | |    q n  | j |	  q; W| s d Sy t |   }
 WnZ t	 k
 rS} | j
 \ } } } } | | } | | } t d j | | | |    n X|
 S(   u&  
    Perform basic validation of model inputs--that they are mutually
    broadcastable and that they have the minimum dimensions for the given
    model_set_axis.

    If validation succeeds, returns the total shape that will result from
    broadcasting the input arrays with each other.
    i   NuD   For model_set_axis={0}, all inputs must be at least {1}-dimensional.ur   Input argument {0!r} does not have the correct dimensions in model_set_axis={1} for a model set with n_models={2}.u]   Model input argument {0!r} of shape {1!r} cannot be broadcast with input {2!r} of shape {3!r}(   R   R   R   R   RZ   Rt   Rf   R   R   R   Ru   (   R[   t   argnamesR+  R   t   validate_broadcastingt   check_model_set_axisR[  R   R,  R  t   input_broadcastR}   R^  R_  R`  Ra  t   arg_at   arg_b(    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyR"    s:    


(i   R,   t
   __future__R    R   R   R   Rq  R   RF   R  R  R  Rx   t   collectionsR   R   t	   itertoolsR   R   t   numpyR   t   utilsR   R	   R
   t   externR   t   extern.six.movesR   R   t   tableR   R   R   R   R   t   units.utilsR   R   R   R   R   R   R   R   t   utils.codegenR   t   utils.compatR   t   utils.compat.funcsigsR   R   R   R   R    R!   R"   R#   t   nddata.utilsR$   R%   Rv   R&   R'   R(   t   __all__RC  R)   R4   t   ABCMetaR5   t   add_metaclassRm   R   Rs  Rv  Rw  R{  R|  R}  RJ   t   subt   mult   truedivt   powR  t   _ORDER_OF_OPERATORSR  R   R   t   opsRz  R-   R  R  Rl   R  R  R)  R/  R*  R0  R"  t   pickleRY   (    (    (    s4   lib/python2.7/site-packages/astropy/modeling/core.pyt   <module>   s   "44	       (			
*	  O	S=^	;		A		8