B
    Qaq                 @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ	 ddgZ
dZdd Zdd	d
Zdd ZdddZedkreejdd  dS )    N)	RAMP_LIST)readfileutilszmintpy.derampzmintpy.deramp.maskFilezexample:
  remove_ramp.py  timeseries.h5      -m maskTempCoh.h5
  remove_ramp.py  ifgramStack.h5     -m maskTempCoh.h5  -d unwrapPhase_bridging
  remove_ramp.py  090214_101120.unw  -m maskTempCoh.h5  -s quadratic
c              C   s   t jdt jtd} | jddd | jdddd	d
d | jdddtdd | jddddd | jdddd | jddddd | jdddd d | S )!NzRemove phase ramp)descriptionformatter_classepilogfilezFile for ramp removal)helpz-mz--mask	mask_filezmaskTempCoh.h5zXmask for pixels used in ramp estimation
default - maskTempCoh.h5
no - use the whole area)destdefaultr	   z-ssurface_typelinearz1type of surface/ramp to remove, linear by default)r   r   choicesr	   z-dz--dsetdsetz]dataset name to be derampped in ifgramStack file
e.g.: unwrapPhase
      unwrapPhase_bridging)r   r	   z-oz	--outfilezOutput file name.z--save-ramp-coeffsave_ramp_coeff
store_truez4Save the estimated ramp coefficients into text file.)r   actionr	   z--updateupdate_modezEnable update mode, and skip inversion if:
1) output file already exists, readable and newer than input file
2) all configuration parameters are the same.)argparseArgumentParserRawTextHelpFormatterEXAMPLEadd_argumentr   )parser r   H/home/centos/operations/rsmas_insar/sources/MintPy/mintpy/remove_ramp.pycreate_parser   s     


r   c             C   s2   t  }|j| d}|jr.|js.d|_td |S )N)argsFzRupdate_mode is chosen but NOT turned on because the required --outfile is missing.)r   
parse_argsr   outfilewarningswarn)iargsr   inpsr   r   r   cmd_line_parse:   s    
r%   c                s(  t d t d d}tj| js8d}t d| j ntt d| j | jg}| jrb|| j t	dd |D }tj
| j}||krd}t d	| nt d
| |dkri | jd< | jd< t| j t fddtD rd}t dt nt dt t d| |S )Nz2--------------------------------------------------zupdate mode: ONskiprunz1) output file {} NOT found.z!1) output file {} already exists.c             s   s   | ]}t j|V  qd S )N)ospathgetmtime).0ir   r   r   	<genexpr>S   s    zrun_or_skip.<locals>.<genexpr>z02) output file is NOT newer than input file: {}.z,2) output file is newer than input file: {}.zmintpy.derampzmintpy.deramp.maskFilec             3   s&   | ]}t |  |d kV  qdS )NoneN)strget)r+   key)atriDictr   r   r-   a   s    z73) NOT all key configuration parameters are the same:{}z33) all key configuration parameters are the same:{}zrun or skip: {}.)printr(   r)   isfiler    formatr   r
   appendmaxr*   r   r   read_attributeany
configKeys)r$   flaginfilestitor   )r2   r3   r   run_or_skipE   s6    


r@   c             C   sx   t | }|jr t|dkr |jS tj|j|j|j|j|j	|j
d}tdt i }|j|d< |j|d< t|| d S )Nr&   )	ramp_typer
   out_filedatasetNamer   z;add/update the following configuration metadata to file:
{}zmintpy.derampzmintpy.deramp.maskFile)r%   r   r@   r    ut
run_derampr   r   r
   r   r   r4   r6   r;   add_attribute)r#   r$   rB   atr_newr   r   r   mainm   s    


rH   __main__   )N)N)r(   sysr   r!   mintpy.objectsr   mintpy.utilsr   r   rD   r;   r   r   r%   r@   rH   __name__argvr   r   r   r   <module>	   s   	
(
