B
    d81                 @   s   d dl Zd dl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 d dlmZ d d	lmZmZmZmZ d
gZdZG dd
 d
eZdS )    N)deepcopy   )
NDDataBase)NDUncertaintyUnknownUncertainty)log)UnitQuantity)MetaData)BaseLowLevelWCSBaseHighLevelWCSSlicedLowLevelWCSHighLevelWCSWrapperNDDataz<`dict`-like : Additional meta information about the dataset.c                   s   e Zd ZdZeeddZd fdd	Zdd Zd	d
 Z	e
dd Ze
dd Zejdd Ze
dd Ze
dd Zejdd Ze
dd Zejdd Z  ZS )r   a  
    A container for `numpy.ndarray`-based datasets, using the
    `~astropy.nddata.NDDataBase` interface.

    The key distinction from raw `numpy.ndarray` is the presence of
    additional metadata such as uncertainty, mask, unit, a coordinate system
    and/or a dictionary containing further meta information. This class *only*
    provides a container for *storing* such datasets. For further functionality
    take a look at the ``See also`` section.

    See also: https://docs.astropy.org/en/stable/nddata/

    Parameters
    -----------
    data : `numpy.ndarray`-like or `NDData`-like
        The dataset.

    uncertainty : any type, optional
        Uncertainty in the dataset.
        Should have an attribute ``uncertainty_type`` that defines what kind of
        uncertainty is stored, for example ``"std"`` for standard deviation or
        ``"var"`` for variance. A metaclass defining such an interface is
        `NDUncertainty` - but isn't mandatory. If the uncertainty has no such
        attribute the uncertainty is stored as `UnknownUncertainty`.
        Defaults to ``None``.

    mask : any type, optional
        Mask for the dataset. Masks should follow the ``numpy`` convention that
        **valid** data points are marked by ``False`` and **invalid** ones with
        ``True``.
        Defaults to ``None``.

    wcs : any type, optional
        World coordinate system (WCS) for the dataset.
        Default is ``None``.

    meta : `dict`-like object, optional
        Additional meta information about the dataset. If no meta is provided
        an empty `collections.OrderedDict` is created.
        Default is ``None``.

    unit : unit-like, optional
        Unit for the dataset. Strings that can be converted to a
        `~astropy.units.Unit` are allowed.
        Default is ``None``.

    copy : `bool`, optional
        Indicates whether to save the arguments as copy. ``True`` copies
        every attribute before saving it while ``False`` tries to save every
        parameter as reference.
        Note however that it is not always possible to save the input as
        reference.
        Default is ``False``.

        .. versionadded:: 1.2

    Raises
    ------
    TypeError
        In case ``data`` or ``meta`` don't meet the restrictions.

    Notes
    -----
    Each attribute can be accessed through the homonymous instance attribute:
    ``data`` in a `NDData` object can be accessed through the `data`
    attribute::

        >>> from astropy.nddata import NDData
        >>> nd = NDData([1,2,3])
        >>> nd.data
        array([1, 2, 3])

    Given a conflicting implicit and an explicit parameter during
    initialization, for example the ``data`` is a `~astropy.units.Quantity` and
    the unit parameter is not ``None``, then the implicit parameter is replaced
    (without conversion) by the explicit one and a warning is issued::

        >>> import numpy as np
        >>> import astropy.units as u
        >>> q = np.array([1,2,3,4]) * u.m
        >>> nd2 = NDData(q, unit=u.cm)
        INFO: overwriting Quantity's current unit with specified unit. [astropy.nddata.nddata]
        >>> nd2.data  # doctest: +FLOAT_CMP
        array([1., 2., 3., 4.])
        >>> nd2.unit
        Unit("cm")

    See also
    --------
    NDDataRef
    NDDataArray
    F)doccopyNc                s<  t    t|tr|d k	r>|jd k	r>||jkr>td n|jd k	rN|j}|d k	rl|jd k	rltd n|jd k	r||j}|d k	r|jd k	rtd n|jd k	r|j}|d k	r|j	d k	rtd n|j	d k	r|j	}|d k	r|j
