B
    Qa#                 @   sT   d dl Z d dlZd dlmZ d dlmZ dddZdddZdd	d
Z	dddZ
dS )    N)
coordinate)readfileTc             C   s  t  }x$t|  D ]\}}t|||< qW |dkrPddt|d t|d f}|d |d  |d |d   }}	|| }
|	| }td|
| t|
|d< t||d< t|d |d	< t|d |d
< t|d |d  |d< t|
d |d  |d< tt|dd| |d< tt|dd| |d< |r@td d| krt|t	|d  |d< t|t	|d  |d< |rtd d| krt|t	|d  |d< |rtd d| krt|t	|d  |d< |rtd d| krPtt|d |d  | |d< tt|d |d  | |d< |rPtd d| krtt|d |d  | |d< tt|d |d  | |d< tt|d |d  | |d< tt|d |d  | |d< |rtd |S ) a  update input dictionary of attributes due to multilooking

    Parameters: atr_in - dict, input dictionary of attributes
                lks_y  - int, number of looks in y/row/azimuth  direction
                lks_x  - int, number of looks in x/column/range direction
                box    - tuple of 4 int indicating (x0, y0, x1, y1)
                         if --margin option is used in multilook.py
    Returns:    atr    - dict, updated dictionary of attributes
    Nr   WIDTHLENGTH         zoutput data in size: {}, {}XMINYMINXMAXYMAXRLOOKS1ALOOKSz*update LENGTH, WIDTH, Y/XMIN/MAX, A/RLOOKSY_STEPX_STEPzupdate Y/X_STEPAZIMUTH_PIXEL_SIZEzupdate AZIMUTH_PIXEL_SIZERANGE_PIXEL_SIZEzupdate RANGE_PIXEL_SIZEREF_YREF_Xzupdate REF_Y/XSUBSET_XMINSUBSET_YMINSUBSET_YMAXSUBSET_XMAXz!update SUBSET_XMIN/XMAX/YMIN/YMAX)
dictiteritemsstrintprintformatgetkeysfloat)atr_inZlks_yZlks_xbox	print_msgatrkeyvaluelengthwidthZ
length_mliZ	width_mli r,   L/home/centos/operations/rsmas_insar/sources/MintPy/mintpy/utils/attribute.pyupdate_attribute4multilook   sZ    "      r.   c             C   s\   t | }|dk	r|j|jf}|d |d< |d |d< x"dD ]}|| kr:|| q:W |S )a  update input dictionary of attributes due to resampling from geo to radar coordinates

    Parameters: atr_in  - dict, input dictionary of attributes
                # combination 1
                shape2d - tuple of 2 int in (length, width)
                # combination 2
                res_obj   - mintpy.objects.resample.resample object
    Returns:    atr     - dict, updated dictionary of attributes
    Nr   r   r   r   )
Y_FIRSTr   Y_UNITX_FIRSTr   X_UNITr   r   REF_LATREF_LON)r   r*   r+   r"   pop)r$   shape2dres_objr&   r'   r(   r,   r,   r-   update_attribute4geo2radarV   s    
r8   c             C   s  t | }|dk	r.|j|jf}|j}|j}|j}|d |d< |d |d< |d |d< |d |d< |d |d< |d	 |d
< t|}|dd|d< |dd|d< d|	 krt
| |d}	|	jtt|d tt|d dddd	 \}
}t|
 rt| rtt|
t|d  t|d  }tt|t|d
  t|d  }t|
|d< t||d< t||d< t||d< |rtd nVtd y|d |d W n   Y nX y|d |d W n   Y nX |S )aP  update input dictionary of attributes due to resampling from radar to geo coordinates

    Parameters: atr_in  - dict, input dictionary of attributes
                # combination 1
                shape2d - tuple of 2 int in (length, width)
                lalo_step - tuple of 2 float, step size in lat/lon direction
                SNWE      - tuple of 4 float
                lut_file  - str, path of lookup table file
                # combination 2
                res_obj   - mintpy.objects.resample.resample object
    Returns:    atr     - dict, updated dictionary of attributes
    Nr   r   r   r   r   r   r/   r   r1   r0   degreesr2   r   )lookup_filer   F)r&   r3   r4   zupdate REF_LAT/LON/Y/XzDoriginal reference pixel is out of .trans file's coverage. Continue.)r   r*   r+   	lalo_stepSNWElut_filer   read_attributer!   r"   r   	radar2geonparrayr   isnanrintr#   r   r   warningswarnr5   )r$   r6   r;   r<   r=   r7   r&   r'   lut_metacoordref_latref_lonref_yref_xr,   r,   r-   update_attribute4radar2geot   sR    
&&



rL   c             C   sv  |dkr| S |d |d g}|d |d g}t | }t|d |d  |d< t|d |d  |d< t|d |d  d |d< t|d |d  d |d	< |rtd
 t|d t| dd |d< t|d t| dd |d< t|d t| dd |d< t|d t| dd |d< |rTtdj|d |d |d |d d d| krtt|d |d t|d   |d< tt|d |d t|d   |d< |rtd d| krtt|d |d  |d< tt|d |d  |d< |rtd d|  krryBt|d |d< |d  t|d |d  7  < |rbtd W n   Y nX |S )a  update input dictionary of attributes due to subset

    Parameters: atr_in     - dict, data attributes to update
                subset_box - 4-tuple of int, subset box defined in (x0, y0, x1, y1)
    Returns:    atr        - dict, updated data attributes
    Nr   r   r   r   r   r   r   r   zupdate LENGTH, WIDTH, Y/XMAXr   0r   r   r   z:update/add SUBSET_XMIN/YMIN/XMAX/YMAX: {x0}/{y0}/{x1}/{y1})x0y0x1y1r/   r   r1   r   zupdate Y/X_FIRSTr   r   zupdate REF_Y/XSTARTING_RANGEr   zupdate STARTING_RANGE)r   r   r   r   r!   r    r"   r#   )r$   Z
subset_boxr&   sub_xsub_yr'   r,   r,   r-   update_attribute4subset   sP        (( rU   )NT)NNT)NNNNNT)T)rD   numpyr@   mintpy.objects.coordr   mintpy.utilsr   r.   r8   rL   rU   r,   r,   r,   r-   <module>   s   
D
 
@