a
    «ˆcn  ã                   @   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*   z| d  W n t tfy$   Y dS 0 dS )NÚ r   é   )Ú	TypeErrorÚ
ValueError)Úobj© r   úd/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/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>   ó    z_getconv.<locals>.<lambda>c                 S   s   t t| ƒƒS r
   )r   Úfloatr   r   r   r   r      r   )
ÚtypeÚ
issubclassÚnpZbool_ÚintegerZfloatingr   Zcomplex_ÚcomplexÚstr)ÚdtypeÚtypr   r   r   Ú_getconv   s    r   ú#Fc                    sŽ  t | ƒr2|  d¡r&ddl}| | ¡}	qJt| dƒ}	nt| dƒrB| }	ntdƒ‚g }
t ˆ¡‰tˆƒ‰d‰ˆ du rŽi ‰ ˆj	durŽ‡fdd„ˆj	D ƒ‰t
|	ƒD ]Ì\}}||k r¨q–| |¡}|d	krÌ|d|…  ¡ }n| ¡ }t|ƒsÞq–| |¡‰ˆdu �r‡ ‡fd
d„ttˆƒƒD ƒ‰|du�r.‡‡fdd„|D ƒ}n‡fdd„t
ˆƒD ƒ}ˆj	du�rXt|ƒ}|
 |¡ q–t |
ˆ¡}
t |
¡}
|�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>éÿÿÿÿc                    s   g | ]}ˆ   |ˆ¡‘qS r   )Úget©r   Új)Ú
convertersÚdefconvr   r   r!   v   s   ÿc                    s   g | ]}ˆ | ˆ| ƒ‘qS r   r   r$   )ÚconverterseqÚvalsr   r   r!   y   r   c                    s   g | ]\}}ˆ | |ƒ‘qS r   r   )r   r%   Úval)r(   r   r   r!   {   r   )r	   ÚendswithÚgzipÚopenÚhasattrr   r   r   r   ÚnamesÚ	enumerateÚfindÚstripÚlenÚsplitÚrangeÚtupleÚappendÚarrayZsqueezeÚT)Úfnamer   ÚcommentsÚ	delimiterr&   ZskiprowsZusecolsÚunpackr,   ÚfhÚXÚiÚlineÚcomment_startÚrowr   )r&   r(   r'   r   r)   r   Úloadtxt    sV    5




ÿ



ÿ

rD   )Únumpyr   r	   r   r   rD   r   r   r   r   Ú<module>   s
   ÿ