B
    d                 @   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 : `~astropy.uncertainty.Distribution` or object
        The sampled Gaussian distribution.
        The type will be the same as the parameter ``cls``.

    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
ValueError	broadcastshapenewaxisrandomZrandn)	centerr	   r
   r   	n_samplesr   kwargs	randshapesamples r   n/work/yifan.wang/ringdown/master-ringdown-env/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rtd| jt || j }||f|S )ux  
    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 : `~astropy.uncertainty.Distribution` or object
        The sampled Poisson distribution.
        The type will be the same as the parameter ``cls``.
    FunitT.zADUs 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   M   s    




)lowerupperr   widthr   c       	      K   s   |dkr:|dkr:t | } t |}| j|jkrt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 )a1  
    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 : `~astropy.uncertainty.Distribution` or object
        The sampled uniform distribution.
        The type will be the same as the parameter ``cls``.
    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   }   s$    $





)__doc__warningsr   numpyr   Zastropyr   r   corer   __all__r   countZelectronZdimensionless_unscaledZchanbinZvoxbitbyter   r   r   r   r   r   r   <module>   s   
8$0