Current File : //usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyc
�
E�`Qc
@s�dZdZddlZddlZddlmZmZmZmZm	Z
ddljj
ZddlmZmZejjjZejZddljZddlmZmZmZmZmZmZmZm Z ejj!Z!ddl"Z"ddd	d
ddgZ#d
dddgZ$d�Z%e&d�Z'd�Z(dee)fd��YZ*d�Z+e*Z,e&e&e&e&e&e-e&e&d�Ze&e&e&e&e&e-e&e&ed�	Zd�Z.d�Z/e&dde&e&d�Z0e&d�Z1dS(s":mod:`numpy.ma..mrecords`

Defines the equivalent of :class:`numpy.recarrays` for masked arrays,
where fields can be accessed as attributes.
Note that :class:`numpy.ma.MaskedArray` already supports structured datatypes
and the masking of individual fields.

:author: Pierre Gerard-Marchant
sPierre GF Gerard-Marchanti����N(tbool_tdtypetndarraytrecarraytarray(t
fromarraystfromrecords(tMAErrortMaskedArraytmaskedtnomasktmasked_arraytgetdatatgetmaskarraytfilledt
MaskedRecordst	mrecarrayRRtfromtextfiletaddfieldt_datat_maskt
_fieldmaskRcCs�t|d�r9djg|jjD]}|d^q"�Sd}xd|D]\}tj|�}|t|jj7}t|jjt	j
�r�||j
7}n|d7}qFW|d S(sKReturns the formats of each array of arraylist as a comma-separated string.Rt,iti����(thasattrtjoinRtdescrtnptasarrayt_typestrttypet
issubclasstntypestflexibletitemsize(tdatatdesctformatstobj((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_getformats-s*
c
CsVt|�}gt|�D]}d|^q}|dkrD|}nyt|ttf�rb|}n2t|t�r�|jd�}ntd|
��t|�}||kr�|||7}ng}x�t	|||j
�D]l\}}}	|tkr.|	dtkr|j||	df�qE|j|	�q�|j||	df�q�Wt
j|�S(s�Checks that the field names of the descriptor ``descr`` are not some
reserved keywords. If this is the case, a default 'f%i' is substituted.
If the argument `names` is not None, updates the field names to valid names.
    sf%iRsillegal input names %siiN(tlentrangetNonet
isinstancettupletlisttstrtsplitt	NameErrortzipRtreserved_fieldstappendRR(
Rtnamestndescrtit
default_namest	new_namestnnamestntdtt((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_checknames;s(#		%cCs]g|jjD]}|df^q
}tj|jd|�}ttgt|��|_|S(Ns|b1R(	RR4RtemptytshapeR,tFalseR(tflat(tselfR:tmdescrtfdmask((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_get_fieldmaskZs%cBs
eZdZddddddddeeedeed�Zd�Zd�Z	e
de	�Zd�Ze
de�Z
d�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zddd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�ZRS(s�

*IVariables*:
    _data : {recarray}
        Underlying data, as a record array.
    _mask : {boolean array}
        Mask of the records. A record is masked when all its fields are masked.
    _fieldmask : {boolean recarray}
        Record array of booleans, setting the mask of each individual field of each record.
    _fill_value : {record}
        Filling values for each field.
    icKs�tj||d|d|d|d|d|d|d|d|	d	|
�	}tj|j�}|tksvtj|�r�|s�tt	gt
|��|_q�n&tj|d
|�}|j
|j
krI|j|j}}|dkr�tj||j
�}nD||kr tj||j
�}n dd
}t|||f��t}n|sh|j|�t|_n\|j|kr�|}n;tjg|D]}t|gt
|��^q�d|�}||_|S(NRtbuftoffsettstridesR%R4ttitlest	byteordertalignedtcopyis/Mask and data not compatible: data size is %i, smask size is %i.(Rt__new__tmatmake_mask_descrRR
RtsizeR,R@R(RRR?tresizetreshapeRtTruet__setmask__t_sharedmask(tclsR?RRFRGRHR%R4RIRJRKtmaskt	hard_maskt
fill_valuet	keep_maskRLtoptionsRBtmdtypetndtnmtmsgRtm((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRMos8!	"	
	2		cCst|dd�}|dkr�t|dt�}tj|d�}|tkritj|jd|�}q�tj|�}t	g|D]}t
|gt|��^q�d|�jt
�}n|j}|jd|�|j|�|dtkr�t
|d<ndS(NRRt
_baseclass(tgetattrR*R
Rt__getattribute__RNtmake_mask_noneR?ROtnarrayR,R(tviewRt__dict__tupdatet_update_from(RBR&Rtobjmaskt_dtypeRCR`t_dict((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__array_finalize__�s/	

cCstj|t�S(sReturns the data as a recarray.(RRfR(RB((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_getdata�stfgetcCs|jS(s
Alias to mask(R(RB((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt
_getfieldmask�scCs#|jrt|j�St|j�S(sReturns the length(tndimR(RR(RB((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__len__�s	
c
Cs�ytj||�SWntk
r'nXtj|d�j}y||d }Wn'ttfk
rxtd|��nXtj|d�}tj||d�}|j|�}|j	jr�t
d��nt}|jdd�}|dk	rAy||}Wntk
rnX|jtjt|j	�p/df�j�}n|jsP|r�|jt�}t|_t|_||_|jd	d�}	|	dk	r�y|	||_Wq�tk
r�d|_q�Xq�n|j�}|S(
NRis record array has no attribute %sRgRas6MaskedRecords is currently limited tosimple records...Rit_fill_value(tobjectRctAttributeErrorRtfieldst	TypeErrortKeyErrorRftgetfieldRtNotImplementedErrorR@tgetR*t
IndexErrorRtboolR(tanyR?RRaRSt_isfieldRRst
ValueErrortitem(
RBtattrt	fielddicttrest
_localdictRR&t	hasmaskedRRs((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRc�sF

0			
c	Cs�|dkr|j|�dStj|d�}||k}ytj|||�}Wnttj|d�jpri}tj|d�p�i}||kp�||kstj�d \}}	||	�qnTXtj|d�jp�i}||kr�|S|rytj||�Wq|SXny||d }
Wn't	t
fk
rYtd|��nX|tkr�|d	}|dk	r�|d	|}n|}t}
nt|�}t|�}
tj|d
�j||
�}|dj||
�|S(
s)Sets the attribute attr to the value val.RWt	fieldmaskNRgRt_optinfois record array has no attribute %sRsRR(smaskR�(RTRtRct__setattr__RRvtsystexc_infot__delattr__RwRxRuR	R*RSRR
tsetfieldt__setitem__(RBR�tvalR�tnewattrtretR�toptinfotexctypetvalueR�RstdvaltmvalR&((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR��sH

	cCs�|j}tj|d�}tj||d�}t|t�r�||jt�}|||_t|_	|d}|dk	r�|||_n|jr�|jr�t
