o
    SdF                     @   sP   d dl Z d dlZd dlZd dlmZ d dlmZm	Z	m
ZmZ dd Zdd ZdS )    N)resample)	attributereadfileutils	writefilec                 C   s   t |jdkr|jr|jS tjtj| \}}|jrdnd}|jr&|jn|}| | | }|j	rPtj
|j	sHt|j	 td|j	  tj|j	|}|S )N   Zgeo_Zrdr_zcreate directory: )lenfileoutfileospathsplitextbasename	radar2geodsetout_dirisdirmakedirsprintjoin)in_fileinpsfbasefextprefixsuffixout_file r   G/home/exouser/operations/rsmas_insar/tools/MintPy/src/mintpy/geocode.pyauto_output_filename   s   r   c                 C   sr  t   }tdd | jD }t| j| j| j| j| j	dd}| j
r.| jr.| j
|d< | j|d< td.| j| j| | j| jd|}|  |  | jD ]R}tdd	|   tj|| jd
}t|| }| jrxtd tj||| jgddkrxqK| jrtj||d}ntj||d}tj |d dv }|rt!|}	tj"|dd}
t#j$|||
||	d nt }tj%|| jd
}t&dd |D }|D ]}|stj'|j(|j)f|d d||< t*|j+D ]}|j,| }|j-| }td|d  d|j+   tdj.|||tj/|d tj0|||ddd }|j1||d}|j2dkr0d|j3d |d |d |d |d  g}n|d |d |d |d  g}|rVtd!| d"|  t#j4||||dd# q||| |d |d |d  |d f< q|sztj5|| |j6d||< q|st7|8 |d$< t#j9||||d% | j
r| jrt#j:||d& qKt;t   | d'\}}td(|d)d*|d+d, |S )/zgeocode all input filesc                 S   s   g | ]}t j|qS r   )r   r   getsize.0ir   r   r   
<listcomp>)   s    zrun_geocode.<locals>.<listcomp>T)interp_method
fill_valuenprocs
max_memorysoftware	print_msglat_filelon_file)lut_filesrc_fileSNWE	lalo_stepz2--------------------------------------------------z
resampling file: )datasetNamezupdate mode: ON)r   skip)res_objr   )z.h5z.he5UNIT)key)metadatads_unit_dictref_filecompressionc                 s   s    | ]}t |V  qd S )N)r   r!   r   r   r   	<genexpr>c   s    zrun_geocode.<locals>.<genexpr>	DATA_TYPE)dtype/z*reading {d:<{w}} in block {b} from {f} ...)dwbfF)r1   boxr*   r   )src_databox_ind      zwrite data in block z
 to file: )datar1   blockr*   BANDS)r   r6   r8   )fname<   ztime used: z02.0fz mins z02.1fz secs.
Nr   )<timenpargmaxr	   dictinterpMethod	fillValuer'   	maxMemoryr)   latFilelonFiler   
lookupFiler/   laloStepopenpreparer   r   read_attributer   r   
updateModeutrun_or_skipr   attrupdate_attribute4radar2geoupdate_attribute4geo2radarr   r   r   get_hdf5_compressionget_hdf5_dataset_attrsr   layout_hdf5get_dataset_listmaxzeroslengthwidthrangenum_boxsrc_box_listdest_box_listformatr   readrun_resamplendimshapewrite_hdf5_blockarrayr<   r   keyswritewrite_isce_xmldivmod)r   
start_timeZind_maxkwargsr3   infileatrr
   Z	hdf5_filer9   r7   ZdsDictdsNamesmaxDigitdsNamer#   src_boxdest_boxrG   rH   msr   r   r   run_geocode$   s   






r   )r   rL   numpyrM   mintpy.objects.resampler   mintpy.utilsr   r]   r   r   r[   r   r   r   r   r   r   r   <module>   s   