
    Zf:(                     \    d Z ddlZddlZddlmZ ddlmZ d
dZddZ	ddZ
	 	 ddZd
d	Zy)z!Update attributes for operations.    N)
coordinate)readfilec                    |rt         nd }i | }t        |d         |d   z  }t        |d         |d   z  } |d|d    d|d           |d   |d<   |d   |d<   t        j                  t        |j	                  dd            |z        j                  t              |d<   t        j                  t        |j	                  d	d            |z        j                  t              |d	<    |d
       d|j                         v rt        |d         |z  |d<    |d       d|j                         v rt        |d         |z  |d<    |d       d|j                         v rt        |d         |z  |z  |d<    |d       |S )a
  update input dictionary of attributes due to resizing

    Parameters: atr_in       - dict, input dictionary of attributes
                resize2shape - tuple of 2 int, for the resized shape
    Returns:    atr          - dict, updated dictionary of attributes
    c                       y N argskwargss     O/home/exouser/operations/rsmas_insar/tools/MintPy/src/mintpy/utils/attribute.py<lambda>z)update_attribute4resize.<locals>.<lambda>           LENGTHr   WIDTH   output data in size: , ALOOKSRLOOKS*update LENGTH, WIDTH, Y/XMIN/MAX, A/RLOOKSAZIMUTH_PIXEL_SIZEupdate AZIMUTH_PIXEL_SIZERANGE_PIXEL_SIZEupdate RANGE_PIXEL_SIZE
NCORRLOOKSzupdate NCORRLOOKS)printintnprintgetastypekeysfloat)atr_inresize2shape	print_msgvprintatryscalexscales          r   update_attribute4resizer,      s     U%AF
V*CX,q/1FWa0F
"<?"32l1o5FGH OCM?CLGGC! 45>?FFsKCMGGC! 45>?FFsKCM
78sxxz)$)#.B*C$Dv$M !*+SXXZ'"',>(?"@6"I()sxxz!!#l"34v=FL"#Jr   c                    |rt         nd }i | }|ddt        |d         t        |d         f}|d   |d   z
  |d   |d   z
  }}||z  }	||z  }
 |d|	 d	|
        t        |	      |d<   t        |
      |d<   t        |d         |d
<   t        |d         |d<   t        |
dz
  |d   z         |d<   t        |	dz
  |d   z         |d<   t        t        |j                  dd            |z        |d<   t        t        |j                  dd            |z        |d<    |d       d|j	                         v rBt        |t        |d         z        |d<   t        |t        |d         z        |d<    |d       d|j	                         v r%t        |t        |d         z        |d<    |d       d|j	                         v r%t        |t        |d         z        |d<    |d       d|j	                         v rNt        t        |d         |d   z
  |z        |d<   t        t        |d         |d   z
  |z        |d<    |d       d|j	                         v rt        t        |d         |d   z
  |z        |d<   t        t        |d         |d   z
  |z        |d<   t        t        |d         |d   z
  |z        |d<   t        t        |d         |d   z
  |z        |d<    |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
    c                       y r   r   r	   s     r   r   z,update_attribute4multilook.<locals>.<lambda>A   r   r   r   r   r      r      r   r   XMINYMINXMAXYMAXr   1r   r   Y_STEPX_STEPzupdate Y/X_STEPr   r   r   r   REF_YREF_Xupdate REF_Y/XSUBSET_XMINSUBSET_YMINSUBSET_YMAXSUBSET_XMAXz!update SUBSET_XMIN/XMAX/YMIN/YMAX)r   r   strr!   r#   r$   )r%   lks_ylks_xboxr'   r(   r)   lengthwidth
length_mli	width_mlis              r   update_attribute4multilookrG   7   s      U%AF V*C
{!SW&CM(:;FSVOSVc!f_EF5JI
":,b<= 
OCMy>CLc!f+CKc!f+CKi!mc!f,-CKj1ns1v-.CKCGGHc23e;<CMCGGHc23e;<CM
78388:EE#h-$889HEE#h-$889H !sxxz)$'c:N6O0P(P$Q !*+SXXZ'"%eeC8J4K.L&L"M()#((*SW.Q7EACGSW.Q7EACG 
" 3s='9#:SV#C"MOM 3s='9#:SV#C"MOM 3s='9#:SV#C"MOM 3s='9#:SV#C"MOM23Jr   c                     i | }||j                   |j                  f}|d   |d<   |d   |d<   dD ]&  }||j                         v s|j                  |       ( |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
    r   r   r   r   )
Y_FIRSTr6   Y_UNITX_FIRSTr7   X_UNITr8   r9   REF_LATREF_LON)rC   rD   r#   pop)r%   shape2dres_objr'   r)   keys         r   update_attribute4geo2radarrS   t   sv     V*C >>7==1 AJCM1:CL8  #((*GGCL	
 Jr   c           	         i | }|<|j                   |j                  f}|j                  }|j                  }|j                  }|d   |d<   |d   |d<   |d   |d<   |d   |d<   |d   |d<   |d   |d	<   t        j                  |      }|j                  d