S|Stj||dt�jt�}tj||dt�jt�|_|S(shReturns all the fields sharing the same fieldname base.
The fieldname base is either `_data` or `_mask`.RRaRsRLN(RgRRcRfR+t
basestringRRRSRUR*RsRqR	RRR@RR(RBtindxR�RRR&tfval((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__getitem__!s 	
	
"%cCs?tj|||�t|t�r;tj|�|j|<ndS(sSets the given record to value.N(RR�R+R�RNR
R(RBR�R�((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR�=scCs|jdkr�gtg|jjD]}t||�^q"�D]2}ddjg|D]}t|�^qT�^q>}ddj|�Sgtg|jjD]}t||�^q��D]2}ddjg|D]}t|�^q��^q�}ddj|�SdS(s%Calculates the string representation.is(%s)Rs[%s]s, s%sN(RPR1RR4RbRR.(RBtftsR6tmstr((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__str__DsddcCs�|jj}dtg|D]}t|�^q�df}g|jjD]}||t||�f^qI}|jdd�|j|d|jfdg�tdj	|��S(s#Calculates the repr representation.s%%%is : %%siismasked_records(s    fill_values              )s
(
RR4tmaxR(RbtinserttextendRYR.R(RBt_namesR:tfmtR�treprstr((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__repr__Os02
cCs�|dkr?|dkr*tj|�}q(tj||�}n�|dkry@t|t�rxtj||�}d}ntj||�}Wq(tk
rtj|�}|jdkr�|jj	d}|j
�j||�}|j|�ntj||�}d|_q(Xntj|||�}t
|dt�tk	r|tj|j�}|jj|t�|_|j|j_n|S(s Returns a view of the mrecarray.iRN(R*RRfRRwRRRvt	__class__t	__bases__t	__array__RiRsRbR
RNRORR?(RBRRtoutputtbasetypeR\((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRfYs0	
cCs
t|_dS(sForces the mask to hardN(RSt	_hardmask(RB((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pytharden_maskscCs
t|_dS(sForces the mask to softN(R@R�(RB((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pytsoften_mask�scCs=|j}|jj�jt|��}|jj�|_|S(s$Returns a copy of the masked record.(RgRRLRfRR(RBR�tcopied((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRL�s	cCsf|dk	r|j|�j�St|j�j�dt�}t|jj��}d||<|j�S(sLCopy the data portion of the array to a hierarchical python
        list and returns that list.

        Data items are converted to the nearest compatible Python
        type.  Masked values are converted to fill_value. If
        fill_value is None, the corresponding entries in the output
        list will be ``None``.

        RN(R*RttolistReRtR(RBRYtresultRW((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR��s

cCs@d|j|j|jj|jj�|jj�|jf}|S(sOReturn the internal state of the masked array, for pickling purposes.

        i(R?RtflagstfncRttostringRRs(RBtstate((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt__getstate__�s	cCs�|\}}}}}}}tj|||||f�tg|jjD]\}	}
|	tf^qG�}|jdj||||f�||_dS(sbRestore the internal state of the masked array, for pickling purposes.
    ``state`` is typically the output of the ``__getstate__`` output, and is a
    5-tuple:

        - class name
        - a tuple giving the shape of the data
        - a typecode for the data
        - a binary string for the data
        - a binary string for the mask.

        RN(Rt__setstate__RRRRgRY(RBR�tvertshpttyptisftrawtmsktflvtkt_R\((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR��s
1 cCs%t|j|jddf|j�fS(s6Return a 3-tuple for pickling a MaskedArray.

        itb(i(t_mrreconstructR�RaR�(RB((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt
__reduce__�sN(t__name__t
__module__t__doc__R*R@R
RSRMRmRntpropertyRRpRRrRcR�R�R�R�R�RfR�R�RLR�R�R�R�(((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRas4	%					-	5				
&					cCsOtj|||�j|�}tjt|d�}|j||d|d|�S(sbInternal function that builds a new MaskedArray from the
    information stored in a pickle.

    tb1RWR(RRMRf(tsubtypet	baseclasst	baseshapeR�RR((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR��sc	
Cs�g|D]}	t|	�^q}
g|D]}	tjt|	��^q&}t|
d|d|d|d|d|d|d|�jt�}t|�|j_	|dk	r�||_n|S(	sCreates a mrecarray from a (flat) list of masked arrays.

    Parameters
    ----------
    arraylist : sequence
        A list of (masked) arrays. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dtype : {None, dtype}, optional
        Data type descriptor.
    shape : {None, integer}, optional
        Number of records. If None, shape is defined from the shape of the
        first array in the list.
    formats : {None, sequence}, optional
        Sequence of formats for each individual field. If None, the formats will
        be autodetected by inspecting the fields and selecting the highest dtype
        possible.
    names : {None, sequence}, optional
        Sequence of the names of each field.
    fill_value : {None, sequence}, optional
        Sequence of data to be used as filling values.

    Notes
    -----
    Lists of tuples should be preferred over lists of lists for faster processing.
    RR?R%R4RIRKRJN(RRt
atleast_1dR
t
recfromarraysRfRR1RRAR*RY(
t	arraylistRR?R%R4RIRKRJRYtxtdatalisttmasklistt_array((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR�s(	c
Cs�t|dd�}
yt|d�}Wn$tk
rLt|dj�}nXt|t�r�t|t�r�|j�j	t�}n|dkr�|j}n|j
�}nt|d|d|d|d|d|d|d	|�j	t�}|dk	r||_
n|	tk	r�tj|	d
t�}	t|	j�}
|
rF|	|j_q�t|	j�dkr�g|	D]}t|�^qb|j_q�|j|	�n|
dk	r�|
|j(n|S(
sHCreates a MaskedRecords from a list of records.

    Parameters
    ----------
    reclist : sequence
        A list of records. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dtype : {None, dtype}, optional
        Data type descriptor.
    shape : {None,int}, optional
        Number of records. If None, ``shape`` is defined from the shape of the
        first array in the list.
    formats : {None, sequence}, optional
        Sequence of formats for each individual field. If None, the formats will
        be autodetected by inspecting the fields and selecting the highest dtype
        possible.
    names : {None, sequence}, optional
        Sequence of the names of each field.
    fill_value : {None, sequence}, optional
        Sequence of data to be used as filling values.
    mask : {nomask, sequence}, optional.
        External mask to apply on the data.

    Notes
    -----
    Lists of tuples should be preferred over lists of lists for faster processing.
    RiRR?R%R4RIRKRJRLiN(RbR*R(RwRR+RRRRfR�trecfromrecordsRRYR
RRR@RRAR?R,RT(treclistRR?R%R4RIRKRJRYRWRtnfieldstmrectmaskrecordlengthR`((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRs6 
(
cCs*g}tj|�}t|j�dkr7|d}n$t|j�dkr[td��nx�|D]�}yt|�Wn�tk
ryt|�Wn[tk
r�yt|�}Wn!tk
r�|j|j	�qX|jtj	t��q"X|jtj	t��qbX|jtj	t��qbW|S(sTries to guess the dtypes of the str_ ndarray `arr`, by testing element-wise
conversion. Returns a list of dtypes.
The array is first converted to ndarray. If the array is 2D, the test is performed
on the first line. An exception is raised if the file is 3D or more.
    iisThe array should be 2D at most!(
RRR(R?R�tinttfloattcomplexR3R(tarrtvartypesR�R�((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt_guessvartypesEs*




cCs�t|d�r|Syt|�}Wn!tk
rFtd|��nX|j�d dkrq|jdd�|S|j�td��dS(s%Opens the file handle of file `fname`treadlinesNo such file: '%s'is\xisWow, binary fileN(RtopentIOErrorR�tseektcloseRz(tfnameR�((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pytopenfilees

t#Rc
Cs2t|�}xTtrb|j�}||j|� j�}|j|�}	t|	�dkrPqqW|dkrx|	}ntg|D]=}|d|kr�t|�dkr�|j�j|�^q��}
|
j	\}}|j
�|dkrt|
d�}ntg|D]}
tj
|
�^q}t|�|krtd}|d7}tj|t|�|f�t|
d�}ngt||�D]\}}||f^q�}g|D]}tj|�^q�}|
j|k}gt|
j|||�D]0\}}}}t|d|d|d|�^q�}t|d|�S(	s�Creates a mrecarray from data stored in the file `filename`.

    Parameters
    ----------
    filename : {file name/handle}
        Handle of an opened file.
    delimitor : {None, string}, optional
        Alphanumeric character used to separate columns in the file.
        If None, any (group of) white spacestring(s) will be used.
    commentchar : {'#', string}, optional
        Alphanumeric character used to mark the start of a comment.
    missingchar : {'', string}, optional
        String indicating missing data, and used to create the masks.
    varnames : {None, sequence}, optional
        Sequence of the variable names. If None, a list will be created from
        the first non empty line of the file.
    vartypes : {None, sequence}, optional
        Sequence of the variables dtypes. If None, it will be estimated from
        the first non-commented line.


    Ultra simple: the varnames are in the header, one lineiis&Attempting to %i dtypes for %i fields!s Reverting to default.RWRRYN(R�RSR�tfindtstripR/R(R*RR?R�R�RRtwarningstwarnR1RNtdefault_fill_valuetTR(R�t	delimitortcommentchartmissingchartvarnamesR�R�tlinet	firstlinet	_varnamest
_variablesR�R�tvR_R:RCtmfillvRtaR`R<t	_datalist((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyRvs6		@
"
."LcCs�|j}|j}|dks*|tkr@dt|j�}ntj|�}tj|jj	||jfg�}t
|j|�}g|jjj
�D]!}|j|j|�|�^q�|j|j|jj|�|jt�}tjg|jD]}|tf^q��}	t
|j|	�}
g|jjj
�D]!}|
j|j|�|�^q:|
jt|�|
jj|�|
|_|S(s�Adds a new field to the masked record array, using `newfield` as data
and `newfieldname` as name. If `newfieldname` is None, the new field name is
set to 'fi', where `i` is the number of existing fields.
    sf%iN(RRR*R2R(RRNRRRRR?RvtvaluesR�RyRfRR4RR
(tmrecordtnewfieldtnewfieldnameRRtnewdtypetnewdataR�R:t	newmdtypetnewmask((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyR�s&		%5+5	(2R�t
__author__R�tnumpyRRRRRRRetnumpy.core.numerictypestcoretnumerictypesR tnumpy.core.recordsRR�RR�trecordst_byteorderconvRtnumpy.maRNRRR	R
RRR
Rt_check_fill_valueR�t__all__R2R'R*R=RERtRR�RR@R�R�RR(((s7/usr/lib64/python2.7/site-packages/numpy/ma/mrecords.pyt<module>	sB(	:		�g		(	@	 		B