B
    îq\$  ã               @   s˜   d Z ddlmZ ddlZddlmZ ddlm	Z	 ddd	gZ
ddde	d
œdd„ZejejejejejejejejfZe	fdd„Zdddde	dœdd	„ZdS )z+
Built-in distribution-creation functions.
é    )ÚwarnN)Úunitsé   )ÚDistributionÚnormalÚpoissonÚuniform)ÚstdÚvarÚivarÚclsc      	      K   s¾   t  | ¡} |dk	r2|dkr*t  |¡d }ntdƒ‚|dk	rZ|dkrRt  |¡d }ntdƒ‚|dkrltdƒ‚n
t  |¡}t  || ¡j|f }| dt jf t jj|Ž |dt jf   }||f|ŽS )u´  
    Create a Gaussian/normal distribution.

    Parameters
    ----------
    center : `~astropy.units.Quantity`
        The center of this distribution
    std : `~astropy.units.Quantity` or `None`
        The standard deviation/Ïƒ of this distribution. Shape must match and unit
        must be compatible with ``center``, or be `None` (if ``var`` or ``ivar``
        are set).
    var : `~astropy.units.Quantity` or `None`
        The variance of this distribution. Shape must match and unit must be
        compatible with ``center``, or be `None` (if ``std`` or ``ivar`` are set).
    ivar : `~astropy.units.Quantity` or `None`
        The inverse variance of this distribution. Shape must match and unit
        must be compatible with ``center``, or be `None` (if ``std`` or ``var``
        are set).
    n_samples : int
        The number of Monte Carlo samples to use with this distribution
    cls : class
        The class to use to create this distribution.  Typically a
        `Distribution` subclass.

    Remaining keywords are passed into the constructor of the ``cls``

    Returns
    -------
    distr : ``cls``, usually `Distribution`
        The sampled Gaussian distribution.
    Ng      à?z#normal cannot take both std and varg      à¿z/normal cannot take both ivar and and std or varz(normal requires one of std, var, or ivar.)ÚnpÚ
asanyarrayÚ
ValueErrorZ	broadcastÚshapeÚnewaxisÚrandomZrandn)	Úcenterr	   r
   r   Ú	n_samplesr   ÚkwargsÚ	randshapeÚsamples© r   ú@lib/python3.7/site-packages/astropy/uncertainty/distributions.pyr      s    !


(c             K   sš   d}t | dƒr d}t | j¡}n
t | ¡}|j|f }tj |dtjf |¡}|rŽ| jt	j
krhtdƒ n| jtkr„td | jt¡ƒ || j }||f|ŽS )u.  
    Create a Poisson distribution.

    Parameters
    ----------
    center : `~astropy.units.Quantity`
        The center value of this distribution (i.e., Î»).
    n_samples : int
        The number of Monte Carlo samples to use with this distribution
    cls : class
        The class to use to create this distribution.  Typically a
        `Distribution` subclass.

    Remaining keywords are passed into the constructor of the ``cls``

    Returns
    -------
    distr : ``cls``, usually `Distribution`
        The sampled poisson distribution.
    FÚunitT.z­ADUs were provided to poisson.  ADUs are not strictly countunits because they need the gain to be applied. It is recommended you apply the gain to convert to e.g. electrons.zUnit {} was provided to poisson, which is not one of {}, and therefore suspect as a "counting" unit.  Ensure you mean to use Poisson statistics.)Úhasattrr   r   Úvaluer   r   r   r   r   ÚuZadur   ÚCOUNT_UNITSÚformat)r   r   r   r   Zhas_unitZ
poissonarrr   r   r   r   r   r   J   s    




)ÚlowerÚupperr   Úwidthr   c       	      K   sø   |dkr:|dkr:t  | ¡} t  |¡}| j|jkr€tdƒ‚nF|dkrx| dkrxt  |¡}t  |¡}||d  } ||d  }ntdƒ‚| j|f }| jtƒ kr®|jtƒ kr®||  }n(||  dd…t jf }| dd…t jf } | |t jj|d  }||f|ŽS )aç  
    Create a Uniform distriution from the lower and upper bounds.

    Note that this function requires keywords to be explicit, and requires
    either ``lower``/``upper`` or ``center``/``width``.

    Parameters
    ----------
    lower : array-like
        The lower edge of this distribution. If a `~astropy.units.Quantity`, the
        distribution will have the same units as ``lower``.
    upper : `~astropy.units.Quantity`
        The upper edge of this distribution. Must match shape and if a
        `~astropy.units.Quantity` must have compatible units with ``lower``.
    center : array-like
        The center value of the distribution. Cannot be provided at the same
        time as ``lower``/``upper``.
    width : array-like
        The width of the distribution.  Must have the same shape and compatible
        units with ``center`` (if any).
    n_samples : int
        The number of Monte Carlo samples to use with this distribution
    cls : class
        The class to use to create this distribution.  Typically a
        `Distribution` subclass.

    Remaining keywords are passed into the constructor of the ``cls``

    Returns
    -------
    distr : ``cls``, usually `Distribution`
        The sampled uniform distribution.
    Nz+lower and upper must have consistent shapesé   z^either upper/lower or center/width must be given to uniform - other combinations are not valid)Úsize)r   r   r   r   Útupler   r   r   )	r    r!   r   r"   r   r   r   Znewshaper   r   r   r   r   y   s$    #





)Ú__doc__Úwarningsr   Znumpyr   Zastropyr   r   Zcorer   Ú__all__r   ÚcountZelectronZdimensionless_unscaledZchanÚbinZvoxÚbitZbyter   r   r   r   r   r   r   Ú<module>   s   
6$/