d k	rtd n|j
d k	r|j
}|j}ntt|drJt|drJ|d k	r>td n|j}|j}t|tr|d k	rx||jkrxtd	 n|j}|j}t|d
rt|drt|dstj|ddd}|jdkrtd|d k	rt|}|rt|}t|}t|}t|}t|}t|}|| _|| _|| _|| _
|| _|| _d S )Nz6overwriting NDData's current unit with specified unit.zDoverwriting NDData's current uncertainty with specified uncertainty.z6overwriting NDData's current mask with specified mask.z4overwriting NDData's current wcs with specified wcs.z6overwriting NDData's current meta with specified meta.maskdataz>overwriting Masked Objects's current mask with specified mask.z8overwriting Quantity's current unit with specified unit.shape__getitem__Z	__array__TF)Zsubokr   Oz&could not convert data to numpy array.)super__init__
isinstancer   unitr   infouncertaintyr   wcsmetar   hasattrr	   valuenparrayZdtype	TypeErrorr   r   _data_wcs_unit)selfr   r   r   r   r   r   r   )	__class__ b/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/astropy/nddata/nddata.pyr   w   sl    







zNDData.__init__c             C   s,   t | j}| jd k	r d| j nd}|| S )N  )strr   r   )r'   r   r   r)   r)   r*   __str__   s    
zNDData.__str__c             C   sL   | j jd }tj| jd|d}| jd k	r6d| j dnd}d|||dfS )N(z, )	separatorprefixz, unit=''r,   ))r(   __name__r!   Zarray2stringr   r   join)r'   r1   r   r   r)   r)   r*   __repr__   s    zNDData.__repr__c             C   s   | j S )z=
        `~numpy.ndarray`-like : The stored dataset.
        )r$   )r'   r)   r)   r*   r      s    zNDData.datac             C   s   | j S )z
        any type : Mask for the dataset, if any.

        Masks should follow the ``numpy`` convention that valid data points are
        marked by ``False`` and invalid ones with ``True``.
        )_mask)r'   r)   r)   r*   r      s    zNDData.maskc             C   s
   || _ d S )N)r7   )r'   r    r)   r)   r*   r   
  s    c             C   s   | j S )zG
        `~astropy.units.Unit` : Unit for the dataset, if any.
        )r&   )r'   r)   r)   r*   r     s    zNDData.unitc             C   s   | j S )zU
        any type : A world coordinate system (WCS) for the dataset, if any.
        )r%   )r'   r)   r)   r*   r     s    z
NDData.wcsc             C   sV   | j d k	r|d k	rtd|d ks,t|tr4|| _ nt|trJt|| _ ntdd S )NzCYou can only set the wcs attribute with a WCS if no WCS is present.zEThe wcs argument must implement either the high or low level WCS API.)r%   
ValueErrorr   r   r   r   r#   )r'   r   r)   r)   r*   r     s    
c             C   s   | j S )ac  
        any type : Uncertainty in the dataset, if any.

        Should have an attribute ``uncertainty_type`` that defines what kind of
        uncertainty is stored, such as ``'std'`` for standard deviation or
        ``'var'`` for variance. A metaclass defining such an interface is
        `~astropy.nddata.NDUncertainty` but isn't mandatory.
        )_uncertainty)r'   r)   r)   r*   r   )  s    
zNDData.uncertaintyc             C   sZ   |d k	rPt |ds(td t|dd}t|trP|jd k	rJ|j|dd}| |_|| _	d S )NZuncertainty_typez3uncertainty should have attribute uncertainty_type.F)r   )
r   r   r   r   r   r   Z_parent_nddatar(   Zparent_nddatar9   )r'   r    r)   r)   r*   r   5  s    



)NNNNNF)r4   
__module____qualname____doc__r
   	_meta_docr   r   r.   r6   propertyr   r   setterr   r   r   __classcell__r)   r)   )r(   r*   r      s   \ t
)numpyr!   r   r   Znddata_baser   Znduncertaintyr   r   Zastropyr   Zastropy.unitsr   r	   Zastropy.utils.metadatar
   Zastropy.wcs.wcsapir   r   r   r   __all__r=   r   r)   r)   r)   r*   <module>   s   