o
    <c\                     @   s   d dl Z d dlZd dlZd dlmZmZmZmZm	Z	 d dl
mZmZ dddZddd	Zdd
dZdd ZdddZdddZdd Zdd Zdd ZdS )    N)HDFEOSgiantIfgramStackgiantTimeseriesifgramStack
timeseries)ptimereadfileT   c                 C   s   t dd t|  D dg }d}d}t|  dd dD ].\}}|d7 }||kr1|d	7 } |S z|d
}W n   Y |d|d| d| d7 }q|S )Nc                 S   s   g | ]}t |qS  len).0keyr
   r
   D/home/exouser/operations/rsmas_insar/tools/MintPy/src/mintpy/info.py
<listcomp>   s    z%attributes2string.<locals>.<listcomp>r    c                 S   s   | d S )Nr   r
   )xr
   r
   r   <lambda>   s    z#attributes2string.<locals>.<lambda>)r      z  ...
utf8z  <z    
)maxlistkeyssorteditemsdecode)atrZsortingmax_meta_numdigitsatr_strir   valuer
   r
   r   attributes2string   s    	 r$   c                 C   s   t | |d}t| d S )Nr   )r$   print)r   r   r!   r
   r
   r   print_attributes-   s   r'   c                    s   da  fdd}t| dD}t|j}t|dkr(t d7 a t t| dd 7 a td	d
 | D a	tdt	d a	|
dddkrFt	d7 a	|| W d    n1 sUw   Y  tt  t S )Nr   c                    s   t |tjrtd|  d7 an)t |tjr8td| dt dt|jdd7 atdt|jd	d
|j	 d7 at
|j}t|dkrMtt| d7 ad S d S )NzHDF5 group   "/z"
zHDF5 dataset "/r   z	": shape=z<20z, zdtype=z<10z, compression=r   r   r%   )
isinstanceh5pyGrouph5_strDatasetmaxDigitstrshapedtypecompressiondictattrsr   r$   )nameobjr   r%   r
   r   hdf5_structure2string7   s   & 
z3print_hdf5_structure.<locals>.hdf5_structure2stringrr   zAttributes in / level:
r%   r   c                 s   s    | ]}t |V  qd S Nr   )r   r"   r
   r
   r   	<genexpr>L   s    z'print_hdf5_structure.<locals>.<genexpr>   r   	FILE_TYPEr   r   #   )r+   r)   Filer2   r3   r   r$   r   r   r-   get
visititemsr&   )fnamer   r6   fr   r
   r%   r   print_hdf5_structure2   s   
rB   c                 C   s`   t | d }td| d   td| d   tdt|   tdt|dd	 d S )
Nr   zStart Date: r   zEnd   Date: zNumber of dates  : zSTD of datetimes : z.2fz years)r   date_list2vectorr&   r   npstd)dateList
datevectorr
   r
   r   print_timseries_date_stat[   s   rI   allF     @c                 C   sh  t | d }d}|dv rt|  }nb|dkrt|  }nW|dkr*t|  }nL|dv r5t|  }nA|dv rnt| }|j	dd	 |jdd
}|jdd
}	|dkrXt
|}n|dkrat
|	}ntt
t|t|	 }ntd| d t|}|r|dur|d| D ]!}
|r|dv r||
}n||
}|
 d| }n|
}t| q|t|k rtd |S )zPrint time/date info of filer;   Nr   r   r   )r   )r   F	print_msg)
dropIfgramTrJ   Zkeptz$--date option can not be applied to z file, ignore it.	z...
)r   read_attributer   get_date_listr   r   r   get_date12_listr   openr   r   setr&   intindexr   )r@   disp_ifgramdisp_nummax_numrN   krG   r5   ZdateListAllZdateListKeptdnummsgr
   r
   r   print_date_listh   sD   



r_   c                 C   s$   t | }|r|D ]}t| q	|S )zPrint slice info of file)r   get_slice_listr&   )r@   rN   
slice_listZ
slice_namer
   r
   r   print_slice_list   s
   

rb   c                 C   s   zJt | }|d }tddd td|d   td|d   d| v r-td	 ntd
 |dv rHt| }tddd t| W d S W d S    Y d S )Nr;   z
{} {:*<40}********************zBasic File Info zfile name: 	FILE_PATHzfile type: Y_FIRSTzcoordinates : GEOzcoordinates : RADARrL   
{} {:*<40}zDate Stat Info )r   rQ   r&   formatr   r_   rI   )r@   r   r[   rG   r
   r
   r   print_aux_info   s&   


rh   c                 C   s   dd }g a t| d}|| W d    n1 sw   Y  |t vr6d| d}|dt  7 }t|t| d}|| d d  }t| W d    n1 sSw   Y  td|j  tdt| d	t	|  td
t
t|  d S )Nc                 S   s   t |tjrt|  d S d S r8   )r(   r)   r,   dsNamesappend)r4   r5   r
   r
   r   get_hdf5_dataset   s   z'print_dataset.<locals>.get_hdf5_datasetr7   zinput dataset z not found!z
available datasets: zdataset size: zdataset min / max: z / znumber of pixels in NaN: )ri   r)   r=   r?   
ValueErrorr&   r/   rE   nanminnanmaxsumisnan)r@   dsNamerk   rA   r^   datar
   r
   r   print_dataset   s"   
 rs   c                 C   s   | j s| jrt| j| j| j| jdd dS | jr*| jdkr!tdt| jdd dS | j	r7t
| j| j	d dS t| j tj| jd  }|d	v r]td
dd t| j| jd dS td
dd t| j}t|| jd dS )z7Extract and print the input file structure information.T)rX   rY   rZ   rN   NrJ   z2--show-ifgram option is not applicable to --slice.rM   )rq   r   )z.h5z.he5rf   rc   zHDF5 File Structure r%   zBinary File Attributes )Z	disp_daterY   r_   filerX   r   Z
disp_slicerl   rb   dsetrs   rh   ospathsplitextlowerr&   rg   rB   r   rQ   r'   )inpsfextr   r
   r
   r   
print_info   sB   

r|   )Tr	   )r	   )rJ   FrK   F)F)rv   r)   numpyrE   mintpy.objectsr   r   r   r   r   mintpy.utilsr   r   r$   r'   rB   rI   r_   rb   rh   rs   r|   r
   r
   r
   r   <module>   s   


)

7	 