d      |d
<   |j                  dd      |d<   d|j                         v rt        | |      }	|	j                  t        j                  t        |d               t        j                  t        |d               d      dd \  }
}t        j                  |
       rt        j                  |       rt        t        j                  |
t!        |d         z
  t!        |d         z              }t        t        j                  |t!        |d	         z
  t!        |d         z              }t#        |
      |d<   t#        |      |d<   t#        |      |d<   t#        |      |d<   |rt%        d       |S t'        j(                  d       	 |j+                  d       |j+                  d       	 |j+                  d       |j+                  d       |S |S #  Y +xY w#  Y |S xY w)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
    r   r   r   r   r6   r7   rI   r0   rK   rJ   degreesrL   r8   )lookup_filer9   F)r'   rM   rN   zupdate REF_LAT/LON/Y/XzDoriginal reference pixel is out of .trans file's coverage. Continue.)rC   rD   	lalo_stepSNWElut_filer   read_attributer!   r#   r   	radar2geor   arrayr   isnanr    r$   r?   r   warningswarnrO   )r%   rP   rW   rX   rY   rQ   r'   r)   lut_metacoordref_latref_lonref_yref_xs                 r   update_attribute4radar2georf      sg    V*C >>7==1%%	||##AJCM1:CLaLCMaLCM!WC	N!WC	N&&x0HLL95CMLL95CM #((*6x8 ??288CG4E+F+-88CG4E+F5: + <<=aA HHW288G#4"45Y+@!@E#h-DX XYZE5Y+@!@E#h-DX XYZE \C	N \C	Nu:CLu:CL./ J MM`a  	"	" J3JJs   +"I4 "I; 4I8;J c           	      ,   |rt         nd }|| S |d   |d   g}|d   |d   g}i | }t        |d   |d   z
        |d<   t        |d   |d   z
        |d<   t        |d   |d   z
  dz
        |d<   t        |d   |d   z
  dz
        |d	<    |d
       t        |d   t        | j                  dd            z         |d<   t        |d   t        | j                  dd            z         |d<   t        |d   t        | j                  dd            z         |d<   t        |d   t        | j                  dd            z         |d<    |dj	                  |d   |d   |d   |d                d|j                         v rft        t        |d         |d   t        |d         z  z         |d<   t        t        |d         |d   t        |d         z  z         |d<    |d       d|j                         v rHt        t        |d         |d   z
        |d<   t        t        |d         |d   z
        |d<    |d       d| j                         vr;	 t        |d         |d<   |dxx   t        |d         |d   z  z  cc<    |d       |S |S #  Y |S xY w)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
    c                       y r   r   r	   s     r   r   z)update_attribute4subset.<locals>.<lambda>   r   r   r   r0   r   r/   r   r   r4   r3   zupdate LENGTH, WIDTH, Y/XMAXr<   0r=   r;   r>   z:update/add SUBSET_XMIN/YMIN/XMAX/YMAX: {x0}/{y0}/{x1}/{y1})x0y0x1y1rI   r6   rK   r7   zupdate Y/X_FIRSTr8   r9   r:   STARTING_RANGEr   zupdate STARTING_RANGE)r   r?   r   r!   formatr#   r$   )r%   
subset_boxr'   r(   sub_xsub_yr)   s          r   update_attribute4subsetrs      s     U%AF]JqM*E]JqM*E V*Caq)*CMuQxa()CLeAhuQx'!+,CKeAhuQx'!+,CK
)* U1XFJJ}c,J(KKLCU1XFJJ}c,J(KKLCU1XFJJ}c,J(KKLCU1XFJJ}c,J(KKLC
 "#)6S-?-0-?-0-?-0-? $* $AB CHHJU3y>2U1XeCM>R5RRSIU3y>2U1XeCM>R5RRSI!" #((*3s7|,uQx78G3s7|,uQx78G  %	$)#.>*?$@C ! !U3/A+B%CE!H%LL!*+ J3J	Js   8J J)T)NT)NNT)NNNNNT)__doc__r^   numpyr   mintpy.objects.coordr   mintpy.utilsr   r,   rG   rS   rf   rs   r   r   r   <module>rx      s<    '   + !!H:z< Z^7;>B7r   