
    Zf\                         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ZddZddZd ZddZdd	Zd
 Zd Zd Zy)    N)HDFEOSgiantIfgramStackgiantTimeseriesifgramStack
timeseries)ptimereadfilec                 R   t        t        | j                               D cg c]  }t        |       c}dgz         }d}d}t	        | j                         d       D ]:  \  }}|dz  }||kD  r|dz  } |S 	 |j                  d      }|d|d	| dd
| dz  }< |S c c}w #  Y xY w)Nr    c                     | d   S )Nr    )xs    D/home/exouser/operations/rsmas_insar/tools/MintPy/src/mintpy/info.py<lambda>z#attributes2string.<locals>.<lambda>   s
    !     )key   z  ...
utf8z  <z    
)maxlistkeyslensorteditemsdecode)atrsortingmax_meta_numr   digitsatr_strivalues           r   attributes2stringr%      s    d388:&67s#c(71#=>FG	ASYY[n= 9
U	Q|y G NV, C&z?$ugR88G9 N! 8s   B7B""B&c                 4    t        | |      }t        |       y )Nr    )r%   print)r   r    r"   s      r   print_attributesr)   -   s    ,?G	'Nr   c                    da fd}t        j                  | d      5 }t        |j                        }t        |      dkD  r t         dz  a t         t        |      dz   z  a t        d |j                         D              a	t        d	t        d
z         a	|j                  dd      dk(  r	t        dz  a	|j                  |       d d d        t        t                t         S # 1 sw Y   xY w)Nr   c                    t        |t        j                        rt        d|  dz  anut        |t        j                        r[t        d| dt
         ddt        |j                        ddz  at        d	t        |j                        d
d|j                   dz  at        |j                        }t        |      dkD  rt        t        |      z  ay y )NzHDF5 group   "/z"
zHDF5 dataset "/r   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    s      r   hdf5_structure2stringz3print_hdf5_structure.<locals>.hdf5_structure2string7   s    c4::&vS11FT\\*Qxj L'93syy>RUBVVXYYFs399~c2.@QQSTTF399os8a<',GGF r   rr   zAttributes in / level:
r'   r   c              3   2   K   | ]  }t        |        y wN)r   ).0r#   s     r   	<genexpr>z'print_hdf5_structure.<locals>.<genexpr>L   s     0!s1v0s      r   	FILE_TYPEr   r   #   )r/   r-   Filer6   r7   r   r%   r   r   r1   get
visititemsr(   )fnamer    r:   fr   s    `   r   print_hdf5_structurerH   2   s     F
H 
5#	 ,! 177ms8a<00F',GLLF 0qvvx00r8A:&77;-9NH 	
*+,$ 
&MM), ,s   B&C""C+c                     t        j                  |       d   }t        d| d           t        d| d           t        dt        |               t        dt	        j
                  |      dd	       y )
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
datevectors     r   print_timseries_date_statrP   [   st    ''1!4J	L!
&'	L"
'(	H
/0	z 237v
>?
 r   c                 N   t        j                  |       d   }d}|dv rt        |       j                         }n|dk(  rt	        |       j                         }n|dk(  rt        |       j                         }n|dv rt        |       j                         }n|dv rt        |       }|j                  d	       |j                  d
      }|j                  d
      }	|dk(  rt        |      }nJ|dk(  rt        |	      }n9t        t        t        |      t        |	      z
              }nt        d| d       t        |      }|rc|a|d| D ]@  }
|r/|dv rj                  |
      }n|j                  |
      }|
 d| }n|
}t        |       B |t!        |      k  rt        d       |S )zPrint time/date info of filerA   Nr   r   r   )r   )r   F	print_msg)
dropIfgramTall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   )rF   disp_ifgramdisp_nummax_numrT   krN   r9   dateListAlldateListKeptdnummsgs                r   print_date_listri   h   s   &{3AHNe$224	
h%=..0	
	"5)779 
"	"#E*::<	
o	% 5!))U);**d*; %K(HF"L)Hd3{#3c,6G#GHIH 	4QC7HIJ 'lGX)(7# 		A'%++A.C"..+C2cUm#J		 S]"'NOr   c                 X    t        j                  |       }|r|D ]  }t        |        |S )zPrint slice info of file)r	   get_slice_listr(   )rF   rT   
slice_list
slice_names       r   print_slice_listrn      s2    ((/J$ 	J*	r   c                 ~   	 t        j                  |       }|d   }t        dj                  dd             t        d|d   z          t        d|d   z          d|j	                         v rt        d	       nt        d
       |dv r1t        |       }t        dj                  dd             t        |       y #  Y y xY w)NrA   z
{} {:*<40}********************zBasic File Info zfile name: 	FILE_PATHzfile type: Y_FIRSTzcoordinates : GEOzcoordinates : RADARrR   
{} {:*<40}zDate Stat Info )r	   rY   r(   formatr   ri   rP   )rF   r   rc   rN   s       r   print_aux_inforu      s    %%e,l!!&*<=>mC,,-mC,,-
"%&'(&u-H.''0ABC%h/ 
s   B5B8 8B<c                 R   d }g a t        j                  | d      5 }|j                  |       d d d        |t         vrd| d}|dt          z  }t	        |      t        j                  | d      5 }||   d d  }t        |       d d d        t        dj                          t        dt        j                  |       dt        j                  |              t        d	t        j                  t        j                  |                    y # 1 sw Y   xY w# 1 sw Y   xY w)
Nc                 d    t        |t        j                        rt        j	                  |        y y r=   )r,   r-   r0   dsNamesappend)r8   r9   s     r   get_hdf5_datasetz'print_dataset.<locals>.get_hdf5_dataset   s!    c4<<(NN4  )r   r;   zinput dataset z not found!z
available datasets: zdataset size: zdataset min / max: z / znumber of pixels in NaN: )rx   r-   rC   rE   
ValueErrorr(   r3   rL   nanminnanmaxsumisnan)rF   dsNamerz   rG   rh   datas         r   print_datasetr      s   !
 G	5#	 '!	%&' Wvhk2'y11o 
5#	 !y|d
 
N4::,
'(			$0BIIdO3D
EF	%bffRXXd^&<%=
>?
'' ' s   D1DDD&c                 @   | j                   s| j                  r9t        | j                  | j                  | j                  | j
                  d       y| j                  r2| j                  dk7  rt        d      t        | j                  d       y| j                  r"t        | j                  | j                         yt        | j                         t        j                  j                  | j                        d   j                         }|d	v r=t!        d
j#                  dd             t%        | j                  | j
                         yt!        d
j#                  dd             t'        j(                  | j                        }t+        || j
                         y)z7Extract and print the input file structure information.T)r`   ra   rb   rT   NrV   z2--show-ifgram option is not applicable to --slice.rS   )r   r   )z.h5z.he5rs   rp   zHDF5 File Structure r'   zBinary File Attributes )	disp_datera   ri   filer`   r    
disp_slicer{   rn   dsetr   ru   ospathsplitextlowerr(   rt   rH   r	   rY   r)   )inpsfextr   s      r   
print_infor      sI    ~~II((]]%%	
 	 u$QRRd3 yydii		2 499 77DII&q)//1Dn##F,BCDII**	
  	n##F,EFG%%dii0**	

 r   )T   )r   )rV   Fg     @F)F)r   r-   numpyrL   mintpy.objectsr   r   r   r   r   mintpy.utilsr   r	   r%   r)   rH   rP   ri   rn   ru   r   r   r   r   r   <module>r      sO    
    )*
%R
4n(@.r   