3
ÌœŸWm  ã               @   s4   d dl Zdd„ Zdd„ Zedddd ddfdd	„ZdS )
é    Nc             C   s*   y| d  W n t tfk
r$   dS X dS )NÚ r   é   )Ú	TypeErrorÚ
ValueError)Úobj© r   úd/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/tools/data_wizards/loadtxt.pyÚ_string_like
   s
    r	   c             C   sV   | j }t|tjƒrdd„ S t|tjƒr.dd„ S t|tjƒr>tS t|tjƒrNtS tS d S )Nc             S   s   t t| ƒƒS )N)ÚboolÚint)Úxr   r   r   Ú<lambda>   s    z_getconv.<locals>.<lambda>c             S   s   t t| ƒƒS )N)r   Úfloat)r   r   r   r   r      s    )	ÚtypeÚ
issubclassÚnpÚbool_ÚintegerÚfloatingr   ÚcomplexÚstr)ÚdtypeÚtypr   r   r   Ú_getconv   s    r   ú#Fc                s’  t | ƒr2| jdƒr&ddl}|j| ƒ}	qJt| dƒ}	nt| dƒrB| }	ntdƒ‚g }
tjˆƒ‰tˆƒ‰d‰ˆ dkrŽi ‰ ˆj	dk	rŽ‡fdd„ˆj	D ƒ‰xØt
|	ƒD ]Ì\}}||k rªq˜|j|ƒ}|dkrÎ|d|… jƒ }n|jƒ }t|ƒsàq˜|j|ƒ‰ˆdk�r‡ ‡fd
d„ttˆƒƒD ƒ‰|dk	�r0‡‡fdd„|D ƒ}n‡fdd„t
ˆƒD ƒ}ˆj	dk	�rZt|ƒ}|
j|ƒ q˜W tj|
ˆƒ}
tj|
ƒ}
|�rŠ|
jS |
S dS )an  
    Load ASCII data from fname into an array and return the array.

    The data must be regular, same number of values in every row

    Parameters
    ----------
    fname : filename or a file handle.
      Support for gzipped files is automatic, if the filename ends in .gz

    dtype : data-type
      Data type of the resulting array.  If this is a record data-type, the
      resulting array will be 1-d and each row will be interpreted as an
      element of the array. The number of columns used must match the number
      of fields in the data-type in this case.

    comments : str
      The character used to indicate the start of a comment in the file.

    delimiter : str
      A string-like character used to separate values in the file. If delimiter
      is unspecified or none, any whitespace string is a separator.

    converters : {}
      A dictionary mapping column number to a function that will convert that
      column to a float.  Eg, if column 0 is a date string:
      converters={0:datestr2num}. Converters can also be used to provide
      a default value for missing data: converters={3:lambda s: float(s or 0)}.

    skiprows : int
      The number of rows from the top to skip.

    usecols : sequence
      A sequence of integer column indexes to extract where 0 is the first
      column, eg. usecols=(1,4,5) will extract the 2nd, 5th and 6th columns.

    unpack : bool
      If True, will transpose the matrix allowing you to unpack into named
      arguments on the left hand side.

    Examples
    --------
      >>> X = loadtxt('test.dat')  # data in two columns
      >>> x,y,z = load('somefile.dat', usecols=(3,5,7), unpack=True)
      >>> r = np.loadtxt('record.dat',
                         dtype={'names':('gender','age','weight'),
                         'formats': ('S1','i4', 'f4')})

    SeeAlso: scipy.io.loadmat to read and write matfiles.
    z.gzr   NÚrÚseekz%fname must be a string or file handlec                s   g | ]}t ˆ j| d  ƒ‘qS )r   )r   Úfields)Ú.0Úname)r   r   r   ú
<listcomp>g   s   zloadtxt.<locals>.<listcomp>r   c                s   g | ]}ˆ j |ˆƒ‘qS r   )Úget)r   Új)Ú
convertersÚdefconvr   r   r    v   s   c                s   g | ]}ˆ | ˆ| ƒ‘qS r   r   )r   r"   )ÚconverterseqÚvalsr   r   r    y   s    c                s   g | ]\}}ˆ | |ƒ‘qS r   r   )r   r"   Úval)r%   r   r   r    {   s    éÿÿÿÿ)r	   ÚendswithÚgzipÚopenÚhasattrr   r   r   r   ÚnamesÚ	enumerateÚfindÚstripÚlenÚsplitÚrangeÚtupleÚappendÚarrayÚsqueezeÚT)Úfnamer   ÚcommentsÚ	delimiterr#   ÚskiprowsÚusecolsÚunpackr*   ÚfhÚXÚiÚlineÚcomment_startÚrowr   )r#   r%   r$   r   r&   r   Úloadtxt    sR    5










rE   )Únumpyr   r	   r   r   rE   r   r   r   r   Ú<module>   s   